PK QPUK K plot_correlations.ipynb{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"%matplotlib inline"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"\n# Correlations\n\nIn this example, we illustrate the use of the :class:`.Correlations` plot\non the Sobieski's SSBJ problem.\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"from gemseo.api import configure_logger\nfrom gemseo.api import create_discipline\nfrom gemseo.api import create_scenario\nfrom gemseo.problems.sobieski.core.problem import SobieskiProblem\nfrom matplotlib import pyplot as plt"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Import\nThe first step is to import some functions from the API\nand a method to get the design space.\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"configure_logger()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Description\n\nA correlation coefficient indicates whether there is a linear\nrelationship between 2 quantities $x$ and $y$, in which case\nit equals 1 or -1. It is the normalized covariance between the two\nquantities:\n\n\\begin{align}R_{xy}=\\frac {\\sum \\limits _{i=1}^n(x_i-{\\bar{x}})(y_i-{\\bar{y}})}{ns_{x}s_{y}}\n =\\frac {\\sum \\limits _{i=1}^n(x_i-{\\bar{x}})(y_i-{\\bar{y}})}{\\sqrt {\\sum\n \\limits _{i=1}^n(x_i-{\\bar{x}})^{2}\\sum \\limits _{i=1}^n(y_i-{\\bar{y}})^{2}}}\\end{align}\n\nThe **Correlations** post-processing builds scatter plots of correlated variables\namong design variables, output functions, and constraints.\n\nThe plot method considers all variable correlations greater than 95%. A different\nthreshold value and/or a sublist of variable names can be passed as options.\n\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Create disciplines\nThen, we instantiate the disciplines of the Sobieski's SSBJ problem:\nPropulsion, Aerodynamics, Structure and Mission\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"disciplines = create_discipline(\n [\n \"SobieskiPropulsion\",\n \"SobieskiAerodynamics\",\n \"SobieskiStructure\",\n \"SobieskiMission\",\n ]\n)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Create design space\nWe also read the design space from the :class:`.SobieskiProblem`.\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"design_space = SobieskiProblem().design_space"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Create and execute scenario\nThe next step is to build an MDO scenario in order to maximize the range,\nencoded 'y_4', with respect to the design parameters, while satisfying the\ninequality constraints 'g_1', 'g_2' and 'g_3'. We can use the MDF formulation,\nthe SLSQP optimization algorithm\nand a maximum number of iterations equal to 100.\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"scenario = create_scenario(\n disciplines,\n formulation=\"MDF\",\n objective_name=\"y_4\",\n maximize_objective=True,\n design_space=design_space,\n)\nscenario.set_differentiation_method(\"user\")\nfor constraint in [\"g_1\", \"g_2\", \"g_3\"]:\n scenario.add_constraint(constraint, \"ineq\")\nscenario.execute({\"algo\": \"SLSQP\", \"max_iter\": 10})"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Post-process scenario\nLastly, we post-process the scenario by means of the :class:`.Correlations`\nplot which provides scatter plots of correlated variables among design\nvariables, outputs functions and constraints any of the constraint or\nobjective functions w.r.t. optimization iterations or sampling snapshots.\nThis method requires the list of functions names to plot.\n\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
".. tip::\n\n Each post-processing method requires different inputs and offers a variety\n of customization options. Use the API function\n :meth:`~gemseo.api.get_post_processing_options_schema` to print a table with\n the options for any post-processing algorithm.\n Or refer to our dedicated page:\n `gen_post_algos`.\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"scenario.post_process(\"Correlations\", save=False, show=False)\n# Workaround for HTML rendering, instead of ``show=True``\nplt.show()"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.13"
}
},
"nbformat": 4,
"nbformat_minor": 0
}PK NPUԘe e plot_basic_history.ipynb{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"%matplotlib inline"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"\n# Basic history\n\nIn this example, we illustrate the use of the :class:`.BasicHistory` plot\non the Sobieski's SSBJ problem.\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"from gemseo.api import configure_logger\nfrom gemseo.api import create_discipline\nfrom gemseo.api import create_scenario\nfrom gemseo.problems.sobieski.core.problem import SobieskiProblem\nfrom matplotlib import pyplot as plt"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Import\nThe first step is to import some functions from the API\nand a method to get the design space.\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"configure_logger()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Description\nThe :class:`~gemseo.post.basic_history.BasicHistory` post-processing\nplots any of the constraint or objective functions\nw.r.t. the optimization iterations or sampling snapshots.\n\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Create disciplines\nAt this point, we instantiate the disciplines of Sobieski's SSBJ problem:\nPropulsion, Aerodynamics, Structure and Mission\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"disciplines = create_discipline(\n [\n \"SobieskiPropulsion\",\n \"SobieskiAerodynamics\",\n \"SobieskiStructure\",\n \"SobieskiMission\",\n ]\n)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Create design space\nWe also read the design space from the :class:`.SobieskiProblem`.\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"design_space = SobieskiProblem().design_space"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Create and execute scenario\nThe next step is to build an MDO scenario in order to maximize the range,\nencoded 'y_4', with respect to the design parameters, while satisfying the\ninequality constraints 'g_1', 'g_2' and 'g_3'. We can use the MDF formulation,\nthe SLSQP optimization algorithm\nand a maximum number of iterations equal to 100.\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"scenario = create_scenario(\n disciplines,\n formulation=\"MDF\",\n objective_name=\"y_4\",\n maximize_objective=True,\n design_space=design_space,\n)\nscenario.set_differentiation_method(\"user\")\nfor constraint in [\"g_1\", \"g_2\", \"g_3\"]:\n scenario.add_constraint(constraint, \"ineq\")\nscenario.execute({\"algo\": \"SLSQP\", \"max_iter\": 10})"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Post-process scenario\nLastly, we post-process the scenario by means of the :class:`.BasicHistory`\nplot which plots any of the constraint or objective functions\nw.r.t. optimization iterations or sampling snapshots.\n\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
".. tip::\n\n Each post-processing method requires different inputs and offers a variety\n of customization options. Use the API function\n :meth:`~gemseo.api.get_post_processing_options_schema` to print a table with\n the options for any post-processing algorithm.\n Or refer to our dedicated page:\n `gen_post_algos`.\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"scenario.post_process(\n \"BasicHistory\", variable_names=[\"g_1\", \"g_2\", \"g_3\"], save=False, show=False\n)\nscenario.post_process(\"BasicHistory\", variable_names=[\"y_4\"], save=False, show=False)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"
Note
Set the boolean instance attribute\n :attr:`.OptimizationProblem.use_standardized_objective` to ``False``\n to plot the objective to maximize as a performance function.
\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"scenario.use_standardized_objective = False\nscenario.post_process(\"BasicHistory\", variable_names=[\"y_4\"], save=False, show=False)\n# Workaround for HTML rendering, instead of ``show=True``\nplt.show()"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.13"
}
},
"nbformat": 4,
"nbformat_minor": 0
}PK \PUHs/a a plot_pareto_front.ipynb{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"%matplotlib inline"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"\n# Pareto front\n\nIn this example, we illustrate the use of the :class:`.ParetoFront` plot\non the Sobieski's SSBJ problem.\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"from gemseo.api import configure_logger\nfrom gemseo.api import create_discipline\nfrom gemseo.api import create_scenario\nfrom gemseo.problems.sobieski.core.problem import SobieskiProblem\nfrom matplotlib import pyplot as plt"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Import\nThe first step is to import some functions from the API\nand a method to get the design space.\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"configure_logger()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Description\n\nThe :class:`~gemseo.post.pareto_front.ParetoFront` post-processing generates\na plot or a matrix of plots (if there are more than\n2 objectives). It indicates in red the locally nondominated points for the\ncurrent objectives, and in green the globally (all objectives) Pareto optimal\npoints.\n\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Create disciplines\nAt this point, we instantiate the disciplines of Sobieski's SSBJ problem:\nPropulsion, Aerodynamics, Structure and Mission\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"disciplines = create_discipline(\n [\n \"SobieskiPropulsion\",\n \"SobieskiAerodynamics\",\n \"SobieskiStructure\",\n \"SobieskiMission\",\n ]\n)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Create design space\nWe also read the design space from the :class:`.SobieskiProblem`.\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"design_space = SobieskiProblem().design_space"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Create and execute scenario\nThe next step is to build an MDO scenario in order to maximize the range,\nencoded 'y_4', with respect to the design parameters, while satisfying the\ninequality constraints 'g_1', 'g_2' and 'g_3'. We can use the MDF formulation,\nthe SLSQP optimization algorithm\nand a maximum number of iterations equal to 100.\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"scenario = create_scenario(\n disciplines,\n formulation=\"MDF\",\n objective_name=\"y_4\",\n maximize_objective=True,\n design_space=design_space,\n)\nscenario.set_differentiation_method(\"user\")\nfor constraint in [\"g_1\", \"g_2\", \"g_3\"]:\n scenario.add_constraint(constraint, \"ineq\")\nscenario.execute({\"algo\": \"SLSQP\", \"max_iter\": 10})"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Post-process scenario\nLastly, we post-process the scenario by means of the :class:`.ParetoFront`.\n\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
".. tip::\n\n Each post-processing method requires different inputs and offers a variety\n of customization options. Use the API function\n :meth:`~gemseo.api.get_post_processing_options_schema` to print a table with\n the options for any post-processing algorithm.\n Or refer to our dedicated page:\n `gen_post_algos`.\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"scenario.post_process(\"ParetoFront\", objectives=[\"g_3\", \"-y_4\"], save=False, show=False)\n# Workaround for HTML rendering, instead of ``show=True``\nplt.show()"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.13"
}
},
"nbformat": 4,
"nbformat_minor": 0
}PK `PU
( plot_pareto_front_binhkorn_bilevel.ipynb{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"%matplotlib inline"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"\n# Pareto front on Binh and Korn problem using a BiLevel formulation\n\nIn this example,\nwe illustrate the computation of a Pareto front plot for the Binh and Korn problem.\nWe use a BiLevel formulation in order to only compute the Pareto-optimal points.\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Import\nThe first step is to import some functions from the API,\nand to configure the logger.\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"from gemseo.api import configure_logger\nfrom gemseo.api import create_design_space\nfrom gemseo.api import create_discipline\nfrom gemseo.api import create_scenario\nfrom gemseo.disciplines.scenario_adapter import MDOScenarioAdapter\nfrom matplotlib import pyplot as plt\nfrom numpy import array\n\nconfigure_logger()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Definition of the disciplines\n\nIn this example,\nwe create the Binh and Korn disciplines from scratch by declaring their expressions and using\nthe :class:`.AnalyticDiscipline`.\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"expr_binh_korn = {\n \"obj1\": \"4*x1**2 + 4*x2**2\",\n \"obj2\": \"(x1-5.)**2 + (x2-5.)**2\",\n \"cstr1\": \"(x1-5.)**2 + x2**2 - 25.\",\n \"cstr2\": \"-(x1-8.)**2 - (x2+3)**2 + 7.7\",\n}"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"This constraint will be used to set `obj1` to a target value for the lower-level scenario.\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"expr_cstr_obj1_target = {\"cstr3\": \"obj1 - obj1_target\"}"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Instantiation of the disciplines\n\nHere, we create the disciplines from their expressions.\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"discipline_binh_korn = create_discipline(\n \"AnalyticDiscipline\", expressions=expr_binh_korn\n)\ndiscipline_cstr_obj1 = create_discipline(\n \"AnalyticDiscipline\", expressions=expr_cstr_obj1_target\n)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Definition of the lower-level design space\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"design_space = create_design_space()\ndesign_space.add_variable(\"x1\", l_b=array([0.0]), u_b=array([5.0]), value=array([2.0]))\ndesign_space.add_variable(\"x2\", l_b=array([-5.0]), u_b=array([3.0]), value=array([2.0]))\n\ndisciplines = [\n discipline_binh_korn,\n discipline_cstr_obj1,\n]"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Creation of the lower-level scenario\nThis scenario aims at finding the `obj2` optimal value for a specific value of `obj1`.\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"scenario = create_scenario(\n disciplines,\n \"DisciplinaryOpt\",\n design_space=design_space,\n objective_name=\"obj2\",\n)\n\nscenario.default_inputs = {\"algo\": \"NLOPT_SLSQP\", \"max_iter\": 100}"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"We add the Binh and Korn problem constraints.\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"scenario.add_constraint(\"cstr1\", \"ineq\")\nscenario.add_constraint(\"cstr2\", \"ineq\")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"We add a constraint to force the value of `obj1` to `obj1_target`.\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"scenario.add_constraint(\"cstr3\", \"eq\")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Creation of an MDOScenarioAdapter\n\nAn :class:`.MDOScenarioAdapter` is created to use the lower-level scenario as a discipline.\nThis newly created discipline takes as input a target `obj_1`,\nand returns `obj1`, `obj2` and `cstr3`.\nThe latter variable is used by the upper level scenario\nto check if `obj1` = `obj1_target` at the end of the lower-lever scenario execution.\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"scenario_adapter = MDOScenarioAdapter(\n scenario, [\"obj1_target\"], [\"obj1\", \"obj2\", \"cstr3\"]\n)\ndesign_space_doe = create_design_space()\ndesign_space_doe.add_variable(\n \"obj1_target\", l_b=array([0.1]), u_b=array([100.0]), value=array([1.0])\n)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Creation of a DOEScenario\nCreate a DOE Scenario, which will take as input the scenario adapter.\nIt will perform a DOE over the `obj1_target` variable.\nNote that `obj2` shall be added as an observable of `scenario_doe`,\notherwise it cannot be used by the ParetoFront post-processing.\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"scenario_doe = create_scenario(\n scenario_adapter,\n formulation=\"DisciplinaryOpt\",\n objective_name=\"obj1\",\n design_space=design_space_doe,\n scenario_type=\"DOE\",\n)\nscenario_doe.add_constraint(\"cstr3\", \"eq\")\nscenario_doe.add_observable(\"obj2\")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Run the scenario\nFinally, we run a full-factorial DOE using 100 samples and we run the post-processing.\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"run_inputs = {\"n_samples\": 50, \"algo\": \"fullfact\"}\nscenario_doe.execute(run_inputs)\nscenario_doe.post_process(\n \"ParetoFront\", objectives=[\"obj1\", \"obj2\"], save=False, show=False\n)\nplt.show()"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.13"
}
},
"nbformat": 4,
"nbformat_minor": 0
}PK bPUfk " plot_constraints_radar_chart.ipynb{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"%matplotlib inline"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"\n# Radar chart\n\nIn this example, we illustrate the use of the\n:class:`~gemseo.post.radar_chart.RadarChart` plot\non the Sobieski's SSBJ problem.\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"from gemseo.api import configure_logger\nfrom gemseo.api import create_discipline\nfrom gemseo.api import create_scenario\nfrom gemseo.problems.sobieski.core.problem import SobieskiProblem\nfrom matplotlib import pyplot as plt"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Import\nThe first step is to import some functions from the API\nand a method to get the design space.\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"configure_logger()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Description\n\nThe :class:`~gemseo.post.radar_chart.RadarChart` post-processing\nplots on a radar style chart a list of constraint functions\nat a given iteration.\n\nBy default, the last iteration is used. This plot scales better with the number\nof constraints than the constraint plot provided by the `opt_history_view`.\n\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Create disciplines\nAt this point, we instantiate the disciplines of Sobieski's SSBJ problem:\nPropulsion, Aerodynamics, Structure and Mission\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"disciplines = create_discipline(\n [\n \"SobieskiPropulsion\",\n \"SobieskiAerodynamics\",\n \"SobieskiStructure\",\n \"SobieskiMission\",\n ]\n)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Create design space\nWe also read the design space from the :class:`.SobieskiProblem`.\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"design_space = SobieskiProblem().design_space"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Create and execute scenario\nThe next step is to build an MDO scenario in order to maximize the range,\nencoded 'y_4', with respect to the design parameters, while satisfying the\ninequality constraints 'g_1', 'g_2' and 'g_3'. We can use the MDF formulation,\nthe SLSQP optimization algorithm\nand a maximum number of iterations equal to 100.\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"scenario = create_scenario(\n disciplines,\n formulation=\"MDF\",\n objective_name=\"y_4\",\n maximize_objective=True,\n design_space=design_space,\n)\nscenario.set_differentiation_method(\"user\")\nfor constraint in [\"g_1\", \"g_2\", \"g_3\"]:\n scenario.add_constraint(constraint, \"ineq\")\nscenario.execute({\"algo\": \"SLSQP\", \"max_iter\": 10})"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Post-process scenario\nLastly, we post-process the scenario by means of the\n:class:`~gemseo.post.radar_chart.RadarChart`.\n\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
".. tip::\n\n Each post-processing method requires different inputs and offers a variety\n of customization options. Use the API function\n :meth:`~gemseo.api.get_post_processing_options_schema` to print a table with\n the options for any post-processing algorithm.\n Or refer to our dedicated page:\n `gen_post_algos`.\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"scenario.post_process(\n \"RadarChart\",\n constraint_names=[\"g_1\", \"g_2\", \"g_3\"],\n save=False,\n show=False,\n fig_size=(5, 5),\n)\n# Workaround for HTML rendering, instead of ``show=True``\nplt.show()"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.13"
}
},
"nbformat": 4,
"nbformat_minor": 0
}PK gPU
R R plot_som.ipynb{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"%matplotlib inline"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"\n# Self-Organizing Map\n\nIn this example, we illustrate the use of the :class:`~gemseo.post.som.SOM` plot\non the Sobieski's SSBJ problem.\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"from gemseo.api import configure_logger\nfrom gemseo.api import create_discipline\nfrom gemseo.api import create_scenario\nfrom gemseo.problems.sobieski.core.problem import SobieskiProblem\nfrom matplotlib import pyplot as plt"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Import\nThe first step is to import some functions from the API\nand a method to get the design space.\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"configure_logger()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Description\n\nThe :class:`~gemseo.post.som.SOM` post-processing performs a Self Organizing Map\nclustering on the optimization history.\nA :class:`~gemseo.post.som.SOM` is a 2D representation of a design of experiments\nwhich requires dimensionality reduction since it may be in a very high dimension.\n\nA :term:`SOM` is built by using an unsupervised artificial neural network\n:cite:`Kohonen:2001`.\nA map of size ``n_x.n_y`` is generated, where\n``n_x`` is the number of neurons in the $x$ direction and ``n_y``\nis the number of neurons in the $y$ direction. The design space\n(whatever the dimension) is reduced to a 2D representation based on\n``n_x.n_y`` neurons. Samples are clustered to a neuron when their design\nvariables are close in terms of their L2 norm. A neuron is always located at the\nsame place on a map. Each neuron is colored according to the average value for\na given criterion. This helps to qualitatively analyze whether parts of the design\nspace are good according to some criteria and not for others, and where\ncompromises should be made. A white neuron has no sample associated with\nit: not enough evaluations were provided to train the SOM.\n\nSOM's provide a qualitative view of the :term:`objective function`, the\n:term:`constraints`, and of their relative behaviors.\n\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Create disciplines\nAt this point, we instantiate the disciplines of Sobieski's SSBJ problem:\nPropulsion, Aerodynamics, Structure and Mission\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"disciplines = create_discipline(\n [\n \"SobieskiPropulsion\",\n \"SobieskiAerodynamics\",\n \"SobieskiStructure\",\n \"SobieskiMission\",\n ]\n)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Create design space\nWe also read the design space from the :class:`.SobieskiProblem`.\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"design_space = SobieskiProblem().design_space"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Create and execute scenario\nThe next step is to build an MDO scenario in order to maximize the range,\nencoded 'y_4', with respect to the design parameters, while satisfying the\ninequality constraints 'g_1', 'g_2' and 'g_3'. We can use the MDF formulation,\nthe Monte Carlo DOE algorithm and 30 samples.\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"scenario = create_scenario(\n disciplines,\n formulation=\"MDF\",\n objective_name=\"y_4\",\n maximize_objective=True,\n design_space=design_space,\n scenario_type=\"DOE\",\n)\nscenario.set_differentiation_method(\"user\")\nfor constraint in [\"g_1\", \"g_2\", \"g_3\"]:\n scenario.add_constraint(constraint, \"ineq\")\nscenario.execute({\"algo\": \"OT_MONTE_CARLO\", \"n_samples\": 30})"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Post-process scenario\nLastly, we post-process the scenario by means of the\n:class:`~gemseo.post.som.SOM` plot which performs a self organizing map\nclustering on optimization history.\n\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
".. tip::\n\n Each post-processing method requires different inputs and offers a variety\n of customization options. Use the API function\n :meth:`~gemseo.api.get_post_processing_options_schema` to print a table with\n the options for any post-processing algorithm.\n Or refer to our dedicated page:\n `gen_post_algos`.\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"scenario.post_process(\"SOM\", save=False, show=False)\n# Workaround for HTML rendering, instead of ``show=True``\nplt.show()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Figure `fig-ssbj-mdf-som100` illustrates another :term:`SOM` on the Sobieski\nuse case. The optimization method is a (costly) derivative free algorithm\n(``NLOPT_COBYLA``), indeed all the relevant information for the optimization\nis obtained at the cost of numerous evaluations of the functions. For\nmore details, please read the paper by\n:cite:`kumano2006multidisciplinary` on wing MDO post-processing\nusing SOM.\n\n\n.. figure:: /tutorials/ssbj/figs/MDOScenario_SOM_v100.png\n :scale: 10 %\n\n SOM example on the Sobieski problem.\n\nA DOE may also be a good way to produce SOM maps.\nFigure `fig-ssbj-mdf-som10000` shows an example with 10000 points on\nthe same test case. This produces more relevant SOM plots.\n\n\n.. figure:: /tutorials/ssbj/figs/som_fine.png\n :scale: 55 %\n\n SOM example on the Sobieski problem with a 10 000 samples DOE.\n\n"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.13"
}
},
"nbformat": 4,
"nbformat_minor": 0
}PK ePUwh h ! plot_history_scatter_matrix.ipynb{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"%matplotlib inline"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"\n# Scatter plot matrix\n\nIn this example, we illustrate the use of the :class:`.ScatterPlotMatrix` plot\non the Sobieski's SSBJ problem.\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"from gemseo.api import configure_logger\nfrom gemseo.api import create_discipline\nfrom gemseo.api import create_scenario\nfrom gemseo.problems.sobieski.core.problem import SobieskiProblem\nfrom matplotlib import pyplot as plt"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Import\nThe first step is to import some functions from the API\nand a method to get the design space.\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"configure_logger()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Description\n\nThe **ScatterPlotMatrix** post-processing builds the scatter plot matrix among\ndesign variables and outputs functions.\nEach non-diagonal block represents the samples\naccording to the x- and y- coordinates names while the diagonal ones approximate\nthe probability distributions of the variables, using a kernel-density estimator.\n\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Create disciplines\nAt this point, we instantiate the disciplines of Sobieski's SSBJ problem:\nPropulsion, Aerodynamics, Structure and Mission\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"disciplines = create_discipline(\n [\n \"SobieskiPropulsion\",\n \"SobieskiAerodynamics\",\n \"SobieskiStructure\",\n \"SobieskiMission\",\n ]\n)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Create design space\nWe also read the design space from the :class:`.SobieskiProblem`.\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"design_space = SobieskiProblem().design_space"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Create and execute scenario\nThe next step is to build a DOE scenario in order to maximize the range,\nencoded 'y_4', with respect to the design parameters, while satisfying the\ninequality constraints 'g_1', 'g_2' and 'g_3'. We can use the MDF formulation,\nthe Monte Carlo DOE algorithm and 30 samples.\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"scenario = create_scenario(\n disciplines,\n formulation=\"MDF\",\n objective_name=\"y_4\",\n maximize_objective=True,\n design_space=design_space,\n scenario_type=\"DOE\",\n)\nscenario.set_differentiation_method(\"user\")\nfor constraint in [\"g_1\", \"g_2\", \"g_3\"]:\n scenario.add_constraint(constraint, \"ineq\")\nscenario.execute({\"algo\": \"OT_MONTE_CARLO\", \"n_samples\": 30})"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Post-process scenario\nLastly, we post-process the scenario by means of the :class:`.ScatterPlotMatrix`\nplot which builds scatter plot matrix among design variables, objective\nfunction and constraints.\n\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
".. tip::\n\n Each post-processing method requires different inputs and offers a variety\n of customization options. Use the API function\n :meth:`~gemseo.api.get_post_processing_options_schema` to print a table with\n the options for any post-processing algorithm.\n Or refer to our dedicated page:\n `gen_post_algos`.\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"design_variables = [\"x_shared\", \"x_1\", \"x_2\", \"x_3\"]\nscenario.post_process(\n \"ScatterPlotMatrix\",\n save=False,\n show=False,\n variable_names=design_variables + [\"-y_4\"],\n)\n# Workaround for HTML rendering, instead of ``show=True``\nplt.show()"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.13"
}
},
"nbformat": 4,
"nbformat_minor": 0
}PK ]PUv plot_pareto_front_binhkorn.ipynb{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"%matplotlib inline"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"\n# Pareto front on Binh and Korn problem\n\nIn this example, we illustrate the use of the :class:`.ParetoFront` plot\non the Binh and Korn multi-objective problem.\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"from gemseo.algos.doe.doe_factory import DOEFactory\nfrom gemseo.api import configure_logger\nfrom gemseo.post.post_factory import PostFactory\nfrom gemseo.problems.analytical.binh_korn import BinhKorn\nfrom matplotlib import pyplot as plt"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Import\nThe first step is to import some functions from the API\nand a method to get the design space.\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"configure_logger()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Import the optimization problem\nThen, we instantiate the BinkKorn optimization problem.\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"problem = BinhKorn()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Create and execute scenario\nThen, we create a Design of Experiment factory,\nand we request the execution a a full-factorial DOE using 100 samples\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"doe_factory = DOEFactory()\ndoe_factory.execute(problem, algo_name=\"OT_OPT_LHS\", n_samples=100)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Post-process scenario\nLastly, we post-process the scenario by means of the :class:`.ParetoFront`\nplot which generates a plot or a matrix of plots if there are more than\n2 objectives, plots in blue the locally non dominated points for the current\ntwo objectives, plots in green the globally (all objectives) Pareto optimal\npoints. The plots in green denotes non-feasible points. Note that the user\ncan avoid the display of the non-feasible points.\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"PostFactory().execute(\n problem,\n \"ParetoFront\",\n save=False,\n show=False,\n show_non_feasible=False,\n objectives=[\"compute_binhkorn\"],\n objectives_labels=[\"f1\", \"f2\"],\n)\n\nPostFactory().execute(\n problem,\n \"ParetoFront\",\n save=False,\n show=False,\n show_non_feasible=True,\n objectives=[\"compute_binhkorn\"],\n objectives_labels=[\"f1\", \"f2\"],\n)\n# Workaround for HTML rendering, instead of ``show=True``\nplt.show()"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.13"
}
},
"nbformat": 4,
"nbformat_minor": 0
}PK aPU9'T plot_quad_approx.ipynb{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"%matplotlib inline"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"\n# Quadratic approximations\n\nIn this example, we illustrate the use of the :class:`.QuadApprox` plot\non the Sobieski's SSBJ problem.\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"from gemseo.api import configure_logger\nfrom gemseo.api import create_discipline\nfrom gemseo.api import create_scenario\nfrom gemseo.problems.sobieski.core.problem import SobieskiProblem\nfrom matplotlib import pyplot as plt"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Import\nThe first step is to import some functions from the API\nand a method to get the design space.\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"configure_logger()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Description\n\nThe :class:`~gemseo.post.quad_approx.QuadApprox` post-processing\nperforms a quadratic approximation of a given function\nfrom an optimization history\nand plot the results as cuts of the approximation.\n\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Create disciplines\nThen, we instantiate the disciplines of the Sobieski's SSBJ problem:\nPropulsion, Aerodynamics, Structure and Mission\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"disciplines = create_discipline(\n [\n \"SobieskiPropulsion\",\n \"SobieskiAerodynamics\",\n \"SobieskiStructure\",\n \"SobieskiMission\",\n ]\n)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Create design space\nWe also read the design space from the :class:`.SobieskiProblem`.\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"design_space = SobieskiProblem().design_space"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Create and execute scenario\nThe next step is to build an MDO scenario in order to maximize the range,\nencoded 'y_4', with respect to the design parameters, while satisfying the\ninequality constraints 'g_1', 'g_2' and 'g_3'. We can use the MDF formulation,\nthe SLSQP optimization algorithm\nand a maximum number of iterations equal to 100.\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"scenario = create_scenario(\n disciplines,\n formulation=\"MDF\",\n objective_name=\"y_4\",\n maximize_objective=True,\n design_space=design_space,\n)\nscenario.set_differentiation_method(\"user\")\nfor constraint in [\"g_1\", \"g_2\", \"g_3\"]:\n scenario.add_constraint(constraint, \"ineq\")\nscenario.execute({\"algo\": \"SLSQP\", \"max_iter\": 10})"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Post-process scenario\nLastly, we post-process the scenario by means of the :class:`.QuadApprox`\nplot which performs a quadratic approximation of a given function\nfrom an optimization history and plot the results as cuts of the\napproximation.\n\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
".. tip::\n\n Each post-processing method requires different inputs and offers a variety\n of customization options. Use the API function\n :meth:`~gemseo.api.get_post_processing_options_schema` to print a table with\n the options for any post-processing algorithm.\n Or refer to our dedicated page:\n `gen_post_algos`.\n\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"The first plot shows an approximation of the Hessian matrix\n$\\frac{\\partial^2 f}{\\partial x_i \\partial x_j}$ based on the\n*Symmetric Rank 1* method (SR1) :cite:`Nocedal2006`. The\ncolor map uses a symmetric logarithmic (symlog) scale.\nThis plots the cross influence of the design variables on the objective function\nor constraints. For instance, on the last figure, the maximal second-order\nsensitivity is $\\frac{\\partial^2 -y_4}{\\partial^2 x_0} = 2.10^5$,\nwhich means that the $x_0$ is the most influential variable. Then,\nthe cross derivative\n$\\frac{\\partial^2 -y_4}{\\partial x_0 \\partial x_2} = 5.10^4$\nis positive and relatively high compared to the previous one but the combined\neffects of $x_0$ and $x_2$ are non-negligible in comparison.\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"scenario.post_process(\"QuadApprox\", function=\"-y_4\", save=False, show=False)\n# Workaround for HTML rendering, instead of ``show=True``\nplt.show()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"The second plot represents the quadratic approximation of the objective around the\noptimal solution : $a_{i}(t)=0.5 (t-x^*_i)^2\n\\frac{\\partial^2 f}{\\partial x_i^2} + (t-x^*_i) \\frac{\\partial\nf}{\\partial x_i} + f(x^*)$, where $x^*$ is the optimal solution.\nThis approximation highlights the sensitivity of the :term:`objective function`\nwith respect to the :term:`design variables`: we notice that the design\nvariables $x\\_1, x\\_5, x\\_6$ have little influence , whereas\n$x\\_0, x\\_2, x\\_9$ have a huge influence on the objective. This\ntrend is also noted in the diagonal terms of the :term:`Hessian` matrix\n$\\frac{\\partial^2 f}{\\partial x_i^2}$.\n\n"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.13"
}
},
"nbformat": 4,
"nbformat_minor": 0
}PK hPUR| | plot_variable_influence.ipynb{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"%matplotlib inline"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"\n# Variables influence\n\nIn this example, we illustrate the use of the :class:`.VariableInfluence` plot\non the Sobieski's SSBJ problem.\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"from gemseo.api import configure_logger\nfrom gemseo.api import create_discipline\nfrom gemseo.api import create_scenario\nfrom gemseo.problems.sobieski.core.problem import SobieskiProblem\nfrom matplotlib import pyplot as plt"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Import\nThe first step is to import some functions from the API\nand a method to get the design space.\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"configure_logger()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Description\n\nThe **VariableInfluence** post-processing performs first-order variable\ninfluence analysis.\n\nThe method computes $\\frac{d f}{d x_i} \\cdot \\left(x_{i_*} -\nx_{initial_design}\\right)$,\nwhere $x_{initial_design}$ is the initial value of the variable\nand $x_{i_*}$ is the optimal value of the variable.\n\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Create disciplines\nAt this point, we instantiate the disciplines of Sobieski's SSBJ problem:\nPropulsion, Aerodynamics, Structure and Mission\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"disciplines = create_discipline(\n [\n \"SobieskiPropulsion\",\n \"SobieskiAerodynamics\",\n \"SobieskiStructure\",\n \"SobieskiMission\",\n ]\n)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Create design space\nWe also read the design space from the :class:`.SobieskiProblem`.\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"design_space = SobieskiProblem().design_space"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Create and execute scenario\nThe next step is to build an MDO scenario in order to maximize the range,\nencoded 'y_4', with respect to the design parameters, while satisfying the\ninequality constraints 'g_1', 'g_2' and 'g_3'. We can use the MDF formulation,\nthe SLSQP optimization algorithm\nand a maximum number of iterations equal to 100.\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"scenario = create_scenario(\n disciplines,\n formulation=\"MDF\",\n objective_name=\"y_4\",\n maximize_objective=True,\n design_space=design_space,\n)\nscenario.set_differentiation_method(\"user\")\nfor constraint in [\"g_1\", \"g_2\", \"g_3\"]:\n scenario.add_constraint(constraint, \"ineq\")\nscenario.execute({\"algo\": \"SLSQP\", \"max_iter\": 10})"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Post-process scenario\nLastly, we post-process the scenario by means of the :class:`.BasicHistory`\nplot.\n\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
".. tip::\n\n Each post-processing method requires different inputs and offers a variety\n of customization options. Use the API function\n :meth:`~gemseo.api.get_post_processing_options_schema` to print a table with\n the options for any post-processing algorithm.\n Or refer to our dedicated page:\n `gen_post_algos`.\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"scenario.post_process(\"VariableInfluence\", save=False, show=False, fig_size=(15, 12))\n# Workaround for HTML rendering, instead of ``show=True``\nplt.show()"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.13"
}
},
"nbformat": 4,
"nbformat_minor": 0
}PK YPU}1 plot_gradient_sensitivity.ipynb{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"%matplotlib inline"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"\n# Gradient Sensitivity\n\nIn this example, we illustrate the use of the :class:`.GradientSensitivity`\nplot on the Sobieski's SSBJ problem.\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"from gemseo.api import configure_logger\nfrom gemseo.api import create_discipline\nfrom gemseo.api import create_scenario\nfrom gemseo.problems.sobieski.core.problem import SobieskiProblem\nfrom matplotlib import pyplot as plt"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Import\nThe first step is to import some functions from the API\nand a method to get the design space.\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"configure_logger()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Description\n\nThe **GradientSensitivity** post-processing\nbuilds histograms of derivatives of the objective and the constraints.\n\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Create disciplines\nAt this point, we instantiate the disciplines of Sobieski's SSBJ problem:\nPropulsion, Aerodynamics, Structure and Mission\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"disciplines = create_discipline(\n [\n \"SobieskiPropulsion\",\n \"SobieskiAerodynamics\",\n \"SobieskiStructure\",\n \"SobieskiMission\",\n ]\n)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Create design space\nWe also read the design space from the :class:`.SobieskiProblem`.\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"design_space = SobieskiProblem().design_space"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Create and execute scenario\nThe next step is to build an MDO scenario in order to maximize the range,\nencoded 'y_4', with respect to the design parameters, while satisfying the\ninequality constraints 'g_1', 'g_2' and 'g_3'. We can use the MDF formulation,\nthe SLSQP optimization algorithm\nand a maximum number of iterations equal to 100.\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"scenario = create_scenario(\n disciplines,\n formulation=\"MDF\",\n objective_name=\"y_4\",\n maximize_objective=True,\n design_space=design_space,\n)\nscenario.set_differentiation_method(\"finite_differences\")\nfor constraint in [\"g_1\", \"g_2\", \"g_3\"]:\n scenario.add_constraint(constraint, \"ineq\")\nscenario.execute({\"algo\": \"SLSQP\", \"max_iter\": 10})"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Post-process scenario\nLastly, we post-process the scenario by means of the :class:`.GradientSensitivity`\nplot which builds histograms of derivatives of objective and constraints.\n\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
".. tip::\n\n Each post-processing method requires different inputs and offers a variety\n of customization options. Use the API function\n :meth:`~gemseo.api.get_post_processing_options_schema` to print a table with\n the options for any post-processing algorithm.\n Or refer to our dedicated page:\n `gen_post_algos`.\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"scenario.post_process(\"GradientSensitivity\", save=False, show=False)\n# Workaround for HTML rendering, instead of ``show=True``\nplt.show()"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.13"
}
},
"nbformat": 4,
"nbformat_minor": 0
}PK ZPUA@d0 0 plot_obj_constr_hist.ipynb{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"%matplotlib inline"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"\n# Objective and constraints history\n\nIn this example, we illustrate the use of the :class:`.ObjConstrHist` plot\non the Sobieski's SSBJ problem.\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"from gemseo.api import configure_logger\nfrom gemseo.api import create_discipline\nfrom gemseo.api import create_scenario\nfrom gemseo.problems.sobieski.core.problem import SobieskiProblem\nfrom matplotlib import pyplot as plt"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Import\nThe first step is to import some functions from the API\nand a method to get the design space.\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"configure_logger()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Description\n\nThe :class:`~gemseo.post.obj_constr_hist.ObjConstrHist` post-processing\nplots the objective history in a line chart\nwith constraint violation indication by color in the background.\n\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Create disciplines\nAt this point, we instantiate the disciplines of Sobieski's SSBJ problem:\nPropulsion, Aerodynamics, Structure and Mission\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"disciplines = create_discipline(\n [\n \"SobieskiPropulsion\",\n \"SobieskiAerodynamics\",\n \"SobieskiStructure\",\n \"SobieskiMission\",\n ]\n)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Create design space\nWe also read the design space from the :class:`.SobieskiProblem`.\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"design_space = SobieskiProblem().design_space"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Create and execute scenario\nThe next step is to build an MDO scenario in order to maximize the range,\nencoded 'y_4', with respect to the design parameters, while satisfying the\ninequality constraints 'g_1', 'g_2' and 'g_3'. We can use the MDF formulation,\nthe SLSQP optimization algorithm\nand a maximum number of iterations equal to 100.\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"scenario = create_scenario(\n disciplines,\n formulation=\"MDF\",\n objective_name=\"y_4\",\n maximize_objective=True,\n design_space=design_space,\n)\nscenario.set_differentiation_method(\"user\")\nfor constraint in [\"g_1\", \"g_2\", \"g_3\"]:\n scenario.add_constraint(constraint, \"ineq\")\nscenario.execute({\"algo\": \"SLSQP\", \"max_iter\": 10})"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Post-process scenario\nLastly, we post-process the scenario by means of the :class:`.ObjConstrHist`\nplot which plots the constraint functions history in lines charts.\n\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
".. tip::\n\n Each post-processing method requires different inputs and offers a variety\n of customization options. Use the API function\n :meth:`~gemseo.api.get_post_processing_options_schema` to print a table with\n the options for any post-processing algorithm.\n Or refer to our dedicated page:\n `gen_post_algos`.\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"scenario.post_process(\"ObjConstrHist\", save=False, show=False)\n# Workaround for HTML rendering, instead of ``show=True``\nplt.show()"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.13"
}
},
"nbformat": 4,
"nbformat_minor": 0
}PK [PUȔ plot_opt_hist_view.ipynb{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"%matplotlib inline"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"\n# Optimization History View\n\nIn this example, we illustrate the use of the :class:`.OptHistoryView` plot\non the Sobieski's SSBJ problem.\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"from gemseo.api import configure_logger\nfrom gemseo.api import create_discipline\nfrom gemseo.api import create_scenario\nfrom gemseo.problems.sobieski.core.problem import SobieskiProblem\nfrom matplotlib import pyplot as plt"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Import\nThe first step is to import some functions from the API\nand a method to get the design space.\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"configure_logger()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Description\nThe **OptHistoryView** post-processing\ncreates a series of plots:\n\n- The design variables history - This graph shows the normalized values of the\n design variables, the $y$ axis is the index of the inputs in the vector;\n and the $x$ axis represents the iterations.\n- The objective function history - It shows the evolution of the objective\n value during the optimization.\n- The distance to the best design variables - Plots the vector\n $log( ||x-x^*|| )$ in log scale.\n- The history of the Hessian approximation of the objective - Plots an approximation\n of the second order derivatives of the objective function\n $\\frac{\\partial^2 f(x)}{\\partial x^2}$, which is a measure of\n the sensitivity of the function with respect to the design variables,\n and of the anisotropy of the problem (differences of curvatures in the\n design space).\n- The inequality constraint history - Portrays the evolution of the values of the\n :term:`constraints`. The inequality constraints must be non-positive, that is why\n the plot must be green or white for satisfied constraints (white = active,\n red = violated). For an `IDF formulation `, an additional\n plot is created to track the equality constraint history.\n\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Create disciplines\nAt this point we instantiate the disciplines of Sobieski's SSBJ problem:\nPropulsion, Aerodynamics, Structure and Mission\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"disciplines = create_discipline(\n [\n \"SobieskiPropulsion\",\n \"SobieskiAerodynamics\",\n \"SobieskiStructure\",\n \"SobieskiMission\",\n ]\n)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Create design space\nWe also read the design space from the :class:`.SobieskiProblem`.\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"design_space = SobieskiProblem().design_space"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Create and execute scenario\nThe next step is to build an MDO scenario in order to maximize the range,\nencoded 'y_4', with respect to the design parameters, while satisfying the\ninequality constraints 'g_1', 'g_2' and 'g_3'. We can use the MDF formulation,\nthe SLSQP optimization algorithm\nand a maximum number of iterations equal to 100.\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"scenario = create_scenario(\n disciplines,\n formulation=\"MDF\",\n objective_name=\"y_4\",\n maximize_objective=True,\n design_space=design_space,\n)\nscenario.set_differentiation_method(\"user\")\nfor constraint in [\"g_1\", \"g_2\", \"g_3\"]:\n scenario.add_constraint(constraint, \"ineq\")\nscenario.execute({\"algo\": \"SLSQP\", \"max_iter\": 10})"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Post-process scenario\nLastly, we post-process the scenario by means of the :class:`.OptHistoryView`\nplot which plots the history of optimization for both objective function,\nconstraints, design parameters and distance to the optimum.\n\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
".. tip::\n\n Each post-processing method requires different inputs and offers a variety\n of customization options. Use the API function\n :meth:`~gemseo.api.get_post_processing_options_schema` to print a table with\n the options for any post-processing algorithm.\n Or refer to our dedicated page:\n `gen_post_algos`.\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"scenario.post_process(\"OptHistoryView\", save=False, show=False)\n# Workaround for HTML rendering, instead of ``show=True``\nplt.show()"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.13"
}
},
"nbformat": 4,
"nbformat_minor": 0
}PK RPU.r7d d plot_gantt_chart.ipynb{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"%matplotlib inline"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"\n# Gantt Chart\n\nIn this example, we illustrate the use of the Gantt chart plot\non the Sobieski's SSBJ problem.\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Import\nThe first step is to import some functions from the API\nand a method to get the design space.\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"from gemseo.api import configure_logger\nfrom gemseo.api import create_discipline\nfrom gemseo.api import create_scenario\nfrom gemseo.core.discipline import MDODiscipline\nfrom gemseo.post.core.gantt_chart import create_gantt_chart\nfrom gemseo.problems.sobieski.core.problem import SobieskiProblem\nfrom matplotlib import pyplot as plt\n\nconfigure_logger()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Create disciplines\nThen, we instantiate the disciplines of the Sobieski's SSBJ problem:\nPropulsion, Aerodynamics, Structure and Mission\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"disciplines = create_discipline(\n [\n \"SobieskiPropulsion\",\n \"SobieskiAerodynamics\",\n \"SobieskiStructure\",\n \"SobieskiMission\",\n ]\n)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Create design space\nWe also read the design space from the :class:`.SobieskiProblem`.\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"design_space = SobieskiProblem().design_space"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Create and execute scenario\nThe next step is to build an MDO scenario in order to maximize the range,\nencoded 'y_4', with respect to the design parameters, while satisfying the\ninequality constraints 'g_1', 'g_2' and 'g_3'. We can use the MDF formulation,\nthe SLSQP optimization algorithm\nand a maximum number of iterations equal to 100.\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"scenario = create_scenario(\n disciplines,\n formulation=\"MDF\",\n objective_name=\"y_4\",\n maximize_objective=True,\n design_space=design_space,\n)\n\nfor constraint in [\"g_1\", \"g_2\", \"g_3\"]:\n scenario.add_constraint(constraint, \"ineq\")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Activate time stamps\nIn order to record all time stamps recording, we have to call this method\nbefore the execution of the scenarios\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"MDODiscipline.activate_time_stamps()\n\nscenario.execute({\"algo\": \"SLSQP\", \"max_iter\": 10})"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Post-process scenario\nLastly, we plot the Gantt chart.\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"create_gantt_chart(show=False, save=False)\n# Workaround for HTML rendering, instead of ``show=True``\nplt.show()\n\n# Finally, we deactivate the time stamps for other executions\nMDODiscipline.deactivate_time_stamps()"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.13"
}
},
"nbformat": 4,
"nbformat_minor": 0
}PK \PU"E!/ / plot_para_coord.ipynb{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"%matplotlib inline"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"\n# Parallel coordinates\n\nIn this example, we illustrate the use of the\n:class:`~gemseo.post.para_coord.ParallelCoordinates` plot on the Sobieski's SSBJ\nproblem.\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"from gemseo.api import configure_logger\nfrom gemseo.api import create_discipline\nfrom gemseo.api import create_scenario\nfrom gemseo.problems.sobieski.core.problem import SobieskiProblem\nfrom matplotlib import pyplot as plt"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Import\nThe first step is to import some functions from the API\nand a method to get the design space.\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"configure_logger()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Description\n\nThe :class:`~gemseo.post.para_coord.ParallelCoordinates` post-processing\nbuilds parallel coordinates plots among design\nvariables, outputs functions and constraints.\n\nThe :class:`~gemseo.post.para_coord.ParallelCoordinates` portrays the design\nvariables history during the scenario execution. Each vertical coordinate is\ndedicated to a design variable, normalized by its bounds.\n\nA polyline joins all components of a given design vector and is colored\nby objective function values. This highlights the correlations between\nthe values of the design variables and the values of the objective function.\n\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Create disciplines\nAt this point, we instantiate the disciplines of Sobieski's SSBJ problem:\nPropulsion, Aerodynamics, Structure and Mission\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"disciplines = create_discipline(\n [\n \"SobieskiPropulsion\",\n \"SobieskiAerodynamics\",\n \"SobieskiStructure\",\n \"SobieskiMission\",\n ]\n)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Create design space\nWe also read the design space from the :class:`.SobieskiProblem`.\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"design_space = SobieskiProblem().design_space"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Create and execute scenario\nThe next step is to build an MDO scenario in order to maximize the range,\nencoded 'y_4', with respect to the design parameters, while satisfying the\ninequality constraints 'g_1', 'g_2' and 'g_3'. We can use the MDF formulation,\nthe SLSQP optimization algorithm\nand a maximum number of iterations equal to 100.\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"scenario = create_scenario(\n disciplines,\n formulation=\"MDF\",\n objective_name=\"y_4\",\n maximize_objective=True,\n design_space=design_space,\n)\nscenario.set_differentiation_method(\"user\")\nfor constraint in [\"g_1\", \"g_2\", \"g_3\"]:\n scenario.add_constraint(constraint, \"ineq\")\nscenario.execute({\"algo\": \"SLSQP\", \"max_iter\": 10})"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Post-process scenario\nLastly, we post-process the scenario by means of the\n:class:`~gemseo.post.para_coord.ParallelCoordinates` plot which parallel\ncoordinates plots among design variables, objective function and constraints.\n\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
".. tip::\n\n Each post-processing method requires different inputs and offers a variety\n of customization options. Use the API function\n :meth:`~gemseo.api.get_post_processing_options_schema` to print a table with\n the options for any post-processing algorithm.\n Or refer to our dedicated page:\n `gen_post_algos`.\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"scenario.post_process(\"ParallelCoordinates\", save=False, show=False)\n# Workaround for HTML rendering, instead of ``show=True``\nplt.show()"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.13"
}
},
"nbformat": 4,
"nbformat_minor": 0
}PK OPUo9# # plot_constraints_history.ipynb{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"%matplotlib inline"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"\n# Constraints history\n\nIn this example, we illustrate the use of the :class:`.ConstraintsHistory` plot\non the Sobieski's SSBJ problem.\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"from gemseo.api import configure_logger\nfrom gemseo.api import create_discipline\nfrom gemseo.api import create_scenario\nfrom gemseo.problems.sobieski.core.problem import SobieskiProblem\nfrom matplotlib import pyplot as plt"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Import\nThe first step is to import some functions from the API\nand a method to get the design space.\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"configure_logger()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Description\n\nThe :class:`~gemseo.post.constraints_history.ConstraintsHistory` post-processing\nplots the constraints functions history in line charts\nwith violation indication by color on the background.\n\nThis plot is more precise than the constraint plot provided by the\n`opt_history_view` but scales less with the number of constraints.\n\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Create disciplines\nAt this point, we instantiate the disciplines of Sobieski's SSBJ problem:\nPropulsion, Aerodynamics, Structure and Mission\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"disciplines = create_discipline(\n [\n \"SobieskiPropulsion\",\n \"SobieskiAerodynamics\",\n \"SobieskiStructure\",\n \"SobieskiMission\",\n ]\n)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Create design space\nWe also read the design space from the :class:`.SobieskiProblem`.\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"design_space = SobieskiProblem().design_space"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Create and execute scenario\nThe next step is to build an MDO scenario in order to maximize the range,\nencoded 'y_4', with respect to the design parameters, while satisfying the\ninequality constraints 'g_1', 'g_2' and 'g_3'. We can use the MDF formulation,\nthe SLSQP optimization algorithm\nand a maximum number of iterations equal to 100.\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"scenario = create_scenario(\n disciplines,\n formulation=\"MDF\",\n objective_name=\"y_4\",\n maximize_objective=True,\n design_space=design_space,\n)\nscenario.set_differentiation_method(\"user\")\nall_constraints = [\"g_1\", \"g_2\", \"g_3\"]\nfor constraint in all_constraints:\n scenario.add_constraint(constraint, \"ineq\")\nscenario.execute({\"algo\": \"SLSQP\", \"max_iter\": 10})"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Post-process scenario\nLastly, we post-process the scenario by means of the\n:class:`.ConstraintsHistory` plot which plots the history of constraints\npassed as argument by the user. Each constraint history is represented by\na subplot where the value of the constraints is drawn by a line. Moreover,\nthe background color represents a qualitative view of these values: active\nareas are white, violated ones are red and satisfied ones are green.\n\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
".. tip::\n\n Each post-processing method requires different inputs and offers a variety\n of customization options. Use the API function\n :meth:`~gemseo.api.get_post_processing_options_schema` to print a table with\n the options for any post-processing algorithm.\n Or refer to our dedicated page:\n `gen_post_algos`.\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"scenario.post_process(\n \"ConstraintsHistory\", constraint_names=all_constraints, save=False, show=False\n)\n# Workaround for HTML rendering, instead of ``show=True``\nplt.show()"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.13"
}
},
"nbformat": 4,
"nbformat_minor": 0
}PK bPUN]צ plot_robustness.ipynb{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"%matplotlib inline"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"\n# Robustness\n\nIn this example, we illustrate the use of the :class:`.Robustness` plot\non the Sobieski's SSBJ problem.\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"from gemseo.api import configure_logger\nfrom gemseo.api import create_discipline\nfrom gemseo.api import create_scenario\nfrom gemseo.problems.sobieski.core.problem import SobieskiProblem\nfrom matplotlib import pyplot as plt"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Import\nThe first step is to import some functions from the API\nand a method to get the design space.\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"configure_logger()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Description\n\nIn the :class:`~gemseo.post.robustness.Robustness` post-processing,\nthe robustness of the optimum is represented by a box plot. Using the\nquadratic approximations of all the output functions, we\npropagate analytically a normal distribution with 1% standard deviation\non all the design variables, assuming no cross-correlations of inputs,\nto obtain the mean and standard deviation of the resulting normal\ndistribution. A series of samples are randomly generated from the resulting\ndistribution, whose quartiles are plotted, relatively to the values of\nthe function at the optimum. For each function (in abscissa), the plot\nshows the extreme values encountered in the samples (top and bottom\nbars). Then, 95% of the values are within the blue boxes. The average is\ngiven by the red bar.\n\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Create disciplines\nAt this point, we instantiate the disciplines of Sobieski's SSBJ problem:\nPropulsion, Aerodynamics, Structure and Mission\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"disciplines = create_discipline(\n [\n \"SobieskiPropulsion\",\n \"SobieskiAerodynamics\",\n \"SobieskiStructure\",\n \"SobieskiMission\",\n ]\n)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Create design space\nWe also read the design space from the :class:`.SobieskiProblem`.\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"design_space = SobieskiProblem().design_space"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Create and execute scenario\nThe next step is to build an MDO scenario in order to maximize the range,\nencoded 'y_4', with respect to the design parameters, while satisfying the\ninequality constraints 'g_1', 'g_2' and 'g_3'. We can use the MDF formulation,\nthe SLSQP optimization algorithm\nand a maximum number of iterations equal to 100.\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"scenario = create_scenario(\n disciplines,\n formulation=\"MDF\",\n objective_name=\"y_4\",\n maximize_objective=True,\n design_space=design_space,\n)\nscenario.set_differentiation_method(\"user\")\nfor constraint in [\"g_1\", \"g_2\", \"g_3\"]:\n scenario.add_constraint(constraint, \"ineq\")\nscenario.execute({\"algo\": \"SLSQP\", \"max_iter\": 10})"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Post-process scenario\nLastly, we post-process the scenario by means of the :class:`.Robustness`\nwhich plots any of the constraint or\nobjective functions w.r.t. the optimization iterations or sampling snapshots.\n\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
".. tip::\n\n Each post-processing method requires different inputs and offers a variety\n of customization options. Use the API function\n :meth:`~gemseo.api.get_post_processing_options_schema` to print a table with\n the options for any post-processing algorithm.\n Or refer to our dedicated page:\n `gen_post_algos`.\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"scenario.post_process(\"Robustness\", save=False, show=False)\n# Workaround for HTML rendering, instead of ``show=True``\nplt.show()"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.13"
}
},
"nbformat": 4,
"nbformat_minor": 0
}PK QPUK K plot_correlations.ipynbPK NPUԘe e plot_basic_history.ipynbPK \PUHs/a a / plot_pareto_front.ipynbPK `PU
( C plot_pareto_front_binhkorn_bilevel.ipynbPK bPUfk " c plot_constraints_radar_chart.ipynbPK gPU
R R 1x plot_som.ipynbPK ePUwh h ! plot_history_scatter_matrix.ipynbPK ]PUv V plot_pareto_front_binhkorn.ipynbPK aPU9'T " plot_quad_approx.ipynbPK hPUR| | V plot_variable_influence.ipynbPK YPU}1
plot_gradient_sensitivity.ipynbPK ZPUA@d0 0 Q plot_obj_constr_hist.ipynbPK [PUȔ plot_opt_hist_view.ipynbPK RPU.r7d d + plot_gantt_chart.ipynbPK \PU"E!/ / > plot_para_coord.ipynbPK OPUo9# # }T plot_constraints_history.ipynbPK bPUN]צ j plot_robustness.ipynbPK