metacountregressor 0.1.34__py3-none-any.whl → 0.1.35__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.
@@ -18,9 +18,9 @@ import pandas as pd
18
18
  import helperprocess
19
19
  print('loaded helper')
20
20
 
21
- from metaheuristics import (differential_evolution_non_mp,
22
- harmony_search_non_mp,
23
- simulated_annealing_non_mp)
21
+ from metaheuristics import (differential_evolution,
22
+ harmony_search,
23
+ simulated_annealing)
24
24
  print('loaded algorithnms')
25
25
  from solution import ObjectiveFunction
26
26
  print('loaded solution')
@@ -299,7 +299,7 @@ def main(args):
299
299
  'transformations': ['no', 'no', 'no', 'no'],
300
300
  'dispersion': 0
301
301
  }
302
- manual_fit_spec = None
302
+ #manual_fit_spec = None
303
303
 
304
304
 
305
305
  elif dataset == 8:
@@ -418,7 +418,7 @@ def main(args):
418
418
 
419
419
  # results = simulated_annealing(obj_fun, 1, 1, None, arguments_hyperparamaters)
420
420
 
421
- results = simulated_annealing_non_mp(obj_fun, None, **arguments_hyperparamaters)
421
+ results = simulated_annealing(obj_fun, None, **arguments_hyperparamaters)
422
422
  helperprocess.results_printer(results, arguments['algorithm'], int(arguments['is_multi']))
423
423
  if dual_complexities:
424
424
  arguments['complexity_level'] = secondary_complexity
@@ -426,7 +426,7 @@ def main(args):
426
426
 
427
427
  #results = simulated_annealing(obj_fun, 1, 1, None, arguments_hyperparamaters)
428
428
 
429
- results = simulated_annealing_non_mp(obj_fun, None, **arguments_hyperparamaters)
429
+ results = simulated_annealing(obj_fun, None, **arguments_hyperparamaters)
430
430
  helperprocess.results_printer(results, arguments['algorithm'], int(arguments['is_multi']))
431
431
 
432
432
  elif arguments['algorithm'] == 'hs':
@@ -435,7 +435,7 @@ def main(args):
435
435
  arguments_hyperparamaters = {
436
436
  'Manual_Fit': arguments['Manual_Fit']}
437
437
 
438
- results = harmony_search_non_mp(obj_fun, None, **arguments_hyperparamaters)
438
+ results = harmony_search(obj_fun, None, **arguments_hyperparamaters)
439
439
  helperprocess.results_printer(results, arguments['algorithm'], int(arguments['is_multi']))
440
440
 
441
441
  if dual_complexities:
@@ -444,12 +444,12 @@ def main(args):
444
444
  #if multi_threaded:
445
445
  # results = harmony_search(obj_fun, 1, 1, None)
446
446
  #else:
447
- results = harmony_search_non_mp(obj_fun, None, **arguments_hyperparamaters)
447
+ results = harmony_search(obj_fun, None, **arguments_hyperparamaters)
448
448
  helperprocess.results_printer(results, arguments['algorithm'], int(arguments['is_multi']))
449
449
 
450
450
 
451
451
  elif arguments['algorithm'] =='de':
