metacountregressor 1.0.4__tar.gz → 1.0.6__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.
Files changed (32) hide show
  1. {metacountregressor-1.0.4/metacountregressor.egg-info → metacountregressor-1.0.6}/PKG-INFO +11 -14
  2. {metacountregressor-1.0.4 → metacountregressor-1.0.6}/README.md +10 -13
  3. {metacountregressor-1.0.4 → metacountregressor-1.0.6}/README.rst +10 -13
  4. {metacountregressor-1.0.4 → metacountregressor-1.0.6}/metacountregressor/metaheuristics.py +41 -30
  5. {metacountregressor-1.0.4 → metacountregressor-1.0.6}/metacountregressor/solution.py +25 -12
  6. {metacountregressor-1.0.4 → metacountregressor-1.0.6/metacountregressor.egg-info}/PKG-INFO +11 -14
  7. metacountregressor-1.0.6/version.txt +1 -0
  8. metacountregressor-1.0.4/version.txt +0 -1
  9. {metacountregressor-1.0.4 → metacountregressor-1.0.6}/LICENSE.txt +0 -0
  10. {metacountregressor-1.0.4 → metacountregressor-1.0.6}/MANIFEST.in +0 -0
  11. {metacountregressor-1.0.4 → metacountregressor-1.0.6}/metacountregressor/__init__.py +0 -0
  12. {metacountregressor-1.0.4 → metacountregressor-1.0.6}/metacountregressor/_device_cust.py +0 -0
  13. {metacountregressor-1.0.4 → metacountregressor-1.0.6}/metacountregressor/app_main.py +0 -0
  14. {metacountregressor-1.0.4 → metacountregressor-1.0.6}/metacountregressor/data_split_helper.py +0 -0
  15. {metacountregressor-1.0.4 → metacountregressor-1.0.6}/metacountregressor/halton.py +0 -0
  16. {metacountregressor-1.0.4 → metacountregressor-1.0.6}/metacountregressor/helperprocess.py +0 -0
  17. {metacountregressor-1.0.4 → metacountregressor-1.0.6}/metacountregressor/main.py +0 -0
  18. {metacountregressor-1.0.4 → metacountregressor-1.0.6}/metacountregressor/main_old.py +0 -0
  19. {metacountregressor-1.0.4 → metacountregressor-1.0.6}/metacountregressor/pareto_file.py +0 -0
  20. {metacountregressor-1.0.4 → metacountregressor-1.0.6}/metacountregressor/pareto_logger__plot.py +0 -0
  21. {metacountregressor-1.0.4 → metacountregressor-1.0.6}/metacountregressor/setup.py +0 -0
  22. {metacountregressor-1.0.4 → metacountregressor-1.0.6}/metacountregressor/single_objective_finder.py +0 -0
  23. {metacountregressor-1.0.4 → metacountregressor-1.0.6}/metacountregressor/test_code.py +0 -0
  24. {metacountregressor-1.0.4 → metacountregressor-1.0.6}/metacountregressor/test_generated_paper2.py +0 -0
  25. {metacountregressor-1.0.4 → metacountregressor-1.0.6}/metacountregressor.egg-info/SOURCES.txt +0 -0
  26. {metacountregressor-1.0.4 → metacountregressor-1.0.6}/metacountregressor.egg-info/dependency_links.txt +0 -0
  27. {metacountregressor-1.0.4 → metacountregressor-1.0.6}/metacountregressor.egg-info/not-zip-safe +0 -0
  28. {metacountregressor-1.0.4 → metacountregressor-1.0.6}/metacountregressor.egg-info/requires.txt +0 -0
  29. {metacountregressor-1.0.4 → metacountregressor-1.0.6}/metacountregressor.egg-info/top_level.txt +0 -0
  30. {metacountregressor-1.0.4 → metacountregressor-1.0.6}/setup.cfg +0 -0
  31. {metacountregressor-1.0.4 → metacountregressor-1.0.6}/setup.py +0 -0
  32. {metacountregressor-1.0.4 → metacountregressor-1.0.6}/tests/test.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: metacountregressor
3
- Version: 1.0.4
3
+ Version: 1.0.6
4
4
  Summary: Extensive Testing for Estimation of Data Count Models
5
5
  Home-page: https://github.com/zahern/CountDataEstimation
6
6
  Author: Zeke Ahern
@@ -95,7 +95,7 @@ X['Offset'] = np.log(df['AADT']) # Explicitley define how to offset the data, no
95
95
  X = df.drop(columns=['FREQ', 'ID', 'AADT'])
96
96
 
97
97
  #some example argument, these are defualt so the following line is just for claritity. See the later agruments section for detials.
