hdim-opt 1.2.2__py3-none-any.whl → 1.2.3__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.
hdim_opt/__init__.py CHANGED
@@ -1,7 +1,7 @@
1
1
  # hdim_opt/__init__.py
2
2
 
3
3
  # package version
4
- __version__ = "1.2.2"
4
+ __version__ = "1.2.3"
5
5
  __all__ = ['quasar', 'hds', 'sobol', 'sensitivity', 'test_functions', 'quasar_helpers'] # available for star imports
6
6
 
7
7
  # import core components
@@ -32,14 +32,14 @@ def initialize_population(popsize, bounds, init, hds_weights, seed, verbose):
32
32
 
33
33
  # generate samples
34
34
  if verbose:
35
- print(f'Initializing: Hyperellipsoid population (N={popsize}, D={n_dimensions}).')
35
+ print(f'Initializing: Hyperellipsoid pop. (N={popsize}, D={n_dimensions}).')
36
36
  initial_population = hds.sample(popsize, bounds, weights=hds_weights,
37
37
  seed=seed, verbose=False)
38
38
 
39
39
  # generate sobol sequence
40
40
  elif init == 'sobol':
41
41
  if verbose:
42
- print(f'Initializing: Sobol population (N={popsize}, D={n_dimensions}).')
42
+ print(f'Initializing: Sobol (N={popsize}, D={n_dimensions}).')
43
43
  import warnings
44
44
  warnings.filterwarnings('ignore', category=UserWarning) # ignore power-of-2 warning
45
45
  sobol_sampler = stats.qmc.Sobol(d=n_dimensions, seed=seed)
@@ -48,14 +48,14 @@ def initialize_population(popsize, bounds, init, hds_weights, seed, verbose):
48
48
 
49
49
  elif (init == 'lhs') or (init == 'latinhypercube'):
50
50
  if verbose:
51
- print(f'Initializing: Latin Hypercube population (N={popsize}, D={n_dimensions}).')
51
+ print(f'Initializing: Latin Hypercube (N={popsize}, D={n_dimensions}).')
52
52
  lhs_sampler = stats.qmc.LatinHypercube(d=n_dimensions, seed=seed)
53
53
  lhs_samples_unit = lhs_sampler.random(n=popsize)
54
54
  initial_population = stats.qmc.scale(lhs_samples_unit, bounds[:, 0], bounds[:, 1])
55
55
 
56
56
  elif init == 'random':
57
57
  if verbose:
58
- print(f'Initializing: Random population (N={popsize}, D={n_dimensions}).')
58
+ print(f'Initializing: Random (N={popsize}, D={n_dimensions}).')
59
59
  initial_population = np.random.uniform(low=bounds[:, 0], high=bounds[:, 1], size=(popsize, n_dimensions))
60
60
  else:
61
61
  if init.ndim == 1:
@@ -64,7 +64,7 @@ def initialize_population(popsize, bounds, init, hds_weights, seed, verbose):
64
64
  initial_population = init
65
65
  if verbose:
66
66
  custom_popsize, custom_n_dimensions = initial_population.shape
67
- print(f'Initializing: Custom population (N={custom_popsize}, D={custom_n_dimensions}).')
67
+ print(f'Initializing: Custom (N={custom_popsize}, D={custom_n_dimensions}).')
68
68
 
69
69
  return initial_population
70
70
 
@@ -374,7 +374,7 @@ def optimize(func, bounds, args=(),
374
374
  patience=np.inf, vectorized=False,
375
375
  hds_weights=None, kwargs={},
376
376
  constraints=None, constraint_penalty=1e9,
377
- reinitialization=True, reinitialization_method='covariance',
377
+ reinitialization_method='covariance',
378
378
  verbose=True, plot_solutions=True, num_to_plot=10, plot_contour=True,
379
379
  workers=1, seed=None
380
380
  ):
