Note
Go to the end to download the full example code.
Calibration of a polynomial regression#
from __future__ import annotations
import matplotlib.pyplot as plt
from matplotlib.tri import Triangulation
from gemseo.algos.design_space import DesignSpace
from gemseo.mlearning.core.calibration import MLAlgoCalibration
from gemseo.mlearning.regression.quality.mse_measure import MSEMeasure
from gemseo.problems.dataset.rosenbrock import create_rosenbrock_dataset
Load the dataset#
dataset = create_rosenbrock_dataset(opt_naming=False, n_samples=25)
Define the measure#
test_dataset = create_rosenbrock_dataset(opt_naming=False)
measure_evaluation_method_name = "TEST"
measure_options = {"test_data": test_dataset}
Calibrate the degree of the polynomial regression#
Define and execute the calibration#
calibration_space = DesignSpace()
calibration_space.add_variable("degree", 1, "integer", 1, 10, 1)
calibration = MLAlgoCalibration(
"PolynomialRegressor",
dataset,
["degree"],
calibration_space,
MSEMeasure,
measure_evaluation_method_name=measure_evaluation_method_name,
measure_options=measure_options,
)
calibration.execute(algo_name="PYDOE_FULLFACT", n_samples=10)
x_opt = calibration.optimal_parameters
f_opt = calibration.optimal_criterion
degree = x_opt["degree"][0]
f"optimal degree = {degree}; optimal criterion = {f_opt}"
INFO - 16:21:57: *** Start DOEScenario execution ***
INFO - 16:21:57: DOEScenario
INFO - 16:21:57: Disciplines: MLAlgoAssessor
INFO - 16:21:57: MDO formulation: DisciplinaryOpt
INFO - 16:21:57: Optimization problem:
INFO - 16:21:57: minimize criterion(degree)
INFO - 16:21:57: with respect to degree
INFO - 16:21:57: over the design space:
INFO - 16:21:57: +--------+-------------+-------+-------------+---------+
INFO - 16:21:57: | Name | Lower bound | Value | Upper bound | Type |
INFO - 16:21:57: +--------+-------------+-------+-------------+---------+
INFO - 16:21:57: | degree | 1 | 1 | 10 | integer |
INFO - 16:21:57: +--------+-------------+-------+-------------+---------+
INFO - 16:21:57: Solving optimization problem with algorithm PYDOE_FULLFACT:
INFO - 16:21:57: 10%|█ | 1/10 [00:00<00:00, 24.08 it/sec, feas=True, obj=5.89e+5]
INFO - 16:21:57: 20%|██ | 2/10 [00:00<00:00, 41.88 it/sec, feas=True, obj=1.73e+5]
INFO - 16:21:57: 30%|███ | 3/10 [00:00<00:00, 55.79 it/sec, feas=True, obj=3e+4]
INFO - 16:21:57: 40%|████ | 4/10 [00:00<00:00, 66.88 it/sec, feas=True, obj=1.1e-24]
INFO - 16:21:57: 50%|█████ | 5/10 [00:00<00:00, 75.96 it/sec, feas=True, obj=0.11]
INFO - 16:21:57: 60%|██████ | 6/10 [00:00<00:00, 83.50 it/sec, feas=True, obj=1.18e+3]
INFO - 16:21:57: 70%|███████ | 7/10 [00:00<00:00, 89.70 it/sec, feas=True, obj=6.9e+3]
INFO - 16:21:57: 80%|████████ | 8/10 [00:00<00:00, 95.06 it/sec, feas=True, obj=1.36e+4]
INFO - 16:21:57: 90%|█████████ | 9/10 [00:00<00:00, 99.70 it/sec, feas=True, obj=9.18e+4]
INFO - 16:21:57: 100%|██████████| 10/10 [00:00<00:00, 103.58 it/sec, feas=True, obj=1.63e+5]
INFO - 16:21:57: Optimization result:
INFO - 16:21:57: Optimizer info:
INFO - 16:21:57: Status: None
INFO - 16:21:57: Message: None
INFO - 16:21:57: Solution:
INFO - 16:21:57: Objective: 1.0957626812742524e-24
INFO - 16:21:57: Design space:
INFO - 16:21:57: +--------+-------------+-------+-------------+---------+
INFO - 16:21:57: | Name | Lower bound | Value | Upper bound | Type |
INFO - 16:21:57: +--------+-------------+-------+-------------+---------+
INFO - 16:21:57: | degree | 1 | 4 | 10 | integer |
INFO - 16:21:57: +--------+-------------+-------+-------------+---------+
INFO - 16:21:57: *** End DOEScenario execution ***
'optimal degree = 4; optimal criterion = 1.0957626812742524e-24'
Get the history#
calibration.dataset
Visualize the results#
degree = calibration.get_history("degree")
criterion = calibration.get_history("criterion")
learning = calibration.get_history("learning")
plt.plot(degree, criterion, "-o", label="test", color="red")
plt.plot(degree, learning, "-o", label="learning", color="blue")
plt.xlabel("polynomial degree")
plt.ylabel("quality")
plt.axvline(x_opt["degree"], color="red", ls="--")
plt.legend()
plt.show()