98
- arguments = {'algorithm': 'hs', 'test_percentage': 0.15, 'test_complexity': 6, 'instance_number':1,
98
+ arguments = {'algorithm': 'hs', 'test_percentage': 0.15, 'test_complexity': 6, 'instance_name':1,
99
99
  'val_percentage':0.15, 'obj_1': 'bic', '_obj_2': 'RMSE_TEST', "_max_time": 6}
100
100
  # Fit the model with metacountregressor
101
101
  obj_fun = ObjectiveFunction(X, y, **arguments)
@@ -135,9 +135,9 @@ arguments = {
135
135
  'test_percentage': 0.2, # used in multi-objective optimisation only. Saves 20% of data for testing.
136
136
  'val_percenetage:': 0.2, # Saves 20% of data for testing.
137
137
  'test_complexity': 6, # Complexity level for testing (6 tests all) or a list to consider potential differences in complexity
138
- 'instance_number': 'name', # used for creeating a named folder where your models are saved into from the directory
138
+ 'instance_name': 'name', # used for creeting a named folder where your models are saved into from the directory
139
139
  'distribution': ['Normal', 'LnNormal', 'Triangular', 'Uniform'],
140
- 'Model': [0,1], # or equivalently ['POS', 'NB']
140
+ 'model_types': [[0,1]], # or equivalently ['POS', 'NB']
141
141
  'transformations': ['no', 'sqrt', 'archsinh'],
142
142
  'method_ll': 'BFGS_2',
143
143
  '_max_time': 10
@@ -156,7 +156,7 @@ manual_fit_spec = {
156
156
  'fixed_terms': ['SINGLE', 'LENGTH'],
157
157
  'rdm_terms': ['AADT:normal'],
158
158
  'rdm_cor_terms': ['GRADEBR:normal', 'CURVES:normal'],
159
- 'grouped_terms': [],
159
+ 'grouped_rdm': [],
160
160
  'hetro_in_means': ['ACCESS:normal', 'MINRAD:normal'],
161
161
  'transformations': ['no', 'no', 'log', 'no', 'no', 'no', 'no'],
162
162
  'dispersion': 0
@@ -168,7 +168,7 @@ arguments = {
168
168
  'algorithm': 'hs',
169
169
  'test_percentage': 0.2,
170
170
  'test_complexity': 6,
171
- 'instance_number': 'name',
171
+ 'instance_name': 'name',
172
172
  'Manual_Fit': manual_fit_spec
173
173
  }
174
174
  obj_fun = ObjectiveFunction(X, y, **arguments)
@@ -268,25 +268,22 @@ The following list describes the arguments available in this function. By defaul
268
268
 
269
269
  2. **`distributions`**: This argument accepts a list of strings where each string corresponds to a distribution. Valid options include:
270
270
  - "Normal"
271
- - "Lindley"
272
271
  - "Uniform"
273
272
  - "LogNormal"
274
273
  - "Triangular"
275
- - "Gamma"
276
274
  - "TruncatedNormal"
277
275
  - Any of the above, concatenated with ":" (e.g., "Normal:grouped"; requires a grouping term defined in the model)
278
276
 
279
277
  3. **`Model`**: This argument specifies the model form. It can be a list of integers representing different models to test:
280
278
  - 0: Poisson
281
279
  - 1: Negative-Binomial
282
- - 2: Generalized-Poisson
283
280
 
284
281
  4. **`transformations`**: This argument accepts a list of strings representing available transformations within the framework. Valid options include:
285
282
  - "no"
286
283
  - "square-root"
287
284
  - "logarithmic"
288
285
  - "archsinh"
289
- - "as_factor"
286
+ - "nil"
290
287
 
291
288
  5. **`is_multi`**: This argument accepts an integer indicating whether single or multiple objectives are to be tested (0 for single, 1 for multiple).
292
289
 
@@ -320,9 +317,9 @@ arguments = {
320
317
  'val_percentage:': 0.2, # Saves 20% of data for testing.
321
318
  'test_complexity': 3, # For Very simple Models
322
319
  'obj_1': 'BIC', '_obj_2': 'RMSE_TEST',
323
- 'instance_number': 'hs_run', # used for creeating a named folder where your models are saved into from the directory
320
+ 'instance_name': 'hs_run', # used for creeating a named folder where your models are saved into from the directory
324
321
  'distribution': ['Normal'],
325
- 'Model': [0, 1], # or equivalently ['POS', 'NB']
322
+ 'model_types': [0, 1], # or equivalently ['POS', 'NB']
326
323
  'transformations': ['no', 'sqrt', 'archsinh'],
327
324
  '_max_time': 10000
328
325
  } '''Arguments for the solution algorithm'''
@@ -398,7 +395,7 @@ manual_fit_spec = {
398
395
  'fixed_terms': ['const','YEAR'],
399
396
  'rdm_terms': [],
400
397
  'rdm_cor_terms': [],
401
- 'grouped_terms': [],
398
+ 'grouped_rdm': [],
402
399
  'hetro_in_means': [],
403
400
  'transformations': ['no', 'no'],
404
401
  'dispersion': 1 #Negative Binomial
@@ -410,7 +407,7 @@ arguments = {
410
407
  'algorithm': 'hs',
411
408
  'test_percentage': 0,
412
409
  'test_complexity': 6,
413
- 'instance_number': 'name',
410
+ 'instance': 'name',
414
411
  'Manual_Fit': manual_fit_spec
415
412
  }
416
413
  obj_fun = ObjectiveFunction(data_exog, data_endog, **arguments)
@@ -64,7 +64,7 @@ X['Offset'] = np.log(df['AADT']) # Explicitley define how to offset the data, no
64
64
  X = df.drop(columns=['FREQ', 'ID', 'AADT'])
65
65
 
66
66
  #some example argument, these are defualt so the following line is just for claritity. See the later agruments section for detials.
67
- arguments = {'algorithm': 'hs', 'test_percentage': 0.15, 'test_complexity': 6, 'instance_number':1,
67
+ arguments = {'algorithm': 'hs', 'test_percentage': 0.15, 'test_complexity': 6, 'instance_name':1,
68
68
  'val_percentage':0.15, 'obj_1': 'bic', '_obj_2': 'RMSE_TEST', "_max_time": 6}
69
69
  # Fit the model with metacountregressor
70
70
  obj_fun = ObjectiveFunction(X, y, **arguments)
@@ -104,9 +104,9 @@ arguments = {
104
104
  'test_percentage': 0.2, # used in multi-objective optimisation only. Saves 20% of data for testing.
105
105
  'val_percenetage:': 0.2, # Saves 20% of data for testing.
106
106
  'test_complexity': 6, # Complexity level for testing (6 tests all) or a list to consider potential differences in complexity
107
- 'instance_number': 'name', # used for creeating a named folder where your models are saved into from the directory
107
+ 'instance_name': 'name', # used for creeting a named folder where your models are saved into from the directory
108
108
  'distribution': ['Normal', 'LnNormal', 'Triangular', 'Uniform'],
109
- 'Model': [0,1], # or equivalently ['POS', 'NB']
109
+ 'model_types': [[0,1]], # or equivalently ['POS', 'NB']
110
110
  'transformations': ['no', 'sqrt', 'archsinh'],
111
111
  'method_ll': 'BFGS_2',
112
112
  '_max_time': 10
@@ -125,7 +125,7 @@ manual_fit_spec = {
125
125
  'fixed_terms': ['SINGLE', 'LENGTH'],
126
126
  'rdm_terms': ['AADT:normal'],
127
127
  'rdm_cor_terms': ['GRADEBR:normal', 'CURVES:normal'],
128
- 'grouped_terms': [],
128
+ 'grouped_rdm': [],
129
129
  'hetro_in_means': ['ACCESS:normal', 'MINRAD:normal'],
130
130
  'transformations': ['no', 'no', 'log', 'no', 'no', 'no', 'no'],
131
131
  'dispersion': 0
@@ -137,7 +137,7 @@ arguments = {
137
137
  'algorithm': 'hs',
138
138
  'test_percentage': 0.2,
139
139
  'test_complexity': 6,
140
- 'instance_number': 'name',
140
+ 'instance_name': 'name',
141
141
  'Manual_Fit': manual_fit_spec
142
142
  }
143
143
  obj_fun = ObjectiveFunction(X, y, **arguments)
@@ -237,25 +237,22 @@ The following list describes the arguments available in this function. By defaul
237
237
 
238
238
  2. **`distributions`**: This argument accepts a list of strings where each string corresponds to a distribution. Valid options include:
239
239
  - "Normal"
240
- - "Lindley"
241
240
  - "Uniform"
242
241
  - "LogNormal"
243
242
  - "Triangular"
244
- - "Gamma"
245
243
  - "TruncatedNormal"
246
244
  - Any of the above, concatenated with ":" (e.g., "Normal:grouped"; requires a grouping term defined in the model)
247
245
 
248
246
  3. **`Model`**: This argument specifies the model form. It can be a list of integers representing different models to test:
249
247
  - 0: Poisson
250
248
  - 1: Negative-Binomial
251
- - 2: Generalized-Poisson
252
249
 
253
250
  4. **`transformations`**: This argument accepts a list of strings representing available transformations within the framework. Valid options include:
254
251
  - "no"
255
252
  - "square-root"
256
253
  - "logarithmic"
257
254
  - "archsinh"
258
- - "as_factor"
255
+ - "nil"
259
256
 
260
257
  5. **`is_multi`**: This argument accepts an integer indicating whether single or multiple objectives are to be tested (0 for single, 1 for multiple).
261
258
 
@@ -289,9 +286,9 @@ arguments = {
289
286
  'val_percentage:': 0.2, # Saves 20% of data for testing.
290
287
  'test_complexity': 3, # For Very simple Models
291
288
  'obj_1': 'BIC', '_obj_2': 'RMSE_TEST',
292
- 'instance_number': 'hs_run', # used for creeating a named folder where your models are saved into from the directory
289
+ 'instance_name': 'hs_run', # used for creeating a named folder where your models are saved into from the directory
293
290
  'distribution': ['Normal'],
294
- 'Model': [0, 1], # or equivalently ['POS', 'NB']
291
+ 'model_types': [0, 1], # or equivalently ['POS', 'NB']
295
292
  'transformations': ['no', 'sqrt', 'archsinh'],
296
293
  '_max_time': 10000
297
294
  } '''Arguments for the solution algorithm'''
@@ -367,7 +364,7 @@ manual_fit_spec = {
367
364
  'fixed_terms': ['const','YEAR'],
368
365
  'rdm_terms': [],
369
366
  'rdm_cor_terms': [],
370
- 'grouped_terms': [],
367
+ 'grouped_rdm': [],
371
368
  'hetro_in_means': [],
372
369
  'transformations': ['no', 'no'],
373
370
  'dispersion': 1 #Negative Binomial
@@ -379,7 +376,7 @@ arguments = {
379
376
  'algorithm': 'hs',
380
377
  'test_percentage': 0,
381
378
  'test_complexity': 6,
382
- 'instance_number': 'name',
379
+ 'instance': 'name',
383
380
  'Manual_Fit': manual_fit_spec
384
381
  }
385
382
  obj_fun = ObjectiveFunction(data_exog, data_endog, **arguments)
@@ -91,7 +91,7 @@ the Pareto frontier.
91
91
  X = df.drop(columns=['FREQ', 'ID', 'AADT'])
92
92
 
93
93
  #some example argument, these are defualt so the following line is just for claritity. See the later agruments section for detials.
94
- arguments = {'algorithm': 'hs', 'test_percentage': 0.15, 'test_complexity': 6, 'instance_number':1,
94
+ arguments = {'algorithm': 'hs', 'test_percentage': 0.15, 'test_complexity': 6, 'instance_name':1,
95
95
  'val_percentage':0.15, 'obj_1': 'bic', '_obj_2': 'RMSE_TEST', "_max_time": 6}
96
96
  # Fit the model with metacountregressor
97
97
  obj_fun = ObjectiveFunction(X, y, **arguments)
@@ -158,9 +158,9 @@ code as a guide.
158
158
  'test_percentage': 0.2, # used in multi-objective optimisation only. Saves 20% of data for testing.
159
159
  'val_percenetage:': 0.2, # Saves 20% of data for testing.
160
160
  'test_complexity': 6, # Complexity level for testing (6 tests all) or a list to consider potential differences in complexity
161
- 'instance_number': 'name', # used for creeating a named folder where your models are saved into from the directory
161
+ 'instance_name': 'name', # used for creeting a named folder where your models are saved into from the directory
162
162
  'distribution': ['Normal', 'LnNormal', 'Triangular', 'Uniform'],
163
- 'Model': [0,1], # or equivalently ['POS', 'NB']
163
+ 'model_types': [[0,1]], # or equivalently ['POS', 'NB']
164
164
  'transformations': ['no', 'sqrt', 'archsinh'],
165
165
  'method_ll': 'BFGS_2',
166
166
  '_max_time': 10
@@ -184,7 +184,7 @@ modeling components may completely replace the initial solution.
184
184
  'fixed_terms': ['SINGLE', 'LENGTH'],
185
185
  'rdm_terms': ['AADT:normal'],
186
186
  'rdm_cor_terms': ['GRADEBR:normal', 'CURVES:normal'],
187
- 'grouped_terms': [],
187
+ 'grouped_rdm': [],
188
188
  'hetro_in_means': ['ACCESS:normal', 'MINRAD:normal'],
189
189
  'transformations': ['no', 'no', 'log', 'no', 'no', 'no', 'no'],
190
190
  'dispersion': 0
@@ -196,7 +196,7 @@ modeling components may completely replace the initial solution.
196
196
  'algorithm': 'hs',
197
197
  'test_percentage': 0.2,
198
198
  'test_complexity': 6,
199
- 'instance_number': 'name',
199
+ 'instance_name': 'name',
200
200
  'Manual_Fit': manual_fit_spec
201
201
  }
202
202
  obj_fun = ObjectiveFunction(X, y, **arguments)
@@ -341,11 +341,9 @@ considered. Example code will be provided later in this guide.
341
341
  each string corresponds to a distribution. Valid options include:
342
342
 
343
343
  - �Normal�
344
- - �Lindley�
345
344
  - �Uniform�
346
345
  - �LogNormal�
347
346
  - �Triangular�
348
- - �Gamma�
349
347
  - �TruncatedNormal�
350
348
  - Any of the above, concatenated with �:� (e.g., �Normal:grouped�;
351
349
  requires a grouping term defined in the model)
@@ -355,7 +353,6 @@ considered. Example code will be provided later in this guide.
355
353
 
356
354
  - 0: Poisson
357
355
  - 1: Negative-Binomial
358
- - 2: Generalized-Poisson
359
356
 
360
357
  4. **``transformations``**: This argument accepts a list of strings
361
358
  representing available transformations within the framework. Valid
@@ -365,7 +362,7 @@ considered. Example code will be provided later in this guide.
365
362
  - �square-root�
366
363
  - �logarithmic�
367
364
  - �archsinh�
368
- - �as_factor
365
+ - �nil
369
366
 
370
367
  5. **``is_multi``**: This argument accepts an integer indicating whether
371
368
  single or multiple objectives are to be tested (0 for single, 1 for
@@ -413,9 +410,9 @@ factors for our search.
413
410
  'val_percentage:': 0.2, # Saves 20% of data for testing.
414
411
  'test_complexity': 3, # For Very simple Models
415
412
  'obj_1': 'BIC', '_obj_2': 'RMSE_TEST',
416
- 'instance_number': 'hs_run', # used for creeating a named folder where your models are saved into from the directory
413
+ 'instance_name': 'hs_run', # used for creeating a named folder where your models are saved into from the directory
417
414
  'distribution': ['Normal'],
418
- 'Model': [0, 1], # or equivalently ['POS', 'NB']
415
+ 'model_types': [0, 1], # or equivalently ['POS', 'NB']
419
416
  'transformations': ['no', 'sqrt', 'archsinh'],
420
417
  '_max_time': 10000
421
418
  } '''Arguments for the solution algorithm'''
@@ -495,7 +492,7 @@ packages, including Statsmodels.
495
492
  'fixed_terms': ['const','YEAR'],
496
493
  'rdm_terms': [],
497
494
  'rdm_cor_terms': [],
498
- 'grouped_terms': [],
495
+ 'grouped_rdm': [],
499
496
  'hetro_in_means': [],
500
497
  'transformations': ['no', 'no'],
501
498
  'dispersion': 1 #Negative Binomial
@@ -507,7 +504,7 @@ packages, including Statsmodels.
507
504
  'algorithm': 'hs',
508
505
  'test_percentage': 0,
509
506
  'test_complexity': 6,
510
- 'instance_number': 'name',
507
+ 'instance': 'name',
511
508
  'Manual_Fit': manual_fit_spec
512
509
  }
513
510
  obj_fun = ObjectiveFunction(data_exog, data_endog, **arguments)
@@ -265,6 +265,10 @@ def simulated_annealing(objective_function, initial_slns=None, **kwargs):
265
265
  # else:
266
266
  # TEMP_ALPHA, MAX_STEPS, INTL_ACCEPT, STEPS, SWAP_PERC, NUM_INTL_SLNS, IS_MULTI= hyperparameters
267
267
  man = None
268
+ try:
269
+ objective_function.instance_name = str(0)
270
+ except:
271
+ pass
268
272
  if 'Manual_Fit' in kwargs:
269
273
  if kwargs['Manual_Fit'] is not None:
270
274
  man = kwargs['Manual_Fit']
@@ -292,7 +296,10 @@ def harmony_search(objective_function, initial_harmonies=None, hyperparameters=N
292
296
  objective_function._hms = kwargs.get('_hms')
293
297
  if kwargs.get('_hmcr') is not None:
294
298
  objective_function._hmcr = kwargs.get('_hmcr')
295
-
299
+ try:
300
+ objective_function.instance_name = f"run_hs_{str(0)}"
301
+ except:
302
+ pass
296
303
 
297
304
  man = None
298
305
  if 'Manual_Fit' in kwargs:
@@ -328,7 +335,7 @@ class Metaheuristic(object):
328
335
  self.F = kwargs['_AI'] # mustation scale
329
336
  self.iter = kwargs.get('_max_iter', 10000)
330
337
  self.cr = kwargs.get('_crossover_perc') or kwargs.get('_cr', 0.2)
331
- self.instance_number = str(kwargs.get('instance_number', 1))
338
+ self.instance_name = str(kwargs.get('instance_name', 1))
332
339
  if objective_function.is_multi:
333
340
 
334
341
  self.obj_1 = objective_function._obj_1
@@ -416,6 +423,10 @@ class DifferentialEvolution(object):
416
423
 
417
424
  def __init__(self, objective_function, **kwargs):
418
425
  objective_function.algorithm = 'de'
426
+ try:
427
+ objective_function.instance_name = str(0)
428
+ except:
429
+ pass
419
430
  self._obj_fun = objective_function
420
431
  if self._obj_fun._obj_1 is None:
421
432
  print('no objective found, automatically selecting BIC')
@@ -431,8 +442,8 @@ class DifferentialEvolution(object):
431
442
  self.F = kwargs.get('_AI', 2) # mutation scale
432
443
  self.iter = kwargs.get('_max_iter', 10000)
433
444
  self.cr = kwargs.get('_crossover_perc') or kwargs.get('_cr', 0.2)
434
- self.instance_number = str(kwargs.get('instance_number', 1))
435
- self.instance_number = objective_function.instance_number
445
+ self.instance_name = str(kwargs.get('instance_name', 1))
446
+ self.instance_name = objective_function.instance_name
436
447
  self.get_directory()
437
448
 
438
449
  self._population = list()
@@ -450,13 +461,13 @@ class DifferentialEvolution(object):
450
461
  def get_directory(self):
451
462
  # checking if the directory demo_folder2
452
463
  # exist or not.
453
- if not os.path.isdir(self.instance_number):
464
+ if not os.path.isdir(self.instance_name):
454
465
  # if the demo_folder2 directory is
455
466
  # not present then create it.
456
- os.makedirs(self.instance_number)
467
+ os.makedirs(self.instance_name)
457
468
 
458
469
  def get_instance_name(self):
459
- name = str(self.instance_number) + '/log.csv'
470
+ name = str(self.instance_name) + '/log.csv'
460
471
  return name
461
472
 
462
473
  def _random_selection(self, sln, i):
@@ -655,18 +666,18 @@ class DifferentialEvolution(object):
655
666
  self._population[j] = obj_trial
656
667
 
657
668
  logger(self.it_process, obj_trial, self._population, True,
658
- self.instance_number + '/population_logger_strict_non_pareto.csv', 1)
669
+ self.instance_name + '/population_logger_strict_non_pareto.csv', 1)
659
670
  logger(self.it_process, obj_trial, self._pareto_population, True,
660
- self.instance_number + '/population_logger_pareto.csv', 1)
671
+ self.instance_name + '/population_logger_pareto.csv', 1)
661
672
  else:
662
673
  if self.pf.calculate_difference(obj_trial, self._population[j]):
663
674
  iterations_without_improvement = 0
664
675
  self._population[j] = obj_trial
665
676
  self._pareto_population = self.pf.Pareto_F
666
677
  logger(self.it_process, obj_trial, self._population, True,
667
- self.instance_number + '/population_logger_strict_non_pareto.csv', 1)
678
+ self.instance_name + '/population_logger_strict_non_pareto.csv', 1)
668
679
  logger(self.it_process, obj_trial, self._pareto_population, True,
669
- self.instance_number + '/population_logger_pareto.csv', 1)
680
+ self.instance_name + '/population_logger_pareto.csv', 1)
670
681
 
671
682
  if it_best is None:
672
683
  it_best = obj_trial
@@ -811,7 +822,7 @@ class SimulatedAnnealing(object):
811
822
  self.temp_min = 0.05
812
823
  self._MAX_ITERATIONS = int(kwargs.get('MAX_ITERATIONS', 10000)) or int(kwargs.get('_max_iter', 10000))
813
824
 
814
- self.instance_number = str(objective_function.instance_number)
825
+ self.instance_name = str(objective_function.instance_name)
815
826
  self.accept = 0
816
827
  self.profiler = []
817
828
  self.update_t = self.cooling_linear_m
@@ -832,12 +843,12 @@ class SimulatedAnnealing(object):
832
843
  def get_directory(self):
833
844
  # checking if the directory demo_folder2
834
845
  # exist or not.
835
- if not os.path.isdir(self.instance_number):
846
+ if not os.path.isdir(self.instance_name):
836
847
  # not present then create it.
837
- os.makedirs(self.instance_number)
848
+ os.makedirs(self.instance_name)
838
849
 
839
850
  def get_instance_name(self):
840
- name = str(self.instance_number) + '/log.csv'
851
+ name = str(self.instance_name) + '/log.csv'
841
852
  return name
842
853
 
843
854
  def run(self, initial_slns=None, mod_init=None):
@@ -928,7 +939,7 @@ class SimulatedAnnealing(object):
928
939
  didchange = self.pf.did_it_change()
929
940
  if didchange:
930
941
  pareto_logger(self.pf.Pareto_F, iteration, self._obj_fun.complexity_level,
931
- self._obj_fun.instance_number)
942
+ self._obj_fun.instance_name)
932
943
  self._current_energy = nbr_energy
933
944
  self.current_struct = nbr_struct
934
945
  self.accept += 1
@@ -1273,7 +1284,7 @@ class HarmonySearch(object):
1273
1284
  self.F = kwargs.get('_AI', 2) # mutation scale
1274
1285
  self.iter = kwargs.get('_max_iter', 10000)
1275
1286
  self.cr = kwargs.get('_crossover_perc') or kwargs.get('_cr', 0.2)
1276
- self.instance_number = str(kwargs.get('instance_number', 1))
1287
+ self.instance_name = str(kwargs.get('instance_name', 1))
1277
1288
 
1278
1289
 
1279
1290
 
@@ -1284,7 +1295,7 @@ class HarmonySearch(object):
1284
1295
  # harmony_history stores all hms harmonies every nth improvisations (i.e., one 'generation')
1285
1296
  self._harmony_history = list()
1286
1297
  # saves the best fitness
1287
- self.instance_number = str(objective_function.instance_number)
1298
+ self.instance_name = str(objective_function.instance_name)
1288
1299
  self.get_directory()
1289
1300
  self._harmony_trace_best = list()
1290
1301
  self._harmony_trace_incumbent = list()
@@ -1304,13 +1315,13 @@ class HarmonySearch(object):
1304
1315
  def get_directory(self):
1305
1316
  # checking if the directory demo_folder2
1306
1317
  # exist or not.
1307
- if not os.path.isdir(self.instance_number):
1318
+ if not os.path.isdir(self.instance_name):
1308
1319
  # if the demo_folder2 directory is
1309
1320
  # not present then create it.
1310
- os.makedirs(self.instance_number)
1321
+ os.makedirs(self.instance_name)
1311
1322
 
1312
1323
  def get_instance_name(self):
1313
- name = str(self.instance_number) + '/log.csv'
1324
+ name = str(self.instance_name) + '/log.csv'
1314
1325
  return name
1315
1326
 
1316
1327
  def hard_mutate_index_and_value(self):
@@ -1421,7 +1432,7 @@ class HarmonySearch(object):
1421
1432
  1) # for consistency
1422
1433
  except Exception as e:
1423
1434
  print(e, 'logger run hs')
1424
- # logger(num_imp, fitness, self._pareto_harmony_memory, True, self.instance_number +'/log_for_pareto_harmony_memory.csv', 1)
1435
+ # logger(num_imp, fitness, self._pareto_harmony_memory, True, self.instance_name +'/log_for_pareto_harmony_memory.csv', 1)
1425
1436
 
1426
1437
 
1427
1438
  else:
@@ -1466,7 +1477,7 @@ class HarmonySearch(object):
1466
1477
 
1467
1478
  else:
1468
1479
  pareto_logger(self._pareto_harmony_memory, num_imp / self._obj_fun.get_hms(),
1469
- self._obj_fun.complexity_level, self._obj_fun.instance_number)
1480
+ self._obj_fun.complexity_level, self._obj_fun.instance_name)
1470
1481
  generation += 1
1471
1482
  iterations_without_improvement += 1
1472
1483
 
@@ -1904,7 +1915,7 @@ class Mutlithreaded_Meta(DifferentialEvolution, SimulatedAnnealing, HarmonySearc
1904
1915
  logger(num_imp, fitness, self._harmony_memory, True, self.get_instance_name(),
1905
1916
  1) # for consistency
1906
1917
  logger(num_imp, fitness, self._pareto_harmony_memory, True,
1907
- self.instance_number + '/log_for_pareto_harmony_memory.csv', 1)
1918
+ self.instance_name + '/log_for_pareto_harmony_memory.csv', 1)
1908
1919
 
1909
1920
 
1910
1921
  else:
@@ -1949,7 +1960,7 @@ class Mutlithreaded_Meta(DifferentialEvolution, SimulatedAnnealing, HarmonySearc
1949
1960
 
1950
1961
  else:
1951
1962
  pareto_logger(self._pareto_harmony_memory, num_imp / self._obj_fun.get_hms(),
1952
- self._obj_fun.complexity_level, self._obj_fun.instance_number)
1963
+ self._obj_fun.complexity_level, self._obj_fun.instance_name)
1953
1964
  generation += 1
1954
1965
  iterations_without_improvement += 1
1955
1966
 
@@ -2070,7 +2081,7 @@ class Mutlithreaded_Meta(DifferentialEvolution, SimulatedAnnealing, HarmonySearc
2070
2081
  didchange = self.pf.did_it_change()
2071
2082
  if didchange:
2072
2083
  pareto_logger(self.pf.Pareto_F, iteration, self._obj_fun.complexity_level,
2073
- self._obj_fun.instance_number)
2084
+ self._obj_fun.instance_name)
2074
2085
  current_energy[j] = nbr_energy
2075
2086
 
2076
2087
  self.accept += 1
@@ -2267,18 +2278,18 @@ class Mutlithreaded_Meta(DifferentialEvolution, SimulatedAnnealing, HarmonySearc
2267
2278
  self._population[j] = obj_trial
2268
2279
 
2269
2280
  logger(self.it_process, obj_trial, self._population, True,
2270
- self.instance_number + '/population_logger_strict_non_pareto.csv', 1)
2281
+ self.instance_name + '/population_logger_strict_non_pareto.csv', 1)
2271
2282
  logger(self.it_process, obj_trial, self._pareto_population, True,
2272
- self.instance_number + '/population_logger_pareto.csv', 1)
2283
+ self.instance_name + '/population_logger_pareto.csv', 1)
2273
2284
  else:
