Skip to content

Commit

Permalink
CircleCI build openturns 16607
Browse files Browse the repository at this point in the history
  • Loading branch information
CircleCI committed Mar 21, 2024
1 parent 9f280b5 commit 6259d5b
Show file tree
Hide file tree
Showing 313 changed files with 2,900 additions and 2,261 deletions.
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,24 @@
"quantileLevel = 0.1\nalgo = ot.NAIS(myEvent, quantileLevel)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"In order to get all the inputs and outputs that realize the event, you have to mention it now:\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"algo.setKeepSample(True)"
]
},
{
"cell_type": "markdown",
"metadata": {},
Expand Down Expand Up @@ -223,7 +241,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"## Draw the NAIS samples used by the algorithm\n\nThe following manipulations are possible only if you have created a :class:`~openturns.MemoizeFunction` that enables to store all the inputs and outputs of the function $g$.\n\nGet all the inputs and outputs where $g$ were evaluated:\n\n"
"You can also get the successive thresholds used by the algorithm:\n\n"
]
},
{
Expand All @@ -234,14 +252,21 @@
},
"outputs": [],
"source": [
"inputNAIS = g.getInputHistory()\noutputNAIS = g.getOutputHistory()\nnTotal = inputNAIS.getSize()\nprint(\"Number of evaluations of g = \", nTotal)"
"levels = algo.getThresholdPerStep()\nprint(\"Levels of g = \", levels)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Draw the NAIS samples used by the algorithm\n\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Within each step of the algorithm, a sample of size $N$ is created, where:\n\n"
"You can get the number $N_s$ of steps with:\n\n"
]
},
{
Expand All @@ -252,14 +277,14 @@
},
"outputs": [],
"source": [
"N = algo.getMaximumOuterSampling() * algo.getBlockSize()\nprint(\"Size of each subset = \", N)"
"Ns = algo.getStepsNumber()\nprint(\"Number of steps= \", Ns)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"You can get the number $N_s$ of steps with:\n\n"
"Get all the inputs where $g$ was evaluated at each step\n\n"
]
},
{
Expand All @@ -270,14 +295,14 @@
},
"outputs": [],
"source": [
"Ns = int(nTotal / N)\nprint(\"Number of steps = \", Ns)"
"list_subSamples = list()\nfor step in range(Ns):\n list_subSamples.append(algo.getInputSample(step))"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Now, we can split the initial sample into NAIS samples of size $N_s$:\n\n"
"The following graph draws each NAIS sample and the frontier $g(x_1, x_2) = l_i$ where $l_i$ is the threshold at the step $i$:\n\n"
]
},
{
Expand All @@ -288,14 +313,14 @@
},
"outputs": [],
"source": [
"listNAISSamples = list()\nlistOutputNAISSamples = list()\nfor i in range(Ns):\n listNAISSamples.append(inputNAIS[i * N: i * N + N])\n listOutputNAISSamples.append(outputNAIS[i * N: i * N + N])"
"graph = ot.Graph()\ngraph.setAxes(True)\ngraph.setGrid(True)\ngraph.setTitle(\"NAIS sampling: samples\")\ngraph.setXTitle(r\"$x_1$\")\ngraph.setYTitle(r\"$x_2$\")\ngraph.setLegendPosition(\"lower left\")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"And get all the levels defining the intermediate and final thresholds given by the empirical quantiles of each NAIS output sample:\n\n"
"Add all the NAIS samples:\n\n"
]
},
{
Expand All @@ -306,14 +331,25 @@
},
"outputs": [],
"source": [
"levels = []\nfor i in range(Ns - 1):\n levels.append(listOutputNAISSamples[i].computeQuantile(quantileLevel)[0])\nlevels.append(threshold)"
"for i in range(Ns):\n cloud = ot.Cloud(list_subSamples[i])\n # cloud.setPointStyle(\"dot\")\n graph.add(cloud)\ncol = graph.getColors()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"The following graph draws each NAIS sample and the frontier $g(x_1, x_2) = l_i$ where $l_i$ is the threshold at the step $i$:\n\n"
"Add the frontiers $g(x_1, x_2) = l_i$ where $l_i$ is the threshold at the step $i$:\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"gIsoLines = g.draw([-5] * 2, [5] * 2, [128] * 2)\ndr = gIsoLines.getDrawable(0)\nfor i, lv in enumerate(levels):\n dr.setLevels([lv])\n dr.setLineStyle(\"solid\")\n dr.setLegend(r\"$g(X) = $\" + str(round(lv, 2)))\n dr.setLineWidth(3)\n dr.setColor(col[i])\n graph.add(dr)"
]
},
{
Expand All @@ -324,14 +360,14 @@
},
"outputs": [],
"source": [
"graph = ot.Graph(\"NAIS samples\", \"x1\", \"x2\", True, \"lower left\")\ngraph.setGrid(True)"
"_ = View(graph)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Add all the NAIS samples:\n\n"
"## Draw the frontiers only\n\nThe following graph enables to understand the progression of the algorithm:\n\n"
]
},
{
Expand All @@ -342,14 +378,14 @@
},
"outputs": [],
"source": [
"for i in range(Ns):\n cloud = ot.Cloud(listNAISSamples[i])\n graph.add(cloud)\ncol = ot.Drawable().BuildDefaultPalette(Ns)\ngraph.setColors(col)"
"graph = ot.Graph()\ngraph.setAxes(True)\ngraph.setGrid(True)\ndr = gIsoLines.getDrawable(0)\nfor i, lv in enumerate(levels):\n dr.setLevels([lv])\n dr.setLineStyle(\"solid\")\n dr.setLegend(r\"$g(X) = $\" + str(round(lv, 2)))\n dr.setLineWidth(3)\n graph.add(dr)\n\ngraph.setColors(col)\ngraph.setLegendPosition(\"lower left\")\ngraph.setTitle(\"NAIS sampling: thresholds\")\ngraph.setXTitle(r\"$x_1$\")\ngraph.setYTitle(r\"$x_2$\")\n\n_ = View(graph)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Add the frontiers $g(x_1, x_2) = l_i$ where $l_i$ is the threshold at the step $i$:\n\n"
"## Get all the input and output points that realized the event\nThe following lines are possible only if you have mentioned that you wanted to keep samples with the method *algo.setKeepSample(True)*\n\n"
]
},
{
Expand All @@ -360,14 +396,14 @@
},
"outputs": [],
"source": [
"gIsoLines = g.draw([-8] * 2, [8] * 2, [128] * 2)\ndr = gIsoLines.getDrawable(2)\nfor i, lv in enumerate(levels):\n dr.setLevels([lv])\n dr.setLineStyle(\"solid\")\n dr.setLegend(r\"$g(X) = $\" + str(round(lv, 2)))\n dr.setLineWidth(3)\n dr.setColor(col[i])\n graph.add(dr)\n\n# sphinx_gallery_thumbnail_number = 2\nview = View(graph)"
"select = ot.NAIS.EVENT1 # points that realize the event\nstep = Ns - 1 # get the working sample from last iteration\ninputEventSample = algo.getInputSample(step, select)\noutputEventSample = algo.getOutputSample(step, select)\nprint(\"Number of event realizations = \", inputEventSample.getSize())"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Draw the frontiers only\n\nThe following graph enables to understand the progression of the algorithm from the mean value of the initial distribution to the limit state function:\n\n"
"Draw them! They are all in the event space.\n\n"
]
},
{
Expand All @@ -378,7 +414,7 @@
},
"outputs": [],
"source": [
"graph = ot.Graph(\"NAIS thresholds\", \"x1\", \"x2\", True, \"lower left\")\ngraph.setGrid(True)\ndr = gIsoLines.getDrawable(0)\nfor i, lv in enumerate(levels):\n dr.setLevels([lv])\n dr.setLineStyle(\"solid\")\n dr.setLegend(r\"$g(X) = $\" + str(round(lv, 2)))\n dr.setLineWidth(3)\n graph.add(dr)\n\ngraph.setColors(col)\nview = View(graph)"
"graph = ot.Graph()\ngraph.setAxes(True)\ngraph.setGrid(True)\ncloud = ot.Cloud(inputEventSample)\ncloud.setPointStyle(\"bullet\")\ngraph.add(cloud)\ngIsoLines = g.draw([-5] * 2, [5] * 2, [1000] * 2)\ndr = gIsoLines.getDrawable(0)\ndr.setLevels([0.0])\ndr.setColor(\"red\")\ngraph.add(dr)\n_ = View(graph)\n\nView.ShowAll()"
]
}
],
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,12 @@ def fourBranch(x):
quantileLevel = 0.1
algo = ot.NAIS(myEvent, quantileLevel)

