metacountregressor 0.1.47__py3-none-any.whl → 0.1.49__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,543 +0,0 @@
1
- Metadata-Version: 2.1
2
- Name: metacountregressor
3
- Version: 0.1.47
4
- Summary: A python package for count regression of rare events assisted by metaheuristics
5
- Author: zahern
6
- Author-email: zeke.ahern@hdr.qut.edu.au
7
- Requires-Python: >=3.10,<3.11
8
- Classifier: Programming Language :: Python :: 3
9
- Classifier: Programming Language :: Python :: 3.10
10
- Requires-Dist: latextable (>=1.0.0,<2.0.0)
11
- Requires-Dist: matplotlib (>=3.7.1,<4.0.0)
12
- Requires-Dist: numpy (>=1.24.3,<2.0.0)
13
- Requires-Dist: pandas (>=2.0.2,<3.0.0)
14
- Requires-Dist: psutil (>=5.9.5,<6.0.0)
15
- Requires-Dist: scikit-learn (>=1.2.2,<2.0.0)
16
- Requires-Dist: scipy (>=1.10.1,<2.0.0)
17
- Requires-Dist: statsmodels (>=0.14.0,<0.15.0)
18
- Requires-Dist: tabulate (>=0.9.0,<0.10.0)
19
- Description-Content-Type: text/markdown
20
-
21
- ##### The Below code demonstrates how to set up automatic optimization assisted by the harmony search algorithm. References to the Differential Evolution and Simulated Annealing has been mentioned (change accordingly)
22
-
23
- ## Quick install: Requires Python 3.10
24
-
25
- Install `metacountregressor` using pip as follows:
26
-
27
- ```bash
28
- pip install metacountregressor
29
-
30
-
31
- ```python
32
- import pandas as pd
33
- import numpy as np
34
- from metacountregressor.solution import ObjectiveFunction
35
- from metacountregressor.metaheuristics import (harmony_search,
36
- differential_evolution,
37
- simulated_annealing)
38
- ```
39
-
40
- #### Basic setup. Read in data, and select optimization algorithm
41
-
42
-
43
- ```python
44
- # Read data from CSV file
45
- df = pd.read_csv(
46
- "https://raw.githubusercontent.com/zahern/data/main/Ex-16-3.csv")
47
- X = df
48
- y = df['FREQ'] # Frequency of crashes
49
- X['Offset'] = np.log(df['AADT']) # Explicitley define how to offset the data, no offset otherwise
50
- # Drop Y, selected offset term and ID as there are no panels
51
- X = df.drop(columns=['FREQ', 'ID', 'AADT'])
52
- #some example argument, these are defualt so the following line is just for claritity
53
- arguments = {'algorithm': 'hs', 'test_percentage': 0.2, 'test_complexity': 6, 'instance_number':1}
54
- # Fit the model with metacountregressor
55
- obj_fun = ObjectiveFunction(X, y, **arguments)
56
- #replace with other metaheuristics if desired
57
- results = harmony_search(obj_fun)
58
- ```
59
-
60
- Estimating as Panel Data...
61
- repair constraint violated, skipping over..
62
- repair constraint violated, skipping over..
63
- dominate soltuion
64
- --------------------------------------------------
65
- WARNING: Convergence was not reached during estimation. The given estimates may not be reliable
66
- -------------------------------------------------------------------------------------
67
- Log-Likelihood: -787.6392029228095
68
- -------------------------------------------------------------------------------------
69
- +----------------------------+-----+--------+----------+----------+------------+
70
- | Effect | tau | Coeff | Std. Err | z-values | Prob |z|>Z |
71
- +============================+=====+========+==========+==========+============+
72
- | const | no | -19.65 | 3.37 | -5.82 | 0.00*** |
73
- +----------------------------+-----+--------+----------+----------+------------+
74
- | FC | no | -0.08 | 0.09 | -0.90 | 0.37 |
75
- +----------------------------+-----+--------+----------+----------+------------+
76
- | PEAKHR | no | 3.60 | 1.46 | 2.48 | 0.01* |
77
- +----------------------------+-----+--------+----------+----------+------------+
78
- | TANGENT | no | 9.20 | 3.49 | 2.64 | 0.01* |
79
- +----------------------------+-----+--------+----------+----------+------------+
80
- | CURVES | no | 5.13 | 0.41 | 12.54 | 0.00*** |
81
- +----------------------------+-----+--------+----------+----------+------------+
82
- | MEDWIDTH | no | 0.31 | 0.10 | 3.18 | 0.00*** |
83
- +----------------------------+-----+--------+----------+----------+------------+
84
- | FRICTION | log | 0.35 | 0.16 | 2.22 | 0.03* |
85
- +----------------------------+-----+--------+----------+----------+------------+
86
- | SLOPE | no | -0.11 | 0.17 | -0.64 | 0.52 |
87
- +----------------------------+-----+--------+----------+----------+------------+
88
- | MIMEDSH | no | -0.72 | 0.25 | -2.85 | 0.00*** |
89
- +----------------------------+-----+--------+----------+----------+------------+
90
- | INCLANES | no | -0.42 | 0.24 | -1.74 | 0.08. |
91
- +----------------------------+-----+--------+----------+----------+------------+
92
- | MIMEDSH (Std. Dev.) | | 0.10 | 0.22 | 0.45 | 0.65 |
93
- | tn_normal | | | | | |
94
- +----------------------------+-----+--------+----------+----------+------------+
95
- | (Chol.) INCLANEStn_normal | | 0.10 | 0.24 | 0.41 | 0.68 |
96
- | .INCLANEStn_normal | | | | | |
97
- +----------------------------+-----+--------+----------+----------+------------+
98
- | nb | | 1.37 | 0.00 | 50.00 | 0.00*** |
99
- +----------------------------+-----+--------+----------+----------+------------+
100
-
101
-
102
-
103
- ---------------------------------------------------------------------------
104
-
105
- KeyboardInterrupt Traceback (most recent call last)
106
-
107
- c:\Users\n9471103\MetaCountRegressor\README.ipynb Cell 5 in <cell line: 14>()
108
- <a href='vscode-notebook-cell:/c%3A/Users/n9471103/MetaCountRegressor/README.ipynb#W3sZmlsZQ%3D%3D?line=11'>12</a> obj_fun = ObjectiveFunction(X, y, **arguments)
109
- <a href='vscode-notebook-cell:/c%3A/Users/n9471103/MetaCountRegressor/README.ipynb#W3sZmlsZQ%3D%3D?line=12'>13</a> #replace with other metaheuristics if desired
110
- ---> <a href='vscode-notebook-cell:/c%3A/Users/n9471103/MetaCountRegressor/README.ipynb#W3sZmlsZQ%3D%3D?line=13'>14</a> results = harmony_search(obj_fun)
111
-
112
-
113
- File c:\Users\n9471103\MetaCountRegressor\metacountregressor\metaheuristics.py:408, in harmony_search(objective_function, initial_harmonies, hyperparameters, **kwargs)
114
- 406 start = datetime.now()
115
- 407 hs = HarmonySearch(objective_function)
116
- --> 408 results = hs.run(initial_harmonies, mod_init = man)
117
- 409 end = datetime.now()
118
- 410 elapsed_time = end - start
119
-
120
-
121
- File c:\Users\n9471103\MetaCountRegressor\metacountregressor\metaheuristics.py:1546, in HarmonySearch.run(self, initial_harmonies, mod_init)
122
- 1544 self._obj_fun.set_random_seed()
123
- 1545 # fill harmony_memory using random parameter values by default, but with initial_harmonies if provided
124
- -> 1546 self._initialize(initial_harmonies, mod_init)
125
- 1547 if self.pf.get_objective_is_multi():
126
- 1548 self._pareto_harmony_memory = self.pf.non_dominant_sorting(self._harmony_memory)
127
-
128
-
129
- File c:\Users\n9471103\MetaCountRegressor\metacountregressor\metaheuristics.py:1825, in HarmonySearch._initialize(self, initial_harmonies, model_nature)
130
- 1821 initial_harmonies[0] = vector
131
- 1823 for i in range(0, self._obj_fun.get_hms()):
132
- 1824 #print(initial_harmonies[i])
133
- -> 1825 fitness = self._obj_fun.get_fitness(initial_harmonies[i], self.pf.get_objective_is_multi(), max_routine = 2)
134
- 1826 #print(initial_harmonies[i])
135
- 1827 if self.pf.get_objective_is_multi():
136
-
137
-
138
- File c:\Users\n9471103\MetaCountRegressor\metacountregressor\solution.py:2319, in ObjectiveFunction.get_fitness(self, vector, multi, verbose, max_routine)
139
- 2314 model_nature = self.get_distinct_model_parts(
140
- 2315 vector) # todo return insignificant p values
141
- 2318 a = {}
142
- -> 2319 obj_1, model_mod = self.makeRegression(model_nature, layout=layout, **a)
143
- 2324 sub_slns.append([obj_1.copy()])
144
- 2326 obj_best = obj_1.copy()
145
-
146
-
147
- File c:\Users\n9471103\MetaCountRegressor\metacountregressor\solution.py:6417, in ObjectiveFunction.makeRegression(self, model_nature, layout, *args, **kwargs)
148
- 6414 try:
149
- 6415 if model_nature.get('dispersion') is not None:
150
- -> 6417 obj_1, log_lik, betas, stderr, pvalues, zvalues, is_halton, is_delete = self.fitRegression(model_nature)
151
- 6418 if obj_1 is None:
152
- 6419 obj_1 = Solution()
153
-
154
-
155
- File c:\Users\n9471103\MetaCountRegressor\metacountregressor\solution.py:5969, in ObjectiveFunction.fitRegression(self, mod, dispersion, maxiter, batch_size, num_hess)
156
- 5967 if self.numerical_hessian_calc:
157
- 5968 try:
158
- -> 5969 bb_hess = self._numerical_hessian(betas_est.x, grad_args, False)
159
- 5970 except Exception as e:
160
- 5971 bb_hess = None
161
-
162
-
163
- File c:\Users\n9471103\MetaCountRegressor\metacountregressor\solution.py:3474, in ObjectiveFunction._numerical_hessian(self, betas, args, jac)
164
- 3471 def loglike(p): return self._loglik_gradient(
165
- 3472 p, *args)
166
- 3473 robust = False
167
- -> 3474 hess = approx_hess(betas, loglike)
168
- 3475 hess /= self.N
169
- 3476 hess_inv1 = np.linalg.pinv(hess)
170
-
171
-
172
- File ~\AppData\Roaming\Python\Python310\site-packages\statsmodels\tools\numdiff.py:454, in approx_hess3(x, f, epsilon, args, kwargs)
173
- 450 for i in range(n):
174
- 451 for j in range(i, n):
175
- 452 hess[i, j] = np.squeeze(
176
- 453 (f(*((x + ee[i, :] + ee[j, :],) + args), **kwargs)
177
- --> 454 - f(*((x + ee[i, :] - ee[j, :],) + args), **kwargs)
178
- 455 - (f(*((x - ee[i, :] + ee[j, :],) + args), **kwargs)
179
- 456 - f(*((x - ee[i, :] - ee[j, :],) + args), **kwargs))
180
- 457 )/(4.*hess[i, j])
181
- 458 )
182
- 459 hess[j, i] = hess[i, j]
183
- 460 return hess
184
-
185
-
186
- File c:\Users\n9471103\MetaCountRegressor\metacountregressor\solution.py:3471, in ObjectiveFunction._numerical_hessian.<locals>.loglike(p)
187
- -> 3471 def loglike(p): return self._loglik_gradient(
188
- 3472 p, *args)
189
-
190
-
191
- File c:\Users\n9471103\MetaCountRegressor\metacountregressor\solution.py:4941, in ObjectiveFunction._loglik_gradient(self, betas, Xd, y, draws, Xf, Xr, batch_size, return_gradient, return_gradient_n, dispersion, test_set, return_EV, verbose, corr_list, zi_list, exog_infl, draws_grouped, Xgroup, model_nature, kwarg, **kwargs)
192
- 4937 chol_mat = self._chol_mat(
193
- 4938 len(self.rdm_cor_fit), br, brstd, self.rdm_cor_fit)
194
- 4939 self.chol_mat = chol_mat.copy()
195
- 4940 Br = br[None, :, None] + \
196
- -> 4941 np.matmul(chol_mat[:len(br), :len(br)], draws_)
197
- 4942 self.Br = Br.copy()
198
- 4945 if model_nature is not None:
199
-
200
-
201
- KeyboardInterrupt:
202
-
203
-
204
- ### Change the arguments.
205
- #### Reduce down the list sizes where necsessary
206
-
207
-
208
- ```python
209
- #Solution Arguments
210
- arguments = {
211
- 'algorithm': 'hs',
212
- 'test_percentage': 0.2,
213
- 'test_complexity': 6, #or list based [0, 1, 2, 6]
214
- 'instance_number': 'name',
215
- 'is_multi': 1,
216
- 'distribution': ['Normal', 'LnNormal', 'Triangular', 'Unifrom'],
217
- 'Model': [0,1], # or equivalently ['POS', 'NB']
218
- 'transformations': ['no', 'sqrt', 'archsinh'],
219
- '_max_time': 10
220
- }
221
- obj_fun = ObjectiveFunction(X, y, **arguments)
222
- results = harmony_search(obj_fun)
223
- ```
224
-
225
- Estimating as Panel Data...
226
-
227
-
228
-
229
- ---------------------------------------------------------------------------
230
-
231
- KeyboardInterrupt Traceback (most recent call last)
232
-
233
- c:\Users\n9471103\MetaCountRegressor\README.ipynb Cell 7 in <cell line: 14>()
234
- <a href='vscode-notebook-cell:/c%3A/Users/n9471103/MetaCountRegressor/README.ipynb#W5sZmlsZQ%3D%3D?line=1'>2</a> arguments = {
235
- <a href='vscode-notebook-cell:/c%3A/Users/n9471103/MetaCountRegressor/README.ipynb#W5sZmlsZQ%3D%3D?line=2'>3</a> 'algorithm': 'hs',
236
- <a href='vscode-notebook-cell:/c%3A/Users/n9471103/MetaCountRegressor/README.ipynb#W5sZmlsZQ%3D%3D?line=3'>4</a> 'test_percentage': 0.2,
237
- (...)
238
- <a href='vscode-notebook-cell:/c%3A/Users/n9471103/MetaCountRegressor/README.ipynb#W5sZmlsZQ%3D%3D?line=10'>11</a> '_max_time': 10
239
- <a href='vscode-notebook-cell:/c%3A/Users/n9471103/MetaCountRegressor/README.ipynb#W5sZmlsZQ%3D%3D?line=11'>12</a> }
240
- <a href='vscode-notebook-cell:/c%3A/Users/n9471103/MetaCountRegressor/README.ipynb#W5sZmlsZQ%3D%3D?line=12'>13</a> obj_fun = ObjectiveFunction(X, y, **arguments)
241
- ---> <a href='vscode-notebook-cell:/c%3A/Users/n9471103/MetaCountRegressor/README.ipynb#W5sZmlsZQ%3D%3D?line=13'>14</a> results = harmony_search(obj_fun)
242
-
243
-
244
- File c:\Users\n9471103\MetaCountRegressor\metacountregressor\metaheuristics.py:408, in harmony_search(objective_function, initial_harmonies, hyperparameters, **kwargs)
245
- 406 start = datetime.now()
246
- 407 hs = HarmonySearch(objective_function)
247
- --> 408 results = hs.run(initial_harmonies, mod_init = man)
248
- 409 end = datetime.now()
249
- 410 elapsed_time = end - start
250
-
251
-
252
- File c:\Users\n9471103\MetaCountRegressor\metacountregressor\metaheuristics.py:1546, in HarmonySearch.run(self, initial_harmonies, mod_init)
253
- 1544 self._obj_fun.set_random_seed()
254
- 1545 # fill harmony_memory using random parameter values by default, but with initial_harmonies if provided
255
- -> 1546 self._initialize(initial_harmonies, mod_init)
256
- 1547 if self.pf.get_objective_is_multi():
257
- 1548 self._pareto_harmony_memory = self.pf.non_dominant_sorting(self._harmony_memory)
258
-
259
-
260
- File c:\Users\n9471103\MetaCountRegressor\metacountregressor\metaheuristics.py:1825, in HarmonySearch._initialize(self, initial_harmonies, model_nature)
261
- 1821 initial_harmonies[0] = vector
262
- 1823 for i in range(0, self._obj_fun.get_hms()):
263
- 1824 #print(initial_harmonies[i])
264
- -> 1825 fitness = self._obj_fun.get_fitness(initial_harmonies[i], self.pf.get_objective_is_multi(), max_routine = 2)
265
- 1826 #print(initial_harmonies[i])
266
- 1827 if self.pf.get_objective_is_multi():
267
-
268
-
269
- File c:\Users\n9471103\MetaCountRegressor\metacountregressor\solution.py:2319, in ObjectiveFunction.get_fitness(self, vector, multi, verbose, max_routine)
270
- 2314 model_nature = self.get_distinct_model_parts(
271
- 2315 vector) # todo return insignificant p values
272
- 2318 a = {}
273
- -> 2319 obj_1, model_mod = self.makeRegression(model_nature, layout=layout, **a)
274
- 2324 sub_slns.append([obj_1.copy()])
275
- 2326 obj_best = obj_1.copy()
276
-
277
-
278
- File c:\Users\n9471103\MetaCountRegressor\metacountregressor\solution.py:6417, in ObjectiveFunction.makeRegression(self, model_nature, layout, *args, **kwargs)
279
- 6414 try:
280
- 6415 if model_nature.get('dispersion') is not None:
281
- -> 6417 obj_1, log_lik, betas, stderr, pvalues, zvalues, is_halton, is_delete = self.fitRegression(model_nature)
282
- 6418 if obj_1 is None:
283
- 6419 obj_1 = Solution()
284
-
285
-
286
- File c:\Users\n9471103\MetaCountRegressor\metacountregressor\solution.py:5963, in ObjectiveFunction.fitRegression(self, mod, dispersion, maxiter, batch_size, num_hess)
287
- 5961 mod['dispersion_penalty'] = abs(b[-1])
288
- 5962 grad_args = (X, y, draws, X, Xr, self.batch_size,False, False, dispersion, 0, False, 0, self.rdm_cor_fit, self.zi_fit, exog_infl, draws_grouped, XG, mod)
289
- -> 5963 betas_est = self._minimize(self._loglik_gradient, b, args=(X, y, draws, X, Xr, self.batch_size,False, False, dispersion, 0, False, 0, self.rdm_cor_fit, self.zi_fit, exog_infl, draws_grouped, XG, mod),
290
- 5964 method=method2, tol=tol['ftol'],
291
- 5965 options={'gtol': tol['gtol']}, bounds = bounds)
292
- 5967 if self.numerical_hessian_calc:
293
- 5968 try:
294
-
295
-
296
- File c:\Users\n9471103\MetaCountRegressor\metacountregressor\solution.py:5260, in ObjectiveFunction._minimize(self, loglik_fn, x, args, method, tol, options, bounds)
297
- 5258 return minimize(loglik_fn, x, args=args, jac=args[6], hess=args[7], method='BFGS', tol=tol, options=options)
298
- 5259 elif method == "L-BFGS-B":
299
- -> 5260 return minimize(loglik_fn, x, args=args, jac=args[6], method='L-BFGS-B', bounds =bounds, tol=tol, options=options)
300
- 5261 else:
301
- 5262 raise ValueError(f"Unknown optimization method: {method}")
302
-
303
-
304
- File ~\AppData\Roaming\Python\Python310\site-packages\scipy\optimize\_minimize.py:710, in minimize(fun, x0, args, method, jac, hess, hessp, bounds, constraints, tol, callback, options)
305
- 707 res = _minimize_newtoncg(fun, x0, args, jac, hess, hessp, callback,
306
- 708 **options)
307
- 709 elif meth == 'l-bfgs-b':
308
- --> 710 res = _minimize_lbfgsb(fun, x0, args, jac, bounds,
309
- 711 callback=callback, **options)
310
- 712 elif meth == 'tnc':
311
- 713 res = _minimize_tnc(fun, x0, args, jac, bounds, callback=callback,
312
- 714 **options)
313
-
314
-
315
- File ~\AppData\Roaming\Python\Python310\site-packages\scipy\optimize\_lbfgsb_py.py:361, in _minimize_lbfgsb(fun, x0, args, jac, bounds, disp, maxcor, ftol, gtol, eps, maxfun, maxiter, iprint, callback, maxls, finite_diff_rel_step, **unknown_options)
316
- 355 task_str = task.tobytes()
317
- 356 if task_str.startswith(b'FG'):
318
- 357 # The minimization routine wants f and g at the current x.
319
- 358 # Note that interruptions due to maxfun are postponed
320
- 359 # until the completion of the current minimization iteration.
321
- 360 # Overwrite f and g:
322
- --> 361 f, g = func_and_grad(x)
323
- 362 elif task_str.startswith(b'NEW_X'):
324
- 363 # new iteration
325
- 364 n_iterations += 1
326
-
327
-
328
- File ~\AppData\Roaming\Python\Python310\site-packages\scipy\optimize\_differentiable_functions.py:286, in ScalarFunction.fun_and_grad(self, x)
329
- 284 self._update_x_impl(x)
330
- 285 self._update_fun()
331
- --> 286 self._update_grad()
332
- 287 return self.f, self.g
333
-
334
-
335
- File ~\AppData\Roaming\Python\Python310\site-packages\scipy\optimize\_differentiable_functions.py:256, in ScalarFunction._update_grad(self)
336
- 254 def _update_grad(self):
337
- 255 if not self.g_updated:
338
- --> 256 self._update_grad_impl()
339
- 257 self.g_updated = True
340
-
341
-
342
- File ~\AppData\Roaming\Python\Python310\site-packages\scipy\optimize\_differentiable_functions.py:173, in ScalarFunction.__init__.<locals>.update_grad()
343
- 171 self._update_fun()
344
- 172 self.ngev += 1
345
- --> 173 self.g = approx_derivative(fun_wrapped, self.x, f0=self.f,
346
- 174 **finite_diff_options)
347
-
348
-
349
- File ~\AppData\Roaming\Python\Python310\site-packages\scipy\optimize\_numdiff.py:505, in approx_derivative(fun, x0, method, rel_step, abs_step, f0, bounds, sparsity, as_linear_operator, args, kwargs)
350
- 502 use_one_sided = False
351
- 504 if sparsity is None:
352
- --> 505 return _dense_difference(fun_wrapped, x0, f0, h,
353
- 506 use_one_sided, method)
354
- 507 else:
355
- 508 if not issparse(sparsity) and len(sparsity) == 2:
356
-
357
-
358
- File ~\AppData\Roaming\Python\Python310\site-packages\scipy\optimize\_numdiff.py:576, in _dense_difference(fun, x0, f0, h, use_one_sided, method)
359
- 574 x = x0 + h_vecs[i]
360
- 575 dx = x[i] - x0[i] # Recompute dx as exactly representable number.
361
- --> 576 df = fun(x) - f0
362
- 577 elif method == '3-point' and use_one_sided[i]:
363
- 578 x1 = x0 + h_vecs[i]
364
-
365
-
366
- File ~\AppData\Roaming\Python\Python310\site-packages\scipy\optimize\_numdiff.py:456, in approx_derivative.<locals>.fun_wrapped(x)
367
- 455 def fun_wrapped(x):
368
- --> 456 f = np.atleast_1d(fun(x, *args, **kwargs))
369
- 457 if f.ndim > 1:
370
- 458 raise RuntimeError("`fun` return value has "
371
- 459 "more than 1 dimension.")
372
-
373
-
374
- File ~\AppData\Roaming\Python\Python310\site-packages\scipy\optimize\_differentiable_functions.py:137, in ScalarFunction.__init__.<locals>.fun_wrapped(x)
375
- 133 self.nfev += 1
376
- 134 # Send a copy because the user may overwrite it.
377
- 135 # Overwriting results in undefined behaviour because
378
- 136 # fun(self.x) will change self.x, with the two no longer linked.
379
- --> 137 fx = fun(np.copy(x), *args)
380
- 138 # Make sure the function returns a true scalar
381
- 139 if not np.isscalar(fx):
382
-
383
-
384
- File c:\Users\n9471103\MetaCountRegressor\metacountregressor\solution.py:5030, in ObjectiveFunction._loglik_gradient(self, betas, Xd, y, draws, Xf, Xr, batch_size, return_gradient, return_gradient_n, dispersion, test_set, return_EV, verbose, corr_list, zi_list, exog_infl, draws_grouped, Xgroup, model_nature, kwarg, **kwargs)
385
- 5027 betas_last = betas[-1]
386
- 5029 # print(betas_last)
387
- -> 5030 proba_, proba_n = self.prob_obs_draws_all_at_once(
388
- 5031 eVd, np.atleast_3d(y), betas_last, dispersion)
389
- 5032 # self._prob_product_against_panels()
390
- 5033
391
- 5034
392
- (...)
393
- 5037
394
- 5038 # print(top_stats)
395
- 5040 proba.append(dev.to_cpu(proba_))
396
-
397
-
398
- File c:\Users\n9471103\MetaCountRegressor\metacountregressor\solution.py:4619, in ObjectiveFunction.prob_obs_draws_all_at_once(self, eVi, y, disp, dispersion)
399
- 4617 def prob_obs_draws_all_at_once(self, eVi, y, disp, dispersion):
400
- 4618 if dispersion == 0:
401
- -> 4619 proba_r = poisson.pmf(y, eVi)
402
- 4620 elif dispersion == 1:
403
- 4621 #print(np.shape(y), print(np.shape(eVi)))
404
- 4622 #proba_r = self._nonlog_nbin(y, eVi, disp)
405
- 4623 #proba_r2 = nbinom.pmf(y, disp*eVi**0, disp/(eVi+disp))
406
- 4624 proba_r = self.nbinom_pmf_batched(y, eVi, disp)
407
-
408
-
409
- File ~\AppData\Roaming\Python\Python310\site-packages\scipy\stats\_distn_infrastructure.py:3378, in rv_discrete.pmf(self, k, *args, **kwds)
410
- 3376 if np.any(cond):
411
- 3377 goodargs = argsreduce(cond, *((k,)+args))
412
- -> 3378 place(output, cond, np.clip(self._pmf(*goodargs), 0, 1))
413
- 3379 if output.ndim == 0:
414
- 3380 return output[()]
415
-
416
-
417
- File ~\AppData\Roaming\Python\Python310\site-packages\scipy\stats\_discrete_distns.py:865, in poisson_gen._pmf(self, k, mu)
418
- 863 def _pmf(self, k, mu):
419
- 864 # poisson.pmf(k) = exp(-mu) * mu**k / k!
420
- --> 865 return exp(self._logpmf(k, mu))
421
-
422
-
423
- File ~\AppData\Roaming\Python\Python310\site-packages\scipy\stats\_discrete_distns.py:860, in poisson_gen._logpmf(self, k, mu)
424
- 859 def _logpmf(self, k, mu):
425
- --> 860 Pk = special.xlogy(k, mu) - gamln(k + 1) - mu
426
- 861 return Pk
427
-
428
-
429
- KeyboardInterrupt:
430
-
431
-
432
- ## Initial Solution Configurement
433
-
434
-
435
- ```python
436
- #Model Decisions, Specify for Intial Optimization
437
- manual_fit_spec = {
438
- 'fixed_terms': ['SINGLE', 'LENGTH'],
439
- 'rdm_terms': ['AADT:normal'],
440
- 'rdm_cor_terms': ['GRADEBR:uniform', 'CURVES:triangular'],
441
- 'grouped_terms': [],
442
- 'hetro_in_means': ['ACCESS:normal', 'MINRAD:normal'],
443
- 'transformations': ['no', 'no', 'log', 'no', 'no', 'no', 'no'],
444
- 'dispersion': 1
445
- }
446
-
447
- #Search Arguments
448
- arguments = {
449
- 'algorithm': 'hs',
450
- 'test_percentage': 0.2,
451
- 'test_complexity': 6,
452
- 'instance_number': 'name',
453
- 'Manual_Fit': manual_fit_spec
454
- }
455
- obj_fun = ObjectiveFunction(X, y, **arguments)
456
- ```
457
-
458
- Estimating as Panel Data...
459
- off for now turn back on
460
-
461
-
462
- ### simarly to return the results feed the objective function into a metaheuristic solution algorithm
463
-
464
- ## Notes
465
- ### Capabilities of the software include:
466
- * Handling of Panel Data
467
- * Support for Data Transformations
468
- * Implementation of Models with Correlated and Non-Correlated Random Parameters
469
- * A variety of mixing distributions for parameter estimations, including normal, lognormal, truncated normal, Lindley, Gamma, triangular, and uniform distributions
470
- Capability to handle heterogeneity in the means of the random parameters
471
- * Use of Halton draws for simulated maximum likelihood estimation
472
- * Support for grouped random parameters with unbalanced groups
473
- * Post-estimation tools for assessing goodness of fit, making predictions, and conducting out-of-sample validation
474
- * Multiple parameter optimization routines, such as the BFGS method
475
- * Comprehensive hypothesis testing using single objectives, such as in-sample BIC and log-likelihood
476
- * Extensive hypothesis testing using multiple objectives, such as in-sample BIC and out-of-sample MAE (Mean Absolute Error), or in-sample AIC and out-of-sample MSPE (mean-square prediction errorr)
477
- * Features that allow analysts to pre-specify variables, interactions, and mixing distributions, among others
478
- * Meta-heuristic Guided Optimization, including techniques like Simulated Annealing, Harmony Search, and Differential Evolution
479
- * Customization of Hyper-parameters to solve problems tailored to your dataset
480
- * Out-of-the-box optimization capability using default metaheuristics
481
-
482
- ### arguments:
483
- #### In reference to the arguments that can be fed into the solution alrogithm, a dictionary system is utilised with relecant names these include
484
- ## Arguments
485
-
486
- The following list describes the arguments available in this function. By default, all of the capabilities described are enabled unless specified otherwise as an argument. For list arguments, include all desired elements in the list to ensure the corresponding options are considered. Example code will be provided later in this guide.
487
-
488
- 1. **`complexity_level`**: This argument accepts an integer between 0 to 5 or a list of such integers. Each integer represents a hierarchy level for estimable models associated with each explanatory variable. Here is a summary of the hierarchy:
489
- - 0: Null model
490
- - 1: Simple fixed effects model
491
- - 2: Random parameters model
492
- - 3: Random correlated parameters model
493
- - 4: Grouped random parameters model
494
- - 5: Heterogeneity in the means random parameter model
495
-
496
- 2. **`distributions`**: This argument accepts a list of strings where each string corresponds to a distribution. Valid options include:
497
- - "Normal"
498
- - "Lindley"
499
- - "Uniform"
500
- - "LogNormal"
501
- - "Triangular"
502
- - "Gamma"
503
- - "TruncatedNormal"
504
- - Any of the above, concatenated with ":grouped" (e.g., "Normal:grouped"; requires a grouping term defined in the model)
505
-
506
- 3. **`Model`**: This argument specifies the model form. It can be a list of integers representing different models to test:
507
- - 0: Poisson
508
- - 1: Negative-Binomial
509
- - 2: Generalized-Poisson
510
-
511
- 4. **`transformations`**: This argument accepts a list of strings representing available transformations within the framework. Valid options include:
512
- - "no"
513
- - "square-root"
514
- - "logarithmic"
515
- - "archsinh"
516
- - "as factor"
517
-
518
- 5. **`is_multi`**: This argument accepts an integer indicating whether single or multiple objectives are to be tested (0 for single, 1 for multiple).
519
-
520
- 6. **`testing_split`**: This argument is used for multi-objective optimization. Define it as a decimal; for example, 0.2 represents 20% of the data for testing.
521
-
522
- 7. **`_max_time`**: This argument is used to add a termination time in the algorithm. It takes values as seconds. Note the time is only dependenant on the time after intial population of solutions are generated.
523
-
524
- ## Contact
525
- If you have any questions, ideas to improve MetaCountRegressor, or want to report a bug, just open a new issue in [metacountregressor GitHub repository](https://github.com/your-github-repo).
526
-
527
- ## Citing MetaCountRegressor
528
- Please cite MetaCountRegressor as follows:
529
-
530
- Ahern, Z., Corry P., Paz A. (2022). MetaCountRegressor [Computer software]. [https://pypi.org/project/metacounregressor/](https://pypi.org/project/metacounregressor/)
531
-
532
- Or using BibTex as follows:
533
-
534
- ```bibtex
535
- @misc{Ahern2023,
536
- author = {Zeke Ahern and Paul Corry and Alexander Paz},
537
- journal = {PyPi},
538
- title = {metacountregressor · PyPI},
539
- url = {https://pypi.org/project/metacountregressor/0.1.28/},
540
- year = {2023},
541
- }
542
-
543
-