metacountregressor 0.1.347__tar.gz → 1.0.2__tar.gz
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-0.1.347/metacountregressor.egg-info → metacountregressor-1.0.2}/PKG-INFO +1 -1
- {metacountregressor-0.1.347 → metacountregressor-1.0.2}/metacountregressor/solution.py +37 -18
- metacountregressor-1.0.2/metacountregressor/test_code.py +43 -0
- {metacountregressor-0.1.347 → metacountregressor-1.0.2/metacountregressor.egg-info}/PKG-INFO +1 -1
- {metacountregressor-0.1.347 → metacountregressor-1.0.2}/metacountregressor.egg-info/SOURCES.txt +1 -0
- metacountregressor-1.0.2/version.txt +1 -0
- metacountregressor-0.1.347/version.txt +0 -1
- {metacountregressor-0.1.347 → metacountregressor-1.0.2}/LICENSE.txt +0 -0
- {metacountregressor-0.1.347 → metacountregressor-1.0.2}/MANIFEST.in +0 -0
- {metacountregressor-0.1.347 → metacountregressor-1.0.2}/README.md +0 -0
- {metacountregressor-0.1.347 → metacountregressor-1.0.2}/README.rst +0 -0
- {metacountregressor-0.1.347 → metacountregressor-1.0.2}/metacountregressor/__init__.py +0 -0
- {metacountregressor-0.1.347 → metacountregressor-1.0.2}/metacountregressor/_device_cust.py +0 -0
- {metacountregressor-0.1.347 → metacountregressor-1.0.2}/metacountregressor/app_main.py +0 -0
- {metacountregressor-0.1.347 → metacountregressor-1.0.2}/metacountregressor/data_split_helper.py +0 -0
- {metacountregressor-0.1.347 → metacountregressor-1.0.2}/metacountregressor/halton.py +0 -0
- {metacountregressor-0.1.347 → metacountregressor-1.0.2}/metacountregressor/helperprocess.py +0 -0
- {metacountregressor-0.1.347 → metacountregressor-1.0.2}/metacountregressor/main.py +0 -0
- {metacountregressor-0.1.347 → metacountregressor-1.0.2}/metacountregressor/main_old.py +0 -0
- {metacountregressor-0.1.347 → metacountregressor-1.0.2}/metacountregressor/metaheuristics.py +0 -0
- {metacountregressor-0.1.347 → metacountregressor-1.0.2}/metacountregressor/pareto_file.py +0 -0
- {metacountregressor-0.1.347 → metacountregressor-1.0.2}/metacountregressor/pareto_logger__plot.py +0 -0
- {metacountregressor-0.1.347 → metacountregressor-1.0.2}/metacountregressor/setup.py +0 -0
- {metacountregressor-0.1.347 → metacountregressor-1.0.2}/metacountregressor/single_objective_finder.py +0 -0
- {metacountregressor-0.1.347 → metacountregressor-1.0.2}/metacountregressor/test_generated_paper2.py +0 -0
- {metacountregressor-0.1.347 → metacountregressor-1.0.2}/metacountregressor.egg-info/dependency_links.txt +0 -0
- {metacountregressor-0.1.347 → metacountregressor-1.0.2}/metacountregressor.egg-info/not-zip-safe +0 -0
- {metacountregressor-0.1.347 → metacountregressor-1.0.2}/metacountregressor.egg-info/requires.txt +0 -0
- {metacountregressor-0.1.347 → metacountregressor-1.0.2}/metacountregressor.egg-info/top_level.txt +0 -0
- {metacountregressor-0.1.347 → metacountregressor-1.0.2}/setup.cfg +0 -0
- {metacountregressor-0.1.347 → metacountregressor-1.0.2}/setup.py +0 -0
- {metacountregressor-0.1.347 → metacountregressor-1.0.2}/tests/test.py +0 -0
@@ -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
|
@@ -1793,23 +1791,40 @@ class ObjectiveFunction(object):
|
|
1793
1791
|
|
1794
1792
|
counter = 0
|
1795
1793
|
while b < self._min_characteristics and counter < max_loops:
|
1796
|
-
counter +=1
|
1794
|
+
counter += 1
|
1797
1795
|
weights = [1 if x == 0 else 0 for x in only_ints_vals]
|
1798
1796
|
get_rdm_i = random.choices(only_ints, weights=weights)[0]
|
1799
1797
|
|
1800
|
-
#
|
1798
|
+
# Safeguard: Check if only one valid value exists to handle the "stuck" case
|
1799
|
+
if len(only_ints_vals) == 1 and only_ints_vals[0] == 0:
|
1800
|
+
print("Breaking out: only one valid value exists and it is 0.")
|
1801
|
+
break
|
1802
|
+
|
1801
1803
|
if vector[get_rdm_i] == 0:
|
1804
|
+
max_inner_loops = 100 # Limit for the inner loop
|
1805
|
+
inner_counter = 0
|
1802
1806
|
while new_j == 0:
|
1803
|
-
|
1804
|
-
|
1805
|
-
|
1807
|
+
inner_counter += 1
|
1808
|
+
if inner_counter > max_inner_loops:
|
1809
|
+
print("Breaking out of inner loop: exceeded maximum iterations.")
|
1810
|
+
break
|
1811
|
+
|
1812
|
+
get_rdm_j = random.randint(0, self.get_num_discrete_values(get_rdm_i) - 1)
|
1806
1813
|
new_j = self.get_value(get_rdm_i, get_rdm_j)
|
1814
|
+
|
1815
|
+
# If the inner loop exited early, check and continue
|
1816
|
+
if new_j == 0:
|
1817
|
+
print("Inner loop exited without finding a valid value.")
|
1818
|
+
break
|
1819
|
+
|
1820
|
+
# Assign the value after successfully exiting the inner loop
|
1807
1821
|
vector[get_rdm_i] = new_j
|
1808
1822
|
prmVect[get_rdm_i] = new_j
|
1809
1823
|
|
1810
1824
|
b += new_j
|
1811
1825
|
new_j = 0
|
1812
1826
|
|
1827
|
+
|
1813
1828
|
if hasattr(self, 'forced_variables'):
|
1814
1829
|
self.force_inclusion(vector)
|
1815
1830
|
|
@@ -2477,7 +2492,7 @@ class ObjectiveFunction(object):
|
|
2477
2492
|
layout = vector.copy()
|
2478
2493
|
|
2479
2494
|
while max_trial <= max_routine and trial_run == 1: # and max_trial <= 200:
|
2480
|
-
|
2495
|
+
|
2481
2496
|
obj_1, model_mod = self.makeRegression(model_nature, layout=layout, **a)
|
2482
2497
|
|
2483
2498
|
if obj_best is None:
|
@@ -7212,7 +7227,7 @@ class ObjectiveFunction(object):
|
|
7212
7227
|
if len(self.none_handler(zi)) > 0:
|
7213
7228
|
the_name = the_name + '_zi'
|
7214
7229
|
if model_nature is not None:
|
7215
|
-
if 'XG' in model_nature:
|
7230
|
+
if 'XG' in model_nature and model_nature.get('XG') is not None:
|
7216
7231
|
if model_nature.get('XG').shape[2] > 0:
|
7217
7232
|
the_name = the_name + 'grp'
|
7218
7233
|
|
@@ -7285,10 +7300,11 @@ class ObjectiveFunction(object):
|
|
7285
7300
|
if grouped_rpm is None:
|
7286
7301
|
a =len(self.rdm_cor_fit)+len(self.rdm_fit) != Xr.shape[2]
|
7287
7302
|
else:
|
7288
|
-
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]
|
7289
7304
|
|
7290
7305
|
if a:
|
7291
7306
|
print('why')
|
7307
|
+
|
7292
7308
|
print('The number of random effects does not match the data')
|
7293
7309
|
print(Xr.shape)
|
7294
7310
|
print(self.rdm_cor_fit)
|
@@ -7368,16 +7384,19 @@ class ObjectiveFunction(object):
|
|
7368
7384
|
self.group_dummies.shape[2]) if self.grouped_rpm != [] else []
|
7369
7385
|
X_set = df_tf[:, :, indices4]
|
7370
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
|
+
|
7371
7390
|
else:
|
7372
7391
|
XG = None
|
7373
7392
|
X = df_tf[:, :, indices]
|
7374
7393
|
XH = df_tf[:, :, indices5]
|
7375
7394
|
|
7376
|
-
if XG is not None:
|
7395
|
+
if XG is not None and self.is_multi:
|
7377
7396
|
indices4_test = np.repeat(self.get_named_indices(self.grouped_rpm),
|
7378
7397
|
self.group_dummies_test.shape[2]) if self.grouped_rpm != [] else []
|
7379
7398
|
XGtest = np.tile(self.group_dummies_test, len(self.grouped_rpm)) * df_test[:, :, indices4_test]
|
7380
|
-
model_nature['XG'] = XG
|
7399
|
+
#model_nature['XG'] = XG
|
7381
7400
|
model_nature['XGtest'] = XGtest
|
7382
7401
|
|
7383
7402
|
model_nature['X'] = X
|
@@ -7396,7 +7415,7 @@ class ObjectiveFunction(object):
|
|
7396
7415
|
if np.isin(X, [np.inf, -np.inf, None, np.nan]).any(): # type ignore
|
7397
7416
|
raise Exception('there is some kind of error in X')
|
7398
7417
|
|
7399
|
-
# numpy data setup
|
7418
|
+
# numpy data setup for estimation
|
7400
7419
|
indices2 = self.get_named_indices(self.rdm_fit)
|
7401
7420
|
Xr = df_tf[:, :, indices2]
|
7402
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)
|
{metacountregressor-0.1.347 → metacountregressor-1.0.2}/metacountregressor.egg-info/SOURCES.txt
RENAMED
@@ -19,6 +19,7 @@ metacountregressor/pareto_logger__plot.py
|
|
19
19
|
metacountregressor/setup.py
|
20
20
|
metacountregressor/single_objective_finder.py
|
21
21
|
metacountregressor/solution.py
|
22
|
+
metacountregressor/test_code.py
|
22
23
|
metacountregressor/test_generated_paper2.py
|
23
24
|
metacountregressor.egg-info/PKG-INFO
|
24
25
|
metacountregressor.egg-info/SOURCES.txt
|
@@ -0,0 +1 @@
|
|
1
|
+
1.0.2
|
@@ -1 +0,0 @@
|
|
1
|
-
0.1.347
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
{metacountregressor-0.1.347 → metacountregressor-1.0.2}/metacountregressor/data_split_helper.py
RENAMED
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
{metacountregressor-0.1.347 → metacountregressor-1.0.2}/metacountregressor/metaheuristics.py
RENAMED
File without changes
|
File without changes
|
{metacountregressor-0.1.347 → metacountregressor-1.0.2}/metacountregressor/pareto_logger__plot.py
RENAMED
File without changes
|
File without changes
|
File without changes
|
{metacountregressor-0.1.347 → metacountregressor-1.0.2}/metacountregressor/test_generated_paper2.py
RENAMED
File without changes
|
File without changes
|
{metacountregressor-0.1.347 → metacountregressor-1.0.2}/metacountregressor.egg-info/not-zip-safe
RENAMED
File without changes
|
{metacountregressor-0.1.347 → metacountregressor-1.0.2}/metacountregressor.egg-info/requires.txt
RENAMED
File without changes
|
{metacountregressor-0.1.347 → metacountregressor-1.0.2}/metacountregressor.egg-info/top_level.txt
RENAMED
File without changes
|
File without changes
|
File without changes
|
File without changes
|