UQPyL 2.0.3__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.
Files changed (109) hide show
  1. {UQPyL-2.0.3 → UQPyL-2.0.5}/PKG-INFO +1 -1
  2. UQPyL-2.0.5/UQPyL/DoE/lhs.py +215 -0
  3. {UQPyL-2.0.3 → UQPyL-2.0.5}/UQPyL/__init__.py +1 -1
  4. {UQPyL-2.0.3 → UQPyL-2.0.5}/UQPyL/optimization/asmo.py +14 -11
  5. {UQPyL-2.0.3 → UQPyL-2.0.5}/UQPyL/problems/single_Benchmarks.py +56 -28
  6. {UQPyL-2.0.3 → UQPyL-2.0.5}/UQPyL/sensibility/fast.py +1 -1
  7. {UQPyL-2.0.3 → UQPyL-2.0.5}/UQPyL/sensibility/morris.py +1 -1
  8. {UQPyL-2.0.3 → UQPyL-2.0.5}/UQPyL/surrogates/gaussian_process.py +3 -3
  9. {UQPyL-2.0.3 → UQPyL-2.0.5}/UQPyL/surrogates/kriging.py +3 -3
  10. {UQPyL-2.0.3 → UQPyL-2.0.5}/UQPyL/utility/__init__.py +2 -2
  11. {UQPyL-2.0.3 → UQPyL-2.0.5}/UQPyL/utility/grid_search.py +3 -3
  12. {UQPyL-2.0.3 → UQPyL-2.0.5}/UQPyL/utility/metrics.py +2 -3
  13. {UQPyL-2.0.3 → UQPyL-2.0.5}/UQPyL.egg-info/PKG-INFO +1 -1
  14. {UQPyL-2.0.3 → UQPyL-2.0.5}/UQPyL.egg-info/SOURCES.txt +0 -1
  15. {UQPyL-2.0.3 → UQPyL-2.0.5}/pyproject.toml +1 -1
  16. {UQPyL-2.0.3 → UQPyL-2.0.5}/setup.py +1 -1
  17. UQPyL-2.0.3/UQPyL/DoE/_lhs.py +0 -90
  18. UQPyL-2.0.3/UQPyL/DoE/lhs.py +0 -73
  19. {UQPyL-2.0.3 → UQPyL-2.0.5}/LICENSE.md +0 -0
  20. {UQPyL-2.0.3 → UQPyL-2.0.5}/README.md +0 -0
  21. {UQPyL-2.0.3 → UQPyL-2.0.5}/UQPyL/DoE/__init__.py +0 -0
  22. {UQPyL-2.0.3 → UQPyL-2.0.5}/UQPyL/DoE/fast_sequence.py +0 -0
  23. {UQPyL-2.0.3 → UQPyL-2.0.5}/UQPyL/DoE/full_fact.py +0 -0
  24. {UQPyL-2.0.3 → UQPyL-2.0.5}/UQPyL/DoE/morris_sequence.py +0 -0
  25. {UQPyL-2.0.3 → UQPyL-2.0.5}/UQPyL/DoE/random.py +0 -0
  26. {UQPyL-2.0.3 → UQPyL-2.0.5}/UQPyL/DoE/sampler_ABC.py +0 -0
  27. {UQPyL-2.0.3 → UQPyL-2.0.5}/UQPyL/DoE/sobol_sequence.py +0 -0
  28. {UQPyL-2.0.3 → UQPyL-2.0.5}/UQPyL/optimization/__init__.py +0 -0
  29. {UQPyL-2.0.3 → UQPyL-2.0.5}/UQPyL/optimization/_binary_ga.py +0 -0
  30. {UQPyL-2.0.3 → UQPyL-2.0.5}/UQPyL/optimization/adam.py +0 -0
  31. {UQPyL-2.0.3 → UQPyL-2.0.5}/UQPyL/optimization/boxmin.py +0 -0
  32. {UQPyL-2.0.3 → UQPyL-2.0.5}/UQPyL/optimization/ga.py +0 -0
  33. {UQPyL-2.0.3 → UQPyL-2.0.5}/UQPyL/optimization/mo_asmo.py +0 -0
  34. {UQPyL-2.0.3 → UQPyL-2.0.5}/UQPyL/optimization/moea_d.py +0 -0
  35. {UQPyL-2.0.3 → UQPyL-2.0.5}/UQPyL/optimization/nsga_ii.py +0 -0
  36. {UQPyL-2.0.3 → UQPyL-2.0.5}/UQPyL/optimization/pso.py +0 -0
  37. {UQPyL-2.0.3 → UQPyL-2.0.5}/UQPyL/optimization/sce_ua.py +0 -0
  38. {UQPyL-2.0.3 → UQPyL-2.0.5}/UQPyL/optimization/utility_functions/_NDsort.py +0 -0
  39. {UQPyL-2.0.3 → UQPyL-2.0.5}/UQPyL/optimization/utility_functions/__init__.py +0 -0
  40. {UQPyL-2.0.3 → UQPyL-2.0.5}/UQPyL/optimization/utility_functions/_uniformPoint.py +0 -0
  41. {UQPyL-2.0.3 → UQPyL-2.0.5}/UQPyL/problems/__init__.py +0 -0
  42. {UQPyL-2.0.3 → UQPyL-2.0.5}/UQPyL/problems/multi_DTLZ.py +0 -0
  43. {UQPyL-2.0.3 → UQPyL-2.0.5}/UQPyL/problems/multi_ZDT.py +0 -0
  44. {UQPyL-2.0.3 → UQPyL-2.0.5}/UQPyL/problems/pratical_problem.py +0 -0
  45. {UQPyL-2.0.3 → UQPyL-2.0.5}/UQPyL/problems/problem_ABC.py +0 -0
  46. {UQPyL-2.0.3 → UQPyL-2.0.5}/UQPyL/problems/utility_functions/_NDsort.py +0 -0
  47. {UQPyL-2.0.3 → UQPyL-2.0.5}/UQPyL/problems/utility_functions/__init__.py +0 -0
  48. {UQPyL-2.0.3 → UQPyL-2.0.5}/UQPyL/problems/utility_functions/_uniformPoint.py +0 -0
  49. {UQPyL-2.0.3 → UQPyL-2.0.5}/UQPyL/sensibility/__init__.py +0 -0
  50. {UQPyL-2.0.3 → UQPyL-2.0.5}/UQPyL/sensibility/delta_test.py +0 -0
  51. {UQPyL-2.0.3 → UQPyL-2.0.5}/UQPyL/sensibility/mars_sa.py +0 -0
  52. {UQPyL-2.0.3 → UQPyL-2.0.5}/UQPyL/sensibility/rbd_fast.py +0 -0
  53. {UQPyL-2.0.3 → UQPyL-2.0.5}/UQPyL/sensibility/rsa.py +0 -0
  54. {UQPyL-2.0.3 → UQPyL-2.0.5}/UQPyL/sensibility/sa_ABC.py +0 -0
  55. {UQPyL-2.0.3 → UQPyL-2.0.5}/UQPyL/sensibility/sobol.py +0 -0
  56. {UQPyL-2.0.3 → UQPyL-2.0.5}/UQPyL/surrogates/BaggingEnsemble.py +0 -0
  57. {UQPyL-2.0.3 → UQPyL-2.0.5}/UQPyL/surrogates/BootstrapEnsemble.py +0 -0
  58. {UQPyL-2.0.3 → UQPyL-2.0.5}/UQPyL/surrogates/__init__.py +0 -0
  59. {UQPyL-2.0.3 → UQPyL-2.0.5}/UQPyL/surrogates/fully_connect_neural_network.py +0 -0
  60. {UQPyL-2.0.3 → UQPyL-2.0.5}/UQPyL/surrogates/gp_kernels/__init__.py +0 -0
  61. {UQPyL-2.0.3 → UQPyL-2.0.5}/UQPyL/surrogates/gp_kernels/base_kernel.py +0 -0
  62. {UQPyL-2.0.3 → UQPyL-2.0.5}/UQPyL/surrogates/gp_kernels/c_kernel.py +0 -0
  63. {UQPyL-2.0.3 → UQPyL-2.0.5}/UQPyL/surrogates/gp_kernels/dot_kernel.py +0 -0
  64. {UQPyL-2.0.3 → UQPyL-2.0.5}/UQPyL/surrogates/gp_kernels/matern_kernel.py +0 -0
  65. {UQPyL-2.0.3 → UQPyL-2.0.5}/UQPyL/surrogates/gp_kernels/rbf_kernel.py +0 -0
  66. {UQPyL-2.0.3 → UQPyL-2.0.5}/UQPyL/surrogates/gp_kernels/rq_kernel.py +0 -0
  67. {UQPyL-2.0.3 → UQPyL-2.0.5}/UQPyL/surrogates/krg_kernels/__init__.py +0 -0
  68. {UQPyL-2.0.3 → UQPyL-2.0.5}/UQPyL/surrogates/krg_kernels/base_kernel.py +0 -0
  69. {UQPyL-2.0.3 → UQPyL-2.0.5}/UQPyL/surrogates/krg_kernels/cubic_kernel.py +0 -0
  70. {UQPyL-2.0.3 → UQPyL-2.0.5}/UQPyL/surrogates/krg_kernels/exp_kernel.py +0 -0
  71. {UQPyL-2.0.3 → UQPyL-2.0.5}/UQPyL/surrogates/krg_kernels/guass_kernel.py +0 -0
  72. {UQPyL-2.0.3 → UQPyL-2.0.5}/UQPyL/surrogates/lasso_/__init__.py +0 -0
  73. {UQPyL-2.0.3 → UQPyL-2.0.5}/UQPyL/surrogates/lasso_/lasso_fast.c +0 -0
  74. {UQPyL-2.0.3 → UQPyL-2.0.5}/UQPyL/surrogates/linear_regression.py +0 -0
  75. {UQPyL-2.0.3 → UQPyL-2.0.5}/UQPyL/surrogates/mars.py +0 -0
  76. {UQPyL-2.0.3 → UQPyL-2.0.5}/UQPyL/surrogates/mars_/__init__.py +0 -0
  77. {UQPyL-2.0.3 → UQPyL-2.0.5}/UQPyL/surrogates/mars_/_basis.c +0 -0
  78. {UQPyL-2.0.3 → UQPyL-2.0.5}/UQPyL/surrogates/mars_/_forward.c +0 -0
  79. {UQPyL-2.0.3 → UQPyL-2.0.5}/UQPyL/surrogates/mars_/_knot_search.c +0 -0
  80. {UQPyL-2.0.3 → UQPyL-2.0.5}/UQPyL/surrogates/mars_/_pruning.c +0 -0
  81. {UQPyL-2.0.3 → UQPyL-2.0.5}/UQPyL/surrogates/mars_/_qr.c +0 -0
  82. {UQPyL-2.0.3 → UQPyL-2.0.5}/UQPyL/surrogates/mars_/_record.c +0 -0
  83. {UQPyL-2.0.3 → UQPyL-2.0.5}/UQPyL/surrogates/mars_/_types.c +0 -0
  84. {UQPyL-2.0.3 → UQPyL-2.0.5}/UQPyL/surrogates/mars_/_util.c +0 -0
  85. {UQPyL-2.0.3 → UQPyL-2.0.5}/UQPyL/surrogates/mars_/pyearth/__init__.py +0 -0
  86. {UQPyL-2.0.3 → UQPyL-2.0.5}/UQPyL/surrogates/mlp_utility/__init__.py +0 -0
  87. {UQPyL-2.0.3 → UQPyL-2.0.5}/UQPyL/surrogates/mlp_utility/_activation_funcs.py +0 -0
  88. {UQPyL-2.0.3 → UQPyL-2.0.5}/UQPyL/surrogates/mlp_utility/base.py +0 -0
  89. {UQPyL-2.0.3 → UQPyL-2.0.5}/UQPyL/surrogates/polynomial_regression.py +0 -0
  90. {UQPyL-2.0.3 → UQPyL-2.0.5}/UQPyL/surrogates/radial_basis_function.py +0 -0
  91. {UQPyL-2.0.3 → UQPyL-2.0.5}/UQPyL/surrogates/rbf_kernels/__init__.py +0 -0
  92. {UQPyL-2.0.3 → UQPyL-2.0.5}/UQPyL/surrogates/rbf_kernels/base_kernel.py +0 -0
  93. {UQPyL-2.0.3 → UQPyL-2.0.5}/UQPyL/surrogates/rbf_kernels/cubic_kernel.py +0 -0
  94. {UQPyL-2.0.3 → UQPyL-2.0.5}/UQPyL/surrogates/rbf_kernels/gaussian_kernel.py +0 -0
  95. {UQPyL-2.0.3 → UQPyL-2.0.5}/UQPyL/surrogates/rbf_kernels/linear_kernel.py +0 -0
  96. {UQPyL-2.0.3 → UQPyL-2.0.5}/UQPyL/surrogates/rbf_kernels/multiquadric_kernel.py +0 -0
  97. {UQPyL-2.0.3 → UQPyL-2.0.5}/UQPyL/surrogates/rbf_kernels/thin_plate_spline_kernel.py +0 -0
  98. {UQPyL-2.0.3 → UQPyL-2.0.5}/UQPyL/surrogates/support_vector_machine.py +0 -0
  99. {UQPyL-2.0.3 → UQPyL-2.0.5}/UQPyL/surrogates/surrogate_ABC.py +0 -0
  100. {UQPyL-2.0.3 → UQPyL-2.0.5}/UQPyL/surrogates/svr_/__init__.py +0 -0
  101. {UQPyL-2.0.3 → UQPyL-2.0.5}/UQPyL/surrogates/svr_/libsvm_interface.cpp +0 -0
  102. {UQPyL-2.0.3 → UQPyL-2.0.5}/UQPyL/surrogates/svr_/svm.cpp +0 -0
  103. {UQPyL-2.0.3 → UQPyL-2.0.5}/UQPyL/utility/model_selections.py +0 -0
  104. {UQPyL-2.0.3 → UQPyL-2.0.5}/UQPyL/utility/polynomial_features.py +0 -0
  105. {UQPyL-2.0.3 → UQPyL-2.0.5}/UQPyL/utility/scalers.py +0 -0
  106. {UQPyL-2.0.3 → UQPyL-2.0.5}/UQPyL.egg-info/dependency_links.txt +0 -0
  107. {UQPyL-2.0.3 → UQPyL-2.0.5}/UQPyL.egg-info/requires.txt +0 -0
  108. {UQPyL-2.0.3 → UQPyL-2.0.5}/UQPyL.egg-info/top_level.txt +0 -0
  109. {UQPyL-2.0.3 → UQPyL-2.0.5}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: UQPyL