2274
2285
  if self.pf.calculate_difference(obj_trial, self._population[j]):
2275
2286
  iterations_without_improvement = 0
2276
2287
  self._population[j] = obj_trial
2277
2288
  self._pareto_population = self.pf.Pareto_F
2278
2289
  logger(self.it_process, obj_trial, self._population, True,
2279
- self.instance_number + '/population_logger_strict_non_pareto.csv', 1)
2290
+ self.instance_name + '/population_logger_strict_non_pareto.csv', 1)
2280
2291
  logger(self.it_process, obj_trial, self._pareto_population, True,
2281
- self.instance_number + '/population_logger_pareto.csv', 1)
2292
+ self.instance_name + '/population_logger_pareto.csv', 1)
2282
2293
 
2283
2294
  if it_best is None:
2284
2295
  it_best = obj_trial
@@ -212,19 +212,19 @@ class ObjectiveFunction(object):
212
212
  if 'complexity_level' in kwargs:
213
213
  self.complexity_level = kwargs['complexity_level']
214
214
 
215
- if 'instance_number' in kwargs:
216
- self.instance_number = str(kwargs['instance_number'])
215
+ if 'instance_name' in kwargs:
216
+ self.instance_name = str(kwargs['instance_name'])
217
217
  else:
218
218
 