# %%
# In order to get all the inputs and outputs that realize the event, you have to mention it now:

# %%
algo.setKeepSample(True)

# %%
# Now you can run the algorithm.

Expand Down Expand Up @@ -138,75 +144,55 @@ def fourBranch(x):
)

# %%
# Draw the NAIS samples used by the algorithm
# -------------------------------------------
#
# The following manipulations are possible only if you have created a :class:`~openturns.MemoizeFunction` that enables to store all the inputs and outputs of the function :math:`g`.
#
# Get all the inputs and outputs where :math:`g` were evaluated:

# %%
inputNAIS = g.getInputHistory()
outputNAIS = g.getOutputHistory()
nTotal = inputNAIS.getSize()
print("Number of evaluations of g = ", nTotal)
# You can also get the successive thresholds used by the algorithm:

# %%
# Within each step of the algorithm, a sample of size :math:`N` is created, where:
levels = algo.getThresholdPerStep()
print("Levels of g = ", levels)

# %%
N = algo.getMaximumOuterSampling() * algo.getBlockSize()
print("Size of each subset = ", N)
# Draw the NAIS samples used by the algorithm
# ---------------------------------------------

# %%
# You can get the number :math:`N_s` of steps with:
Ns = algo.getStepsNumber()
print("Number of steps= ", Ns)

