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]])
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]])
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 different input variables

dataset.design_variable_names
['x', 'y']

the names of the output variables

dataset.constraint_names, dataset.objective_names, dataset.observable_names
(['c'], ['f'], ['o'])

and the names of all variables:

dataset.variable_names
['a', 'c', 'f', 'o', 'x', 'y']

The OptimizationDataset provides also the number of iterations:

dataset.n_iterations
2

and the iterations:

dataset.iterations
[1, 2]

Lastly, we can get the design data as an OptimizationDataset view:

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,

dataset.constraint_dataset
GROUP constraints
VARIABLE c
COMPONENT 0
1 -0.5
2 0.1


dataset.objective_dataset
GROUP objectives
VARIABLE f
COMPONENT 0
1 -1.0
2 -2.0


dataset.observable_dataset
GROUP observables.
VARIABLE o
COMPONENT 0
1 -3.0
2 8.0


Total running time of the script: (0 minutes 0.040 seconds)

Gallery generated by Sphinx-Gallery