219
219
  print('no name set, setting name as 0')
220
- self.instance_number = str(0) # set an arbitrary instance number
220
+ self.instance_name = f"run_{str(0)}" # set an arbitrary instance number
221
221
 
222
222
  if kwargs.get('save_directory', True):
223
223
  self.save_state = True
224
- if not os.path.exists(self.instance_number):
224
+ if not os.path.exists(self.instance_name):
225
225
  if kwargs.get('make_directory', True):
226
226
  print('Making a Directory, if you want to stop from storing the files to this directory set argumet: make_directory:False')
227
- os.makedirs(self.instance_number)
227
+ os.makedirs(self.instance_name)
228
228
  else:
229
229
  self.save_state = False
230
230
  if not hasattr(self, '_obj_1'):
@@ -257,7 +257,7 @@ class ObjectiveFunction(object):
257
257
  self.test_percentage = float(kwargs.get('test_percentage', 0))
258
258
  self.val_percentage = float(kwargs.get('val_percentage', 0))
259
259
  if self.test_percentage == 0:
260
- print('test percentage is 0, please enter arg test_percentage as decimal, eg 0.8')
260
+ print('test percentage is 0, please enter arg test_percentage as decimal if intended for multi objective optimisation, eg 0.8')
261
261
  print('continuing single objective')
