Skip to content

Commit

Permalink
Split examples
Browse files Browse the repository at this point in the history
  • Loading branch information
jschueller committed Oct 8, 2024
1 parent ed9f2fd commit 09c197b
Show file tree
Hide file tree
Showing 44 changed files with 19 additions and 95 deletions.
81 changes: 5 additions & 76 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,27 +17,12 @@ the output of a function is less than a threshold,
* sensitivity problems, i.e. estimating sensitivity indices,
for example Sobol' indices.

Most of the reliability problems were adapted from the RPRepo :
Most of the reliability problems were adapted from the RPRepo:

https://rprepo.readthedocs.io/en/latest/

This module allows you to create a problem, run an algorithm and
compare the computed probability with a reference probability:

```
problem = otb.RminusSReliability()
event = problem.getEvent()
pfReference = problem.getProbability() # exact probability
# Create the Monte-Carlo algorithm
algoProb = ot.ProbabilitySimulationAlgorithm(event)
algoProb.setMaximumOuterSampling(1000)
algoProb.setMaximumCoefficientOfVariation(0.01)
algoProb.run()
resultAlgo = algoProb.getResult()
pf = resultAlgo.getProbabilityEstimate()
absoluteError = abs(pf - pfReference)
```

Moreover, we can loop over all problems and run several methods on these
problems.

Expand All @@ -50,71 +35,15 @@ problems.

## Installation

To install the module, we can use the "git clone" command:
To install the module, we can use either pip or conda:

```
git clone https://github.com/mbaudin47/otbenchmark.git
cd otbenchmark
python setup.py install
pip install otbenchmark
```

## Getting help

The code has docstrings. Hence, using the "help" statement will help. Another way of getting help is to read the examples, which are presented in the next section.

## Overview of the benchmark problems

[Analysis of the R-S case]: https://github.com/mbaudin47/otbenchmark/blob/master/examples/reliability_problems/Cas-R-S.ipynb

[Benchmark the G-Sobol test function]: https://github.com/mbaudin47/otbenchmark/blob/master/examples/sensitivity_problems/GSobolSensitivity.ipynb

[Reliability factories]: https://github.com/mbaudin47/otbenchmark/blob/master/examples/methodFactory.ipynb

[Benchmark on a given set of problems]: https://github.com/mbaudin47/otbenchmark/blob/master/examples/reliability_benchmark.ipynb

[Benchmark the reliability solvers on the problems]: https://github.com/mbaudin47/otbenchmark/blob/master/examples/reliability_benchmark_table.ipynb

[Check reference probabilities with Monte-Carlo]: https://github.com/mbaudin47/otbenchmark/blob/master/examples/reliability_compute_reference_proba.ipynb

The simplest use cas of the library is in [Analysis of the R-S case], which shows how to use this problem with two variables to estimate its failure probability. In the [Benchmark the G-Sobol test function] problem, we show how to estimate sensitivity indices on the G-Sobol' test function. When using a reliability problem, it is convenient to create a given algorithm, e.g. Subset sampling, based on a given problem: the [Reliability factories] shows how to do this for Monte-Carlo, FORM, SORM, Subset and FORM-importance sampling.

The library currently has:
* 26 reliability problems,
* 11 sensitivity problems.

One of the most useful feature of the library is to perform a benchmark that is, loop over the problems. In [Benchmark on a given set of problems], we run several algorithms on all the problems. The associated statistics are gathered in table, presented in [Benchmark the reliability solvers on the problems]. In [Check reference probabilities with Monte-Carlo], we compare the exact (reference) probability with a Monte-Carlo estimate with a large sample.

[Draw events]: https://github.com/mbaudin47/otbenchmark/blob/master/examples/DrawEvent_demo.ipynb
[Draw cross cut of functions]: https://github.com/mbaudin47/otbenchmark/blob/master/examples/CrossCutFunction_Demo.ipynb
[Draw cross cuts of distributions]: https://github.com/mbaudin47/otbenchmark/blob/master/examples/CrossCutDistribution-3D_Demo.ipynb
[Draw conditional distributions]: https://github.com/mbaudin47/otbenchmark/blob/master/examples/ConditionalDistribution_Demo.ipynb

It is often useful to draw a sensitivity or reliability problem. Since many of these problems have dimensions larger than two, this raises a number of practical issues.
* Event: [Draw events] shows how to draw an multidimensional event,
* Function: [Draw cross cut of functions] shows how to draw cross cuts of functions,
* Distribution: [Draw cross cuts of distributions] shows how to draw cross cuts of distributions and [Draw conditional distributions] plots conditional distributions.

The "DrawEvent" class that the module provides typically plots the following figure for the RP57.

![limit_state_surface_RP57.png](figures/limit_state_surface_RP57.png)

The following figure plots cross-cuts of the limit state function for the RP8.