Calibrate the ridge penalty of the polynomial regression#
Define and execute the calibration#
calibration_space = DesignSpace()
calibration_space.add_variable("penalty_level", 1, "float", 0.0, 100.0, 0.0)
calibration = MLAlgoCalibration(
"PolynomialRegressor",
dataset,
["penalty_level"],
calibration_space,
MSEMeasure,
measure_evaluation_method_name=measure_evaluation_method_name,
measure_options=measure_options,
degree=10,
)
calibration.execute(algo_name="PYDOE_FULLFACT", n_samples=10)
x_opt = calibration.optimal_parameters
f_opt = calibration.optimal_criterion
x_opt["penalty_level"][0], f_opt
INFO - 16:21:57: *** Start DOEScenario execution ***
INFO - 16:21:57: DOEScenario
INFO - 16:21:57: Disciplines: MLAlgoAssessor
INFO - 16:21:57: MDO formulation: DisciplinaryOpt
INFO - 16:21:57: Optimization problem:
INFO - 16:21:57: minimize criterion(penalty_level)
INFO - 16:21:57: with respect to penalty_level
INFO - 16:21:57: over the design space:
INFO - 16:21:57: +---------------+-------------+-------+-------------+-------+
INFO - 16:21:57: | Name | Lower bound | Value | Upper bound | Type |
INFO - 16:21:57: +---------------+-------------+-------+-------------+-------+
INFO - 16:21:57: | penalty_level | 0 | 0 | 100 | float |
INFO - 16:21:57: +---------------+-------------+-------+-------------+-------+
INFO - 16:21:57: Solving optimization problem with algorithm PYDOE_FULLFACT:
INFO - 16:21:57: 10%|█ | 1/10 [00:00<00:00, 112.50 it/sec, feas=True, obj=1.63e+5]
INFO - 16:21:57: 20%|██ | 2/10 [00:00<00:00, 127.16 it/sec, feas=True, obj=3.25e+4]
INFO - 16:21:57: 30%|███ | 3/10 [00:00<00:00, 135.23 it/sec, feas=True, obj=1.78e+4]
INFO - 16:21:57: 40%|████ | 4/10 [00:00<00:00, 131.01 it/sec, feas=True, obj=1.72e+4]
INFO - 16:21:57: 50%|█████ | 5/10 [00:00<00:00, 135.78 it/sec, feas=True, obj=2e+4]
INFO - 16:21:57: 60%|██████ | 6/10 [00:00<00:00, 139.08 it/sec, feas=True, obj=2.35e+4]
INFO - 16:21:57: 70%|███████ | 7/10 [00:00<00:00, 141.72 it/sec, feas=True, obj=2.7e+4]
INFO - 16:21:57: 80%|████████ | 8/10 [00:00<00:00, 143.86 it/sec, feas=True, obj=3.03e+4]
INFO - 16:21:57: 90%|█████████ | 9/10 [00:00<00:00, 145.54 it/sec, feas=True, obj=3.33e+4]
INFO - 16:21:57: 100%|██████████| 10/10 [00:00<00:00, 146.20 it/sec, feas=True, obj=3.59e+4]
INFO - 16:21:57: Optimization result:
INFO - 16:21:57: Optimizer info:
INFO - 16:21:57: Status: None
INFO - 16:21:57: Message: None
INFO - 16:21:57: Solution:
INFO - 16:21:57: Objective: 17189.52649297074
INFO - 16:21:57: Design space:
INFO - 16:21:57: +---------------+-------------+-------------------+-------------+-------+
INFO - 16:21:57: | Name | Lower bound | Value | Upper bound | Type |
INFO - 16:21:57: +---------------+-------------+-------------------+-------------+-------+
INFO - 16:21:57: | penalty_level | 0 | 33.33333333333333 | 100 | float |
INFO - 16:21:57: +---------------+-------------+-------------------+-------------+-------+
INFO - 16:21:57: *** End DOEScenario execution ***
(np.float64(33.33333333333333), np.float64(17189.52649297074))
Get the history#
calibration.dataset
Visualize the results#
penalty_level = calibration.get_history("penalty_level")
criterion = calibration.get_history("criterion")
learning = calibration.get_history("learning")
plt.plot(penalty_level, criterion, "-o", label="test", color="red")
plt.plot(penalty_level, learning, "-o", label="learning", color="blue")
plt.axvline(x_opt["penalty_level"], color="red", ls="--")
plt.xlabel("ridge penalty")
plt.ylabel("quality")
plt.legend()
plt.show()