262
262
  time.sleep(2)
263
263
  self.is_multi = False
@@ -296,6 +296,7 @@ class ObjectiveFunction(object):
296
296
  ids = np.random.choice(N, training_size, replace=False)
297
297
  id_unique = np.array([i for i in range(N)])
298
298
  ids = id_unique[ids]
299
+ #todo make sure its split so counts are split
299
300
  train_idx = [ii for ii in range(len(id_unique)) if id_unique[ii] in ids]
300
301
  test_idx = [ii for ii in range(len(id_unique)) if id_unique[ii] not in ids]
301
302
  df_train = x_data.loc[train_idx, :]
@@ -429,7 +430,7 @@ class ObjectiveFunction(object):
429
430
 
430
431
 
431
432
 
432
- self.Ndraws = kwargs.get('Ndraws', 100)
433
+ self.Ndraws = kwargs.get('Ndraws', 200)
433
434
  self.draws1 = None
434
435
  self.initial_sig = 1 # pass the test of a single model
435
436
  self.pvalue_sig_value = .1
@@ -455,7 +456,7 @@ class ObjectiveFunction(object):
455
456
  self._transformations = kwargs.get('_transformations', ["no", "log", "sqrt", "arcsinh", "nil"])
456
457
  # self._distribution = ['triangular', 'uniform', 'normal', 'ln_normal', 'tn_normal', 'lindley']