3
- Version: 2.0.3
3
+ Version: 2.0.5
4
4
  Summary: A python package for parameter uncertainty quantification and optimization
5
5
  Author: wmtSky
6
6
  Author-email: wmtSky <wmtsky@hhu.edu.cn>
@@ -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)
@@ -1,6 +1,6 @@
1
1
  from . import problems, surrogates, optimization, sensibility, DoE, utility
2
2
 
3
- __version__ = "2.0.1"
3
+ __version__ = "2.0.5"
4
4
  __author__ = "wmtSky"
5
5
 
6
6
  __all__=[
@@ -3,6 +3,7 @@ from tqdm import tqdm
3
3
  from typing import Optional
4
4
 
5
5
  from .sce_ua import SCE_UA
6
+ from .pso import PSO
6
7
  from ..DoE import LHS
7
8
  from ..problems import Problem
8
9
  from ..surrogates import Surrogate
@@ -46,11 +47,11 @@ class ASMO():
46
47
  #construct optimization problem to combine surrogate and algorithm
47
48
  self.subProblem=Problem(self.surrogate.predict, self.n_input, 1, self.ub, self.lb)
48
49
 
49
- def run(self,maxFE=1000, Tolerate=0.001, maxTolerateTime=50, oneStep=False):
50
+ def run(self, oneStep=False):
50
51
  '''
51
52
  main procedure
52
53
  '''
53
- show_process=tqdm(total=maxFE)
54
+ show_process=tqdm(total=self.maxFE)
54
55
  FE=0
55
56
  TT=0
56
57
  n_input=self.n_input
@@ -65,8 +66,8 @@ class ASMO():
65
66
  XPop=self.x_init
66
67
  YPop=self.y_init
67
68
 
68
- fe=YPop.shape[0]
69
- show_process.update(fe)
69
+ FE=YPop.shape[0]
70
+ show_process.update(FE)
70
71
  ###
71
72
  idx=np.argsort(YPop, axis=0)
72
73
  BestY=YPop[idx[0,0],0]
@@ -78,11 +79,11 @@ class ASMO():
78
79
  # history_BestY.append(BestY)
79
80
 
80
81
  if (oneStep==False):
81
- while fe<self.maxFE and TT<self.maxTolerateTime:
82
+ while FE<self.maxFE and TT<self.maxTolerateTime:
82
83
  show_process.update(1)
83
84
  # Build surrogate model
84
85
  self.surrogate.fit(XPop, YPop)
85
- res=SCE_UA(self.subProblem).run()
86
+ res=PSO(self.subProblem).run()
86
87
  BestX_SM=res['best_dec']
87
88
 
88
89
  TempY=self.evaluate(BestX_SM)
@@ -91,8 +92,10 @@ class ASMO():
91
92
  YPop=np.vstack((YPop,TempY))
92
93
 
93
94
  if TempY[0,0]<BestY:
94
- BestY=np.copy(TempY)
95
+ BestY=np.copy(TempY[0,0])
95
96
  BestX=np.copy(BestX_SM)
97
+ history_best_decs[FE]=BestX
98
+ history_best_objs[FE]=BestY
96
99
  else:
97
100
  self.surrogate.fit(XPop, YPop)
98
101
  res=SCE_UA(self.subProblem).run()
@@ -100,17 +103,17 @@ class ASMO():
100
103
 
101
104
  TempY=self.evaluate(BestX_SM)
102
105
 
103
- fe+=1
106
+ FE+=1
104
107
  XPop=np.vstack((XPop,BestX_SM))
105
108
  YPop=np.vstack((YPop,TempY))
106
109
 
107
110
  if TempY[0,0]<BestY:
108
111
  BestY=np.copy(TempY)
109
112
  BestX=np.copy(BestX_SM)
110
- history_best_decs[fe]=BestX
111
- history_best_objs[fe]=BestY
113
+ history_best_decs[FE]=BestX
114
+ history_best_objs[FE]=BestY
112
115
 
113
- Result={'best_dec':BestX, 'best_obj':BestY, 'history_best_decs': history_best_decs, 'history_best_objs':history_best_objs ,'FE':fe}
116
+ Result={'best_dec':BestX, 'best_obj':BestY, 'history_best_decs': history_best_decs, 'history_best_objs':history_best_objs ,'FEs':FE}
114
117
 
115
118
  return Result
116
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._unit_X_transform_to_bound(np.atleast_2d(X))
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._unit_X_transform_to_bound(np.atleast_2d(X))
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._unit_X_transform_to_bound(np.atleast_2d(X))
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._unit_X_transform_to_bound(np.atleast_2d(X))
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._unit_X_transform_to_bound(np.atleast_2d(X))
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._unit_X_transform_to_bound(np.atleast_2d(X))
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._unit_X_transform_to_bound(np.atleast_2d(X))
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._unit_X_transform_to_bound(np.atleast_2d(X))
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._unit_X_transform_to_bound(np.atleast_2d(X))
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._unit_X_transform_to_bound(np.atleast_2d(X))
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._unit_X_transform_to_bound(np.atleast_2d(X))
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._unit_X_transform_to_bound(np.atleast_2d(X))
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._unit_X_transform_to_bound(np.atleast_2d(X))
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._unit_X_transform_to_bound(np.atleast_2d(X))
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)
@@ -79,7 +79,7 @@ class FAST(SA):
79
79
  '''
80
80
  n_input=self.n_input; M=self.M
81
81
 
82
- if N<=4*M**2:
82
+ if N<4*M**2:
83
83
  raise ValueError("the number of sample must be greater than 4*M**2!")
84
84
 
85
85
  w=np.zeros(n_input)
@@ -94,7 +94,7 @@ class Morris(SA):
94
94
 
95
95
  N=int(X.shape[0]/self.num_levels)
96
96
 
97
- for i in range(N):
97
+ for i in range(num_trajectory):
98
98
  X_sub=X[i*(n_input+1):(i+1)*(n_input+1), :]
99
99
  Y_sub=Y[i*(n_input+1):(i+1)*(n_input+1), :]
100
100
 
@@ -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 r2_score
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*r2_score(self.Y_scaler.inverse_transform(testY), predictY)
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*r2_score(self.Y_scaler.inverse_transform(testY), predictY)
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 r2_score
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*r2_score(self.__Y_inverse_transform__(testY),predictY)
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*r2_score(self.__Y_inverse_transform__(testY),predictY)
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 r2_score, rank_score, sort_score
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
- 'r2_score',
14
+ 'r_square',
15
15
  'rank_score',
16
16
  'GridSearch'
17
17
  ]
@@ -1,4 +1,4 @@
1
- from .metrics import r2_score, mse, rank_score
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["r2_score", "mse", "rank_score"]="r2_score",
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, "r2_score")
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
@@ -1,7 +1,6 @@
1
1
  import numpy as np
2
- import math
3
- from typing import Tuple
4
- def r2_score(true_Y: np.ndarray, pre_Y: np.ndarray) -> np.ndarray:
2
+
3
+ def r_square(true_Y: np.ndarray, pre_Y: np.ndarray) -> np.ndarray:
5
4
  """
6
5
  R2-score
7
6
  """
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: UQPyL
3
- Version: 2.0.3
3
+ Version: 2.0.5
4
4
  Summary: A python package for parameter uncertainty quantification and optimization
5
5
  Author: wmtSky
6
6
  Author-email: wmtSky <wmtsky@hhu.edu.cn>
@@ -9,7 +9,6 @@ UQPyL.egg-info/dependency_links.txt
9
9
  UQPyL.egg-info/requires.txt
10
10
  UQPyL.egg-info/top_level.txt
11
11
  UQPyL/DoE/__init__.py
12
- UQPyL/DoE/_lhs.py
13
12
  UQPyL/DoE/fast_sequence.py
14
13
  UQPyL/DoE/full_fact.py
15
14
  UQPyL/DoE/lhs.py
@@ -12,7 +12,7 @@ build-backend = "setuptools.build_meta"
12
12
 
13
13
  [project]
14
14
  name = "UQPyL"
15
- version = "2.0.3"
15
+ version = "2.0.5"
16
16
  authors = [
17
17
  {name = "wmtSky", email = "wmtsky@hhu.edu.cn"}
18
18
  ]
@@ -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.3",
44
+ version="2.0.5",
45
45
  author_email="wmtsky@hhu.edu.cn",
46
46
  # ... 其他常规setup参数 ...
47
47
  ext_modules=extensions, # 如果有自定义的编译行为
@@ -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
@@ -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