{ "cells": [ { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "%matplotlib inline" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "\n# Parameter space\n\nIn this example,\nwe will see the basics of :class:`.ParameterSpace`.\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "from matplotlib import pyplot as plt\n\nfrom gemseo.algos.parameter_space import ParameterSpace\nfrom gemseo.api import configure_logger, create_discipline, create_scenario\n\nconfigure_logger()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Create a parameter space\nFirstly,\nthe creation of a :class:`.ParameterSpace` does not require any mandatory argument:\n\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "parameter_space = ParameterSpace()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Then, we can add either deterministic variables\nfrom their lower and upper bounds\n(use :meth:`.ParameterSpace.add_variable`)\nor uncertain variables from their distribution names and parameters\n(use :meth:`.ParameterSpace.add_random_variable`)\n\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "parameter_space.add_variable(\"x\", l_b=-2.0, u_b=2.0)\nparameter_space.add_random_variable(\"y\", \"SPNormalDistribution\", mu=0.0, sigma=1.0)\nprint(parameter_space)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "We can check that the deterministic and uncertain variables are implemented\nas deterministic and deterministic variables respectively:\n\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "print(\"x is deterministic: \", parameter_space.is_deterministic(\"x\"))\nprint(\"y is deterministic: \", parameter_space.is_deterministic(\"y\"))\nprint(\"x is uncertain: \", parameter_space.is_uncertain(\"x\"))\nprint(\"y is uncertain: \", parameter_space.is_uncertain(\"y\"))" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Sample from the parameter space\nWe can sample the uncertain variables from the :class:`.ParameterSpace`\nand get values either as a NumPy array (by default)\nor as a dictionary of NumPy arrays indexed by the names of the variables:\n\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "sample = parameter_space.compute_samples(n_samples=2, as_dict=True)\nprint(sample)\nsample = parameter_space.compute_samples(n_samples=4)\nprint(sample)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Sample a discipline over the parameter space\nWe can also sample a discipline over the parameter space.\nFor simplicity,\nwe instantiate an :class:`.AnalyticDiscipline` from a dictionary of expressions:\n\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "discipline = create_discipline(\"AnalyticDiscipline\", expressions_dict={\"z\": \"x+y\"})" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "From these parameter space and discipline,\nwe build a :class:`.DOEScenario`\nand execute it with a Latin Hypercube Sampling algorithm and 100 samples.\n\n
A :class:`.DOEScenario` considers all the variables\n available in its :class:`.DesignSpace`.\n By inheritance,\n in the special case of a :class:`.ParameterSpace`,\n a :class:`.DOEScenario` considers all the variables\n available in this :class:`.ParameterSpace`.\n Thus,\n if we do not filter the uncertain variables,\n the :class:`.DOEScenario` will consider\n both the deterministic variables as uniformly distributed variables\n and the uncertain variables with their specified probability distributions.