457
458
 
458
- self._distribution = kwargs.get('_distributions', ['triangular', 'uniform', 'normal', 'tn_normal'])
459
+ self._distribution = kwargs.get('_distributions', ['triangular', 'uniform', 'normal', 'tn_normal', 'ln_normal'])
459
460
 
460
461
  if self.G is not None:
461
462
  #TODO need to handle this for groups
@@ -484,12 +485,24 @@ class ObjectiveFunction(object):
484
485
  self._discrete_values = self._discrete_values + \
485
486
  self.define_distributions_analyst(extra=kwargs.get('decisions', None))
486
487
 
487
- if 'model_types' in kwargs:
488
- model_types = kwargs['model_types']
488
+ if 'model_types' in kwargs or 'Model' in kwargs:
489
+ model_type_mapping = {
490
+ 'POS': 0,
491
+ 'NB': 1
492
+ }
493
+ model_types = kwargs.get('model_types', kwargs.get('Model', [[0,1]]))
494
+ converted_model_types = [
495
+ [model_type_mapping.get(item, item) for item in sublist]
496
+ for sublist in model_types
497
+ ]
498
+ model_types = converted_model_types
499
+ #this should be a list of list like [[0, 1]]
500
+ # also if it is [['POS', 'NB']] then it will be converted to [0, 1]
489
501
  else:
