Note
Go to the end to download the full example code
The optimisation dataset¶
The OptimizationDataset
proposes several particular group names,
namely DESIGN_GROUP
,
OBJECTIVE_GROUP
,
OBSERVABLE_GROUP
,
and CONSTRAINT_GROUP
.
This particular Dataset
is useful
to post-process an optimization history.
from __future__ import annotations
from gemseo.datasets.optimization_dataset import OptimizationDataset
First,
we instantiate the OptimizationDataset
:
dataset = OptimizationDataset()
and add some data of interest
using the methods
add_design_variable()
,
add_constraint_variable()
,
add_objective_variable()
,
and add_observable_variable()
that are based on Dataset.add_variable()
:
dataset.add_design_variable("x", [[1.0, 2.0], [4.0, 5.0]])
dataset.add_design_variable("z", [[3.0], [6.0]])
dataset.add_objective_variable("f", [[-1.0], [-2.0]])
dataset.add_constraint_variable("c", [[-0.5], [0.1]])
dataset.add_observable_variable("o", [[-3.0], [8.0]])
as well as another variable:
dataset.add_variable("a", [[10.0], [20.0]])
print(dataset)
GROUP designs objectives constraints observables. parameters
VARIABLE x z f c o a
COMPONENT 0 1 0 0 0 0 0
1 1.0 2.0 3.0 -1.0 -0.5 -3.0 10.0
2 4.0 5.0 6.0 -2.0 0.1 8.0 20.0
We could also do the same with the methods
add_design_group()
,
add_constraint_group()
,
add_objective_group()
,
and add_observable_group()
dataset = OptimizationDataset()
dataset.add_design_group(
[[1.0, 2.0, 3.0], [4.0, 5.0, 6.0]], ["x", "y"], {"x": 2, "y": 1}
)
dataset.add_objective_group([[-1.0], [-2.0]], ["f"])
dataset.add_constraint_group([[-0.5], [0.1]], ["c"])
dataset.add_observable_group([[-3.0], [8.0]], ["o"])
dataset.add_variable("a", [[10.0], [20.0]])
print(dataset)
GROUP designs objectives constraints observables. parameters
VARIABLE x y f c o a
COMPONENT 0 1 0 0 0 0 0
1 1.0 2.0 3.0 -1.0 -0.5 -3.0 10.0
2 4.0 5.0 6.0 -2.0 0.1 8.0 20.0
Then, we can easily access the names of the input and output variables:
print(dataset.design_variable_names)
print(dataset.constraint_names)
print(dataset.objective_names)
print(dataset.observable_names)
['x', 'y']
['c']
['f']
['o']
and those of all variables:
print(dataset.variable_names)
['a', 'c', 'f', 'o', 'x', 'y']
The OptimizationDataset
provides also the number of iterations:
print(dataset.n_iterations)
2
and the iterations:
print(dataset.iterations)
[1, 2]
Lastly,
we can get the design data as an OptimizationDataset
view:
print(dataset.design_dataset)
GROUP designs
VARIABLE x y
COMPONENT 0 1 0
1 1.0 2.0 3.0
2 4.0 5.0 6.0
and the same for the other data groups:
print(dataset.constraint_dataset)
print(dataset.objective_dataset)
print(dataset.observable_dataset)
GROUP constraints
VARIABLE c
COMPONENT 0
1 -0.5
2 0.1
GROUP objectives
VARIABLE f
COMPONENT 0
1 -1.0
2 -2.0
GROUP observables.
VARIABLE o
COMPONENT 0
1 -3.0
2 8.0
Total running time of the script: ( 0 minutes 0.070 seconds)