hdim-opt 1.2.1__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.1 → hdim_opt-1.2.3}/PKG-INFO +1 -1
- {hdim_opt-1.2.1 → hdim_opt-1.2.3}/hdim_opt/__init__.py +1 -1
- {hdim_opt-1.2.1 → hdim_opt-1.2.3}/hdim_opt/quasar_optimization.py +23 -15
- {hdim_opt-1.2.1 → hdim_opt-1.2.3}/hdim_opt.egg-info/PKG-INFO +1 -1
- {hdim_opt-1.2.1 → hdim_opt-1.2.3}/pyproject.toml +1 -1
- {hdim_opt-1.2.1 → hdim_opt-1.2.3}/README.md +0 -0
- {hdim_opt-1.2.1 → hdim_opt-1.2.3}/hdim_opt/hyperellipsoid_sampling.py +0 -0
- {hdim_opt-1.2.1 → hdim_opt-1.2.3}/hdim_opt/quasar_helpers.py +0 -0
- {hdim_opt-1.2.1 → hdim_opt-1.2.3}/hdim_opt/sobol_sampling.py +0 -0
- {hdim_opt-1.2.1 → hdim_opt-1.2.3}/hdim_opt/sobol_sensitivity.py +0 -0
- {hdim_opt-1.2.1 → hdim_opt-1.2.3}/hdim_opt/test_functions.py +0 -0
- {hdim_opt-1.2.1 → hdim_opt-1.2.3}/hdim_opt.egg-info/SOURCES.txt +0 -0
- {hdim_opt-1.2.1 → hdim_opt-1.2.3}/hdim_opt.egg-info/dependency_links.txt +0 -0
- {hdim_opt-1.2.1 → hdim_opt-1.2.3}/hdim_opt.egg-info/requires.txt +0 -0
- {hdim_opt-1.2.1 → hdim_opt-1.2.3}/hdim_opt.egg-info/top_level.txt +0 -0
- {hdim_opt-1.2.1 → 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,20 +48,23 @@ 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:
|
|
62
|
+
initial_population = init.reshape(-1,1)
|
|
63
|
+
else:
|
|
64
|
+
initial_population = init
|
|
62
65
|
if verbose:
|
|
63
|
-
custom_popsize, custom_n_dimensions =
|
|
64
|
-
print(f'Initializing: Custom
|
|
66
|
+
custom_popsize, custom_n_dimensions = initial_population.shape
|
|
67
|
+
print(f'Initializing: Custom (N={custom_popsize}, D={custom_n_dimensions}).')
|
|
65
68
|
|
|
66
69
|
return initial_population
|
|
67
70
|
|
|
@@ -371,7 +374,7 @@ def optimize(func, bounds, args=(),
|
|
|
371
374
|
patience=np.inf, vectorized=False,
|
|
372
375
|
hds_weights=None, kwargs={},
|
|
373
376
|
constraints=None, constraint_penalty=1e9,
|
|
374
|
-
|
|
377
|
+
reinitialization_method='covariance',
|
|
375
378
|
verbose=True, plot_solutions=True, num_to_plot=10, plot_contour=True,
|
|
376
379
|
workers=1, seed=None
|
|
377
380
|
):
|
|
@@ -379,6 +382,7 @@ def optimize(func, bounds, args=(),
|
|
|
379
382
|
Objective:
|
|
380
383
|
- Finds the optimal solution for a given objective function.
|
|
381
384
|
- Designed for non-differentiable, high-dimensional problems.
|
|
385
|
+
- For explorative problems chance reinitialization_method to '
|
|
382
386
|
- Test functions available for local testing, called as hdim_opt.test_functions.function_name.
|
|
383
387
|
- Existing test functions: [rastrigin, ackley, sinusoid, sphere, shubert].
|
|
384
388
|
|
|
@@ -429,13 +433,11 @@ def optimize(func, bounds, args=(),
|
|
|
429
433
|
}
|
|
430
434
|
- constraint_penalty: Penalty applied to each constraint violated, defaults to 1e12.
|
|
431
435
|
|
|
432
|
-
- reinitialization: Boolean to disable covariance reinitialization if needed.
|
|
433
|
-
- For cases where the population size is computationally prohibitive.
|
|
434
|
-
- Disabled by default for 1D problems.
|
|
435
436
|
- reinitialization_method: Type of re-sampling to use in the asymptotic reinitialization.
|
|
436
437
|
- Options are ['covariance', 'sobol'].
|
|
437
438
|
- 'covariance' (exploitative) is default for most problems.
|
|
438
439
|
- 'sobol' (explorative) is optional, for high exploration and faster computation.
|
|
440
|
+
- None to disable reinitialization calculations.
|
|
439
441
|
|
|
440
442
|
- verbose: Displays prints and plots.
|
|
441
443
|
- Mutation factor distribution shown with hdim_opt.test_functions.plot_mutations()
|
|
@@ -505,9 +507,11 @@ def optimize(func, bounds, args=(),
|
|
|
505
507
|
if not isinstance(init, str):
|
|
506
508
|
popsize = init.shape[0]
|
|
507
509
|
|
|
508
|
-
# default popsize to 10*n_dimensions
|
|
510
|
+
# default popsize to highest power of 2 from 10*n_dimensions
|
|
509
511
|
if popsize == None:
|
|
510
|
-
|
|
512
|
+
min_popsize = 2**7
|
|
513
|
+
default_popsize = int(2**np.ceil(np.log2(10*n_dimensions)))
|
|
514
|
+
popsize = max(min_popsize, default_popsize)
|
|
511
515
|
|
|
512
516
|
# ensure integers
|
|
513
517
|
popsize, maxiter = int(popsize), int(maxiter)
|
|
@@ -533,7 +537,11 @@ def optimize(func, bounds, args=(),
|
|
|
533
537
|
# generate initial population
|
|
534
538
|
initial_population = initialize_population(popsize, bounds, init, hds_weights, seed, verbose)
|
|
535
539
|
if verbose:
|
|
536
|
-
|
|
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}):')
|
|
537
545
|
|
|
538
546
|
# match differential evolution conventions
|
|
539
547
|
if vectorized:
|
|
@@ -640,7 +648,7 @@ def optimize(func, bounds, args=(),
|
|
|
640
648
|
# apply asymptotic covariance reinitialization to population
|
|
641
649
|
final_proba = 0.33
|
|
642
650
|
decay_generation = 0.33
|
|
643
|
-
if
|
|
651
|
+
if reinitialization_method in ['sobol','covariance']:
|
|
644
652
|
reinit_proba = np.e**((np.log(final_proba)/(decay_generation*maxiter))*generation)
|
|
645
653
|
else:
|
|
646
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
|