Skip to content

Commit

Permalink
GitHub Actions build openturns/otbenchmark 10943979829
Browse files Browse the repository at this point in the history
  • Loading branch information
GitHub Actions committed Sep 19, 2024
1 parent 7cbb5c7 commit ff52c6f
Show file tree
Hide file tree
Showing 210 changed files with 13,052 additions and 576 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,235 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"\n# Benchmark the Borgonovo test function\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"import openturns as ot\nimport otbenchmark as otb\nimport openturns.viewer as otv"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"problem = otb.BorgonovoSensitivity()\nprint(problem)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"distribution = problem.getInputDistribution()\nmodel = problem.getFunction()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Exact first and total order\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"exact_first_order = problem.getFirstOrderIndices()\nexact_first_order"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"exact_total_order = problem.getTotalOrderIndices()\nexact_total_order"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Plot the function\n\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Create X/Y data\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"ot.RandomGenerator.SetSeed(0)\nsize = 200\ninputDesign = ot.MonteCarloExperiment(distribution, size).generate()\noutputDesign = model(inputDesign)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"dimension = distribution.getDimension()\nfull_sample = ot.Sample(size, 1 + dimension)\nfull_sample[:, range(dimension)] = inputDesign\nfull_sample[:, dimension] = outputDesign\nfull_description = list(inputDesign.getDescription())\nfull_description.append(outputDesign.getDescription()[0])\nfull_sample.setDescription(full_description)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"marginal_distribution = ot.ComposedDistribution(\n [\n ot.KernelSmoothing().build(full_sample.getMarginal(i))\n for i in range(1 + dimension)\n ]\n)\nclouds = ot.VisualTest.DrawPairsMarginals(full_sample, marginal_distribution)\n_ = otv.View(clouds, figure_kw={\"figsize\": (6.0, 6.0)})"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"output_distribution = ot.KernelSmoothing().build(outputDesign)\n_ = otv.View(output_distribution.drawPDF())"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Perform sensitivity analysis\n\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Create X/Y data\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"ot.RandomGenerator.SetSeed(0)\nsize = 10000\ninputDesign = ot.SobolIndicesExperiment(distribution, size).generate()\noutputDesign = model(inputDesign)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Compute first order indices using the Saltelli estimator\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"sensitivityAnalysis = ot.SaltelliSensitivityAlgorithm(inputDesign, outputDesign, size)\ncomputed_first_order = sensitivityAnalysis.getFirstOrderIndices()\ncomputed_total_order = sensitivityAnalysis.getTotalOrderIndices()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Compare with exact results\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"print(\"Sample size : \", size)\n# First order\n# Compute absolute error (the LRE cannot be computed,\n# because S can be zero)\nprint(\"Computed first order = \", computed_first_order)\nprint(\"Exact first order = \", exact_first_order)\n# Total order\nprint(\"Computed total order = \", computed_total_order)\nprint(\"Exact total order = \", exact_total_order)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"_ = otv.View(sensitivityAnalysis.draw())"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"otv.View.ShowAll()"
]
}
],
"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.20"
}
},
"nbformat": 4,
"nbformat_minor": 0
}
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading

0 comments on commit ff52c6f

Please sign in to comment.