metacountregressor 0.1.350__py3-none-any.whl → 1.0.5__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.
- metacountregressor/solution.py +15 -13
- metacountregressor/test_code.py +43 -0
- {metacountregressor-0.1.350.dist-info → metacountregressor-1.0.5.dist-info}/METADATA +1 -1
- {metacountregressor-0.1.350.dist-info → metacountregressor-1.0.5.dist-info}/RECORD +7 -6
- {metacountregressor-0.1.350.dist-info → metacountregressor-1.0.5.dist-info}/WHEEL +1 -1
- {metacountregressor-0.1.350.dist-info → metacountregressor-1.0.5.dist-info}/licenses/LICENSE.txt +0 -0
- {metacountregressor-0.1.350.dist-info → metacountregressor-1.0.5.dist-info}/top_level.txt +0 -0
metacountregressor/solution.py
CHANGED
@@ -171,7 +171,7 @@ class ObjectiveFunction(object):
|
|
171
171
|
# defalt paramaters for hs #TODO unpack into harmony search class
|
172
172
|
self.algorithm = kwargs.get('algorithm', 'hs') # 'sa' 'de' also avialable
|
173
173
|
self._hms = 20
|
174
|
-
self._max_time = kwargs.get('_max_time', 0.8* 60 * 60 * 24)
|
174
|
+
self._max_time = self._max_time = kwargs.get('_max_time', kwargs.get('MAX_TIME', 0.8 * 60 * 60 * 24))
|
175
175
|
self._hmcr = kwargs.get('_hmcr', .5)
|
176
176
|
self._par = 0.3 #dont think this gets useted
|
177
177
|
self._mpai = 1
|
@@ -459,14 +459,12 @@ class ObjectiveFunction(object):
|
|
459
459
|
|
460
460
|
if self.G is not None:
|
461
461
|
#TODO need to handle this for groups
|
462
|
-
|
463
|
-
|
464
|
-
|
465
|
-
self._distribution = ["trad| " + item for item in self._distribution
|
462
|
+
|
463
|
+
|
464
|
+
self._distribution = ["trad| " + item for item in self._distribution
|
466
465
|
] + ["grpd| " + item for item in self._distribution]
|
467
|
-
|
468
|
-
|
469
|
-
]
|
466
|
+
|
467
|
+
|
470
468
|
|
471
469
|
# output information
|
472
470
|
self.convergence = None
|
@@ -7229,7 +7227,7 @@ class ObjectiveFunction(object):
|
|
7229
7227
|
if len(self.none_handler(zi)) > 0:
|
7230
7228
|
the_name = the_name + '_zi'
|
7231
7229
|
if model_nature is not None:
|
7232
|
-
if 'XG' in model_nature:
|
7230
|
+
if 'XG' in model_nature and model_nature.get('XG') is not None:
|
7233
7231
|
if model_nature.get('XG').shape[2] > 0:
|
7234
7232
|
the_name = the_name + 'grp'
|
7235
7233
|
|
@@ -7302,10 +7300,11 @@ class ObjectiveFunction(object):
|
|
7302
7300
|
if grouped_rpm is None:
|
7303
7301
|
a =len(self.rdm_cor_fit)+len(self.rdm_fit) != Xr.shape[2]
|
7304
7302
|
else:
|
7305
|
-
a = len(self.none_handler(self.rdm_cor_fit)) + len(self.none_handler(self.rdm_fit)) + len(self.none_handler(grouped_rpm)) != Xr.shape[2]
|
7303
|
+
a = len(self.none_handler(self.rdm_cor_fit)) + len(self.none_handler(self.rdm_fit)) + len(self.none_handler(grouped_rpm))*self._Gnum != Xr.shape[2]
|
7306
7304
|
|
7307
7305
|
if a:
|
7308
7306
|
print('why')
|
7307
|
+
|
7309
7308
|
print('The number of random effects does not match the data')
|
7310
7309
|
print(Xr.shape)
|
7311
7310
|
print(self.rdm_cor_fit)
|
@@ -7385,16 +7384,19 @@ class ObjectiveFunction(object):
|
|
7385
7384
|
self.group_dummies.shape[2]) if self.grouped_rpm != [] else []
|
7386
7385
|
X_set = df_tf[:, :, indices4]
|
7387
7386
|
XG = np.tile(self.group_dummies, len(self.grouped_rpm)) * X_set if X_set.shape[2] != 0 else None
|
7387
|
+
if XG is not None:
|
7388
|
+
model_nature['XG'] = XG
|
7389
|
+
|
7388
7390
|
else:
|
7389
7391
|
XG = None
|
7390
7392
|
X = df_tf[:, :, indices]
|
7391
7393
|
XH = df_tf[:, :, indices5]
|
7392
7394
|
|
7393
|
-
if XG is not None:
|
7395
|
+
if XG is not None and self.is_multi:
|
7394
7396
|
indices4_test = np.repeat(self.get_named_indices(self.grouped_rpm),
|
7395
7397
|
self.group_dummies_test.shape[2]) if self.grouped_rpm != [] else []
|
7396
7398
|
XGtest = np.tile(self.group_dummies_test, len(self.grouped_rpm)) * df_test[:, :, indices4_test]
|
7397
|
-
model_nature['XG'] = XG
|
7399
|
+
#model_nature['XG'] = XG
|
7398
7400
|
model_nature['XGtest'] = XGtest
|
7399
7401
|
|
7400
7402
|
model_nature['X'] = X
|
@@ -7413,7 +7415,7 @@ class ObjectiveFunction(object):
|
|
7413
7415
|
if np.isin(X, [np.inf, -np.inf, None, np.nan]).any(): # type ignore
|
7414
7416
|
raise Exception('there is some kind of error in X')
|
7415
7417
|
|
7416
|
-
# numpy data setup
|
7418
|
+
# numpy data setup for estimation
|
7417
7419
|
indices2 = self.get_named_indices(self.rdm_fit)
|
7418
7420
|
Xr = df_tf[:, :, indices2]
|
7419
7421
|
if self.rdm_cor_fit is not None:
|
@@ -0,0 +1,43 @@
|
|
1
|
+
from solution import ObjectiveFunction
|
2
|
+
from metaheuristics import (harmony_search,differential_evolution,simulated_annealing)
|
3
|
+
#from . import helperprocess
|
4
|
+
import pandas as pd
|
5
|
+
|
6
|
+
df = pd.read_csv("https://raw.githubusercontent.com/zahern/data/refs/heads/main/rural_int.csv")
|
7
|
+
y = df['crashes'] # Frequency of crashes
|
8
|
+
|
9
|
+
df.drop(columns=[ 'year', 'orig_ID',
|
10
|
+
'jurisdiction', 'town', 'maint_region', 'weather_station', 'dummy_winter_2', 'month', 'inj.fat', 'PDO', 'zonal_ID', 'ln_AADT', 'ln_seg'], inplace=True) # was dropped postcode
|
11
|
+
|
12
|
+
|
13
|
+
|
14
|
+
arguments_hs = {'_par': 0.3, '_hms': 20}
|
15
|
+
arguments = {'test_percentage': 0.2, 'complexity_level': 5, 'reg_penalty':0} #Objective args
|
16
|
+
# Step 2: Process Data
|
17
|
+
model_terms = {
|
18
|
+
'Y': 'crashes', # Dependent variable
|
19
|
+
'group': 'county', # Grouping column (if any)
|
20
|
+
'panels': 'element_ID', # Panel column (if any)
|
21
|
+
'Offset': None # Offset column (if any)
|
22
|
+
}
|
23
|
+
|
24
|
+
|
25
|
+
X = df.drop(columns=['crashes']) # setup X based on data
|
26
|
+
X.columns
|
27
|
+
print(X.columns)
|
28
|
+
|
29
|
+
manual_fit_spec = {
|
30
|
+
'fixed_terms': ['const', 'DP10'],
|
31
|
+
'rdm_terms': [ 'DX32:normal'],
|
32
|
+
'rdm_cor_terms': [],
|
33
|
+
'group_rdm': ['DPO1:triangular'],
|
34
|
+
'hetro_in_means': [],
|
35
|
+
'transformations': ['no', 'no', 'no', 'no', 'no', 'no'],
|
36
|
+
'dispersion': 0
|
37
|
+
}
|
38
|
+
arguments = {'test_percentage': 0.2, 'complexity_level': 6, 'reg_penalty':0, 'group':'county', 'panels':'element_ID'} #Objective args
|
39
|
+
arguments['Manual_Fit'] = manual_fit_spec
|
40
|
+
#initial_solution = None
|
41
|
+
obj_fun = ObjectiveFunction(X, y, **arguments)
|
42
|
+
initial_solution = None
|
43
|
+
results_hs = harmony_search(obj_fun, initial_solution, **arguments_hs)
|
@@ -11,10 +11,11 @@ metacountregressor/pareto_file.py,sha256=whySaoPAUWYjyI8zo0hwAOa3rFk6SIUlHSpqZiL
|
|
11
11
|
metacountregressor/pareto_logger__plot.py,sha256=mEU2QN4wmsM7t39GJ_XhJ_jjsdl09JOmG0U2jICrAkI,30037
|
12
12
|
metacountregressor/setup.py,sha256=5UcQCCLR8Fm5odA3MX78WwahavxFq4mVD6oq0IuQvAY,936
|
13
13
|
metacountregressor/single_objective_finder.py,sha256=jVG7GJBqzSP4_riYr-kMMKy_LE3SlGmKMunNhHYxgRg,8011
|
14
|
-
metacountregressor/solution.py,sha256=
|
14
|
+
metacountregressor/solution.py,sha256=ZyKFq39Mug5865vZQt4G2vv-oPgsnYuyrJJJVvwO1dA,323939
|
15
|
+
metacountregressor/test_code.py,sha256=_7Emm2JbhK_NVhxoqMhshN2JeHZtihZuSDl3Jpe7Ajk,1641
|
15
16
|
metacountregressor/test_generated_paper2.py,sha256=pwOoRzl1jJIIOUAAvbkT6HmmTQ81mwpsshn9SLdKOg8,3927
|
16
|
-
metacountregressor-0.
|
17
|
-
metacountregressor-0.
|
18
|
-
metacountregressor-0.
|
19
|
-
metacountregressor-0.
|
20
|
-
metacountregressor-0.
|
17
|
+
metacountregressor-1.0.5.dist-info/licenses/LICENSE.txt,sha256=OXLcl0T2SZ8Pmy2_dmlvKuetivmyPd5m1q-Gyd-zaYY,35149
|
18
|
+
metacountregressor-1.0.5.dist-info/METADATA,sha256=utJe5zUXxsSoUvcaR3bzoUPhMeu8zfIstgn16eroHlo,23618
|
19
|
+
metacountregressor-1.0.5.dist-info/WHEEL,sha256=pxyMxgL8-pra_rKaQ4drOZAegBVuX-G_4nRHjjgWbmo,91
|
20
|
+
metacountregressor-1.0.5.dist-info/top_level.txt,sha256=zGG7UC5WIpr76gsFUpwJ4En2aCcoNTONBaS3OewwjR0,19
|
21
|
+
metacountregressor-1.0.5.dist-info/RECORD,,
|
{metacountregressor-0.1.350.dist-info → metacountregressor-1.0.5.dist-info}/licenses/LICENSE.txt
RENAMED
File without changes
|
File without changes
|