![cross_cut_function_RP8.png](figures/cross_cut_function_RP8.png)

[Examples]: https://github.com/mbaudin47/otbenchmark/tree/master/examples

[BBRC]: https://github.com/mbaudin47/otbenchmark/blob/master/examples-on-server/BBRC.ipynb

[Convergence of Monte-Carlo to estimate the probability in a reliability problem]: https://github.com/mbaudin47/otbenchmark/blob/master/examples/convergence-reliability-Monte-Carlo.ipynb

The [Convergence of Monte-Carlo to estimate the probability in a reliability problem] example might be interesting for those who want to plot convergence graphics.

![convergence_montecarlo.png](figures/convergence_montecarlo.png)

We provide in [BBRC] an example which shows how to use the "evaluate" function that the module provides to evaluate a function which is available in the remote BBRC server.
## Documentation

The [Examples] directory has many other examples: please read the notebooks and see if one of the examples fits your needs.
The documentation is available here: https://openturns.github.io/otbenchmark/master/

## TODO-List

Expand Down
File renamed without changes.
File renamed without changes.
6 changes: 0 additions & 6 deletions otbenchmark/_AxialStressedBeamReliability.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,6 @@ def __init__(self, threshold=0.0):
Create a axial stressed beam reliability problem.
The inputs are R, the Yield strength, and F, the traction load.
The event is {g(X) < threshold} where
.. math::
g(R, F) = R - F/(\pi * 100.0)
We have R ~ LogNormalMuSigma() and F ~ Normal().
Parameters
Expand Down
12 changes: 6 additions & 6 deletions otbenchmark/_DirichletSensitivity.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def __init__(self, alpha=ot.Point([1.0 / 2.0, 1.0 / 3.0, 1.0 / 4.0])):
Parameters
----------
alpha : ot.Point(p), optional
alpha : sequence of float, optional
The coefficients of the model.
Returns
Expand Down Expand Up @@ -100,7 +100,7 @@ def ComputeIndices(alpha):
return exact

def __init__(self, alpha=ot.Point([1.0 / 2.0, 1.0 / 3.0, 1.0 / 4.0])):
"""
r"""
Create a Dirichlet sensitivity problem.
The function is defined by the equation:
Expand All @@ -111,19 +111,19 @@ def __init__(self, alpha=ot.Point([1.0 / 2.0, 1.0 / 3.0, 1.0 / 4.0])):
where:
.. math::
g_i(x) = alpha_i * d_i(x)
g_i(x) = \alpha_i * d_i(x)
for any x in [0, 1], where d_i is the Dirichlet kernel:
.. math::
d_i(x) = (1 / sqrt(2i)) * (sin((2i + 1) pi x) / sin(pi x) - 1)
d_i(x) = \frac{1}{\sqrt(2i)} \frac{\sin((2i + 1) \pi x}{\sin(\pi x) - 1}
for i=1, 2, ..., p.
By continuity, we set:
.. math::
d_i(0) = 1 / sqrt(2i) for i=1, 2, ..., p.
d_i(0) = i\frac{1}{\sqrt(2i)} for i=1, 2, ..., p.
The Dirichlet kernel has the properties:
Expand All @@ -135,7 +135,7 @@ def __init__(self, alpha=ot.Point([1.0 / 2.0, 1.0 / 3.0, 1.0 / 4.0])):
Parameters
----------
alpha : ot.Point(p)
alpha : sequence of float
The vector of coefficients.
Examples
Expand Down
4 changes: 2 additions & 2 deletions otbenchmark/_OakleyOHaganSensitivity.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ class OakleyOHaganSensitivity(SensitivityBenchmarkProblem):
"""Class to define a Oakley-O'Hagan sensitivity benchmark problem."""

def __init__(self):
"""
r"""
Create a Oakley-O'Hagan sensitivity problem.
The function is defined by the equation:
.. math::
g(x) = x'Mx+a1'x + a2' sin(x) + a3'cos(x)
where x1, ..., x15 ~ N(0, 1).
where :math:`x_1, \hdots, x_{15} \tilde N(0, 1)`
The input random variables are independent.
Expand Down
11 changes: 6 additions & 5 deletions otbenchmark/_ReliabilityProblem33.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,16 @@ def __init__(
"""
Creates a reliability problem RP33.
The event is {g(X) < threshold} where
The limit-state g is defined by:
g(x1, x2, x3) = min(g1, g2) with
g(x1, x2, x3) = min(g1, g2) with
g1 = -x1 - x2 - x3 + 3 * sqrt(3)
g1 = -x1 - x2 - x3 + 3 * sqrt(3)
g2 = -x3 + 3
g2 = -x3 + 3
We have:
We have :
x1 ~ Normal(mu[0], sigma[0])
x2 ~ Normal(mu[1], sigma[1])
Expand Down

0 comments on commit 09c197b

Please sign in to comment.