# %%
Ns = int(nTotal / N)
print("Number of steps = ", Ns)

# %%
# Now, we can split the initial sample into NAIS samples of size :math:`N_s`:

# %%
listNAISSamples = list()
listOutputNAISSamples = list()
for i in range(Ns):
listNAISSamples.append(inputNAIS[i * N: i * N + N])
listOutputNAISSamples.append(outputNAIS[i * N: i * N + N])

# %%
# And get all the levels defining the intermediate and final thresholds given by the empirical quantiles of each NAIS output sample:

# %%
levels = []
for i in range(Ns - 1):
levels.append(listOutputNAISSamples[i].computeQuantile(quantileLevel)[0])
levels.append(threshold)
# Get all the inputs where :math:`g` was evaluated at each step
list_subSamples = list()
for step in range(Ns):
list_subSamples.append(algo.getInputSample(step))

# %%
# The following graph draws each NAIS sample and the frontier :math:`g(x_1, x_2) = l_i` where :math:`l_i` is the threshold at the step :math:`i`:

# %%
graph = ot.Graph("NAIS samples", "x1", "x2", True, "lower left")
graph = ot.Graph()
graph.setAxes(True)
graph.setGrid(True)
graph.setTitle("NAIS sampling: samples")
graph.setXTitle(r"$x_1$")
graph.setYTitle(r"$x_2$")
graph.setLegendPosition("lower left")

# %%
# Add all the NAIS samples:

# %%
for i in range(Ns):
cloud = ot.Cloud(listNAISSamples[i])
cloud = ot.Cloud(list_subSamples[i])
# cloud.setPointStyle("dot")
graph.add(cloud)
col = ot.Drawable().BuildDefaultPalette(Ns)
graph.setColors(col)
col = graph.getColors()

# %%
# Add the frontiers :math:`g(x_1, x_2) = l_i` where :math:`l_i` is the threshold at the step :math:`i`:

# %%
gIsoLines = g.draw([-8] * 2, [8] * 2, [128] * 2)
dr = gIsoLines.getDrawable(2)
gIsoLines = g.draw([-5] * 2, [5] * 2, [128] * 2)
dr = gIsoLines.getDrawable(0)
for i, lv in enumerate(levels):
dr.setLevels([lv])
dr.setLineStyle("solid")
Expand All @@ -215,17 +201,18 @@ def fourBranch(x):
dr.setColor(col[i])
graph.add(dr)

# sphinx_gallery_thumbnail_number = 2
view = View(graph)
# %%
_ = View(graph)