Calibrate the lasso penalty of the polynomial regression#
Define and execute the calibration#
calibration_space = DesignSpace()
calibration_space.add_variable("penalty_level", 1, "float", 0.0, 100.0, 0.0)
calibration = MLAlgoCalibration(
"PolynomialRegressor",
dataset,
["penalty_level"],
calibration_space,
MSEMeasure,
measure_evaluation_method_name=measure_evaluation_method_name,
measure_options=measure_options,
degree=10,
l2_penalty_ratio=0.0,
)
calibration.execute(algo_name="PYDOE_FULLFACT", n_samples=10)
x_opt = calibration.optimal_parameters
f_opt = calibration.optimal_criterion
x_opt["penalty_level"][0], f_opt
INFO - 16:21:57: *** Start DOEScenario execution ***
INFO - 16:21:57: DOEScenario
INFO - 16:21:57: Disciplines: MLAlgoAssessor
INFO - 16:21:57: MDO formulation: DisciplinaryOpt
INFO - 16:21:57: Optimization problem:
INFO - 16:21:57: minimize criterion(penalty_level)
INFO - 16:21:57: with respect to penalty_level
INFO - 16:21:57: over the design space:
INFO - 16:21:57: +---------------+-------------+-------+-------------+-------+
INFO - 16:21:57: | Name | Lower bound | Value | Upper bound | Type |
INFO - 16:21:57: +---------------+-------------+-------+-------------+-------+
INFO - 16:21:57: | penalty_level | 0 | 0 | 100 | float |
INFO - 16:21:57: +---------------+-------------+-------+-------------+-------+
INFO - 16:21:57: Solving optimization problem with algorithm PYDOE_FULLFACT:
INFO - 16:21:57: 10%|█ | 1/10 [00:00<00:00, 113.27 it/sec, feas=True, obj=1.63e+5]
INFO - 16:21:57: 20%|██ | 2/10 [00:00<00:00, 115.59 it/sec, feas=True, obj=1.58e+4]
INFO - 16:21:57: 30%|███ | 3/10 [00:00<00:00, 117.98 it/sec, feas=True, obj=3.15e+4]
INFO - 16:21:57: 40%|████ | 4/10 [00:00<00:00, 119.63 it/sec, feas=True, obj=4.74e+4]
INFO - 16:21:57: 50%|█████ | 5/10 [00:00<00:00, 121.05 it/sec, feas=True, obj=5.94e+4]
INFO - 16:21:57: 60%|██████ | 6/10 [00:00<00:00, 122.12 it/sec, feas=True, obj=6.27e+4]
INFO - 16:21:57: 70%|███████ | 7/10 [00:00<00:00, 122.88 it/sec, feas=True, obj=6.63e+4]
INFO - 16:21:57: 80%|████████ | 8/10 [00:00<00:00, 120.46 it/sec, feas=True, obj=6.93e+4]
INFO - 16:21:57: 90%|█████████ | 9/10 [00:00<00:00, 113.78 it/sec, feas=True, obj=7.25e+4]
INFO - 16:21:57: 100%|██████████| 10/10 [00:00<00:00, 114.68 it/sec, feas=True, obj=7.57e+4]
INFO - 16:21:57: Optimization result:
INFO - 16:21:57: Optimizer info:
INFO - 16:21:57: Status: None
INFO - 16:21:57: Message: None
INFO - 16:21:57: Solution:
INFO - 16:21:57: Objective: 15775.989581125898
INFO - 16:21:57: Design space:
INFO - 16:21:57: +---------------+-------------+-------------------+-------------+-------+
INFO - 16:21:57: | Name | Lower bound | Value | Upper bound | Type |
INFO - 16:21:57: +---------------+-------------+-------------------+-------------+-------+
INFO - 16:21:57: | penalty_level | 0 | 11.11111111111111 | 100 | float |
INFO - 16:21:57: +---------------+-------------+-------------------+-------------+-------+
INFO - 16:21:57: *** End DOEScenario execution ***
(np.float64(11.11111111111111), np.float64(15775.989581125898))
Get the history#
calibration.dataset
Visualize the results#
penalty_level = calibration.get_history("penalty_level")
criterion = calibration.get_history("criterion")
learning = calibration.get_history("learning")
plt.plot(penalty_level, criterion, "-o", label="test", color="red")
plt.plot(penalty_level, learning, "-o", label="learning", color="blue")
plt.axvline(x_opt["penalty_level"], color="red", ls="--")
plt.xlabel("lasso penalty")
plt.ylabel("quality")
plt.legend()
plt.show()

