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,17 @@
|
|
|
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
|
+
"""Main entry point."""
|
|
16
|
+
|
|
17
|
+
from __future__ import annotations
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "MFMapperAdapter_input",
|
|
3
|
+
"required": [
|
|
4
|
+
"x_best"
|
|
5
|
+
],
|
|
6
|
+
"properties": {
|
|
7
|
+
"x_best": {},
|
|
8
|
+
"x_reference": {},
|
|
9
|
+
"output_reference": {
|
|
10
|
+
"type": "object"
|
|
11
|
+
},
|
|
12
|
+
"output_options": {
|
|
13
|
+
"type": "object"
|
|
14
|
+
},
|
|
15
|
+
"output_status": {
|
|
16
|
+
"type": "string"
|
|
17
|
+
}
|
|
18
|
+
},
|
|
19
|
+
"$schema": "http://json-schema.org/draft-04/schema",
|
|
20
|
+
"type": "object",
|
|
21
|
+
"id": "#MFMapperAdapter_input"
|
|
22
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "MFMapperAdapter_output",
|
|
3
|
+
"required": [
|
|
4
|
+
"x_start"
|
|
5
|
+
],
|
|
6
|
+
"properties": {
|
|
7
|
+
"x_start": {},
|
|
8
|
+
"x_reference": {},
|
|
9
|
+
"output_reference": {
|
|
10
|
+
"type": "object"
|
|
11
|
+
},
|
|
12
|
+
"input_options": {
|
|
13
|
+
"type": "object"
|
|
14
|
+
},
|
|
15
|
+
"output_status": {
|
|
16
|
+
"type": "string"
|
|
17
|
+
}
|
|
18
|
+
},
|
|
19
|
+
"$schema": "http://json-schema.org/draft-04/schema",
|
|
20
|
+
"type": "object",
|
|
21
|
+
"id": "#MFMapperAdapter_output"
|
|
22
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "MFMapperAdapter_output",
|
|
3
|
+
"required": [
|
|
4
|
+
"x_start"
|
|
5
|
+
],
|
|
6
|
+
"properties": {
|
|
7
|
+
"x_start": {},
|
|
8
|
+
"x_reference": {},
|
|
9
|
+
"output_reference": {
|
|
10
|
+
"type": "object"
|
|
11
|
+
},
|
|
12
|
+
"input_options": {
|
|
13
|
+
"type": "object"
|
|
14
|
+
},
|
|
15
|
+
"output_status": {
|
|
16
|
+
"type": "string"
|
|
17
|
+
}
|
|
18
|
+
},
|
|
19
|
+
"$schema": "http://json-schema.org/draft-04/schema",
|
|
20
|
+
"type": "object",
|
|
21
|
+
"id": "#MFMapperAdapter_output"
|
|
22
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "MFMapperAdapter_input",
|
|
3
|
+
"required": [
|
|
4
|
+
"x_best"
|
|
5
|
+
],
|
|
6
|
+
"properties": {
|
|
7
|
+
"x_best": {},
|
|
8
|
+
"x_reference": {},
|
|
9
|
+
"output_reference": {
|
|
10
|
+
"type": "object"
|
|
11
|
+
},
|
|
12
|
+
"output_options": {
|
|
13
|
+
"type": "object"
|
|
14
|
+
},
|
|
15
|
+
"output_status": {
|
|
16
|
+
"type": "string"
|
|
17
|
+
}
|
|
18
|
+
},
|
|
19
|
+
"$schema": "http://json-schema.org/draft-04/schema",
|
|
20
|
+
"type": "object",
|
|
21
|
+
"id": "#MFMapperAdapter_input"
|
|
22
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "MFScenarioAdapter_input",
|
|
3
|
+
"required": [
|
|
4
|
+
"x_start"
|
|
5
|
+
],
|
|
6
|
+
"properties": {
|
|
7
|
+
"algo_name": {
|
|
8
|
+
"type": "string"
|
|
9
|
+
},
|
|
10
|
+
"max_iter": {
|
|
11
|
+
"type": "integer",
|
|
12
|
+
"minimum": 1
|
|
13
|
+
},
|
|
14
|
+
"algo_options": {
|
|
15
|
+
"type": "object"
|
|
16
|
+
},
|
|
17
|
+
"x_start": {},
|
|
18
|
+
"input_options": {
|
|
19
|
+
"type": "object"
|
|
20
|
+
},
|
|
21
|
+
"x_reference": {},
|
|
22
|
+
"output_reference": {
|
|
23
|
+
"type": "object"
|
|
24
|
+
},
|
|
25
|
+
"on_entry_callbacks": {},
|
|
26
|
+
"return_callback": {},
|
|
27
|
+
"on_exit_callbacks": {},
|
|
28
|
+
"max_corr_rad": {
|
|
29
|
+
"type": "number",
|
|
30
|
+
"minimum": 0.0001
|
|
31
|
+
},
|
|
32
|
+
"hotstart_options": {},
|
|
33
|
+
"validation_map": {},
|
|
34
|
+
"validation_jac_map": {}
|
|
35
|
+
},
|
|
36
|
+
"$schema": "http://json-schema.org/draft-04/schema",
|
|
37
|
+
"type": "object",
|
|
38
|
+
"id": "#MFScenarioAdapter_input"
|
|
39
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "MFScenarioAdapter_output",
|
|
3
|
+
"required": [
|
|
4
|
+
"x_best",
|
|
5
|
+
"output_status"
|
|
6
|
+
],
|
|
7
|
+
"properties": {
|
|
8
|
+
"x_best": {},
|
|
9
|
+
"output_status": {
|
|
10
|
+
"type": "string"
|
|
11
|
+
},
|
|
12
|
+
"output_options": {
|
|
13
|
+
"type": "object"
|
|
14
|
+
},
|
|
15
|
+
"x_reference": {},
|
|
16
|
+
"output_reference": {
|
|
17
|
+
"type": "object"
|
|
18
|
+
}
|
|
19
|
+
},
|
|
20
|
+
"$schema": "http://json-schema.org/draft-04/schema",
|
|
21
|
+
"type": "object",
|
|
22
|
+
"id": "#MFScenarioAdapter_output"
|
|
23
|
+
}
|
|
@@ -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
|
+
"""Core."""
|
|
@@ -0,0 +1,242 @@
|
|
|
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
|
+
# Contributors:
|
|
19
|
+
# INITIAL AUTHORS - API and implementation and/or documentation
|
|
20
|
+
# :author: Romain Olivanti
|
|
21
|
+
# OTHER AUTHORS - MACROSCOPIC CHANGES
|
|
22
|
+
"""Boxed Domain."""
|
|
23
|
+
|
|
24
|
+
from __future__ import annotations
|
|
25
|
+
|
|
26
|
+
from typing import TYPE_CHECKING
|
|
27
|
+
|
|
28
|
+
from numpy import all as np_all
|
|
29
|
+
from numpy import any as np_any
|
|
30
|
+
from numpy import array
|
|
31
|
+
from numpy import array_equal
|
|
32
|
+
from numpy import max as np_max
|
|
33
|
+
from numpy import min as np_min
|
|
34
|
+
from numpy import vstack
|
|
35
|
+
from numpy import where
|
|
36
|
+
from numpy import zeros
|
|
37
|
+
|
|
38
|
+
from gemseo_multi_fidelity.core.errors import ConsistencyError
|
|
39
|
+
|
|
40
|
+
if TYPE_CHECKING:
|
|
41
|
+
from numpy.typing import NDArray
|
|
42
|
+
from typing_extensions import Self
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
class BoxedDomain:
|
|
46
|
+
"""Basic boxed domain."""
|
|
47
|
+
|
|
48
|
+
def __init__(self, lower: NDArray, upper: NDArray) -> None:
|
|
49
|
+
"""Initialize the boxed domain.
|
|
50
|
+
|
|
51
|
+
Args:
|
|
52
|
+
lower: The lower bounds, 1d array_like.
|
|
53
|
+
upper: The upper bounds, 1d array_like.
|
|
54
|
+
"""
|
|
55
|
+
self.lower = array(lower, copy=True).flatten()
|
|
56
|
+
self.upper = array(upper, copy=True).flatten()
|
|
57
|
+
|
|
58
|
+
if self.lower.shape != self.upper.shape:
|
|
59
|
+
msg = "Dimension mismatch between lower and upper"
|
|
60
|
+
raise ConsistencyError(msg)
|
|
61
|
+
|
|
62
|
+
if np_any(self.upper < self.lower):
|
|
63
|
+
msg = "upper < lower"
|
|
64
|
+
raise ConsistencyError(msg)
|
|
65
|
+
|
|
66
|
+
def _check_vect(self, x_vect: NDArray) -> NDArray:
|
|
67
|
+
"""Check if x_vect is consistent with the bounds of the domain.
|
|
68
|
+
|
|
69
|
+
Converts x_vect to an array if required.
|
|
70
|
+
|
|
71
|
+
Args:
|
|
72
|
+
x_vect: The 1d array_like.
|
|
73
|
+
|
|
74
|
+
Returns:
|
|
75
|
+
Array.
|
|
76
|
+
|
|
77
|
+
Raises:
|
|
78
|
+
``ConsistencyError`` if the size of x_vect is not consistent with the bounds
|
|
79
|
+
of the domain.
|
|
80
|
+
"""
|
|
81
|
+
x_vect = array(x_vect, copy=False)
|
|
82
|
+
if x_vect.shape != self.lower.shape:
|
|
83
|
+
msg = "Dimension mismatch between x_vect and bounds"
|
|
84
|
+
raise ConsistencyError(msg)
|
|
85
|
+
return x_vect
|
|
86
|
+
|
|
87
|
+
def contains(self, x_vect: NDArray, tol: float | NDArray = 0.0) -> bool:
|
|
88
|
+
"""Check if x_vect belongs to the domain within the provided tolerance.
|
|
89
|
+
|
|
90
|
+
Args:
|
|
91
|
+
x_vect: The 1d array_like.
|
|
92
|
+
tol: The tolerance.
|
|
93
|
+
|
|
94
|
+
Returns:
|
|
95
|
+
``True`` if x_vect belongs to the Domain, ``False`` otherwise.
|
|
96
|
+
|
|
97
|
+
Raises:
|
|
98
|
+
``ConsistencyError`` if the size of x_vect is not consistent with the bounds
|
|
99
|
+
of the domain.
|
|
100
|
+
"""
|
|
101
|
+
x_vect = self._check_vect(x_vect)
|
|
102
|
+
return np_all(x_vect >= self.lower - tol) and np_all(x_vect <= self.upper + tol)
|
|
103
|
+
|
|
104
|
+
def __contains__(self, x_vect: NDArray) -> bool:
|
|
105
|
+
"""Override the default implementation using contains without a tolerance.
|
|
106
|
+
|
|
107
|
+
Args:
|
|
108
|
+
x_vect: 1d array_like.
|
|
109
|
+
|
|
110
|
+
Returns:
|
|
111
|
+
``True`` if x_vect belongs to the domain, ``False`` otherwise.
|
|
112
|
+
|
|
113
|
+
Raises:
|
|
114
|
+
``ConsistencyError`` if the size of x_vect is not consistent with the bounds
|
|
115
|
+
of the domain.
|
|
116
|
+
"""
|
|
117
|
+
return self.contains(x_vect, tol=0.0)
|
|
118
|
+
|
|
119
|
+
def __eq__(self, other: object) -> bool:
|
|
120
|
+
"""Override the default implementation.
|
|
121
|
+
|
|
122
|
+
Args:
|
|
123
|
+
other: The other object.
|
|
124
|
+
|
|
125
|
+
Returns:
|
|
126
|
+
``True`` if other is a domain object with identical bounds.
|
|
127
|
+
"""
|
|
128
|
+
ret = False
|
|
129
|
+
if (
|
|
130
|
+
isinstance(other, BoxedDomain)
|
|
131
|
+
and array_equal(self.lower, other.lower)
|
|
132
|
+
and array_equal(self.upper, other.upper)
|
|
133
|
+
):
|
|
134
|
+
ret = True
|
|
135
|
+
return ret
|
|
136
|
+
|
|
137
|
+
def __ne__(self, other: object) -> bool:
|
|
138
|
+
"""Override the default implementation.
|
|
139
|
+
|
|
140
|
+
Args:
|
|
141
|
+
other: The other object.
|
|
142
|
+
|
|
143
|
+
Returns:
|
|
144
|
+
Opposite of self.__eq__.
|
|
145
|
+
"""
|
|
146
|
+
return not self.__eq__(other)
|
|
147
|
+
|
|
148
|
+
def get_dist_upper(self, x_vect: NDArray) -> NDArray:
|
|
149
|
+
"""Get the difference: self.upper - x_vect.
|
|
150
|
+
|
|
151
|
+
Args:
|
|
152
|
+
x_vect: 1d array_like.
|
|
153
|
+
|
|
154
|
+
Returns:
|
|
155
|
+
The difference array.
|
|
156
|
+
|
|
157
|
+
Raises:
|
|
158
|
+
``ConsistencyError`` if the size of x_vect is not consistent with the bounds
|
|
159
|
+
of the domain.
|
|
160
|
+
"""
|
|
161
|
+
return self.upper - self._check_vect(x_vect)
|
|
162
|
+
|
|
163
|
+
def get_dist_lower(self, x_vect: NDArray) -> NDArray:
|
|
164
|
+
"""Get the difference: x_vect - self.lower.
|
|
165
|
+
|
|
166
|
+
Args:
|
|
167
|
+
x_vect: 1d array_like.
|
|
168
|
+
|
|
169
|
+
Returns:
|
|
170
|
+
The difference array.
|
|
171
|
+
|
|
172
|
+
Raises:
|
|
173
|
+
``ConsistencyError`` if the size of x_vect is not consistent with the bounds
|
|
174
|
+
of the domain.
|
|
175
|
+
"""
|
|
176
|
+
return self._check_vect(x_vect) - self.lower
|
|
177
|
+
|
|
178
|
+
def intersect(self, other: Self) -> Self:
|
|
179
|
+
"""Intersect self with another domain.
|
|
180
|
+
|
|
181
|
+
Args:
|
|
182
|
+
other: The BoxedDomain to intersect with.
|
|
183
|
+
|
|
184
|
+
Returns:
|
|
185
|
+
The intersection of BoxedDomains.
|
|
186
|
+
|
|
187
|
+
Raises:
|
|
188
|
+
``ConsistencyError`` if other is not a domain object.
|
|
189
|
+
"""
|
|
190
|
+
if not isinstance(other, BoxedDomain):
|
|
191
|
+
msg = "Can only intersect two BoxedDomain objects"
|
|
192
|
+
raise TypeError(msg)
|
|
193
|
+
|
|
194
|
+
if other.lower.shape != self.lower.shape:
|
|
195
|
+
msg = "Mismatch between bounds"
|
|
196
|
+
raise ConsistencyError(msg)
|
|
197
|
+
|
|
198
|
+
lower = np_max(vstack((self.lower, other.lower)), axis=0)
|
|
199
|
+
upper = np_min(vstack((self.upper, other.upper)), axis=0)
|
|
200
|
+
|
|
201
|
+
try:
|
|
202
|
+
return BoxedDomain(lower, upper)
|
|
203
|
+
except ConsistencyError:
|
|
204
|
+
# Empty intersection i.e. lower > upper
|
|
205
|
+
empty = zeros(self.lower.shape)
|
|
206
|
+
return BoxedDomain(empty, empty)
|
|
207
|
+
|
|
208
|
+
def project(self, x_vect: NDArray) -> NDArray:
|
|
209
|
+
"""Project x_vect onto this domain.
|
|
210
|
+
|
|
211
|
+
Args:
|
|
212
|
+
x_vect: 1d array_like.
|
|
213
|
+
|
|
214
|
+
Returns:
|
|
215
|
+
The projection.
|
|
216
|
+
|
|
217
|
+
Raises:
|
|
218
|
+
``ConsistencyError`` if the size of x_vect is not consistent with the bounds
|
|
219
|
+
of the domain.
|
|
220
|
+
"""
|
|
221
|
+
x_vect = self._check_vect(x_vect)
|
|
222
|
+
projection = x_vect.copy()
|
|
223
|
+
|
|
224
|
+
inds_l = where(x_vect < self.lower)
|
|
225
|
+
inds_u = where(x_vect > self.upper)
|
|
226
|
+
|
|
227
|
+
projection[inds_l] = self.lower[inds_l]
|
|
228
|
+
projection[inds_u] = self.upper[inds_u]
|
|
229
|
+
|
|
230
|
+
return projection
|
|
231
|
+
|
|
232
|
+
def __str__(self) -> str:
|
|
233
|
+
"""Custom string representation.
|
|
234
|
+
|
|
235
|
+
Returns:
|
|
236
|
+
The representation.
|
|
237
|
+
"""
|
|
238
|
+
msg = "========= Domain ========="
|
|
239
|
+
for lower, upper in zip(self.lower, self.upper, strict=False):
|
|
240
|
+
msg += f"\r\n{lower: 9.3f} ------ {upper: 9.3f}"
|
|
241
|
+
msg += "\r\n=========================="
|
|
242
|
+
return msg
|