@@ -382,6 +382,7 @@ def optimize(func, bounds, args=(),
382
382
  Objective:
383
383
  - Finds the optimal solution for a given objective function.
384
384
  - Designed for non-differentiable, high-dimensional problems.
385
+ - For explorative problems chance reinitialization_method to '
385
386
  - Test functions available for local testing, called as hdim_opt.test_functions.function_name.
386
387
  - Existing test functions: [rastrigin, ackley, sinusoid, sphere, shubert].
387
388
 
@@ -432,13 +433,11 @@ def optimize(func, bounds, args=(),
432
433
  }
433
434
  - constraint_penalty: Penalty applied to each constraint violated, defaults to 1e12.
434
435
 
435
- - reinitialization: Boolean to disable covariance reinitialization if needed.
436
- - For cases where the population size is computationally prohibitive.
437
- - Disabled by default for 1D problems.
438
436
  - reinitialization_method: Type of re-sampling to use in the asymptotic reinitialization.
439
437
  - Options are ['covariance', 'sobol'].
440
438
  - 'covariance' (exploitative) is default for most problems.
441
439
  - 'sobol' (explorative) is optional, for high exploration and faster computation.
440
+ - None to disable reinitialization calculations.
442
441
 
443
442
  - verbose: Displays prints and plots.
444
443
  - Mutation factor distribution shown with hdim_opt.test_functions.plot_mutations()
@@ -508,9 +507,11 @@ def optimize(func, bounds, args=(),
508
507
  if not isinstance(init, str):
509
508
  popsize = init.shape[0]
510
509
 
511
- # default popsize to 10*n_dimensions
510
+ # default popsize to highest power of 2 from 10*n_dimensions
512
511
  if popsize == None:
513
- popsize = min(2**7,10*n_dimensions)
512
+ min_popsize = 2**7
513
+ default_popsize = int(2**np.ceil(np.log2(10*n_dimensions)))
514
+ popsize = max(min_popsize, default_popsize)
514
515
 
515
516
  # ensure integers
516
517
  popsize, maxiter = int(popsize), int(maxiter)
@@ -536,7 +537,11 @@ def optimize(func, bounds, args=(),
536
537
  # generate initial population
537
538
  initial_population = initialize_population(popsize, bounds, init, hds_weights, seed, verbose)
538
539
  if verbose:
539
- print('\nEvolving population:')
540
+ if reinitialization_method not in ['sobol', 'covariance', None]:
541
+ print("reinitialization_method must be one of ['covariance', 'sobol', None].")
542
+ print(f'\nEvolving (None):')
543
+ else:
544
+ print(f'\nEvolving ({reinitialization_method}):')
540
545
 
541
546
  # match differential evolution conventions
542
547
  if vectorized:
@@ -643,7 +648,7 @@ def optimize(func, bounds, args=(),
643
648
  # apply asymptotic covariance reinitialization to population
644
649
  final_proba = 0.33
645
650
  decay_generation = 0.33
646
- if reinitialization:
651
+ if reinitialization_method in ['sobol','covariance']:
647
652
  reinit_proba = np.e**((np.log(final_proba)/(decay_generation*maxiter))*generation)
648
653
  else:
649
654
  reinit_proba = 0.0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: hdim_opt
3
- Version: 1.2.2
3
+ Version: 1.2.3
4
4
  Summary: Optimization toolkit for high-dimensional, non-differentiable problems.
5
5
  Author-email: Julian Soltes <jsoltes@regis.edu>
6
6
  License: MIT
@@ -1,11 +1,11 @@
1
- hdim_opt/__init__.py,sha256=eGhYIxj6AUhhlfqgAHtPQdul64gYYLaWl8esUs-vkgI,477
1
+ hdim_opt/__init__.py,sha256=ydO-uyV2qPK9pRTUJXKmmiQ-aUjleHpptXQG1SabgfA,477
2
2
  hdim_opt/hyperellipsoid_sampling.py,sha256=c34JkVciZbdAXjdfNjfC4h5NsrT2CD7Epsxpef5a1xY,24625
3
3
  hdim_opt/quasar_helpers.py,sha256=zTgar2EuWs4MLSLEO7HRcP7At1xbXLP3q4Gg7-GrggQ,14799
4
- hdim_opt/quasar_optimization.py,sha256=cSF_aOijVhdtvr7VEBUNVyBQ1--1s8cOuWZMuPogf5A,32093
4
+ hdim_opt/quasar_optimization.py,sha256=6OSjh49MyHzxK1UY9YIgQ2a45VOAqNQLG7cccisFWxM,32334
5
5
  hdim_opt/sobol_sampling.py,sha256=Xe_Zzs13xMxCben17gT85lFsoV-GKVOAAgi7lMxnlBI,912
6
6
  hdim_opt/sobol_sensitivity.py,sha256=1ebeDSTmcLn03_MKDGiyJJ7r_ZSNCq2AKNcTX-hI23A,4384
7
7
  hdim_opt/test_functions.py,sha256=RqjKYIiwAqWplGUsH4oPHLBrVdnLRyw7f0dJX5iyJ4g,2821
8
- hdim_opt-1.2.2.dist-info/METADATA,sha256=jId-zu3VAQTuQFgwlSQqKTgnCtwbORXuLbqsCVbSvA4,3130
9
- hdim_opt-1.2.2.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
10
- hdim_opt-1.2.2.dist-info/top_level.txt,sha256=1KtWo9tEfEK3GC8D43cwVsC8yVG2Kc-9pl0hhcDjw4o,9
11
- hdim_opt-1.2.2.dist-info/RECORD,,
8
+ hdim_opt-1.2.3.dist-info/METADATA,sha256=enzCv-miFQOJvCVtw9mdE1JKXq1FU7s-HO6AGNVZffQ,3130
9
+ hdim_opt-1.2.3.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
10
+ hdim_opt-1.2.3.dist-info/top_level.txt,sha256=1KtWo9tEfEK3GC8D43cwVsC8yVG2Kc-9pl0hhcDjw4o,9
11
+ hdim_opt-1.2.3.dist-info/RECORD,,