UQPyL 2.0.4__tar.gz → 2.0.5__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.
- {UQPyL-2.0.4 → UQPyL-2.0.5}/PKG-INFO +1 -1
- UQPyL-2.0.5/UQPyL/DoE/lhs.py +215 -0
- {UQPyL-2.0.4 → UQPyL-2.0.5}/UQPyL/__init__.py +1 -1
- {UQPyL-2.0.4 → UQPyL-2.0.5}/UQPyL/optimization/asmo.py +1 -1
- {UQPyL-2.0.4 → UQPyL-2.0.5}/UQPyL/problems/single_Benchmarks.py +56 -28
- {UQPyL-2.0.4 → UQPyL-2.0.5}/UQPyL/sensibility/fast.py +1 -1
- {UQPyL-2.0.4 → UQPyL-2.0.5}/UQPyL/sensibility/morris.py +1 -1
- {UQPyL-2.0.4 → UQPyL-2.0.5}/UQPyL/surrogates/gaussian_process.py +3 -3
- {UQPyL-2.0.4 → UQPyL-2.0.5}/UQPyL/surrogates/kriging.py +3 -3
- {UQPyL-2.0.4 → UQPyL-2.0.5}/UQPyL/utility/__init__.py +2 -2
- {UQPyL-2.0.4 → UQPyL-2.0.5}/UQPyL/utility/grid_search.py +3 -3
- {UQPyL-2.0.4 → UQPyL-2.0.5}/UQPyL/utility/metrics.py +2 -3
- {UQPyL-2.0.4 → UQPyL-2.0.5}/UQPyL.egg-info/PKG-INFO +1 -1
- {UQPyL-2.0.4 → UQPyL-2.0.5}/UQPyL.egg-info/SOURCES.txt +0 -1
- {UQPyL-2.0.4 → UQPyL-2.0.5}/pyproject.toml +1 -1
- {UQPyL-2.0.4 → UQPyL-2.0.5}/setup.py +1 -1
- UQPyL-2.0.4/UQPyL/DoE/_lhs.py +0 -90
- UQPyL-2.0.4/UQPyL/DoE/lhs.py +0 -73
- {UQPyL-2.0.4 → UQPyL-2.0.5}/LICENSE.md +0 -0
- {UQPyL-2.0.4 → UQPyL-2.0.5}/README.md +0 -0
- {UQPyL-2.0.4 → UQPyL-2.0.5}/UQPyL/DoE/__init__.py +0 -0
- {UQPyL-2.0.4 → UQPyL-2.0.5}/UQPyL/DoE/fast_sequence.py +0 -0
- {UQPyL-2.0.4 → UQPyL-2.0.5}/UQPyL/DoE/full_fact.py +0 -0
- {UQPyL-2.0.4 → UQPyL-2.0.5}/UQPyL/DoE/morris_sequence.py +0 -0
- {UQPyL-2.0.4 → UQPyL-2.0.5}/UQPyL/DoE/random.py +0 -0
- {UQPyL-2.0.4 → UQPyL-2.0.5}/UQPyL/DoE/sampler_ABC.py +0 -0
- {UQPyL-2.0.4 → UQPyL-2.0.5}/UQPyL/DoE/sobol_sequence.py +0 -0
- {UQPyL-2.0.4 → UQPyL-2.0.5}/UQPyL/optimization/__init__.py +0 -0
- {UQPyL-2.0.4 → UQPyL-2.0.5}/UQPyL/optimization/_binary_ga.py +0 -0
- {UQPyL-2.0.4 → UQPyL-2.0.5}/UQPyL/optimization/adam.py +0 -0
- {UQPyL-2.0.4 → UQPyL-2.0.5}/UQPyL/optimization/boxmin.py +0 -0
- {UQPyL-2.0.4 → UQPyL-2.0.5}/UQPyL/optimization/ga.py +0 -0
- {UQPyL-2.0.4 → UQPyL-2.0.5}/UQPyL/optimization/mo_asmo.py +0 -0
- {UQPyL-2.0.4 → UQPyL-2.0.5}/UQPyL/optimization/moea_d.py +0 -0
- {UQPyL-2.0.4 → UQPyL-2.0.5}/UQPyL/optimization/nsga_ii.py +0 -0
- {UQPyL-2.0.4 → UQPyL-2.0.5}/UQPyL/optimization/pso.py +0 -0
- {UQPyL-2.0.4 → UQPyL-2.0.5}/UQPyL/optimization/sce_ua.py +0 -0
- {UQPyL-2.0.4 → UQPyL-2.0.5}/UQPyL/optimization/utility_functions/_NDsort.py +0 -0
- {UQPyL-2.0.4 → UQPyL-2.0.5}/UQPyL/optimization/utility_functions/__init__.py +0 -0
- {UQPyL-2.0.4 → UQPyL-2.0.5}/UQPyL/optimization/utility_functions/_uniformPoint.py +0 -0
- {UQPyL-2.0.4 → UQPyL-2.0.5}/UQPyL/problems/__init__.py +0 -0
- {UQPyL-2.0.4 → UQPyL-2.0.5}/UQPyL/problems/multi_DTLZ.py +0 -0
- {UQPyL-2.0.4 → UQPyL-2.0.5}/UQPyL/problems/multi_ZDT.py +0 -0
- {UQPyL-2.0.4 → UQPyL-2.0.5}/UQPyL/problems/pratical_problem.py +0 -0
- {UQPyL-2.0.4 → UQPyL-2.0.5}/UQPyL/problems/problem_ABC.py +0 -0
- {UQPyL-2.0.4 → UQPyL-2.0.5}/UQPyL/problems/utility_functions/_NDsort.py +0 -0
- {UQPyL-2.0.4 → UQPyL-2.0.5}/UQPyL/problems/utility_functions/__init__.py +0 -0
- {UQPyL-2.0.4 → UQPyL-2.0.5}/UQPyL/problems/utility_functions/_uniformPoint.py +0 -0
- {UQPyL-2.0.4 → UQPyL-2.0.5}/UQPyL/sensibility/__init__.py +0 -0
- {UQPyL-2.0.4 → UQPyL-2.0.5}/UQPyL/sensibility/delta_test.py +0 -0
- {UQPyL-2.0.4 → UQPyL-2.0.5}/UQPyL/sensibility/mars_sa.py +0 -0
- {UQPyL-2.0.4 → UQPyL-2.0.5}/UQPyL/sensibility/rbd_fast.py +0 -0
- {UQPyL-2.0.4 → UQPyL-2.0.5}/UQPyL/sensibility/rsa.py +0 -0
- {UQPyL-2.0.4 → UQPyL-2.0.5}/UQPyL/sensibility/sa_ABC.py +0 -0
- {UQPyL-2.0.4 → UQPyL-2.0.5}/UQPyL/sensibility/sobol.py +0 -0
- {UQPyL-2.0.4 → UQPyL-2.0.5}/UQPyL/surrogates/BaggingEnsemble.py +0 -0
- {UQPyL-2.0.4 → UQPyL-2.0.5}/UQPyL/surrogates/BootstrapEnsemble.py +0 -0
- {UQPyL-2.0.4 → UQPyL-2.0.5}/UQPyL/surrogates/__init__.py +0 -0
- {UQPyL-2.0.4 → UQPyL-2.0.5}/UQPyL/surrogates/fully_connect_neural_network.py +0 -0
- {UQPyL-2.0.4 → UQPyL-2.0.5}/UQPyL/surrogates/gp_kernels/__init__.py +0 -0
- {UQPyL-2.0.4 → UQPyL-2.0.5}/UQPyL/surrogates/gp_kernels/base_kernel.py +0 -0
- {UQPyL-2.0.4 → UQPyL-2.0.5}/UQPyL/surrogates/gp_kernels/c_kernel.py +0 -0
- {UQPyL-2.0.4 → UQPyL-2.0.5}/UQPyL/surrogates/gp_kernels/dot_kernel.py +0 -0
- {UQPyL-2.0.4 → UQPyL-2.0.5}/UQPyL/surrogates/gp_kernels/matern_kernel.py +0 -0
- {UQPyL-2.0.4 → UQPyL-2.0.5}/UQPyL/surrogates/gp_kernels/rbf_kernel.py +0 -0
- {UQPyL-2.0.4 → UQPyL-2.0.5}/UQPyL/surrogates/gp_kernels/rq_kernel.py +0 -0
- {UQPyL-2.0.4 → UQPyL-2.0.5}/UQPyL/surrogates/krg_kernels/__init__.py +0 -0
- {UQPyL-2.0.4 → UQPyL-2.0.5}/UQPyL/surrogates/krg_kernels/base_kernel.py +0 -0
- {UQPyL-2.0.4 → UQPyL-2.0.5}/UQPyL/surrogates/krg_kernels/cubic_kernel.py +0 -0
- {UQPyL-2.0.4 → UQPyL-2.0.5}/UQPyL/surrogates/krg_kernels/exp_kernel.py +0 -0
- {UQPyL-2.0.4 → UQPyL-2.0.5}/UQPyL/surrogates/krg_kernels/guass_kernel.py +0 -0
- {UQPyL-2.0.4 → UQPyL-2.0.5}/UQPyL/surrogates/lasso_/__init__.py +0 -0
- {UQPyL-2.0.4 → UQPyL-2.0.5}/UQPyL/surrogates/lasso_/lasso_fast.c +0 -0
- {UQPyL-2.0.4 → UQPyL-2.0.5}/UQPyL/surrogates/linear_regression.py +0 -0
- {UQPyL-2.0.4 → UQPyL-2.0.5}/UQPyL/surrogates/mars.py +0 -0
- {UQPyL-2.0.4 → UQPyL-2.0.5}/UQPyL/surrogates/mars_/__init__.py +0 -0
- {UQPyL-2.0.4 → UQPyL-2.0.5}/UQPyL/surrogates/mars_/_basis.c +0 -0
- {UQPyL-2.0.4 → UQPyL-2.0.5}/UQPyL/surrogates/mars_/_forward.c +0 -0
- {UQPyL-2.0.4 → UQPyL-2.0.5}/UQPyL/surrogates/mars_/_knot_search.c +0 -0
- {UQPyL-2.0.4 → UQPyL-2.0.5}/UQPyL/surrogates/mars_/_pruning.c +0 -0
- {UQPyL-2.0.4 → UQPyL-2.0.5}/UQPyL/surrogates/mars_/_qr.c +0 -0
- {UQPyL-2.0.4 → UQPyL-2.0.5}/UQPyL/surrogates/mars_/_record.c +0 -0
- {UQPyL-2.0.4 → UQPyL-2.0.5}/UQPyL/surrogates/mars_/_types.c +0 -0
- {UQPyL-2.0.4 → UQPyL-2.0.5}/UQPyL/surrogates/mars_/_util.c +0 -0
- {UQPyL-2.0.4 → UQPyL-2.0.5}/UQPyL/surrogates/mars_/pyearth/__init__.py +0 -0
- {UQPyL-2.0.4 → UQPyL-2.0.5}/UQPyL/surrogates/mlp_utility/__init__.py +0 -0
- {UQPyL-2.0.4 → UQPyL-2.0.5}/UQPyL/surrogates/mlp_utility/_activation_funcs.py +0 -0
- {UQPyL-2.0.4 → UQPyL-2.0.5}/UQPyL/surrogates/mlp_utility/base.py +0 -0
- {UQPyL-2.0.4 → UQPyL-2.0.5}/UQPyL/surrogates/polynomial_regression.py +0 -0
- {UQPyL-2.0.4 → UQPyL-2.0.5}/UQPyL/surrogates/radial_basis_function.py +0 -0
- {UQPyL-2.0.4 → UQPyL-2.0.5}/UQPyL/surrogates/rbf_kernels/__init__.py +0 -0
- {UQPyL-2.0.4 → UQPyL-2.0.5}/UQPyL/surrogates/rbf_kernels/base_kernel.py +0 -0
- {UQPyL-2.0.4 → UQPyL-2.0.5}/UQPyL/surrogates/rbf_kernels/cubic_kernel.py +0 -0
- {UQPyL-2.0.4 → UQPyL-2.0.5}/UQPyL/surrogates/rbf_kernels/gaussian_kernel.py +0 -0
- {UQPyL-2.0.4 → UQPyL-2.0.5}/UQPyL/surrogates/rbf_kernels/linear_kernel.py +0 -0
- {UQPyL-2.0.4 → UQPyL-2.0.5}/UQPyL/surrogates/rbf_kernels/multiquadric_kernel.py +0 -0
- {UQPyL-2.0.4 → UQPyL-2.0.5}/UQPyL/surrogates/rbf_kernels/thin_plate_spline_kernel.py +0 -0
- {UQPyL-2.0.4 → UQPyL-2.0.5}/UQPyL/surrogates/support_vector_machine.py +0 -0
- {UQPyL-2.0.4 → UQPyL-2.0.5}/UQPyL/surrogates/surrogate_ABC.py +0 -0
- {UQPyL-2.0.4 → UQPyL-2.0.5}/UQPyL/surrogates/svr_/__init__.py +0 -0
- {UQPyL-2.0.4 → UQPyL-2.0.5}/UQPyL/surrogates/svr_/libsvm_interface.cpp +0 -0
- {UQPyL-2.0.4 → UQPyL-2.0.5}/UQPyL/surrogates/svr_/svm.cpp +0 -0
- {UQPyL-2.0.4 → UQPyL-2.0.5}/UQPyL/utility/model_selections.py +0 -0
- {UQPyL-2.0.4 → UQPyL-2.0.5}/UQPyL/utility/polynomial_features.py +0 -0
- {UQPyL-2.0.4 → UQPyL-2.0.5}/UQPyL/utility/scalers.py +0 -0
- {UQPyL-2.0.4 → UQPyL-2.0.5}/UQPyL.egg-info/dependency_links.txt +0 -0
- {UQPyL-2.0.4 → UQPyL-2.0.5}/UQPyL.egg-info/requires.txt +0 -0
- {UQPyL-2.0.4 → UQPyL-2.0.5}/UQPyL.egg-info/top_level.txt +0 -0
- {UQPyL-2.0.4 → UQPyL-2.0.5}/setup.cfg +0 -0
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
import numpy as np
|
|
2
|
+
from typing import Literal, Optional
|
|
3
|
+
from scipy.spatial.distance import pdist
|
|
4
|
+
|
|
5
|
+
from ..problems import Problem
|
|
6
|
+
|
|
7
|
+
from .sampler_ABC import Sampler
|
|
8
|
+
|
|
9
|
+
# from ._lhs import _lhs_classic, _lhs_centered, _lhs_correlate, _lhs_maximin, _lhs_centered_maximin
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
def _lhs_classic(nt: int, nx: int, random_state=None) -> np.ndarray:
|
|
14
|
+
# Generate the intervals
|
|
15
|
+
if random_state is None:
|
|
16
|
+
random_state=np.random.RandomState()
|
|
17
|
+
cut = np.linspace(0, 1, nt + 1)
|
|
18
|
+
|
|
19
|
+
# Fill points uniformly in each interval
|
|
20
|
+
u = random_state.rand(nt, nx)
|
|
21
|
+
a = cut[:nt]
|
|
22
|
+
b = cut[1:nt + 1]
|
|
23
|
+
rdpoints = np.zeros_like(u)
|
|
24
|
+
for j in range(nx):
|
|
25
|
+
rdpoints[:, j] = u[:, j]*(b-a) + a
|
|
26
|
+
|
|
27
|
+
# Make the random pairings
|
|
28
|
+
H = np.zeros_like(rdpoints)
|
|
29
|
+
for j in range(nx):
|
|
30
|
+
order = random_state.permutation(range(nt))
|
|
31
|
+
H[:, j] = rdpoints[order, j]
|
|
32
|
+
|
|
33
|
+
return H
|
|
34
|
+
|
|
35
|
+
################################################################################
|
|
36
|
+
|
|
37
|
+
def _lhs_centered(nt: int, nx: int, random_state=None) -> np.ndarray:
|
|
38
|
+
|
|
39
|
+
if random_state is None:
|
|
40
|
+
random_state=np.random.RandomState()
|
|
41
|
+
|
|
42
|
+
# Generate the intervals
|
|
43
|
+
cut = np.linspace(0, 1, nt + 1)
|
|
44
|
+
|
|
45
|
+
# Fill points uniformly in each interval
|
|
46
|
+
u = random_state.rand(nt, nx)
|
|
47
|
+
a = cut[:nt]
|
|
48
|
+
b = cut[1:nt + 1]
|
|
49
|
+
_center = (a + b)/2
|
|
50
|
+
|
|
51
|
+
# Make the random pairings
|
|
52
|
+
H = np.zeros_like(u)
|
|
53
|
+
for j in range(nx):
|
|
54
|
+
H[:, j] = random_state.permutation(_center)
|
|
55
|
+
|
|
56
|
+
return H
|
|
57
|
+
|
|
58
|
+
################################################################################
|
|
59
|
+
|
|
60
|
+
def _lhs_maximin(nt: int, nx: int, iterations: int, random_state=None)-> np.ndarray:
|
|
61
|
+
|
|
62
|
+
if random_state is None:
|
|
63
|
+
random_state=np.random.RandomState()
|
|
64
|
+
|
|
65
|
+
maxdist = 0
|
|
66
|
+
|
|
67
|
+
# Maximize the minimum distance between points
|
|
68
|
+
for i in range(iterations):
|
|
69
|
+
|
|
70
|
+
H_candidate = _lhs_classic(nt, nx, random_state)
|
|
71
|
+
|
|
72
|
+
d = pdist(H_candidate,'euclidean')
|
|
73
|
+
if maxdist<np.min(d):
|
|
74
|
+
maxdist = np.min(d)
|
|
75
|
+
H = H_candidate.copy()
|
|
76
|
+
|
|
77
|
+
return H
|
|
78
|
+
|
|
79
|
+
def _lhs_centered_maximin(nt: int, nx: int, iterations: int, random_state=None)-> np.ndarray:
|
|
80
|
+
|
|
81
|
+
if random_state is None:
|
|
82
|
+
random_state=np.random.RandomState()
|
|
83
|
+
|
|
84
|
+
maxdist = 0
|
|
85
|
+
|
|
86
|
+
# Maximize the minimum distance between points
|
|
87
|
+
for i in range(iterations):
|
|
88
|
+
|
|
89
|
+
H_candidate = _lhs_centered(nt, nx, random_state)
|
|
90
|
+
d = pdist(H_candidate,'euclidean')
|
|
91
|
+
if maxdist<np.min(d):
|
|
92
|
+
maxdist = np.min(d)
|
|
93
|
+
H = H_candidate.copy()
|
|
94
|
+
|
|
95
|
+
return H
|
|
96
|
+
################################################################################
|
|
97
|
+
|
|
98
|
+
def _lhs_correlate(nt: int, nx: int, iterations: int, random_state=None) -> np.ndarray:
|
|
99
|
+
|
|
100
|
+
if random_state is None:
|
|
101
|
+
random_state=np.random.RandomState()
|
|
102
|
+
|
|
103
|
+
mincorr = np.inf
|
|
104
|
+
|
|
105
|
+
# Minimize the components correlation coefficients
|
|
106
|
+
for _ in range(iterations):
|
|
107
|
+
# Generate a random LHS
|
|
108
|
+
H_candidate = _lhs_classic(nt, nx, random_state)
|
|
109
|
+
R = np.corrcoef(H_candidate)
|
|
110
|
+
if np.max(np.abs(R[R!=1]))<mincorr:
|
|
111
|
+
mincorr = np.max(np.abs(R-np.eye(R.shape[0])))
|
|
112
|
+
print('new candidate solution found with max,abs corrcoef = {}'.format(mincorr))
|
|
113
|
+
H = H_candidate.copy()
|
|
114
|
+
|
|
115
|
+
return H
|
|
116
|
+
|
|
117
|
+
Criterion=Literal['classic','center','maximin','center_maximin','correlation']
|
|
118
|
+
LHS_METHOD={'classic': _lhs_classic, 'center': _lhs_centered, 'maximin': _lhs_maximin,
|
|
119
|
+
'center_maximin': _lhs_centered_maximin, 'correlation': _lhs_correlate}
|
|
120
|
+
|
|
121
|
+
class LHS(Sampler):
|
|
122
|
+
'''
|
|
123
|
+
Latin-hypercube design
|
|
124
|
+
|
|
125
|
+
Parameters:
|
|
126
|
+
criterion : str
|
|
127
|
+
Allowable values are "classic", "center", "maximin", "center_maximin",
|
|
128
|
+
and "correlation". (Default: classic)
|
|
129
|
+
|
|
130
|
+
iterations : int
|
|
131
|
+
The number of iterations in the maximin, center_maximin and correlations methods
|
|
132
|
+
(Default: 5).
|
|
133
|
+
|
|
134
|
+
problem : problem
|
|
135
|
+
if the problem is provided, the bounds of the problem will be used to generate the samples
|
|
136
|
+
|
|
137
|
+
Methods:
|
|
138
|
+
__call__ or sample: Generate a Latin-hypercube design
|
|
139
|
+
|
|
140
|
+
Examples:
|
|
141
|
+
>>>lhs=LHS('classic')
|
|
142
|
+
>>>samples=lhs(5,10) or samples=lhs.sample(5,10)
|
|
143
|
+
|
|
144
|
+
'''
|
|
145
|
+
def __init__(self, criterion: Criterion ='classic', iterations: int=5, problem: Optional[Problem]=None):
|
|
146
|
+
|
|
147
|
+
self.criterion=criterion
|
|
148
|
+
self.iterations=iterations
|
|
149
|
+
self.problem=problem
|
|
150
|
+
|
|
151
|
+
#initial random state
|
|
152
|
+
self.random_state=np.random.RandomState()
|
|
153
|
+
|
|
154
|
+
def _generate(self, nt: int, nx: int) -> np.ndarray:
|
|
155
|
+
'''
|
|
156
|
+
Generate a Latin-hypercube design
|
|
157
|
+
|
|
158
|
+
Parameters
|
|
159
|
+
nt: int
|
|
160
|
+
the number of sampled points
|
|
161
|
+
nx: int
|
|
162
|
+
the input dimensions of sampled points
|
|
163
|
+
|
|
164
|
+
Returns:
|
|
165
|
+
H: 2d-array
|
|
166
|
+
An n-by-samples design matrix that has been normalized so factor values
|
|
167
|
+
are uniformly spaced between zero and one.
|
|
168
|
+
'''
|
|
169
|
+
|
|
170
|
+
if self.problem is not None:
|
|
171
|
+
if(self.problem.n_input!=nx):
|
|
172
|
+
raise ValueError('The input dimensions of the problem and the samples must be the same')
|
|
173
|
+
|
|
174
|
+
if self.criterion not in LHS_METHOD:
|
|
175
|
+
raise ValueError('The criterion must be one of {}'.format(LHS_METHOD.keys()))
|
|
176
|
+
|
|
177
|
+
Sampling_method=LHS_METHOD[self.criterion]
|
|
178
|
+
|
|
179
|
+
if self.criterion in ['maximin', 'center_maximin', 'correlation']:
|
|
180
|
+
X=Sampling_method(nt, nx, self.iterations, self.random_state)
|
|
181
|
+
else:
|
|
182
|
+
X=Sampling_method(nt, nx, self.random_state)
|
|
183
|
+
|
|
184
|
+
#rescale the samples
|
|
185
|
+
if self.problem is not None:
|
|
186
|
+
X=X*(self.problem.ub-self.problem.lb)+self.problem.lb
|
|
187
|
+
|
|
188
|
+
return X
|
|
189
|
+
|
|
190
|
+
def sample(self, nt: int, nx:int, random_seed: Optional[int]=None) -> np.ndarray:
|
|
191
|
+
'''
|
|
192
|
+
Generate a Latin-hypercube design
|
|
193
|
+
|
|
194
|
+
Parameters
|
|
195
|
+
nt: int
|
|
196
|
+
the number of sampled points
|
|
197
|
+
|
|
198
|
+
nx: int
|
|
199
|
+
the input dimensions of sampled points
|
|
200
|
+
|
|
201
|
+
random_seed: int
|
|
202
|
+
the random seed for the random number generator
|
|
203
|
+
|
|
204
|
+
Returns:
|
|
205
|
+
H: 2d-array
|
|
206
|
+
An n-by-samples design matrix that has been normalized so factor values
|
|
207
|
+
are uniformly spaced between zero and one.
|
|
208
|
+
'''
|
|
209
|
+
|
|
210
|
+
if random_seed is not None:
|
|
211
|
+
self.random_state = np.random.RandomState(random_seed)
|
|
212
|
+
else:
|
|
213
|
+
self.random_state = np.random.RandomState()
|
|
214
|
+
|
|
215
|
+
return self._generate(nt, nx)
|
|
@@ -113,7 +113,7 @@ class ASMO():
|
|
|
113
113
|
history_best_decs[FE]=BestX
|
|
114
114
|
history_best_objs[FE]=BestY
|
|
115
115
|
|
|
116
|
-
Result={'best_dec':BestX, 'best_obj':BestY, 'history_best_decs': history_best_decs, 'history_best_objs':history_best_objs ,'
|
|
116
|
+
Result={'best_dec':BestX, 'best_obj':BestY, 'history_best_decs': history_best_decs, 'history_best_objs':history_best_objs ,'FEs':FE}
|
|
117
117
|
|
|
118
118
|
return Result
|
|
119
119
|
|
|
@@ -59,9 +59,11 @@ class Schwefel_2_22(ProblemABC):
|
|
|
59
59
|
|
|
60
60
|
super().__init__(n_input,1,ub,lb,disc_var,cont_var)
|
|
61
61
|
|
|
62
|
-
def evaluate(self, X: np.ndarray) -> np.ndarray:
|
|
62
|
+
def evaluate(self, X: np.ndarray, unit: bool=False) -> np.ndarray:
|
|
63
63
|
|
|
64
|
-
X=self.
|
|
64
|
+
X=self._check_2d(X)
|
|
65
|
+
if unit:
|
|
66
|
+
X=self._unit_X_transform_to_bound(np.atleast_2d(X))
|
|
65
67
|
F=np.sum(np.abs(X),axis=1).reshape(-1,1)+np.prod(np.abs(X),axis=1).reshape(-1,1)
|
|
66
68
|
return F
|
|
67
69
|
|
|
@@ -85,10 +87,12 @@ class Schwefel_1_22(ProblemABC):
|
|
|
85
87
|
|
|
86
88
|
super().__init__(n_input,1,ub,lb,disc_var,cont_var)
|
|
87
89
|
|
|
88
|
-
def evaluate(self, X: np.ndarray) -> np.ndarray:
|
|
90
|
+
def evaluate(self, X: np.ndarray, unit: bool=False) -> np.ndarray:
|
|
89
91
|
|
|
90
92
|
F=0
|
|
91
|
-
X=self.
|
|
93
|
+
X=self._check_2d(X)
|
|
94
|
+
if unit:
|
|
95
|
+
X=self._unit_X_transform_to_bound(np.atleast_2d(X))
|
|
92
96
|
X=X**2
|
|
93
97
|
for d in range(self.n_input):
|
|
94
98
|
F+=np.sum(X[:,:d],axis=1).reshape(-1,1)
|
|
@@ -113,9 +117,11 @@ class Schwefel_2_21(ProblemABC):
|
|
|
113
117
|
|
|
114
118
|
super().__init__(n_input,1,ub,lb,disc_var,cont_var)
|
|
115
119
|
|
|
116
|
-
def evaluate(self, X: np.ndarray) -> np.ndarray:
|
|
120
|
+
def evaluate(self, X: np.ndarray, unit: bool=False) -> np.ndarray:
|
|
117
121
|
|
|
118
|
-
X=self.
|
|
122
|
+
X=self._check_2d(X)
|
|
123
|
+
if unit:
|
|
124
|
+
X=self._unit_X_transform_to_bound(np.atleast_2d(X))
|
|
119
125
|
X=np.abs(X)
|
|
120
126
|
F=np.max(X,axis=1).reshape(-1,1)
|
|
121
127
|
return F
|
|
@@ -139,9 +145,11 @@ class Rosenbrock(ProblemABC):
|
|
|
139
145
|
|
|
140
146
|
super().__init__(n_input,1,ub,lb,disc_var,cont_var)
|
|
141
147
|
|
|
142
|
-
def evaluate(self, X: np.ndarray) -> np.ndarray:
|
|
148
|
+
def evaluate(self, X: np.ndarray, unit: bool=False) -> np.ndarray:
|
|
143
149
|
|
|
144
|
-
X=self.
|
|
150
|
+
X=self._check_2d(X)
|
|
151
|
+
if unit:
|
|
152
|
+
X=self._unit_X_transform_to_bound(np.atleast_2d(X))
|
|
145
153
|
Temp1=100*np.square(X[:,1:]-np.square(X[:,:-1]))
|
|
146
154
|
Temp2=np.square(X[:,:-1]-1)
|
|
147
155
|
F=np.sum(Temp1+Temp2,axis=1).reshape(-1,1)
|
|
@@ -166,9 +174,11 @@ class Step(ProblemABC):
|
|
|
166
174
|
|
|
167
175
|
super().__init__(n_input,1,ub,lb,disc_var,cont_var)
|
|
168
176
|
|
|
169
|
-
def evaluate(self, X: np.ndarray) -> np.ndarray:
|
|
177
|
+
def evaluate(self, X: np.ndarray, unit: bool=False) -> np.ndarray:
|
|
170
178
|
|
|
171
|
-
X=self.
|
|
179
|
+
X=self._check_2d(X)
|
|
180
|
+
if unit:
|
|
181
|
+
X=self._unit_X_transform_to_bound(np.atleast_2d(X))
|
|
172
182
|
F=np.sum(np.square(np.floor(X)+0.5),axis=1).reshape(-1,1)
|
|
173
183
|
|
|
174
184
|
return F
|
|
@@ -192,9 +202,11 @@ class Quartic(ProblemABC):
|
|
|
192
202
|
|
|
193
203
|
super().__init__(n_input,1,ub,lb,disc_var,cont_var)
|
|
194
204
|
|
|
195
|
-
def evaluate(self, X: np.ndarray) -> np.ndarray:
|
|
205
|
+
def evaluate(self, X: np.ndarray, unit: bool=False) -> np.ndarray:
|
|
196
206
|
|
|
197
|
-
X=self.
|
|
207
|
+
X=self._check_2d(X)
|
|
208
|
+
if unit:
|
|
209
|
+
X=self._unit_X_transform_to_bound(np.atleast_2d(X))
|
|
198
210
|
Temp=np.linspace(1,self.n_input,self.n_input)*np.power(X,4)
|
|
199
211
|
F=np.sum(Temp,axis=1).reshape(-1,1)+np.random.random((Temp.shape[0],1))
|
|
200
212
|
return F
|
|
@@ -218,9 +230,11 @@ class Schwefel_2_26(ProblemABC):
|
|
|
218
230
|
|
|
219
231
|
super().__init__(n_input,1,ub,lb,disc_var,cont_var)
|
|
220
232
|
|
|
221
|
-
def evaluate(self, X: np.ndarray) -> np.ndarray:
|
|
233
|
+
def evaluate(self, X: np.ndarray, unit: bool=False) -> np.ndarray:
|
|
222
234
|
|
|
223
|
-
X=self.
|
|
235
|
+
X=self._check_2d(X)
|
|
236
|
+
if unit:
|
|
237
|
+
X=self._unit_X_transform_to_bound(np.atleast_2d(X))
|
|
224
238
|
Temp=np.sin(np.sqrt(np.abs(X)))*X
|
|
225
239
|
F=np.sum(Temp,axis=1).reshape(-1,1)*-1
|
|
226
240
|
return F
|
|
@@ -244,9 +258,11 @@ class Rastrigin(ProblemABC):
|
|
|
244
258
|
|
|
245
259
|
super().__init__(n_input,1,ub,lb,disc_var,cont_var)
|
|
246
260
|
|
|
247
|
-
def evaluate(self, X: np.ndarray) -> np.ndarray:
|
|
261
|
+
def evaluate(self, X: np.ndarray, unit: bool=False) -> np.ndarray:
|
|
248
262
|
|
|
249
|
-
X=self.
|
|
263
|
+
X=self._check_2d(X)
|
|
264
|
+
if unit:
|
|
265
|
+
X=self._unit_X_transform_to_bound(np.atleast_2d(X))
|
|
250
266
|
F=np.sum(np.square(X)-10*np.cos(2*np.pi*X)+10,axis=1).reshape(-1,1)
|
|
251
267
|
return F
|
|
252
268
|
|
|
@@ -270,9 +286,11 @@ class Ackley(ProblemABC):
|
|
|
270
286
|
|
|
271
287
|
super().__init__(n_input,1,ub,lb,disc_var,cont_var)
|
|
272
288
|
|
|
273
|
-
def evaluate(self, X: np.ndarray) -> np.ndarray:
|
|
289
|
+
def evaluate(self, X: np.ndarray, unit: bool=False) -> np.ndarray:
|
|
274
290
|
|
|
275
|
-
X=self.
|
|
291
|
+
X=self._check_2d(X)
|
|
292
|
+
if unit:
|
|
293
|
+
X=self._unit_X_transform_to_bound(np.atleast_2d(X))
|
|
276
294
|
Temp1=np.exp(np.sqrt(np.sum(np.square(X),axis=1)/self.n_input)*-0.2)*-20
|
|
277
295
|
Temp2=np.exp(np.sum(np.cos(2*np.pi*X),axis=1)/self.n_input)*-1+20+np.e
|
|
278
296
|
F=(Temp1+Temp2).reshape(-1,1)
|
|
@@ -297,9 +315,11 @@ class Griewank(ProblemABC):
|
|
|
297
315
|
|
|
298
316
|
super().__init__(n_input,1,ub,lb,disc_var,cont_var)
|
|
299
317
|
|
|
300
|
-
def evaluate(self, X: np.ndarray) -> np.ndarray:
|
|
318
|
+
def evaluate(self, X: np.ndarray, unit: bool=False) -> np.ndarray:
|
|
301
319
|
|
|
302
|
-
X=self.
|
|
320
|
+
X=self._check_2d(X)
|
|
321
|
+
if unit:
|
|
322
|
+
X=self._unit_X_transform_to_bound(np.atleast_2d(X))
|
|
303
323
|
I=np.sqrt(np.atleast_2d(np.linspace(1,self.n_input,self.n_input)))
|
|
304
324
|
F=np.sum(np.square(X), axis=1).reshape(-1,1)/4000-np.prod(np.cos(X/I),axis=1).reshape(-1,1)+1
|
|
305
325
|
return F
|
|
@@ -327,9 +347,11 @@ class Trid(ProblemABC):
|
|
|
327
347
|
|
|
328
348
|
super().__init__(n_input,1,ub,lb,disc_var,cont_var)
|
|
329
349
|
|
|
330
|
-
def evaluate(self, X: np.ndarray) -> np.ndarray:
|
|
350
|
+
def evaluate(self, X: np.ndarray, unit: bool=False) -> np.ndarray:
|
|
331
351
|
|
|
332
|
-
X=self.
|
|
352
|
+
X=self._check_2d(X)
|
|
353
|
+
if unit:
|
|
354
|
+
X=self._unit_X_transform_to_bound(np.atleast_2d(X))
|
|
333
355
|
F=np.sum(np.square(X-1),axis=1).reshape(-1,1)-np.sum(X[:,1:]*X[:,:-1],axis=1).reshape(-1,1)
|
|
334
356
|
return F
|
|
335
357
|
|
|
@@ -352,9 +374,11 @@ class Bent_Cigar(ProblemABC):
|
|
|
352
374
|
|
|
353
375
|
super().__init__(n_input,1,ub,lb,disc_var,cont_var)
|
|
354
376
|
|
|
355
|
-
def evaluate(self, X: np.ndarray) -> np.ndarray:
|
|
377
|
+
def evaluate(self, X: np.ndarray, unit: bool=False) -> np.ndarray:
|
|
356
378
|
|
|
357
|
-
X=self.
|
|
379
|
+
X=self._check_2d(X)
|
|
380
|
+
if unit:
|
|
381
|
+
X=self._unit_X_transform_to_bound(np.atleast_2d(X))
|
|
358
382
|
F=((X[:,0]**2)+np.sum(np.square(X[:,1:]),axis=1)*(10**6)).reshape(-1,1)
|
|
359
383
|
return F
|
|
360
384
|
|
|
@@ -377,9 +401,11 @@ class Discus(ProblemABC):
|
|
|
377
401
|
|
|
378
402
|
super().__init__(n_input,1,ub,lb,disc_var,cont_var)
|
|
379
403
|
|
|
380
|
-
def evaluate(self, X: np.ndarray) -> np.ndarray:
|
|
404
|
+
def evaluate(self, X: np.ndarray, unit: bool=False) -> np.ndarray:
|
|
381
405
|
|
|
382
|
-
X=self.
|
|
406
|
+
X=self._check_2d(X)
|
|
407
|
+
if unit:
|
|
408
|
+
X=self._unit_X_transform_to_bound(np.atleast_2d(X))
|
|
383
409
|
F=(X[:,0]**2*(10**6)+np.sum(np.square(X[:,1:]),axis=1)).reshape(-1,1)
|
|
384
410
|
return F
|
|
385
411
|
|
|
@@ -406,9 +432,11 @@ class Weierstrass(ProblemABC):
|
|
|
406
432
|
|
|
407
433
|
super().__init__(n_input,1,ub,lb,disc_var,cont_var)
|
|
408
434
|
|
|
409
|
-
def evaluate(self, X: np.ndarray) -> np.ndarray:
|
|
435
|
+
def evaluate(self, X: np.ndarray, unit: bool=False) -> np.ndarray:
|
|
410
436
|
|
|
411
|
-
X=self.
|
|
437
|
+
X=self._check_2d(X)
|
|
438
|
+
if unit:
|
|
439
|
+
X=self._unit_X_transform_to_bound(np.atleast_2d(X))
|
|
412
440
|
K=np.atleast_2d(np.linspace(1,self.kMax,self.kMax))
|
|
413
441
|
aK=np.power(self.a,K)
|
|
414
442
|
bK=np.power(self.b,K)
|
|
@@ -6,7 +6,7 @@ from .surrogate_ABC import Surrogate
|
|
|
6
6
|
from .gp_kernels import RBF, Matern, Gp_Kernel
|
|
7
7
|
from ..optimization import GA, Boxmin, MP_List, EA_List
|
|
8
8
|
from ..utility.model_selections import RandSelect
|
|
9
|
-
from ..utility.metrics import
|
|
9
|
+
from ..utility.metrics import r_square
|
|
10
10
|
from ..utility.scalers import Scaler
|
|
11
11
|
from ..utility.polynomial_features import PolynomialFeatures
|
|
12
12
|
|
|
@@ -88,7 +88,7 @@ class GPR(Surrogate):
|
|
|
88
88
|
self.trainY=trainY
|
|
89
89
|
self._objfunc(theta, record=True)
|
|
90
90
|
predictY=self.predict(self.X_scaler.inverse_transform(testX))
|
|
91
|
-
return -1*
|
|
91
|
+
return -1*r_square(self.Y_scaler.inverse_transform(testY), predictY)
|
|
92
92
|
bestTheta, bestObj=self.OPModel.run(objFunc)
|
|
93
93
|
|
|
94
94
|
elif self.optimizer in EA_List:
|
|
@@ -103,7 +103,7 @@ class GPR(Surrogate):
|
|
|
103
103
|
for i, theta in enumerate(thetas):
|
|
104
104
|
self._objfunc(np.power(np.e,theta),record=True)
|
|
105
105
|
predictY=self.predict(self.X_scaler.inverse_transform(testX))
|
|
106
|
-
objs[i]=-1*
|
|
106
|
+
objs[i]=-1*r_square(self.Y_scaler.inverse_transform(testY), predictY)
|
|
107
107
|
return objs.reshape(-1,1)
|
|
108
108
|
|
|
109
109
|
self.OPFunc=objFunc
|
|
@@ -6,7 +6,7 @@ from concurrent.futures import ThreadPoolExecutor, as_completed
|
|
|
6
6
|
|
|
7
7
|
from .surrogate_ABC import Surrogate, Scale_T
|
|
8
8
|
from .krg_kernels import Krg_Kernel
|
|
9
|
-
from ..utility.metrics import
|
|
9
|
+
from ..utility.metrics import r_square
|
|
10
10
|
from ..optimization import Boxmin, GA, MP_List, EA_List
|
|
11
11
|
from ..utility.model_selections import RandSelect
|
|
12
12
|
from ..utility.scalers import Scaler
|
|
@@ -199,7 +199,7 @@ class KRG(Surrogate):
|
|
|
199
199
|
self._objFunc(theta,record=True)
|
|
200
200
|
self.kernel.theta=theta
|
|
201
201
|
predictY=self.predict(self.__X_inverse_transform__(testX))
|
|
202
|
-
obj=-1*
|
|
202
|
+
obj=-1*r_square(self.__Y_inverse_transform__(testY),predictY)
|
|
203
203
|
return obj
|
|
204
204
|
|
|
205
205
|
self.OPFunc=objFunc
|
|
@@ -218,7 +218,7 @@ class KRG(Surrogate):
|
|
|
218
218
|
self.kernel.theta=np.power(np.e,theta).ravel()
|
|
219
219
|
#TODO
|
|
220
220
|
predictY=self.predict(self.__X_inverse_transform__(testX))
|
|
221
|
-
objs[i]=-1*
|
|
221
|
+
objs[i]=-1*r_square(self.__Y_inverse_transform__(testY),predictY)
|
|
222
222
|
return objs.reshape(-1,1)
|
|
223
223
|
self.OPFunc=objFunc
|
|
224
224
|
|
|
@@ -2,7 +2,7 @@ from .scalers import MinMaxScaler, StandardScaler, Scaler
|
|
|
2
2
|
from .model_selections import KFold, RandSelect
|
|
3
3
|
from .polynomial_features import PolynomialFeatures
|
|
4
4
|
from .grid_search import GridSearch
|
|
5
|
-
from .metrics import
|
|
5
|
+
from .metrics import r_square, rank_score, sort_score
|
|
6
6
|
|
|
7
7
|
__all__=[
|
|
8
8
|
'Scaler',
|
|
@@ -11,7 +11,7 @@ __all__=[
|
|
|
11
11
|
'KFold',
|
|
12
12
|
'RandSelect',
|
|
13
13
|
'PolynomialFeatures',
|
|
14
|
-
'
|
|
14
|
+
'r_square',
|
|
15
15
|
'rank_score',
|
|
16
16
|
'GridSearch'
|
|
17
17
|
]
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
from .metrics import
|
|
1
|
+
from .metrics import r_square, mse, rank_score
|
|
2
2
|
from .model_selections import KFold
|
|
3
3
|
from typing import Dict, Literal
|
|
4
4
|
import numpy as np
|
|
@@ -23,7 +23,7 @@ def fit_predict(evaluator, dataX, dataY, train_sets, test_sets, metric):
|
|
|
23
23
|
|
|
24
24
|
class GridSearch():
|
|
25
25
|
def __init__(self, para_grid: Dict, Evaluator,
|
|
26
|
-
CV: int=5, Metric: Literal["
|
|
26
|
+
CV: int=5, Metric: Literal["r_square", "mse", "rank_score"]="r_square",
|
|
27
27
|
workers: int=8):
|
|
28
28
|
|
|
29
29
|
self.Evaluator=Evaluator
|
|
@@ -49,7 +49,7 @@ class GridSearch():
|
|
|
49
49
|
for para in combinations:
|
|
50
50
|
tempEvaluator=copy.deepcopy(self.Evaluator)
|
|
51
51
|
tempEvaluator.set_Paras(para)
|
|
52
|
-
future=exe.submit(fit_predict, tempEvaluator,dataX, dataY, train_sets, test_sets, "
|
|
52
|
+
future=exe.submit(fit_predict, tempEvaluator,dataX, dataY, train_sets, test_sets, "r_square")
|
|
53
53
|
futures[future]=para
|
|
54
54
|
|
|
55
55
|
bestValue=-np.inf
|
|
@@ -41,7 +41,7 @@ extensions=cythonize(cython_extensions, compiler_directives={'cdivision': True,
|
|
|
41
41
|
setup(
|
|
42
42
|
name="UQPyL",
|
|
43
43
|
author="wmtSky",
|
|
44
|
-
version="2.0.
|
|
44
|
+
version="2.0.5",
|
|
45
45
|
author_email="wmtsky@hhu.edu.cn",
|
|
46
46
|
# ... 其他常规setup参数 ...
|
|
47
47
|
ext_modules=extensions, # 如果有自定义的编译行为
|
UQPyL-2.0.4/UQPyL/DoE/_lhs.py
DELETED
|
@@ -1,90 +0,0 @@
|
|
|
1
|
-
import numpy as np
|
|
2
|
-
from scipy.spatial.distance import pdist,squareform
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
def _lhs_classic(nt: int, nx: int) -> np.ndarray:
|
|
6
|
-
# Generate the intervals
|
|
7
|
-
cut = np.linspace(0, 1, nt + 1)
|
|
8
|
-
|
|
9
|
-
# Fill points uniformly in each interval
|
|
10
|
-
u = np.random.rand(nt, nx)
|
|
11
|
-
a = cut[:nt]
|
|
12
|
-
b = cut[1:nt + 1]
|
|
13
|
-
rdpoints = np.zeros_like(u)
|
|
14
|
-
for j in range(nx):
|
|
15
|
-
rdpoints[:, j] = u[:, j]*(b-a) + a
|
|
16
|
-
|
|
17
|
-
# Make the random pairings
|
|
18
|
-
H = np.zeros_like(rdpoints)
|
|
19
|
-
for j in range(nx):
|
|
20
|
-
order = np.random.permutation(range(nt))
|
|
21
|
-
H[:, j] = rdpoints[order, j]
|
|
22
|
-
|
|
23
|
-
return H
|
|
24
|
-
|
|
25
|
-
################################################################################
|
|
26
|
-
|
|
27
|
-
def _lhs_centered(nt: int, nx: int) -> np.ndarray:
|
|
28
|
-
# Generate the intervals
|
|
29
|
-
cut = np.linspace(0, 1, nt + 1)
|
|
30
|
-
|
|
31
|
-
# Fill points uniformly in each interval
|
|
32
|
-
u = np.random.rand(nt, nx)
|
|
33
|
-
a = cut[:nt]
|
|
34
|
-
b = cut[1:nt + 1]
|
|
35
|
-
_center = (a + b)/2
|
|
36
|
-
|
|
37
|
-
# Make the random pairings
|
|
38
|
-
H = np.zeros_like(u)
|
|
39
|
-
for j in range(nx):
|
|
40
|
-
H[:, j] = np.random.permutation(_center)
|
|
41
|
-
|
|
42
|
-
return H
|
|
43
|
-
|
|
44
|
-
################################################################################
|
|
45
|
-
|
|
46
|
-
def _lhs_maximin(nt: int, nx: int, iterations: int)-> np.ndarray:
|
|
47
|
-
|
|
48
|
-
maxdist = 0
|
|
49
|
-
|
|
50
|
-
# Maximize the minimum distance between points
|
|
51
|
-
for i in range(iterations):
|
|
52
|
-
|
|
53
|
-
H_candidate = _lhs_classic(nt, nx)
|
|
54
|
-
|
|
55
|
-
d = pdist(H_candidate,'euclidean')
|
|
56
|
-
if maxdist<np.min(d):
|
|
57
|
-
maxdist = np.min(d)
|
|
58
|
-
H = H_candidate.copy()
|
|
59
|
-
|
|
60
|
-
return H
|
|
61
|
-
|
|
62
|
-
def _lhs_centered_maximin(nt: int, nx: int, iterations: int)-> np.ndarray:
|
|
63
|
-
maxdist = 0
|
|
64
|
-
|
|
65
|
-
# Maximize the minimum distance between points
|
|
66
|
-
for i in range(iterations):
|
|
67
|
-
|
|
68
|
-
H_candidate = _lhs_centered(nt, nx)
|
|
69
|
-
d = pdist(H_candidate,'euclidean')
|
|
70
|
-
if maxdist<np.min(d):
|
|
71
|
-
maxdist = np.min(d)
|
|
72
|
-
H = H_candidate.copy()
|
|
73
|
-
|
|
74
|
-
return H
|
|
75
|
-
################################################################################
|
|
76
|
-
|
|
77
|
-
def _lhs_correlate(nt: int, nx: int, iterations: int) -> np.ndarray:
|
|
78
|
-
mincorr = np.inf
|
|
79
|
-
|
|
80
|
-
# Minimize the components correlation coefficients
|
|
81
|
-
for i in range(iterations):
|
|
82
|
-
# Generate a random LHS
|
|
83
|
-
H_candidate = _lhs_classic(nt, nx)
|
|
84
|
-
R = np.corrcoef(H_candidate)
|
|
85
|
-
if np.max(np.abs(R[R!=1]))<mincorr:
|
|
86
|
-
mincorr = np.max(np.abs(R-np.eye(R.shape[0])))
|
|
87
|
-
print('new candidate solution found with max,abs corrcoef = {}'.format(mincorr))
|
|
88
|
-
H = H_candidate.copy()
|
|
89
|
-
|
|
90
|
-
return H
|
UQPyL-2.0.4/UQPyL/DoE/lhs.py
DELETED
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
import numpy as np
|
|
2
|
-
from typing import Literal
|
|
3
|
-
|
|
4
|
-
from .sampler_ABC import Sampler
|
|
5
|
-
from ._lhs import _lhs_classic, _lhs_centered, _lhs_correlate, _lhs_maximin, _lhs_centered_maximin
|
|
6
|
-
|
|
7
|
-
Criterion=Literal['classic','center','maximin','center_maximin','correlation']
|
|
8
|
-
LHS_METHOD={'classic': _lhs_classic, 'center': _lhs_centered, 'maximin': _lhs_maximin,
|
|
9
|
-
'center_maximin': _lhs_centered_maximin, 'correlation': _lhs_correlate}
|
|
10
|
-
|
|
11
|
-
class LHS(Sampler):
|
|
12
|
-
'''
|
|
13
|
-
Latin-hypercube design
|
|
14
|
-
|
|
15
|
-
Parameters:
|
|
16
|
-
criterion : str
|
|
17
|
-
Allowable values are "classic", "center", "maximin", "center_maximin",
|
|
18
|
-
and "correlation". (Default: classic)
|
|
19
|
-
|
|
20
|
-
iterations : int
|
|
21
|
-
The number of iterations in the maximin, center_maximin and correlations methods
|
|
22
|
-
(Default: 5).
|
|
23
|
-
|
|
24
|
-
Methods:
|
|
25
|
-
__call__ or sample: Generate a Latin-hypercube design
|
|
26
|
-
|
|
27
|
-
Examples:
|
|
28
|
-
>>>lhs=LHS('classic')
|
|
29
|
-
>>>samples=lhs(5,10) or samples=lhs.sample(5,10)
|
|
30
|
-
|
|
31
|
-
'''
|
|
32
|
-
def __init__(self, criterion: Criterion='classic', iterations: int=5)-> None:
|
|
33
|
-
self.criterion=criterion
|
|
34
|
-
self.iterations=iterations
|
|
35
|
-
|
|
36
|
-
def _generate(self, nt: int, nx: int) -> np.ndarray:
|
|
37
|
-
'''
|
|
38
|
-
Generate a Latin-hypercube design
|
|
39
|
-
|
|
40
|
-
Parameters
|
|
41
|
-
nt: int
|
|
42
|
-
the number of sampled points
|
|
43
|
-
nx: int
|
|
44
|
-
the input dimensions of sampled points
|
|
45
|
-
|
|
46
|
-
Returns:
|
|
47
|
-
H: 2d-array
|
|
48
|
-
An n-by-samples design matrix that has been normalized so factor values
|
|
49
|
-
are uniformly spaced between zero and one.
|
|
50
|
-
'''
|
|
51
|
-
Sampling_method=LHS_METHOD[self.criterion]
|
|
52
|
-
if self.criterion in ['maximin', 'center_maximin', 'correlation']:
|
|
53
|
-
return Sampling_method(nt, nx, self.iterations)
|
|
54
|
-
else:
|
|
55
|
-
return Sampling_method(nt, nx)
|
|
56
|
-
|
|
57
|
-
def sample(self, nt: int, nx:int) -> np.ndarray:
|
|
58
|
-
'''
|
|
59
|
-
Generate a Latin-hypercube design
|
|
60
|
-
|
|
61
|
-
Parameters
|
|
62
|
-
nt: int
|
|
63
|
-
the number of sampled points
|
|
64
|
-
nx: int
|
|
65
|
-
the input dimensions of sampled points
|
|
66
|
-
|
|
67
|
-
Returns:
|
|
68
|
-
H: 2d-array
|
|
69
|
-
An n-by-samples design matrix that has been normalized so factor values
|
|
70
|
-
are uniformly spaced between zero and one.
|
|
71
|
-
'''
|
|
72
|
-
|
|
73
|
-
return self._generate(nt, nx)
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
File without changes
|
|
File without changes
|
|
File without changes
|