490
502
 
491
503
 
492
504
  model_types = [[0, 1]] # add 2 for Generalized Poisson
505
+
493
506
  #model_types = [[0]]
494
507
 
495
508
  if self.linear_regression:
@@ -1250,10 +1263,10 @@ class ObjectiveFunction(object):
1250
1263
  caption = " ".join(caption_parts)
1251
1264
  # print(latextable.draw_latex(table, caption=caption, caption_above = True))
1252
1265
  if solution is None:
1253
- file_name = self.instance_number + "/sln" + \
1266
+ file_name = self.instance_name + "/sln" + \
1254
1267
  "_with_BIC_" + str(self.bic) + ".tex"
1255
1268
  else:
1256
- file_name = self.instance_number + "/sln" + \
1269
+ file_name = self.instance_name + "/sln" + \
1257
1270
  str(solution['sol_num']) + \
1258
1271
  "_with_BIC_" + str(self.bic) + ".tex"
1259
1272
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: metacountregressor
3
- Version: 1.0.4
3
+ Version: 1.0.6
4
4
  Summary: Extensive Testing for Estimation of Data Count Models
5
5
  Home-page: https://github.com/zahern/CountDataEstimation
6
6
  Author: Zeke Ahern
@@ -95,7 +95,7 @@ X['Offset'] = np.log(df['AADT']) # Explicitley define how to offset the data, no
95
95
  X = df.drop(columns=['FREQ', 'ID', 'AADT'])