452
- arguments_hyperparamaters = {'_AI': 1,
452
+ arguments_hyperparamaters = {'_AI': 2,
453
453
  '_crossover_perc': float(arguments['crossover']),
454
454
  '_max_iter': int(arguments['_max_imp'])
455
455
  ,'_pop_size': int(arguments['_hms']), 'instance_number': int(args['line'])
@@ -461,7 +461,7 @@ def main(args):
461
461
 
462
462
  # results = differential_evolution(obj_fun, 1, 1, None, **arguments_hyperparamaters)
463
463
  # else:
464
- results = differential_evolution_non_mp(obj_fun, None, **arguments_hyperparamaters)
464
+ results = differential_evolution(obj_fun, None, **arguments_hyperparamaters)
465
465
 
466
466
  helperprocess.results_printer(results, arguments['algorithm'], int(arguments['is_multi']))
467
467
  if dual_complexities:
@@ -472,7 +472,7 @@ def main(args):
472
472
  # results = differential_evolution(obj_fun, 1, 1, None, **arguments_hyperparamaters)
473
473
 
474
474
 
475
- results = differential_evolution_non_mp(obj_fun, None, **arguments_hyperparamaters)
475
+ results = differential_evolution(obj_fun, None, **arguments_hyperparamaters)
476
476
 
477
477
  helperprocess.results_printer(results, arguments['algorithm'], int(arguments['is_multi']))
478
478
 
@@ -216,7 +216,7 @@ def different_evolution(objective_function, initital_slns=None, **kwargs):
216
216
  _plot(x, y, z, 'Iterations', 'Incumbent', 'Best')
217
217
  return results
218
218
 
219
- def differential_evolution_non_mp(objective_function, initial_slns=None, **kwargs):
219
+ def differential_evolution(objective_function, initial_slns=None, **kwargs):
220
220
  if not isinstance(objective_function, ObjectiveFunction):
221
221
  raise Exception
222
222
  start = datetime.now()
@@ -321,7 +321,7 @@ def differential_evolution(objective_function, num_processes, num_iterations, in
321
321
 
322
322
  """
323
323
 
324
- def simulated_annealing_non_mp(objective_function, initial_slns =None, **kwargs):
324
+ def simulated_annealing(objective_function, initial_slns =None, **kwargs):
325
325
  #if hyperparameters is None:
326
326
  # TEMP_ALPHA = 0.99; MAX_STEPS = 10; INTL_ACCEPT = 0.5; STEPS = 20; SWAP_PERC = 0.2; NUM_INTL_SLNS = 25; IS_MULTI = 0
327
327
  #else:
@@ -388,7 +388,7 @@ def simulated_annealing(objective_function, num_processes, num_iterations, initi
388
388
 
389
389
  """
390
390
 
391
- def harmony_search_non_mp(objective_function, initial_harmonies = None, hyperparameters = None, **kwargs):
391
+ def harmony_search(objective_function, initial_harmonies = None, hyperparameters = None, **kwargs):
392
392
  """ Worker for hamony search, 1 cpu process
393
393
 
394
394
  Args:
@@ -524,6 +524,12 @@ class Metaheuristic(object):
524
524
  self._obj_fun = objective_function
525
525
  self._num_intl_slns = 10
526
526
  self._sa_memory = list()
527
+
528
+ self._pop_size = kwargs.get('_pop_size', 20)
529
+ self.F = kwargs['_AI'] # mustation scale
530
+ self.iter = kwargs.get('_max_iter', 10000)
531
+ self.cr = kwargs.get('_crossover_perc') or kwargs.get('_cr', 0.2)
532
+ self.instance_number = str(kwargs.get('instance_number',1))
527
533
  if objective_function.is_multi:
528
534
 
529
535
 
@@ -625,11 +631,11 @@ class DifferentialEvolution(object):
625
631
  if self._obj_fun._obj_1 is None:
626
632
  raise Exception
627
633
 
628
- self._pop_size = kwargs['_pop_size']
629
- self.F = kwargs['_AI'] # mustation scale
630
- self.iter = kwargs['_max_iter']
631
- self.cr = kwargs['_crossover_perc']
632
- self.instance_number = str(kwargs['instance_number'])
634
+ self._pop_size = kwargs.get('_pop_size', 20)
635
+ self.F = kwargs.get('_AI', 2) # mustation scale
636
+ self.iter = kwargs.get('_max_iter', 10000)
637
+ self.cr = kwargs.get('_crossover_perc') or kwargs.get('_cr', 0.2)
638
+ self.instance_number = str(kwargs.get('instance_number',1))
633
639
  self.get_direcotory()
634
640
 
635
641
  self._population = list()
@@ -719,7 +725,7 @@ class DifferentialEvolution(object):
719
725
  current_index = self._obj_fun.get_index(i, struct_a[i])
720
726
  new_index = current_index + self.F*(self._obj_fun.get_index(i, struct_b[i]) - self._obj_fun.get_index(i, struct_c[i]))
721
727
  except Exception as e:
722
- print(e, 'Exception here')
728
+ print(e, 'Exception here, with the mutation why??')
723
729
  print(struct_a)
724
730
  print(struct_b)
725
731
  print(struct_c)
@@ -757,6 +763,7 @@ class DifferentialEvolution(object):
757
763
  repeats = 0
758
764
  # generate trial vector by binomial crossover
759
765
  unique = True
766
+ trial = target
760
767
  cr = cr_r
761
768
  while unique:
762
769
  p = np.random.rand(dims)
@@ -846,7 +853,8 @@ class DifferentialEvolution(object):
846
853
 
847
854
  i += 1
848
855
  if self.pf.get_objective_is_multi():
849
- self._pareto_population = self.pf.check_if_dominance(self._pareto_population, obj_trial)
856
+ is_updated, self._pareto_population = self.pf.check_if_dominance(self._pareto_population, obj_trial, 1)
857
+
850
858
  if len(self._pareto_population) ==1:
851
859
  print('the size of the population is only 1')
852
860
  if self.pf.check_dominance([obj_trial[self.pf.obj_key_1], obj_trial[self.pf.obj_key_2]], [self._population[j][self.pf.obj_key_1], self._population[j][self.pf.obj_key_2]]):#if solution dominates existing #FIXME some error here true but not entering
@@ -1023,17 +1031,17 @@ class SimulatedAnnealing(object):
1023
1031
  self.current_struct = None
1024
1032
  self.temp_max = 1000000
1025
1033
  self.temp_min = 0.05
1026
- self.MAX_ITERATIONS = int(kwargs['MAX_ITERATIONS'])
1027
- self.STEPS_PER_TEMP = int(kwargs['STEPS_PER_TEMP'])
1028
- self.INTL_ACPT = float(kwargs['INTL_ACPT'])
1029
- self._num_intl_slns = int(kwargs['_num_intl_slns'])
1030
- self.alpha = float(kwargs['alpha'])
1034
+ self.MAX_ITERATIONS = int(kwargs.get('MAX_ITERATIONS', 10000)) or int(kwargs.get('_max_iter', 10000))
1035
+ self.STEPS_PER_TEMP = int(kwargs.get('STEPS_PER_TEMP', 2)) or int(kwargs.get('_ts', 2))
1036
+ self.INTL_ACPT = float(kwargs.get('INTL_ACPT', 0.5))
1037
+ self._num_intl_slns = int(kwargs.get('_num_intl_slns', 20))
1038
+ self.alpha = float(kwargs.get('alpha', 0.95))
1031
1039
  self.instance_number = str(objective_function.instance_number)
1032
1040
  self.accept = 0
1033
1041
  self.profiler = []
1034
1042
  self.update_t = self.cooling_linear_m
1035
1043
  self.get_direcotory()
1036
- self._crossover_perc = float(kwargs['_crossover_perc'])
1044
+ self._crossover_perc = float(kwargs.get('_crossover_perc', 0.2)) or float(kwargs.get('_cr', 0.2))
1037
1045
  if objective_function.is_multi: #TODO Define more specific objectives in the intialiser
1038
1046
  self.obj_1 = objective_function._obj_1
1039
1047
  self.obj_2 = objective_function._obj_2
@@ -1300,7 +1308,7 @@ class SimulatedAnnealing(object):
1300
1308
 
1301
1309
 
1302
1310
  if num_of_changeablePARMs==0:
1303
- print('fuck line 631')
1311
+ print('check this line in particular 631')
1304
1312
  return neighbour
1305
1313
  def _initialize(self, initial_slns=None, model_nature = None):
1306
1314
  """
@@ -15,6 +15,7 @@ class Solution(dict):
15
15
  self['aic'] = 10000000.0
16
16
  self['bic'] = 10000000.0
17
17
  self['MAE'] = 10000000.0
18
+ self['MSE'] = 10000000.0
18
19
  self['layout'] = None
19
20
  self['sol_num'] = Solution.sol_counter
20
21
  self['num_parm'] = 1000
@@ -37,8 +38,10 @@ class Solution(dict):
37
38
  if MAE is not None:
38
39
  if MAE < 10000000:
39
40
  self['MAE'] = MAE
41
+ self['MSE'] = MAE
40
42
  else:
41
43
  self['MAE'] = 10000000
44
+ self['MSE'] = 10000000
42
45
  if loglik is not None:
43
46
  self['loglik'] = loglik
44
47
  if aic is not None:
@@ -148,7 +151,7 @@ class Pareto(object):
148
151
  self.run()
149
152
  return
150
153
 
151
- def check_if_dominance(self, Structs, New_Struct):
154
+ def check_if_dominance(self, Structs, New_Struct, return_struct = 0):
152
155
  """
153
156
  Funtion for non-dominant for newly proposed sln
154
157
  ni - the number of solutions which dominate the solution i
@@ -162,10 +165,13 @@ class Pareto(object):
162
165
 
163
166
  val_key_1 = self.obj_key_1
164
167
  val_key_2 = self.obj_key_2
165
-
168
+ dominance = False
166
169
  if len(Structs) == 0:
167
170
  Structs.append(New_Struct)
168
- return Structs
171
+ if return_struct:
172
+ return True, Structs
173
+ else:
174
+ return True
169
175
 
170
176
  if isinstance(Structs, list):
171
177
 
@@ -177,7 +183,7 @@ class Pareto(object):
177
183
  if dominance:
178
184
 
179
185
  Structs.append(New_Struct)
180
- Structs = self.pareto_run(Structs)
186
+ Structs = self.pareto_run(Structs, True)
181
187
  print('new solution, pareto optimal')
182
188
  break
183
189
  elif self.minimise_1 and not self.minimise_2: # minimise 1 and maximise 2
@@ -186,7 +192,7 @@ class Pareto(object):
186
192
  if dominance:
187
193
 
188
194
  Structs.append(New_Struct)
189
- Structs = self.pareto_run(Structs)
195
+ Structs = self.pareto_run(Structs, True)
190
196
  print('new solution, pareto optimal')
191
197
  break
192
198
  elif not self.minimise_1 and self.minimise_2: # maximise 1 and minise 2
@@ -195,7 +201,7 @@ class Pareto(object):
195
201
  if dominance:
196
202
 
197
203
  Structs.append(New_Struct)
198
- Structs = self.pareto_run(Structs)
204
+ Structs = self.pareto_run(Structs, True)
199
205
  print('new solution, pareto optimal')
200
206
  break
201
207
 
@@ -205,11 +211,14 @@ class Pareto(object):
205
211
  if dominance:
206
212
 
207
213
  Structs.append(New_Struct)
208
- Structs = self.pareto_run(Structs)
214
+ Structs = self.pareto_run(Structs, True)
209
215
  print('new solution, pareto optimal')
210
216
  break
211
-
212
- return Structs
217
+ if return_struct:
218
+ return dominance, Structs
219
+ else:
220
+ return dominance
221
+
213
222
  else:
214
223
  print('not a list')
215
224
  if self.minimise_2:
@@ -244,7 +253,10 @@ class Pareto(object):
244
253
  Structs.append(New_Struct)
245
254
  Structs = self.pareto_run(Structs)
246
255
  print('new solution, pareto optimal')
247
- return Structs
256
+ if return_struct:
257
+ return dominance, Structs
258
+ else:
259
+ return dominance
248
260
 
249
261
  def get_fronts(self, Struct) -> dict: # TODO get rid of HM
250
262
  """