Calibrate the elasticnet penalty of the polynomial regression#
Define and execute the calibration#
calibration_space = DesignSpace()
calibration_space.add_variable("penalty_level", 1, "float", 0.0, 40.0, 0.0)
calibration_space.add_variable("l2_penalty_ratio", 1, "float", 0.0, 1.0, 0.5)
calibration = MLAlgoCalibration(
"PolynomialRegressor",
dataset,
["penalty_level", "l2_penalty_ratio"],
calibration_space,
MSEMeasure,
measure_evaluation_method_name=measure_evaluation_method_name,
measure_options=measure_options,
degree=10,
)
calibration.execute(algo_name="PYDOE_FULLFACT", n_samples=100)
x_opt = calibration.optimal_parameters
f_opt = calibration.optimal_criterion
x_opt["penalty_level"][0], x_opt["l2_penalty_ratio"][0], f_opt
INFO - 16:21:57: *** Start DOEScenario execution ***
INFO - 16:21:57: DOEScenario
INFO - 16:21:57: Disciplines: MLAlgoAssessor
INFO - 16:21:57: MDO formulation: DisciplinaryOpt
INFO - 16:21:57: Optimization problem:
INFO - 16:21:57: minimize criterion(penalty_level, l2_penalty_ratio)
INFO - 16:21:57: with respect to l2_penalty_ratio, penalty_level
INFO - 16:21:57: over the design space:
INFO - 16:21:57: +------------------+-------------+-------+-------------+-------+
INFO - 16:21:57: | Name | Lower bound | Value | Upper bound | Type |
INFO - 16:21:57: +------------------+-------------+-------+-------------+-------+
INFO - 16:21:57: | penalty_level | 0 | 0 | 40 | float |
INFO - 16:21:57: | l2_penalty_ratio | 0 | 0.5 | 1 | float |
INFO - 16:21:57: +------------------+-------------+-------+-------------+-------+
INFO - 16:21:57: Solving optimization problem with algorithm PYDOE_FULLFACT:
INFO - 16:21:57: 1%| | 1/100 [00:00<00:00, 107.61 it/sec, feas=True, obj=1.63e+5]
INFO - 16:21:57: 2%|▏ | 2/100 [00:00<00:00, 111.35 it/sec, feas=True, obj=4.14e+3]
INFO - 16:21:57: 3%|▎ | 3/100 [00:00<00:00, 113.92 it/sec, feas=True, obj=1.34e+4]
INFO - 16:21:57: 4%|▍ | 4/100 [00:00<00:00, 113.85 it/sec, feas=True, obj=1.79e+4]
INFO - 16:21:57: 5%|▌ | 5/100 [00:00<00:00, 115.02 it/sec, feas=True, obj=2.39e+4]
INFO - 16:21:57: 6%|▌ | 6/100 [00:00<00:00, 115.86 it/sec, feas=True, obj=3.15e+4]
INFO - 16:21:57: 7%|▋ | 7/100 [00:00<00:00, 116.43 it/sec, feas=True, obj=3.91e+4]
INFO - 16:21:57: 8%|▊ | 8/100 [00:00<00:00, 116.93 it/sec, feas=True, obj=4.5e+4]
INFO - 16:21:57: 9%|▉ | 9/100 [00:00<00:00, 117.38 it/sec, feas=True, obj=4.95e+4]
INFO - 16:21:57: 10%|█ | 10/100 [00:00<00:00, 117.89 it/sec, feas=True, obj=5.42e+4]
INFO - 16:21:57: 11%|█ | 11/100 [00:00<00:00, 120.44 it/sec, feas=True, obj=1.63e+5]
INFO - 16:21:57: 12%|█▏ | 12/100 [00:00<00:00, 120.22 it/sec, feas=True, obj=1.35e+4]
INFO - 16:21:57: 13%|█▎ | 13/100 [00:00<00:00, 120.27 it/sec, feas=True, obj=2.44e+4]
INFO - 16:21:57: 14%|█▍ | 14/100 [00:00<00:00, 120.12 it/sec, feas=True, obj=3.28e+4]
INFO - 16:21:57: 15%|█▌ | 15/100 [00:00<00:00, 120.02 it/sec, feas=True, obj=4.19e+4]
INFO - 16:21:57: 16%|█▌ | 16/100 [00:00<00:00, 119.95 it/sec, feas=True, obj=4.76e+4]
INFO - 16:21:58: 17%|█▋ | 17/100 [00:00<00:00, 120.02 it/sec, feas=True, obj=5.16e+4]
INFO - 16:21:58: 18%|█▊ | 18/100 [00:00<00:00, 119.87 it/sec, feas=True, obj=5.52e+4]
INFO - 16:21:58: 19%|█▉ | 19/100 [00:00<00:00, 119.90 it/sec, feas=True, obj=5.78e+4]
INFO - 16:21:58: 20%|██ | 20/100 [00:00<00:00, 119.95 it/sec, feas=True, obj=5.98e+4]
INFO - 16:21:58: 21%|██ | 21/100 [00:00<00:00, 121.16 it/sec, feas=True, obj=1.63e+5]
INFO - 16:21:58: 22%|██▏ | 22/100 [00:00<00:00, 120.93 it/sec, feas=True, obj=1.97e+4]
INFO - 16:21:58: 23%|██▎ | 23/100 [00:00<00:00, 120.66 it/sec, feas=True, obj=3.17e+4]
INFO - 16:21:58: 24%|██▍ | 24/100 [00:00<00:00, 120.64 it/sec, feas=True, obj=4.02e+4]
INFO - 16:21:58: 25%|██▌ | 25/100 [00:00<00:00, 120.63 it/sec, feas=True, obj=4.59e+4]
INFO - 16:21:58: 26%|██▌ | 26/100 [00:00<00:00, 120.63 it/sec, feas=True, obj=4.97e+4]
INFO - 16:21:58: 27%|██▋ | 27/100 [00:00<00:00, 120.64 it/sec, feas=True, obj=5.3e+4]
INFO - 16:21:58: 28%|██▊ | 28/100 [00:00<00:00, 120.60 it/sec, feas=True, obj=5.6e+4]
INFO - 16:21:58: 29%|██▉ | 29/100 [00:00<00:00, 120.64 it/sec, feas=True, obj=5.89e+4]
INFO - 16:21:58: 30%|███ | 30/100 [00:00<00:00, 120.77 it/sec, feas=True, obj=6.18e+4]
INFO - 16:21:58: 31%|███ | 31/100 [00:00<00:00, 121.66 it/sec, feas=True, obj=1.63e+5]
INFO - 16:21:58: 32%|███▏ | 32/100 [00:00<00:00, 121.62 it/sec, feas=True, obj=2.43e+4]
INFO - 16:21:58: 33%|███▎ | 33/100 [00:00<00:00, 121.52 it/sec, feas=True, obj=3.58e+4]
INFO - 16:21:58: 34%|███▍ | 34/100 [00:00<00:00, 121.44 it/sec, feas=True, obj=4.29e+4]
INFO - 16:21:58: 35%|███▌ | 35/100 [00:00<00:00, 121.37 it/sec, feas=True, obj=4.77e+4]
INFO - 16:21:58: 36%|███▌ | 36/100 [00:00<00:00, 121.32 it/sec, feas=True, obj=5.12e+4]
INFO - 16:21:58: 37%|███▋ | 37/100 [00:00<00:00, 121.32 it/sec, feas=True, obj=5.43e+4]
INFO - 16:21:58: 38%|███▊ | 38/100 [00:00<00:00, 121.33 it/sec, feas=True, obj=5.74e+4]
INFO - 16:21:58: 39%|███▉ | 39/100 [00:00<00:00, 121.36 it/sec, feas=True, obj=6.05e+4]
INFO - 16:21:58: 40%|████ | 40/100 [00:00<00:00, 120.50 it/sec, feas=True, obj=6.35e+4]
INFO - 16:21:58: 41%|████ | 41/100 [00:00<00:00, 121.13 it/sec, feas=True, obj=1.63e+5]
INFO - 16:21:58: 42%|████▏ | 42/100 [00:00<00:00, 121.04 it/sec, feas=True, obj=2.75e+4]
INFO - 16:21:58: 43%|████▎ | 43/100 [00:00<00:00, 120.97 it/sec, feas=True, obj=3.82e+4]
INFO - 16:21:58: 44%|████▍ | 44/100 [00:00<00:00, 120.94 it/sec, feas=True, obj=4.42e+4]
INFO - 16:21:58: 45%|████▌ | 45/100 [00:00<00:00, 120.94 it/sec, feas=True, obj=4.9e+4]
INFO - 16:21:58: 46%|████▌ | 46/100 [00:00<00:00, 120.98 it/sec, feas=True, obj=5.28e+4]
INFO - 16:21:58: 47%|████▋ | 47/100 [00:00<00:00, 121.01 it/sec, feas=True, obj=5.61e+4]
INFO - 16:21:58: 48%|████▊ | 48/100 [00:00<00:00, 121.09 it/sec, feas=True, obj=5.93e+4]
INFO - 16:21:58: 49%|████▉ | 49/100 [00:00<00:00, 121.15 it/sec, feas=True, obj=6.24e+4]
INFO - 16:21:58: 50%|█████ | 50/100 [00:00<00:00, 121.22 it/sec, feas=True, obj=6.54e+4]
INFO - 16:21:58: 51%|█████ | 51/100 [00:00<00:00, 121.74 it/sec, feas=True, obj=1.63e+5]
INFO - 16:21:58: 52%|█████▏ | 52/100 [00:00<00:00, 121.71 it/sec, feas=True, obj=2.99e+4]
INFO - 16:21:58: 53%|█████▎ | 53/100 [00:00<00:00, 121.69 it/sec, feas=True, obj=3.96e+4]
INFO - 16:21:58: 54%|█████▍ | 54/100 [00:00<00:00, 121.69 it/sec, feas=True, obj=4.51e+4]
INFO - 16:21:58: 55%|█████▌ | 55/100 [00:00<00:00, 121.69 it/sec, feas=True, obj=5e+4]
INFO - 16:21:58: 56%|█████▌ | 56/100 [00:00<00:00, 121.65 it/sec, feas=True, obj=5.43e+4]
INFO - 16:21:58: 57%|█████▋ | 57/100 [00:00<00:00, 121.65 it/sec, feas=True, obj=5.78e+4]
INFO - 16:21:58: 58%|█████▊ | 58/100 [00:00<00:00, 121.68 it/sec, feas=True, obj=6.11e+4]
INFO - 16:21:58: 59%|█████▉ | 59/100 [00:00<00:00, 121.69 it/sec, feas=True, obj=6.41e+4]
INFO - 16:21:58: 60%|██████ | 60/100 [00:00<00:00, 121.71 it/sec, feas=True, obj=6.66e+4]
INFO - 16:21:58: 61%|██████ | 61/100 [00:00<00:00, 122.14 it/sec, feas=True, obj=1.63e+5]
INFO - 16:21:58: 62%|██████▏ | 62/100 [00:00<00:00, 122.08 it/sec, feas=True, obj=3.18e+4]
INFO - 16:21:58: 63%|██████▎ | 63/100 [00:00<00:00, 122.02 it/sec, feas=True, obj=4.07e+4]
INFO - 16:21:58: 64%|██████▍ | 64/100 [00:00<00:00, 121.97 it/sec, feas=True, obj=4.6e+4]
INFO - 16:21:58: 65%|██████▌ | 65/100 [00:00<00:00, 121.90 it/sec, feas=True, obj=5.09e+4]
INFO - 16:21:58: 66%|██████▌ | 66/100 [00:00<00:00, 121.84 it/sec, feas=True, obj=5.53e+4]
INFO - 16:21:58: 67%|██████▋ | 67/100 [00:00<00:00, 121.80 it/sec, feas=True, obj=5.92e+4]
INFO - 16:21:58: 68%|██████▊ | 68/100 [00:00<00:00, 121.75 it/sec, feas=True, obj=6.25e+4]
INFO - 16:21:58: 69%|██████▉ | 69/100 [00:00<00:00, 121.73 it/sec, feas=True, obj=6.52e+4]
INFO - 16:21:58: 70%|███████ | 70/100 [00:00<00:00, 121.69 it/sec, feas=True, obj=6.71e+4]
INFO - 16:21:58: 71%|███████ | 71/100 [00:00<00:00, 122.07 it/sec, feas=True, obj=1.63e+5]
INFO - 16:21:58: 72%|███████▏ | 72/100 [00:00<00:00, 122.01 it/sec, feas=True, obj=3.32e+4]
INFO - 16:21:58: 73%|███████▎ | 73/100 [00:00<00:00, 121.95 it/sec, feas=True, obj=4.15e+4]
INFO - 16:21:58: 74%|███████▍ | 74/100 [00:00<00:00, 121.89 it/sec, feas=True, obj=4.69e+4]
INFO - 16:21:58: 75%|███████▌ | 75/100 [00:00<00:00, 121.86 it/sec, feas=True, obj=5.19e+4]
INFO - 16:21:58: 76%|███████▌ | 76/100 [00:00<00:00, 121.84 it/sec, feas=True, obj=5.63e+4]
INFO - 16:21:58: 77%|███████▋ | 77/100 [00:00<00:00, 121.85 it/sec, feas=True, obj=6.01e+4]
INFO - 16:21:58: 78%|███████▊ | 78/100 [00:00<00:00, 121.84 it/sec, feas=True, obj=6.32e+4]
INFO - 16:21:58: 79%|███████▉ | 79/100 [00:00<00:00, 121.84 it/sec, feas=True, obj=6.55e+4]
INFO - 16:21:58: 80%|████████ | 80/100 [00:00<00:00, 121.85 it/sec, feas=True, obj=6.72e+4]
INFO - 16:21:58: 81%|████████ | 81/100 [00:00<00:00, 122.21 it/sec, feas=True, obj=1.63e+5]
INFO - 16:21:58: 82%|████████▏ | 82/100 [00:00<00:00, 122.19 it/sec, feas=True, obj=3.44e+4]
INFO - 16:21:58: 83%|████████▎ | 83/100 [00:00<00:00, 122.17 it/sec, feas=True, obj=4.23e+4]
INFO - 16:21:58: 84%|████████▍ | 84/100 [00:00<00:00, 122.13 it/sec, feas=True, obj=4.78e+4]
INFO - 16:21:58: 85%|████████▌ | 85/100 [00:00<00:00, 122.12 it/sec, feas=True, obj=5.3e+4]
INFO - 16:21:58: 86%|████████▌ | 86/100 [00:00<00:00, 122.11 it/sec, feas=True, obj=5.74e+4]
INFO - 16:21:58: 87%|████████▋ | 87/100 [00:00<00:00, 122.10 it/sec, feas=True, obj=6.09e+4]
INFO - 16:21:58: 88%|████████▊ | 88/100 [00:00<00:00, 122.10 it/sec, feas=True, obj=6.35e+4]
INFO - 16:21:58: 89%|████████▉ | 89/100 [00:00<00:00, 122.08 it/sec, feas=True, obj=6.53e+4]
INFO - 16:21:58: 90%|█████████ | 90/100 [00:00<00:00, 122.07 it/sec, feas=True, obj=6.67e+4]
INFO - 16:21:58: 91%|█████████ | 91/100 [00:00<00:00, 122.39 it/sec, feas=True, obj=1.63e+5]
INFO - 16:21:58: 92%|█████████▏| 92/100 [00:00<00:00, 122.39 it/sec, feas=True, obj=6.89e+4]
INFO - 16:21:58: 93%|█████████▎| 93/100 [00:00<00:00, 122.70 it/sec, feas=True, obj=4.03e+4]
INFO - 16:21:58: 94%|█████████▍| 94/100 [00:00<00:00, 123.00 it/sec, feas=True, obj=2.71e+4]
INFO - 16:21:58: 95%|█████████▌| 95/100 [00:00<00:00, 123.30 it/sec, feas=True, obj=2.07e+4]
INFO - 16:21:58: 96%|█████████▌| 96/100 [00:00<00:00, 123.59 it/sec, feas=True, obj=1.78e+4]
INFO - 16:21:58: 97%|█████████▋| 97/100 [00:00<00:00, 123.81 it/sec, feas=True, obj=1.68e+4]
INFO - 16:21:58: 98%|█████████▊| 98/100 [00:00<00:00, 124.06 it/sec, feas=True, obj=1.69e+4]
INFO - 16:21:58: 99%|█████████▉| 99/100 [00:00<00:00, 124.31 it/sec, feas=True, obj=1.76e+4]
INFO - 16:21:58: 100%|██████████| 100/100 [00:00<00:00, 124.52 it/sec, feas=True, obj=1.87e+4]
INFO - 16:21:58: Optimization result:
INFO - 16:21:58: Optimizer info:
INFO - 16:21:58: Status: None
INFO - 16:21:58: Message: None
INFO - 16:21:58: Solution:
INFO - 16:21:58: Objective: 4136.820826715568
INFO - 16:21:58: Design space:
INFO - 16:21:58: +------------------+-------------+-------------------+-------------+-------+
INFO - 16:21:58: | Name | Lower bound | Value | Upper bound | Type |
INFO - 16:21:58: +------------------+-------------+-------------------+-------------+-------+
INFO - 16:21:58: | penalty_level | 0 | 4.444444444444445 | 40 | float |
INFO - 16:21:58: | l2_penalty_ratio | 0 | 0 | 1 | float |
INFO - 16:21:58: +------------------+-------------+-------------------+-------------+-------+
INFO - 16:21:58: *** End DOEScenario execution ***
(np.float64(4.444444444444445), np.float64(0.0), np.float64(4136.820826715568))
Get the history#
calibration.dataset
Visualize the results#
penalty_level = calibration.get_history("penalty_level").flatten()
l2_penalty_ratio = calibration.get_history("l2_penalty_ratio").flatten()
criterion = calibration.get_history("criterion").flatten()
learning = calibration.get_history("learning").flatten()
triang = Triangulation(penalty_level, l2_penalty_ratio)
fig = plt.figure()
ax = fig.add_subplot(1, 2, 1)
ax.tricontourf(triang, criterion, cmap="Purples")
ax.scatter(x_opt["penalty_level"][0], x_opt["l2_penalty_ratio"][0])
ax.set_xlabel("penalty level")
ax.set_ylabel("l2 penalty ratio")
ax.set_title("Test measure")
ax = fig.add_subplot(1, 2, 2)
ax.tricontourf(triang, learning, cmap="Purples")
ax.scatter(x_opt["penalty_level"][0], x_opt["l2_penalty_ratio"][0])
ax.set_xlabel("penalty level")
ax.set_ylabel("l2 penalty ratio")
ax.set_title("Learning measure")
plt.show()

