Convert a database to a dataset

In this example, we will see how to convert a Database to a Dataset.

from __future__ import annotations

from gemseo import execute_algo
from gemseo.problems.analytical.rosenbrock import Rosenbrock

Let us solve the Rosenbrock optimization problem with the SLSQP algorithm and 10 iterations:

optimization_problem = Rosenbrock()
execute_algo(optimization_problem, "SLSQP", max_iter=10)
Optimization result:
  • Design variables: [0.57066585 0.31608705]
  • Objective function: 0.19349100516217954
  • Feasible solution: True


Then, the Database attached to this OptimizationProblem can be converted to an OptimizationDataset using its method to_dataset():

dataset = optimization_problem.to_dataset()
dataset
GROUP designs functions
VARIABLE x rosen
COMPONENT 0 1 0
1 0.000000 0.000000 1.000000
2 2.000000 0.000000 1601.000000
3 0.200000 0.000000 0.800000
4 2.000000 0.899368 962.392108
5 0.380000 0.089937 0.681024
6 1.309049 2.000000 8.297426
7 0.682846 0.712569 6.166440
8 0.449476 0.232774 0.397606
9 0.551433 0.290027 0.220957
10 0.570666 0.316087 0.193491


The design variables and output variables are in separate groups. You can also use an IODataset instead of an OptimizationDataset:

dataset = optimization_problem.to_dataset(opt_naming=False)
dataset
GROUP inputs outputs
VARIABLE x rosen
COMPONENT 0 1 0
0 0.000000 0.000000 1.000000
1 2.000000 0.000000 1601.000000
2 0.200000 0.000000 0.800000
3 2.000000 0.899368 962.392108
4 0.380000 0.089937 0.681024
5 1.309049 2.000000 8.297426
6 0.682846 0.712569 6.166440
7 0.449476 0.232774 0.397606
8 0.551433 0.290027 0.220957
9 0.570666 0.316087 0.193491


or simply do not separate the variables

dataset = optimization_problem.to_dataset(categorize=False)
dataset
GROUP parameters
VARIABLE x rosen
COMPONENT 0 1 0
0 0.000000 0.000000 1.000000
1 2.000000 0.000000 1601.000000
2 0.200000 0.000000 0.800000
3 2.000000 0.899368 962.392108
4 0.380000 0.089937 0.681024
5 1.309049 2.000000 8.297426
6 0.682846 0.712569 6.166440
7 0.449476 0.232774 0.397606
8 0.551433 0.290027 0.220957
9 0.570666 0.316087 0.193491


Note

Only design variables and functions (objective function, constraints) are stored in the database. If you want to store state variables, you must add them as observables before the problem is executed. Use the add_observable() method.

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

Gallery generated by Sphinx-Gallery