hdim-opt 1.2.2__tar.gz → 1.2.3__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.
- {hdim_opt-1.2.2 → hdim_opt-1.2.3}/PKG-INFO +1 -1
- {hdim_opt-1.2.2 → hdim_opt-1.2.3}/hdim_opt/__init__.py +1 -1
- {hdim_opt-1.2.2 → hdim_opt-1.2.3}/hdim_opt/quasar_optimization.py +18 -13
- {hdim_opt-1.2.2 → hdim_opt-1.2.3}/hdim_opt.egg-info/PKG-INFO +1 -1
- {hdim_opt-1.2.2 → hdim_opt-1.2.3}/pyproject.toml +1 -1
- {hdim_opt-1.2.2 → hdim_opt-1.2.3}/README.md +0 -0
- {hdim_opt-1.2.2 → hdim_opt-1.2.3}/hdim_opt/hyperellipsoid_sampling.py +0 -0
- {hdim_opt-1.2.2 → hdim_opt-1.2.3}/hdim_opt/quasar_helpers.py +0 -0
- {hdim_opt-1.2.2 → hdim_opt-1.2.3}/hdim_opt/sobol_sampling.py +0 -0
- {hdim_opt-1.2.2 → hdim_opt-1.2.3}/hdim_opt/sobol_sensitivity.py +0 -0
- {hdim_opt-1.2.2 → hdim_opt-1.2.3}/hdim_opt/test_functions.py +0 -0
- {hdim_opt-1.2.2 → hdim_opt-1.2.3}/hdim_opt.egg-info/SOURCES.txt +0 -0
- {hdim_opt-1.2.2 → hdim_opt-1.2.3}/hdim_opt.egg-info/dependency_links.txt +0 -0
- {hdim_opt-1.2.2 → hdim_opt-1.2.3}/hdim_opt.egg-info/requires.txt +0 -0
- {hdim_opt-1.2.2 → hdim_opt-1.2.3}/hdim_opt.egg-info/top_level.txt +0 -0
- {hdim_opt-1.2.2 → hdim_opt-1.2.3}/setup.cfg +0 -0
|
@@ -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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
|
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
|
|
@@ -6,7 +6,7 @@ build-backend = "setuptools.build_meta"
|
|
|
6
6
|
|
|
7
7
|
[project]
|
|
8
8
|
name = "hdim_opt"
|
|
9
|
-
version = "1.2.
|
|
9
|
+
version = "1.2.3" # match __version__ in __init__.py
|
|
10
10
|
description = "Optimization toolkit for high-dimensional, non-differentiable problems."
|
|
11
11
|
readme = {file = "README.md", content-type = "text/markdown"}
|
|
12
12
|
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|