Add an optimization stage#
calibration_space = DesignSpace()
calibration_space.add_variable("penalty_level", 1, "float", 0.0, 40.0, 0.0)
calibration_space.add_variable("l2_penalty_ratio", 1, "float", 0.0, 1.0, 0.5)
calibration = MLAlgoCalibration(
"PolynomialRegressor",
dataset,
["penalty_level", "l2_penalty_ratio"],
calibration_space,
MSEMeasure,
measure_evaluation_method_name=measure_evaluation_method_name,
measure_options=measure_options,
degree=10,
)
calibration.execute("NLOPT_COBYLA", max_iter=100)
x_opt2 = calibration.optimal_parameters
f_opt2 = calibration.optimal_criterion
fig = plt.figure()
ax = fig.add_subplot(1, 2, 1)
ax.tricontourf(triang, criterion, cmap="Purples")
ax.scatter(x_opt["penalty_level"][0], x_opt["l2_penalty_ratio"][0])
ax.scatter(x_opt2["penalty_level"][0], x_opt2["l2_penalty_ratio"][0], color="red")
ax.set_xlabel("penalty level")
ax.set_ylabel("l2 penalty ratio")
ax.set_title("Test measure")
ax = fig.add_subplot(1, 2, 2)
ax.tricontourf(triang, learning, cmap="Purples")
ax.scatter(x_opt["penalty_level"][0], x_opt["l2_penalty_ratio"][0])
ax.scatter(x_opt2["penalty_level"][0], x_opt2["l2_penalty_ratio"][0], color="red")
ax.set_xlabel("penalty level")
ax.set_ylabel("l2 penalty ratio")
ax.set_title("Learning measure")
plt.show()
n_iterations = len(calibration.scenario.disciplines[0].cache)
print(f"MSE with DOE: {f_opt} (100 evaluations)")
print(f"MSE with OPT: {f_opt2} ({n_iterations} evaluations)")
print(f"MSE reduction:{round((f_opt2 - f_opt) / f_opt * 100)}%")