96
96
 
97
97
  #some example argument, these are defualt so the following line is just for claritity. See the later agruments section for detials.
98
- arguments = {'algorithm': 'hs', 'test_percentage': 0.15, 'test_complexity': 6, 'instance_number':1,
98
+ arguments = {'algorithm': 'hs', 'test_percentage': 0.15, 'test_complexity': 6, 'instance_name':1,
99
99
  'val_percentage':0.15, 'obj_1': 'bic', '_obj_2': 'RMSE_TEST', "_max_time": 6}
100
100
  # Fit the model with metacountregressor
101
101
  obj_fun = ObjectiveFunction(X, y, **arguments)
@@ -135,9 +135,9 @@ arguments = {
135
135
  'test_percentage': 0.2, # used in multi-objective optimisation only. Saves 20% of data for testing.
136
136
  'val_percenetage:': 0.2, # Saves 20% of data for testing.
137
137
  'test_complexity': 6, # Complexity level for testing (6 tests all) or a list to consider potential differences in complexity
138
- 'instance_number': 'name', # used for creeating a named folder where your models are saved into from the directory
138
+ 'instance_name': 'name', # used for creeting a named folder where your models are saved into from the directory
139
139
  'distribution': ['Normal', 'LnNormal', 'Triangular', 'Uniform'],
140
- 'Model': [0,1], # or equivalently ['POS', 'NB']
140
+ 'model_types': [[0,1]], # or equivalently ['POS', 'NB']
141
141
  'transformations': ['no', 'sqrt', 'archsinh'],
142
142
  'method_ll': 'BFGS_2',
143
143
  '_max_time': 10
@@ -156,7 +156,7 @@ manual_fit_spec = {
156
156
  'fixed_terms': ['SINGLE', 'LENGTH'],
157
157
  'rdm_terms': ['AADT:normal'],
158
158
  'rdm_cor_terms': ['GRADEBR:normal', 'CURVES:normal'],
159
- 'grouped_terms': [],
159
+ 'grouped_rdm': [],
160
160
  'hetro_in_means': ['ACCESS:normal', 'MINRAD:normal'],
161
161
  'transformations': ['no', 'no', 'log', 'no', 'no', 'no', 'no'],
162
162
  'dispersion': 0
@@ -168,7 +168,7 @@ arguments = {
168
168
  'algorithm': 'hs',
169
169
  'test_percentage': 0.2,
170
170
  'test_complexity': 6,
171
- 'instance_number': 'name',
171
+ 'instance_name': 'name',
172
172
  'Manual_Fit': manual_fit_spec
173
173
  }
174
174
  obj_fun = ObjectiveFunction(X, y, **arguments)
@@ -268,25 +268,22 @@ The following list describes the arguments available in this function. By defaul
268
268
 
269
269
  2. **`distributions`**: This argument accepts a list of strings where each string corresponds to a distribution. Valid options include:
270
270
  - "Normal"
271
- - "Lindley"
272
271
  - "Uniform"
273
272
  - "LogNormal"
274
273
  - "Triangular"
275
- - "Gamma"
276
274
  - "TruncatedNormal"
277
275
  - Any of the above, concatenated with ":" (e.g., "Normal:grouped"; requires a grouping term defined in the model)
278
276
 
279
277
  3. **`Model`**: This argument specifies the model form. It can be a list of integers representing different models to test:
280
278
  - 0: Poisson
281
279
  - 1: Negative-Binomial
282
- - 2: Generalized-Poisson
283
280
 
284
281
  4. **`transformations`**: This argument accepts a list of strings representing available transformations within the framework. Valid options include:
285
282
  - "no"
286
283
  - "square-root"
287
284
  - "logarithmic"
288
285
  - "archsinh"
289
- - "as_factor"
286
+ - "nil"
290
287
 
291
288
  5. **`is_multi`**: This argument accepts an integer indicating whether single or multiple objectives are to be tested (0 for single, 1 for multiple).
292
289
 
@@ -320,9 +317,9 @@ arguments = {
320
317
  'val_percentage:': 0.2, # Saves 20% of data for testing.
321
318
  'test_complexity': 3, # For Very simple Models
322
319
  'obj_1': 'BIC', '_obj_2': 'RMSE_TEST',
323
- 'instance_number': 'hs_run', # used for creeating a named folder where your models are saved into from the directory
320
+ 'instance_name': 'hs_run', # used for creeating a named folder where your models are saved into from the directory
324
321
  'distribution': ['Normal'],
325
- 'Model': [0, 1], # or equivalently ['POS', 'NB']
322
+ 'model_types': [0, 1], # or equivalently ['POS', 'NB']
326
323
  'transformations': ['no', 'sqrt', 'archsinh'],
327
324
  '_max_time': 10000
328
325
  } '''Arguments for the solution algorithm'''
@@ -398,7 +395,7 @@ manual_fit_spec = {
398
395
  'fixed_terms': ['const','YEAR'],
399
396
  'rdm_terms': [],
400
397
  'rdm_cor_terms': [],
401
- 'grouped_terms': [],
398
+ 'grouped_rdm': [],
402
399
  'hetro_in_means': [],
403
400
  'transformations': ['no', 'no'],
404
401
  'dispersion': 1 #Negative Binomial
@@ -410,7 +407,7 @@ arguments = {
410
407
  'algorithm': 'hs',
411
408
  'test_percentage': 0,
412
409
  'test_complexity': 6,
413
- 'instance_number': 'name',
410
+ 'instance': 'name',
414
411
  'Manual_Fit': manual_fit_spec
415
412
  }
416
413
  obj_fun = ObjectiveFunction(data_exog, data_endog, **arguments)
@@ -0,0 +1 @@
1
+ 1.0.6
@@ -1 +0,0 @@
1
- 1.0.4