# %%
# Draw the frontiers only
# -----------------------
#
# The following graph enables to understand the progression of the algorithm from the mean value of the initial distribution to the limit state function:
# The following graph enables to understand the progression of the algorithm:

# %%
graph = ot.Graph("NAIS thresholds", "x1", "x2", True, "lower left")
graph = ot.Graph()
graph.setAxes(True)
graph.setGrid(True)
dr = gIsoLines.getDrawable(0)
for i, lv in enumerate(levels):
Expand All @@ -236,4 +223,40 @@ def fourBranch(x):
graph.add(dr)

graph.setColors(col)
view = View(graph)
graph.setLegendPosition("lower left")
graph.setTitle("NAIS sampling: thresholds")
graph.setXTitle(r"$x_1$")
graph.setYTitle(r"$x_2$")

_ = View(graph)

# %%
# Get all the input and output points that realized the event
# -----------------------------------------------------------
# The following lines are possible only if you have mentioned that you wanted to keep samples with the method *algo.setKeepSample(True)*

# %%
select = ot.NAIS.EVENT1 # points that realize the event
step = Ns - 1 # get the working sample from last iteration
inputEventSample = algo.getInputSample(step, select)
outputEventSample = algo.getOutputSample(step, select)
print("Number of event realizations = ", inputEventSample.getSize())

# %%
# Draw them! They are all in the event space.

# %%
graph = ot.Graph()
graph.setAxes(True)
graph.setGrid(True)
cloud = ot.Cloud(inputEventSample)
cloud.setPointStyle("bullet")
graph.add(cloud)
gIsoLines = g.draw([-5] * 2, [5] * 2, [1000] * 2)
dr = gIsoLines.getDrawable(0)
dr.setLevels([0.0])
dr.setColor("red")
graph.add(dr)
_ = View(graph)

View.ShowAll()
Binary file not shown.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified openturns/master/_images/sphx_glr_plot_axial_stressed_beam_004.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified openturns/master/_images/sphx_glr_plot_axial_stressed_beam_006.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified openturns/master/_images/sphx_glr_plot_create_domain_event_005.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified openturns/master/_images/sphx_glr_plot_ego_003.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified openturns/master/_images/sphx_glr_plot_ego_005.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified openturns/master/_images/sphx_glr_plot_ego_009.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified openturns/master/_images/sphx_glr_plot_ifs_001.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified openturns/master/_images/sphx_glr_plot_ifs_002.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified openturns/master/_images/sphx_glr_plot_ifs_003.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified openturns/master/_images/sphx_glr_plot_ifs_004.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified openturns/master/_images/sphx_glr_plot_ifs_thumb.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified openturns/master/_images/sphx_glr_plot_nais_002.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified openturns/master/_images/sphx_glr_plot_nais_003.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified openturns/master/_images/sphx_glr_plot_nais_thumb.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified openturns/master/_images/sphx_glr_plot_optimization_dlib_002.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified openturns/master/_images/sphx_glr_plot_pce_design_001.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified openturns/master/_images/sphx_glr_plot_pce_design_thumb.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified openturns/master/_images/sphx_glr_plot_subset_sampling_001.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified openturns/master/_images/sphx_glr_plot_subset_sampling_002.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified openturns/master/_images/sphx_glr_plot_subset_sampling_003.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified openturns/master/_images/sphx_glr_plot_subset_sampling_thumb.png
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ Let us plot the posterior density.

.. rst-class:: sphx-glr-timing

**Total running time of the script:** (0 minutes 14.208 seconds)
**Total running time of the script:** (0 minutes 12.689 seconds)


.. _sphx_glr_download_auto_calibration_bayesian_calibration_plot_gibbs.py:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,7 @@ Plot posterior marginal plots only as prior cannot be drawn meaningfully.

.. rst-class:: sphx-glr-timing

**Total running time of the script:** (0 minutes 5.709 seconds)
**Total running time of the script:** (0 minutes 5.875 seconds)


.. _sphx_glr_download_auto_calibration_bayesian_calibration_plot_rwmh_python_distribution.py:
Expand Down
Loading

0 comments on commit 6259d5b

Please sign in to comment.