INFO - 16:21:58: *** Start MDOScenario execution ***
INFO - 16:21:58: MDOScenario
INFO - 16:21:58: Disciplines: MLAlgoAssessor
INFO - 16:21:58: MDO formulation: DisciplinaryOpt
INFO - 16:21:58: Optimization problem:
INFO - 16:21:58: minimize criterion(penalty_level, l2_penalty_ratio)
INFO - 16:21:58: with respect to l2_penalty_ratio, penalty_level
INFO - 16:21:58: over the design space:
INFO - 16:21:58: +------------------+-------------+-------+-------------+-------+
INFO - 16:21:58: | Name | Lower bound | Value | Upper bound | Type |
INFO - 16:21:58: +------------------+-------------+-------+-------------+-------+
INFO - 16:21:58: | penalty_level | 0 | 0 | 40 | float |
INFO - 16:21:58: | l2_penalty_ratio | 0 | 0.5 | 1 | float |
INFO - 16:21:58: +------------------+-------------+-------+-------------+-------+
INFO - 16:21:58: Solving optimization problem with algorithm NLOPT_COBYLA:
INFO - 16:21:58: 1%| | 1/100 [00:00<00:01, 98.10 it/sec, feas=True, obj=1.63e+5]
INFO - 16:21:58: 2%|▏ | 2/100 [00:00<00:01, 95.37 it/sec, feas=True, obj=4.06e+4]
INFO - 16:21:58: 3%|▎ | 3/100 [00:00<00:00, 100.93 it/sec, feas=True, obj=4.28e+4]
INFO - 16:21:58: 4%|▍ | 4/100 [00:00<00:00, 104.28 it/sec, feas=True, obj=5.16e+4]
INFO - 16:21:58: 5%|▌ | 5/100 [00:00<00:00, 106.19 it/sec, feas=True, obj=4.66e+4]
INFO - 16:21:58: 6%|▌ | 6/100 [00:00<00:00, 107.49 it/sec, feas=True, obj=3.63e+4]
INFO - 16:21:58: 7%|▋ | 7/100 [00:00<00:00, 108.30 it/sec, feas=True, obj=3.03e+4]
INFO - 16:21:58: 8%|▊ | 8/100 [00:00<00:00, 109.14 it/sec, feas=True, obj=2.03e+4]
INFO - 16:21:58: 9%|▉ | 9/100 [00:00<00:00, 109.65 it/sec, feas=True, obj=2.75e+3]
INFO - 16:21:58: 10%|█ | 10/100 [00:00<00:00, 111.33 it/sec, feas=True, obj=493]
INFO - 16:21:58: 11%|█ | 11/100 [00:00<00:00, 114.02 it/sec, feas=True, obj=1.63e+5]
INFO - 16:21:58: 12%|█▏ | 12/100 [00:00<00:00, 116.58 it/sec, feas=True, obj=1.63e+5]
INFO - 16:21:58: 13%|█▎ | 13/100 [00:00<00:00, 116.45 it/sec, feas=True, obj=5.23e+3]
INFO - 16:21:58: 14%|█▍ | 14/100 [00:00<00:00, 117.28 it/sec, feas=True, obj=493]
INFO - 16:21:58: 15%|█▌ | 15/100 [00:00<00:00, 118.05 it/sec, feas=True, obj=493]
INFO - 16:21:58: 16%|█▌ | 16/100 [00:00<00:00, 118.71 it/sec, feas=True, obj=493]
INFO - 16:21:58: Optimization result:
INFO - 16:21:58: Optimizer info:
INFO - 16:21:58: Status: None
INFO - 16:21:58: Message: Successive iterates of the objective function are closer than ftol_rel or ftol_abs. GEMSEO stopped the driver.
INFO - 16:21:58: Solution:
INFO - 16:21:58: Objective: 493.1818200496802
INFO - 16:21:58: Design space:
INFO - 16:21:58: +------------------+-------------+-----------------------+-------------+-------+
INFO - 16:21:58: | Name | Lower bound | Value | Upper bound | Type |
INFO - 16:21:58: +------------------+-------------+-----------------------+-------------+-------+
INFO - 16:21:58: | penalty_level | 0 | 2.289834988289385e-15 | 40 | float |
INFO - 16:21:58: | l2_penalty_ratio | 0 | 0.5765298371174132 | 1 | float |
INFO - 16:21:58: +------------------+-------------+-----------------------+-------------+-------+
INFO - 16:21:58: *** End MDOScenario execution ***
MSE with DOE: 4136.820826715568 (100 evaluations)
MSE with OPT: 493.1818200496802 (1 evaluations)
MSE reduction:-88%
Total running time of the script: (0 minutes 1.550 seconds)