gemseo-multi-fidelity 0.0.1__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.
- gemseo_multi_fidelity/__init__.py +17 -0
- gemseo_multi_fidelity/core/MFMapperAdapter_input.json +22 -0
- gemseo_multi_fidelity/core/MFMapperAdapter_output.json +22 -0
- gemseo_multi_fidelity/core/MFMapperLinker_input.json +22 -0
- gemseo_multi_fidelity/core/MFMapperLinker_output.json +22 -0
- gemseo_multi_fidelity/core/MFScenarioAdapter_input.json +39 -0
- gemseo_multi_fidelity/core/MFScenarioAdapter_output.json +23 -0
- gemseo_multi_fidelity/core/__init__.py +16 -0
- gemseo_multi_fidelity/core/boxed_domain.py +242 -0
- gemseo_multi_fidelity/core/corr_function.py +411 -0
- gemseo_multi_fidelity/core/criticality.py +124 -0
- gemseo_multi_fidelity/core/ds_mapper.py +307 -0
- gemseo_multi_fidelity/core/errors.py +42 -0
- gemseo_multi_fidelity/core/eval_mapper.py +188 -0
- gemseo_multi_fidelity/core/id_mapper_adapter.py +61 -0
- gemseo_multi_fidelity/core/mapper_adapter.py +126 -0
- gemseo_multi_fidelity/core/mapper_linker.py +72 -0
- gemseo_multi_fidelity/core/mf_formulation.py +635 -0
- gemseo_multi_fidelity/core/mf_logger.py +216 -0
- gemseo_multi_fidelity/core/mf_opt_problem.py +480 -0
- gemseo_multi_fidelity/core/mf_scenario.py +205 -0
- gemseo_multi_fidelity/core/noise_criterion.py +94 -0
- gemseo_multi_fidelity/core/projpolytope.out +0 -0
- gemseo_multi_fidelity/core/scenario_adapter.py +568 -0
- gemseo_multi_fidelity/core/stop_criteria.py +201 -0
- gemseo_multi_fidelity/core/strict_chain.py +75 -0
- gemseo_multi_fidelity/core/utils_model_quality.py +74 -0
- gemseo_multi_fidelity/corrections/__init__.py +16 -0
- gemseo_multi_fidelity/corrections/add_corr_function.py +80 -0
- gemseo_multi_fidelity/corrections/correction_factory.py +65 -0
- gemseo_multi_fidelity/corrections/mul_corr_function.py +86 -0
- gemseo_multi_fidelity/drivers/__init__.py +16 -0
- gemseo_multi_fidelity/drivers/mf_algo_factory.py +38 -0
- gemseo_multi_fidelity/drivers/mf_driver_lib.py +462 -0
- gemseo_multi_fidelity/drivers/refinement.py +234 -0
- gemseo_multi_fidelity/drivers/settings/__init__.py +16 -0
- gemseo_multi_fidelity/drivers/settings/base_mf_driver_settings.py +59 -0
- gemseo_multi_fidelity/drivers/settings/mf_refine_settings.py +50 -0
- gemseo_multi_fidelity/formulations/__init__.py +16 -0
- gemseo_multi_fidelity/formulations/refinement.py +144 -0
- gemseo_multi_fidelity/mapping/__init__.py +16 -0
- gemseo_multi_fidelity/mapping/identity_mapper.py +74 -0
- gemseo_multi_fidelity/mapping/interp_mapper.py +422 -0
- gemseo_multi_fidelity/mapping/mapper_factory.py +70 -0
- gemseo_multi_fidelity/mapping/mapping_errors.py +46 -0
- gemseo_multi_fidelity/mapping/subset_mapper.py +122 -0
- gemseo_multi_fidelity/mf_rosenbrock/__init__.py +16 -0
- gemseo_multi_fidelity/mf_rosenbrock/delayed_disc.py +136 -0
- gemseo_multi_fidelity/mf_rosenbrock/refact_rosen_testcase.py +46 -0
- gemseo_multi_fidelity/mf_rosenbrock/rosen_mf_case.py +284 -0
- gemseo_multi_fidelity/mf_rosenbrock/rosen_mf_funcs.py +350 -0
- gemseo_multi_fidelity/models/__init__.py +16 -0
- gemseo_multi_fidelity/models/fake_updater.py +112 -0
- gemseo_multi_fidelity/models/model_updater.py +91 -0
- gemseo_multi_fidelity/models/rbf/__init__.py +16 -0
- gemseo_multi_fidelity/models/rbf/kernel_factory.py +66 -0
- gemseo_multi_fidelity/models/rbf/kernels/__init__.py +16 -0
- gemseo_multi_fidelity/models/rbf/kernels/gaussian.py +93 -0
- gemseo_multi_fidelity/models/rbf/kernels/matern_3_2.py +101 -0
- gemseo_multi_fidelity/models/rbf/kernels/matern_5_2.py +101 -0
- gemseo_multi_fidelity/models/rbf/kernels/rbf_kernel.py +172 -0
- gemseo_multi_fidelity/models/rbf/rbf_model.py +422 -0
- gemseo_multi_fidelity/models/sparse_rbf_updater.py +96 -0
- gemseo_multi_fidelity/models/taylor/__init__.py +16 -0
- gemseo_multi_fidelity/models/taylor/taylor.py +212 -0
- gemseo_multi_fidelity/models/taylor_updater.py +66 -0
- gemseo_multi_fidelity/models/updater_factory.py +62 -0
- gemseo_multi_fidelity/settings/__init__.py +16 -0
- gemseo_multi_fidelity/settings/drivers.py +22 -0
- gemseo_multi_fidelity/settings/formulations.py +16 -0
- gemseo_multi_fidelity-0.0.1.dist-info/METADATA +99 -0
- gemseo_multi_fidelity-0.0.1.dist-info/RECORD +76 -0
- gemseo_multi_fidelity-0.0.1.dist-info/WHEEL +5 -0
- gemseo_multi_fidelity-0.0.1.dist-info/entry_points.txt +2 -0
- gemseo_multi_fidelity-0.0.1.dist-info/licenses/LICENSE.txt +165 -0
- gemseo_multi_fidelity-0.0.1.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,350 @@
|
|
|
1
|
+
# Copyright 2021 IRT Saint Exupéry, https://www.irt-saintexupery.com
|
|
2
|
+
#
|
|
3
|
+
# This program is free software; you can redistribute it and/or
|
|
4
|
+
# modify it under the terms of the GNU Lesser General Public
|
|
5
|
+
# License version 3 as published by the Free Software Foundation.
|
|
6
|
+
#
|
|
7
|
+
# This program is distributed in the hope that it will be useful,
|
|
8
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
9
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
10
|
+
# Lesser General Public License for more details.
|
|
11
|
+
#
|
|
12
|
+
# You should have received a copy of the GNU Lesser General Public License
|
|
13
|
+
# along with this program; if not, write to the Free Software Foundation,
|
|
14
|
+
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
15
|
+
|
|
16
|
+
# Copyright (c) 2018 AIRBUS OPERATIONS
|
|
17
|
+
|
|
18
|
+
#
|
|
19
|
+
# Contributors:
|
|
20
|
+
# INITIAL AUTHORS - API and implementation and/or documentation
|
|
21
|
+
# :author: Romain Olivanti
|
|
22
|
+
# OTHER AUTHORS - MACROSCOPIC CHANGES
|
|
23
|
+
"""Customized multi-fidelity Rosenbrock functions."""
|
|
24
|
+
|
|
25
|
+
from __future__ import annotations
|
|
26
|
+
|
|
27
|
+
from typing import TYPE_CHECKING
|
|
28
|
+
|
|
29
|
+
from numpy import asarray
|
|
30
|
+
from numpy import fill_diagonal
|
|
31
|
+
from numpy import roll
|
|
32
|
+
from numpy import sqrt
|
|
33
|
+
from numpy import sum as np_sum
|
|
34
|
+
from numpy import zeros
|
|
35
|
+
|
|
36
|
+
if TYPE_CHECKING:
|
|
37
|
+
from numpy.typing import NDArray
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
def rosen(x_in: NDArray, coef: float = 1e2) -> NDArray:
|
|
41
|
+
"""Rosenbrock function.
|
|
42
|
+
|
|
43
|
+
Scalable Rosenbrock function:
|
|
44
|
+
coef * sum(100*(x[1:] - x[:-1]**2)**2 + (1 - x[:-1])**2.
|
|
45
|
+
|
|
46
|
+
Args:
|
|
47
|
+
x_in: The input.
|
|
48
|
+
coef: The scaling coefficient.
|
|
49
|
+
|
|
50
|
+
Returns:
|
|
51
|
+
The function value.
|
|
52
|
+
"""
|
|
53
|
+
x_in = asarray(x_in)
|
|
54
|
+
return coef * np_sum((x_in[1:] - x_in[:-1] ** 2) ** 2) + np_sum(
|
|
55
|
+
(x_in[:-1] - 1.0) ** 2
|
|
56
|
+
)
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
def rosen_grad(x_in: NDArray, coef: float = 1e2) -> NDArray:
|
|
60
|
+
"""Rosenbrock gradient.
|
|
61
|
+
|
|
62
|
+
Gradient of the scalable Rosenbrock function:
|
|
63
|
+
coef * sum(100*(x[1:] - x[:-1]**2)**2 + (1 - x[:-1])**2.
|
|
64
|
+
|
|
65
|
+
Args:
|
|
66
|
+
x_in: The input.
|
|
67
|
+
coef: The scaling coefficient.
|
|
68
|
+
|
|
69
|
+
Returns:
|
|
70
|
+
The gradient value.
|
|
71
|
+
"""
|
|
72
|
+
x_in = asarray(x_in)
|
|
73
|
+
ret = (
|
|
74
|
+
2.0 * coef * (x_in - roll(x_in, 1) ** 2)
|
|
75
|
+
- 4.0 * coef * x_in * (roll(x_in, -1) - x_in**2)
|
|
76
|
+
+ 2.0 * (x_in - 1.0)
|
|
77
|
+
)
|
|
78
|
+
# Border corrections
|
|
79
|
+
ret[0] = 2.0 * (x_in[0] - 1.0) - 4.0 * coef * x_in[0] * (x_in[1] - x_in[0] ** 2)
|
|
80
|
+
ret[-1] = 2.0 * coef * (x_in[-1] - x_in[-2] ** 2)
|
|
81
|
+
return ret
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
def rosen_hess(x_in: NDArray, coef: float = 1e2) -> NDArray:
|
|
85
|
+
"""Rosenbrock Hessian.
|
|
86
|
+
|
|
87
|
+
Hessian of the scalable Rosenbrock function:
|
|
88
|
+
coef * sum(100*(x[1:] - x[:-1]**2)**2 + (1 - x[:-1])**2.
|
|
89
|
+
|
|
90
|
+
Args:
|
|
91
|
+
x_in: The input.
|
|
92
|
+
coef: The scaling coefficient.
|
|
93
|
+
|
|
94
|
+
Returns:
|
|
95
|
+
The Hessian.
|
|
96
|
+
"""
|
|
97
|
+
x_in = asarray(x_in)
|
|
98
|
+
dim = x_in.shape[0]
|
|
99
|
+
ret = zeros((dim,) * 2)
|
|
100
|
+
for i in range(1, dim - 1):
|
|
101
|
+
ret[i, i - 1] = -4.0 * coef * x_in[i - 1]
|
|
102
|
+
ret[i, i] = 2.0 * (coef + 1.0) - 4 * coef * (x_in[i + 1] - 3.0 * x_in[i] ** 2)
|
|
103
|
+
ret[i, i + 1] = -4 * coef * x_in[i]
|
|
104
|
+
# Border corrections
|
|
105
|
+
ret[0, 0] = 2.0 - 4 * coef * (x_in[1] - 3.0 * x_in[0] ** 2)
|
|
106
|
+
ret[0, 1] = -4 * coef * x_in[0]
|
|
107
|
+
ret[-1, -1] = 2.0 * coef
|
|
108
|
+
ret[-1, -2] = -4.0 * coef * x_in[-2]
|
|
109
|
+
return ret
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
def rosen_sqr(x_in: NDArray, coef: float = 1e2, x_sol: NDArray = None) -> NDArray:
|
|
113
|
+
"""Rosenbrock function (with 'squared' info).
|
|
114
|
+
|
|
115
|
+
Low-fidelity Rosenbrock function with 'squared' information:
|
|
116
|
+
coef * sum(x[1:]**2) + sum(x[:-1]**2).
|
|
117
|
+
|
|
118
|
+
Args:
|
|
119
|
+
x_in: The input.
|
|
120
|
+
coef: The scaling coefficient.
|
|
121
|
+
x_sol: The tunable optimum.
|
|
122
|
+
|
|
123
|
+
Returns:
|
|
124
|
+
The function value.
|
|
125
|
+
"""
|
|
126
|
+
x_in = asarray(x_in)
|
|
127
|
+
x_vect = x_in - x_sol if x_sol is not None else x_in
|
|
128
|
+
return coef * np_sum(x_vect[1:] ** 2) + np_sum(x_vect[:-1] ** 2)
|
|
129
|
+
|
|
130
|
+
|
|
131
|
+
def rosen_sqr_grad(x_in: NDArray, coef: float = 1e2, x_sol: NDArray = None) -> NDArray:
|
|
132
|
+
"""Rosenbrock gradient (with 'squared' info).
|
|
133
|
+
|
|
134
|
+
Gradient of the low-fidelity Rosenbrock function with 'squared' information:
|
|
135
|
+
coef * sum(x[1:]**2) + sum(x[:-1]**2).
|
|
136
|
+
|
|
137
|
+
Args:
|
|
138
|
+
x_in: The input.
|
|
139
|
+
coef: The scaling coefficient.
|
|
140
|
+
x_sol: The tunable optimum.
|
|
141
|
+
|
|
142
|
+
Returns:
|
|
143
|
+
The gradient value.
|
|
144
|
+
"""
|
|
145
|
+
x_in = asarray(x_in)
|
|
146
|
+
x_vect = x_in - x_sol if x_sol is not None else x_in
|
|
147
|
+
ret = 2.0 * (coef + 1.0) * x_vect
|
|
148
|
+
# Border corrections
|
|
149
|
+
ret[0] = 2.0 * x_vect[0]
|
|
150
|
+
ret[-1] = 2.0 * coef * x_vect[-1]
|
|
151
|
+
return ret
|
|
152
|
+
|
|
153
|
+
|
|
154
|
+
def rosen_sqr_hess(x_in: NDArray, coef: float = 1e2, x_sol: NDArray = None) -> NDArray:
|
|
155
|
+
"""Rosenbrock Hessian (with 'squared' info).
|
|
156
|
+
|
|
157
|
+
Hessian of the low-fidelity Rosenbrock function with 'squared' information:
|
|
158
|
+
coef * sum(x[1:]**2) + sum(x[:-1]**2).
|
|
159
|
+
|
|
160
|
+
Args:
|
|
161
|
+
x_in: The input.
|
|
162
|
+
coef: The scaling coefficient.
|
|
163
|
+
x_sol: The tunable optimum.
|
|
164
|
+
|
|
165
|
+
Returns:
|
|
166
|
+
The Hessian.
|
|
167
|
+
"""
|
|
168
|
+
x_in = asarray(x_in)
|
|
169
|
+
dim = x_in.shape[0]
|
|
170
|
+
ret = zeros((dim,) * 2)
|
|
171
|
+
fill_diagonal(ret, 2.0 * (coef + 1))
|
|
172
|
+
# Border corrections
|
|
173
|
+
ret[0, 0] = 2.0
|
|
174
|
+
ret[-1, -1] = 2.0 * coef
|
|
175
|
+
return ret
|
|
176
|
+
|
|
177
|
+
|
|
178
|
+
def rosen_quartic(x_in: NDArray, coef: float = 1e2, x_sol: NDArray = None) -> NDArray:
|
|
179
|
+
"""Rosenbrock function (with 'quartic' info).
|
|
180
|
+
|
|
181
|
+
Low-fidelity Rosenbrock function with 'quartic' information:
|
|
182
|
+
coef * (sum(x[1:]**2) + sum(x[:-1]**4)).
|
|
183
|
+
|
|
184
|
+
Args:
|
|
185
|
+
x_in: The input.
|
|
186
|
+
coef: The scaling coefficient.
|
|
187
|
+
x_sol: The tunable optimum.
|
|
188
|
+
|
|
189
|
+
Returns:
|
|
190
|
+
The function value.
|
|
191
|
+
"""
|
|
192
|
+
x_in = asarray(x_in)
|
|
193
|
+
x_vect = x_in - x_sol if x_sol is not None else x_in
|
|
194
|
+
return coef * (np_sum(x_vect[1:] ** 2) + np_sum(x_vect[:-1] ** 4))
|
|
195
|
+
|
|
196
|
+
|
|
197
|
+
def rosen_quartic_grad(
|
|
198
|
+
x_in: NDArray, coef: float = 1e2, x_sol: NDArray = None
|
|
199
|
+
) -> NDArray:
|
|
200
|
+
"""Rosenbrock gradient (with 'quartic' info).
|
|
201
|
+
|
|
202
|
+
Gradient of the low-fidelity Rosenbrock function with 'quartic' information:
|
|
203
|
+
coef * (sum(x[1:]**2) + sum(x[:-1]**4)).
|
|
204
|
+
|
|
205
|
+
Args:
|
|
206
|
+
x_in: The input.
|
|
207
|
+
coef: The scaling coefficient.
|
|
208
|
+
x_sol: The tunable optimum.
|
|
209
|
+
|
|
210
|
+
Returns:
|
|
211
|
+
The gradient value.
|
|
212
|
+
"""
|
|
213
|
+
x_in = asarray(x_in)
|
|
214
|
+
x_vect = x_in - x_sol if x_sol is not None else x_in
|
|
215
|
+
ret = 2.0 * coef * x_vect * (1.0 + 2.0 * x_vect**2)
|
|
216
|
+
# Border corrections
|
|
217
|
+
ret[0] = 4.0 * coef * x_vect[0] ** 3
|
|
218
|
+
ret[-1] = 2.0 * coef * x_vect[-1]
|
|
219
|
+
return ret
|
|
220
|
+
|
|
221
|
+
|
|
222
|
+
def rosen_quartic_hess(
|
|
223
|
+
x_in: NDArray, coef: float = 1e2, x_sol: NDArray = None
|
|
224
|
+
) -> NDArray:
|
|
225
|
+
"""Rosenbrock Hessian (with 'quartic' info).
|
|
226
|
+
|
|
227
|
+
Hessian of the low-fidelity Rosenbrock function with 'quartic' information:
|
|
228
|
+
coef * (sum(x[1:]**2) + sum(x[:-1]**4)).
|
|
229
|
+
|
|
230
|
+
Args:
|
|
231
|
+
x_in: The input.
|
|
232
|
+
coef: The scaling coefficient.
|
|
233
|
+
x_sol: The tunable optimum.
|
|
234
|
+
|
|
235
|
+
Returns:
|
|
236
|
+
The Hessian.
|
|
237
|
+
"""
|
|
238
|
+
x_in = asarray(x_in)
|
|
239
|
+
x_vect = x_in - x_sol if x_sol is not None else x_in
|
|
240
|
+
dim = x_vect.shape[0]
|
|
241
|
+
ret = zeros((dim,) * 2)
|
|
242
|
+
ret[list(range(1, dim - 1)), list(range(1, dim - 1))] = (
|
|
243
|
+
2.0 * coef * (1.0 + 6.0 * x_vect[1:-1] ** 2)
|
|
244
|
+
)
|
|
245
|
+
# Border corrections
|
|
246
|
+
ret[0, 0] = 12.0 * coef * x_vect[0] ** 2
|
|
247
|
+
ret[-1, -1] = 2.0 * coef
|
|
248
|
+
return ret
|
|
249
|
+
|
|
250
|
+
|
|
251
|
+
def rosen_custom(
|
|
252
|
+
x_in: NDArray, coef: float = 1e2, x_sol: float | None = None
|
|
253
|
+
) -> NDArray:
|
|
254
|
+
"""Custom Rosenbrock function.
|
|
255
|
+
|
|
256
|
+
Rosenbrock custom low-fidelity function:
|
|
257
|
+
coef * sum((x_sol * x[1:] - x[:-1]**2)**2) + 2. * sum((x - x_sol)**2)
|
|
258
|
+
- (x[0] - x_sol)**2 - (x[-1] - x_sol)**2
|
|
259
|
+
Min 0. located at x_sol.
|
|
260
|
+
|
|
261
|
+
Args:
|
|
262
|
+
x_in: The input.
|
|
263
|
+
coef: The scaling coefficient.
|
|
264
|
+
x_sol: The generalized position of the solution [x_sol] * dim.
|
|
265
|
+
|
|
266
|
+
Returns:
|
|
267
|
+
The function value.
|
|
268
|
+
"""
|
|
269
|
+
if x_sol is None:
|
|
270
|
+
x_sol = sqrt(3)
|
|
271
|
+
x_in = asarray(x_in)
|
|
272
|
+
return (
|
|
273
|
+
coef * np_sum((x_sol * x_in[1:] - x_in[:-1] ** 2) ** 2)
|
|
274
|
+
+ 2.0 * np_sum((x_in - x_sol) ** 2)
|
|
275
|
+
- (x_in[0] - x_sol) ** 2
|
|
276
|
+
- (x_in[-1] - x_sol) ** 2
|
|
277
|
+
)
|
|
278
|
+
|
|
279
|
+
|
|
280
|
+
def rosen_custom_grad(
|
|
281
|
+
x_in: NDArray, coef: float = 1e2, x_sol: float | None = None
|
|
282
|
+
) -> NDArray:
|
|
283
|
+
"""Custom Rosenbrock gradient.
|
|
284
|
+
|
|
285
|
+
Gradient of the Rosenbrock custom low-fidelity function:
|
|
286
|
+
coef * sum((x_sol * x[1:] - x[:-1]**2)**2) + 2. * sum((x - x_sol)**2)
|
|
287
|
+
- (x[0] - x_sol)**2 - (x[-1] - x_sol)**2
|
|
288
|
+
Min 0. located at x_sol.
|
|
289
|
+
|
|
290
|
+
Args:
|
|
291
|
+
x_in: The input.
|
|
292
|
+
coef: The scaling coefficient.
|
|
293
|
+
x_sol: The generalized position of the solution [x_sol] * dim.
|
|
294
|
+
|
|
295
|
+
Returns:
|
|
296
|
+
The gradient value.
|
|
297
|
+
"""
|
|
298
|
+
if x_sol is None:
|
|
299
|
+
x_sol = sqrt(3)
|
|
300
|
+
x_in = asarray(x_in)
|
|
301
|
+
ret = (
|
|
302
|
+
2.0 * coef * x_sol * (x_sol * x_in - roll(x_in, 1) ** 2)
|
|
303
|
+
- 4.0 * coef * x_in * (x_sol * roll(x_in, -1) - x_in**2)
|
|
304
|
+
+ 4.0 * (x_in - x_sol)
|
|
305
|
+
)
|
|
306
|
+
# Border corrections
|
|
307
|
+
ret[0] = 2.0 * (x_in[0] - x_sol) - 4.0 * coef * x_in[0] * (
|
|
308
|
+
x_sol * x_in[1] - x_in[0] ** 2
|
|
309
|
+
)
|
|
310
|
+
ret[-1] = 2.0 * (x_in[-1] - x_sol) + 2.0 * coef * x_sol * (
|
|
311
|
+
x_sol * x_in[-1] - x_in[-2] ** 2
|
|
312
|
+
)
|
|
313
|
+
return ret
|
|
314
|
+
|
|
315
|
+
|
|
316
|
+
def rosen_custom_hess(
|
|
317
|
+
x_in: NDArray, coef: float = 1e2, x_sol: float | None = None
|
|
318
|
+
) -> NDArray:
|
|
319
|
+
"""Custom Rosenbrock Hessian.
|
|
320
|
+
|
|
321
|
+
Hessian of the Rosenbrock custom low-fidelity function:
|
|
322
|
+
coef * sum((x_sol * x[1:] - x[:-1]**2)**2) + 2. * sum((x - x_sol)**2)
|
|
323
|
+
- (x[0] - x_sol)**2 - (x[-1] - x_sol)**2
|
|
324
|
+
Min 0. located at x_sol.
|
|
325
|
+
|
|
326
|
+
Args:
|
|
327
|
+
x_in: The input.
|
|
328
|
+
coef: The scaling coefficient.
|
|
329
|
+
x_sol: The generalized position of the solution [x_sol] * dim.
|
|
330
|
+
|
|
331
|
+
Returns:
|
|
332
|
+
The Hessian.
|
|
333
|
+
"""
|
|
334
|
+
if x_sol is None:
|
|
335
|
+
x_sol = sqrt(3)
|
|
336
|
+
x_in = asarray(x_in)
|
|
337
|
+
dim = x_in.shape[0]
|
|
338
|
+
ret = zeros((dim,) * 2)
|
|
339
|
+
for i in range(1, dim - 1):
|
|
340
|
+
ret[i, i - 1] = -4.0 * coef * x_sol * x_in[i - 1]
|
|
341
|
+
ret[i, i] = 2.0 * (coef * x_sol**2 + 2.0) - 4 * coef * (
|
|
342
|
+
x_sol * x_in[i + 1] - 3.0 * x_in[i] ** 2
|
|
343
|
+
)
|
|
344
|
+
ret[i, i + 1] = -4 * coef * x_sol * x_in[i]
|
|
345
|
+
# Border corrections
|
|
346
|
+
ret[0, 0] = 2.0 - 4 * coef * (x_sol * x_in[1] - 3.0 * x_in[0] ** 2)
|
|
347
|
+
ret[0, 1] = -4 * coef * x_sol * x_in[0]
|
|
348
|
+
ret[-1, -1] = 2.0 * (1.0 + coef * x_sol**2)
|
|
349
|
+
ret[-1, -2] = -4.0 * coef * x_sol * x_in[-2]
|
|
350
|
+
return ret
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
# Copyright 2021 IRT Saint Exupéry, https://www.irt-saintexupery.com
|
|
2
|
+
#
|
|
3
|
+
# This program is free software; you can redistribute it and/or
|
|
4
|
+
# modify it under the terms of the GNU Lesser General Public
|
|
5
|
+
# License version 3 as published by the Free Software Foundation.
|
|
6
|
+
#
|
|
7
|
+
# This program is distributed in the hope that it will be useful,
|
|
8
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
9
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
10
|
+
# Lesser General Public License for more details.
|
|
11
|
+
#
|
|
12
|
+
# You should have received a copy of the GNU Lesser General Public License
|
|
13
|
+
# along with this program; if not, write to the Free Software Foundation,
|
|
14
|
+
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
15
|
+
|
|
16
|
+
"""Models."""
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
# Copyright 2021 IRT Saint Exupéry, https://www.irt-saintexupery.com
|
|
2
|
+
#
|
|
3
|
+
# This program is free software; you can redistribute it and/or
|
|
4
|
+
# modify it under the terms of the GNU Lesser General Public
|
|
5
|
+
# License version 3 as published by the Free Software Foundation.
|
|
6
|
+
#
|
|
7
|
+
# This program is distributed in the hope that it will be useful,
|
|
8
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
9
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
10
|
+
# Lesser General Public License for more details.
|
|
11
|
+
#
|
|
12
|
+
# You should have received a copy of the GNU Lesser General Public License
|
|
13
|
+
# along with this program; if not, write to the Free Software Foundation,
|
|
14
|
+
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
15
|
+
|
|
16
|
+
# Copyright (c) 2018 AIRBUS OPERATIONS
|
|
17
|
+
|
|
18
|
+
#
|
|
19
|
+
# Contributors:
|
|
20
|
+
# INITIAL AUTHORS - API and implementation and/or documentation
|
|
21
|
+
# :author: Romain Olivanti
|
|
22
|
+
# OTHER AUTHORS - MACROSCOPIC CHANGES
|
|
23
|
+
"""Fake updater."""
|
|
24
|
+
|
|
25
|
+
from __future__ import annotations
|
|
26
|
+
|
|
27
|
+
from typing import TYPE_CHECKING
|
|
28
|
+
|
|
29
|
+
from gemseo.core.mdo_functions.mdo_function import MDOFunction
|
|
30
|
+
from numpy import array
|
|
31
|
+
from numpy import where
|
|
32
|
+
from numpy import zeros
|
|
33
|
+
from numpy import zeros_like
|
|
34
|
+
from numpy.linalg import norm
|
|
35
|
+
|
|
36
|
+
from gemseo_multi_fidelity.models.model_updater import ModelUpdater
|
|
37
|
+
|
|
38
|
+
if TYPE_CHECKING:
|
|
39
|
+
from numpy.typing import NDArray
|
|
40
|
+
|
|
41
|
+
try:
|
|
42
|
+
_ = MDOFunction.hess
|
|
43
|
+
HAS_HESSIAN = True
|
|
44
|
+
except AttributeError:
|
|
45
|
+
HAS_HESSIAN = False
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
class FakeUpdater(ModelUpdater):
|
|
49
|
+
"""Simple updater.
|
|
50
|
+
|
|
51
|
+
Storing and returning either the reference values for the reference points or
|
|
52
|
+
(0,...) for other points.
|
|
53
|
+
|
|
54
|
+
Only meant to be used for testing purposes and not meant to be differentiated.
|
|
55
|
+
"""
|
|
56
|
+
|
|
57
|
+
HANDLES_MULTI_UPDATE = True
|
|
58
|
+
|
|
59
|
+
def __init__(self, **kwargs) -> None:
|
|
60
|
+
"""Constructor.
|
|
61
|
+
|
|
62
|
+
Args:
|
|
63
|
+
kwargs: The keywords arguments.
|
|
64
|
+
"""
|
|
65
|
+
self.x_ref = None
|
|
66
|
+
self.vals = None
|
|
67
|
+
self.grads = None
|
|
68
|
+
self.hess = None
|
|
69
|
+
super().__init__()
|
|
70
|
+
|
|
71
|
+
def _get_vect_index(self, x_vect: NDArray) -> int | None:
|
|
72
|
+
"""Return the index of the stored data.
|
|
73
|
+
|
|
74
|
+
Only if x_vect exactly matches one row of self.x_ref.
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
"""
|
|
78
|
+
if self.x_ref is not None:
|
|
79
|
+
ind_val = where(norm(self.x_ref - x_vect, axis=1) == 0.0)[0]
|
|
80
|
+
return ind_val[0] if len(ind_val) != 0 else None
|
|
81
|
+
return None
|
|
82
|
+
|
|
83
|
+
def _func(self, x_vect: NDArray) -> float:
|
|
84
|
+
index = self._get_vect_index(x_vect)
|
|
85
|
+
return 0.0 if index is None else self.vals[index]
|
|
86
|
+
|
|
87
|
+
def _jac(self, x_vect: NDArray) -> NDArray:
|
|
88
|
+
index = self._get_vect_index(x_vect)
|
|
89
|
+
return zeros_like(x_vect) if index is None else self.grads[index]
|
|
90
|
+
|
|
91
|
+
def _hess(self, x_vect: NDArray) -> NDArray:
|
|
92
|
+
index = self._get_vect_index(x_vect)
|
|
93
|
+
return zeros((len(x_vect),) * 2) if index is None else self.hess[index]
|
|
94
|
+
|
|
95
|
+
def _set_function(self) -> None:
|
|
96
|
+
"""Set the MDOFunction."""
|
|
97
|
+
self.function = MDOFunction(self._func, "Fake", jac=self._jac)
|
|
98
|
+
if HAS_HESSIAN:
|
|
99
|
+
self.function.hess = self._hess
|
|
100
|
+
|
|
101
|
+
def _update(
|
|
102
|
+
self, vects: NDArray, vals: NDArray, grads: NDArray = None, hess: NDArray = None
|
|
103
|
+
) -> None:
|
|
104
|
+
"""Use all the points provided."""
|
|
105
|
+
self.x_ref = array(vects)
|
|
106
|
+
self.vals = array(vals)
|
|
107
|
+
self.grads = None
|
|
108
|
+
self.hess = None
|
|
109
|
+
if grads is not None:
|
|
110
|
+
self.grads = array(grads)
|
|
111
|
+
if hess is not None:
|
|
112
|
+
self.hess = array(hess)
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
# Copyright 2021 IRT Saint Exupéry, https://www.irt-saintexupery.com
|
|
2
|
+
#
|
|
3
|
+
# This program is free software; you can redistribute it and/or
|
|
4
|
+
# modify it under the terms of the GNU Lesser General Public
|
|
5
|
+
# License version 3 as published by the Free Software Foundation.
|
|
6
|
+
#
|
|
7
|
+
# This program is distributed in the hope that it will be useful,
|
|
8
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
9
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
10
|
+
# Lesser General Public License for more details.
|
|
11
|
+
#
|
|
12
|
+
# You should have received a copy of the GNU Lesser General Public License
|
|
13
|
+
# along with this program; if not, write to the Free Software Foundation,
|
|
14
|
+
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
15
|
+
|
|
16
|
+
# Copyright (c) 2018 AIRBUS OPERATIONS
|
|
17
|
+
|
|
18
|
+
#
|
|
19
|
+
# Contributors:
|
|
20
|
+
# INITIAL AUTHORS - API and implementation and/or documentation
|
|
21
|
+
# :author: Romain Olivanti
|
|
22
|
+
# OTHER AUTHORS - MACROSCOPIC CHANGES
|
|
23
|
+
"""Model Updater."""
|
|
24
|
+
|
|
25
|
+
from __future__ import annotations
|
|
26
|
+
|
|
27
|
+
from typing import TYPE_CHECKING
|
|
28
|
+
|
|
29
|
+
from gemseo.core.mdo_functions.mdo_function import MDOFunction
|
|
30
|
+
|
|
31
|
+
if TYPE_CHECKING:
|
|
32
|
+
from numpy.typing import NDArray
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
class ModelUpdater:
|
|
36
|
+
"""Base class for model updaters."""
|
|
37
|
+
|
|
38
|
+
HANDLES_MULTI_UPDATE = False
|
|
39
|
+
|
|
40
|
+
def __init__(self, **kwargs) -> None:
|
|
41
|
+
"""Constructor.
|
|
42
|
+
|
|
43
|
+
Args:
|
|
44
|
+
kwargs: The keywords arguments.
|
|
45
|
+
"""
|
|
46
|
+
# MDOFunction wrapping the model
|
|
47
|
+
self.function = None
|
|
48
|
+
self._is_set = False
|
|
49
|
+
self._set_function()
|
|
50
|
+
if not isinstance(self.function, MDOFunction):
|
|
51
|
+
msg = "Updater not setting a MDOFunction"
|
|
52
|
+
raise TypeError(msg)
|
|
53
|
+
|
|
54
|
+
@property
|
|
55
|
+
def is_set(self) -> bool:
|
|
56
|
+
"""Return is_set attribute."""
|
|
57
|
+
return self._is_set
|
|
58
|
+
|
|
59
|
+
def _set_function(self):
|
|
60
|
+
"""Set the MDOFunction. To be overloaded by subclasses."""
|
|
61
|
+
raise NotImplementedError
|
|
62
|
+
|
|
63
|
+
def update(
|
|
64
|
+
self, vects: NDArray, vals: NDArray, grads: NDArray = None, hess: NDArray = None
|
|
65
|
+
) -> None:
|
|
66
|
+
"""Update the model using the provided data.
|
|
67
|
+
|
|
68
|
+
The last point is guaranteed to be provided first. Gradient and hessian are
|
|
69
|
+
optional and may not be provided for each vect.
|
|
70
|
+
|
|
71
|
+
Args:
|
|
72
|
+
vects: The input space (3D array).
|
|
73
|
+
vals: The output values (1D array).
|
|
74
|
+
grads: The output gradients (2D array).
|
|
75
|
+
hess: The output hessians (3D array).
|
|
76
|
+
"""
|
|
77
|
+
self._update(vects, vals, grads=grads, hess=hess)
|
|
78
|
+
self._is_set = True
|
|
79
|
+
|
|
80
|
+
def _update(
|
|
81
|
+
self, vects: NDArray, vals: NDArray, grads: NDArray = None, hess: NDArray = None
|
|
82
|
+
):
|
|
83
|
+
"""Real update routine. To be overloaded by subclasses.
|
|
84
|
+
|
|
85
|
+
Args:
|
|
86
|
+
vects: The input space (3D array).
|
|
87
|
+
vals: The output values (1D array).
|
|
88
|
+
grads: The output gradients (2D array).
|
|
89
|
+
hess: The output hessians (3D array).
|
|
90
|
+
"""
|
|
91
|
+
raise NotImplementedError
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
# Copyright 2021 IRT Saint Exupéry, https://www.irt-saintexupery.com
|
|
2
|
+
#
|
|
3
|
+
# This program is free software; you can redistribute it and/or
|
|
4
|
+
# modify it under the terms of the GNU Lesser General Public
|
|
5
|
+
# License version 3 as published by the Free Software Foundation.
|
|
6
|
+
#
|
|
7
|
+
# This program is distributed in the hope that it will be useful,
|
|
8
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
9
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
10
|
+
# Lesser General Public License for more details.
|
|
11
|
+
#
|
|
12
|
+
# You should have received a copy of the GNU Lesser General Public License
|
|
13
|
+
# along with this program; if not, write to the Free Software Foundation,
|
|
14
|
+
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
15
|
+
|
|
16
|
+
"""RBF model."""
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
# Copyright 2021 IRT Saint Exupéry, https://www.irt-saintexupery.com
|
|
2
|
+
#
|
|
3
|
+
# This program is free software; you can redistribute it and/or
|
|
4
|
+
# modify it under the terms of the GNU Lesser General Public
|
|
5
|
+
# License version 3 as published by the Free Software Foundation.
|
|
6
|
+
#
|
|
7
|
+
# This program is distributed in the hope that it will be useful,
|
|
8
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
9
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
10
|
+
# Lesser General Public License for more details.
|
|
11
|
+
#
|
|
12
|
+
# You should have received a copy of the GNU Lesser General Public License
|
|
13
|
+
# along with this program; if not, write to the Free Software Foundation,
|
|
14
|
+
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
15
|
+
|
|
16
|
+
# Copyright (c) 2018 AIRBUS OPERATIONS
|
|
17
|
+
|
|
18
|
+
#
|
|
19
|
+
# Contributors:
|
|
20
|
+
# INITIAL AUTHORS - API and implementation and/or documentation
|
|
21
|
+
# :author: Romain Olivanti
|
|
22
|
+
# OTHER AUTHORS - MACROSCOPIC CHANGES
|
|
23
|
+
"""Kernel factory."""
|
|
24
|
+
|
|
25
|
+
from __future__ import annotations
|
|
26
|
+
|
|
27
|
+
from typing import TYPE_CHECKING
|
|
28
|
+
from typing import ClassVar
|
|
29
|
+
|
|
30
|
+
from gemseo_multi_fidelity.models.rbf.kernels.gaussian import GaussianKernel
|
|
31
|
+
from gemseo_multi_fidelity.models.rbf.kernels.matern_3_2 import Matern32Kernel
|
|
32
|
+
from gemseo_multi_fidelity.models.rbf.kernels.matern_5_2 import Matern52Kernel
|
|
33
|
+
|
|
34
|
+
if TYPE_CHECKING:
|
|
35
|
+
from gemseo_multi_fidelity.models.rbf.kernels.rbf_kernel import RBFKernel
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
class KernelFactory:
|
|
39
|
+
"""Kernel factory to generate a kernel from its name."""
|
|
40
|
+
|
|
41
|
+
GAUSSIAN = "gaussian"
|
|
42
|
+
MATERN_3_2 = "matern_3_2"
|
|
43
|
+
MATERN_5_2 = "matern_5_2"
|
|
44
|
+
AVAILABLE_KERNELS: ClassVar[list] = [GAUSSIAN, MATERN_3_2, MATERN_5_2]
|
|
45
|
+
"""The list of available kernels."""
|
|
46
|
+
|
|
47
|
+
def create(self, name, scaling=1.0) -> RBFKernel:
|
|
48
|
+
"""Factory method to create an RBF kernel.
|
|
49
|
+
|
|
50
|
+
Args:
|
|
51
|
+
name: The name of the kernel.
|
|
52
|
+
scaling: The scaling of the kernel.
|
|
53
|
+
|
|
54
|
+
Returns:
|
|
55
|
+
The RBFKernel object.
|
|
56
|
+
"""
|
|
57
|
+
if name == self.GAUSSIAN:
|
|
58
|
+
kernel = GaussianKernel(scaling=scaling)
|
|
59
|
+
elif name == self.MATERN_3_2:
|
|
60
|
+
kernel = Matern32Kernel(scaling=scaling)
|
|
61
|
+
elif name == self.MATERN_5_2:
|
|
62
|
+
kernel = Matern52Kernel(scaling=scaling)
|
|
63
|
+
else:
|
|
64
|
+
msg = f"{name} not in {self.AVAILABLE_KERNELS}"
|
|
65
|
+
raise ValueError(msg)
|
|
66
|
+
return kernel
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
# Copyright 2021 IRT Saint Exupéry, https://www.irt-saintexupery.com
|
|
2
|
+
#
|
|
3
|
+
# This program is free software; you can redistribute it and/or
|
|
4
|
+
# modify it under the terms of the GNU Lesser General Public
|
|
5
|
+
# License version 3 as published by the Free Software Foundation.
|
|
6
|
+
#
|
|
7
|
+
# This program is distributed in the hope that it will be useful,
|
|
8
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
9
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
10
|
+
# Lesser General Public License for more details.
|
|
11
|
+
#
|
|
12
|
+
# You should have received a copy of the GNU Lesser General Public License
|
|
13
|
+
# along with this program; if not, write to the Free Software Foundation,
|
|
14
|
+
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
15
|
+
|
|
16
|
+
"""RBF model kernels."""
|