Skip to content

Commit

Permalink
InverseFORM: Add test
Browse files Browse the repository at this point in the history
  • Loading branch information
jschueller committed Oct 16, 2024
1 parent d1a3b4e commit 7e722c4
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 5 deletions.
10 changes: 5 additions & 5 deletions lib/test/t_InverseFORM_sphere.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,20 @@ int main()
const UnsignedInteger dim = 3;
const SymbolicFunction function(Description({"R", "e", "mulog_e", "p"}), Description({"700.0-p*R/(2.*e)"}));

const Scalar L0 = -4.715;
ParametricFunction parametric(function, Indices({2}), Point({L0}));
const Scalar mulog_e_0 = -4.715;
ParametricFunction parametric(function, Indices({2}), Point({mulog_e_0}));

Dirac mulog_eDist(L0);
Dirac mulog_eDist(mulog_e_0);
mulog_eDist.setDescription(Description(1, "mulog_e"));
JointDistribution::DistributionCollection eColl; eColl.add(mulog_eDist); eColl.add(Dirac(0.1)); eColl.add(Dirac(0.));
JointDistribution eParams(eColl);

JointDistribution::DistributionCollection coll;
coll.add(Beta(0.117284, 0.117284, 2.9, 3.1));//R
#if OPENTURNS_VERSION >= 102400
DeconditionedDistribution eDist(LogNormal(L0, 0.1, 0.), eParams);
DeconditionedDistribution eDist(LogNormal(mulog_e_0, 0.1, 0.), eParams);
#else
ConditionalDistribution eDist(LogNormal(L0, 0.1, 0.), eParams);
ConditionalDistribution eDist(LogNormal(mulog_e_0, 0.1, 0.), eParams);
#endif
coll.add(eDist);//e
coll.add(WeibullMin(3.16471, 9.21097, 0.0));//p
Expand Down
2 changes: 2 additions & 0 deletions python/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,10 @@ endif ()
ot_pyinstallcheck_test (SubsetInverseSampling_R-S)
ot_pyinstallcheck_test (SubsetInverseSampling_Waarts_system_series)
ot_pyinstallcheck_test (InverseFORM_std IGNOREOUT)
ot_pyinstallcheck_test (InverseFORM_sphere IGNOREOUT)
ot_pyinstallcheck_test (docstring)


if (MATPLOTLIB_FOUND)
file (GLOB_RECURSE PYFILES "${PROJECT_SOURCE_DIR}/python/doc/examples/*.py")
foreach (PYF ${PYFILES})
Expand Down
40 changes: 40 additions & 0 deletions python/test/t_InverseFORM_sphere.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#! /usr/bin/env python

import openturns as ot
import openturns.testing as ott
import otrobopt

ot.Log.Show(ot.Log.INFO)

# sphere under pressure
full = ot.SymbolicFunction(["R", "e", "mulog_e", "p"], ["700.0-p*R/(2.*e)"])
mulog_e_0 = -4.715
g = ot.ParametricFunction(full, [2], [mulog_e_0])

mulog_eDist = ot.Dirac(mulog_e_0)
mulog_eDist.setDescription(["mulog_e"])
eColl = [mulog_eDist, ot.Dirac(0.1), ot.Dirac(0.0)]
eParams = ot.JointDistribution(eColl)
try:
eDist = ot.DeconditionedDistribution(ot.LogNormal(mulog_e_0, 0.1, 0.), eParams)
except AttributeError:
eDist = ot.ConditionalDistribution(ot.LogNormal(mulog_e_0, 0.1, 0.), eParams)

coll = [ot.Beta(0.117284, 0.117284, 2.9, 3.1),
eDist,
ot.WeibullMin(3.16471, 9.21097, 0.0)]

distribution = ot.JointDistribution(coll)
median = [distribution.getMarginal(i).computeQuantile(0.5)[0] for i in range(3)]

vect = ot.RandomVector(distribution)

output = ot.CompositeRandomVector(g, vect)

event = ot.ThresholdEvent(output, ot.Less(), 0.0)

algo = otrobopt.InverseFORM(event, 'mulog_e', median)
algo.run()
result = algo.getResult()
print(result)
ott.assert_almost_equal(result.getParameter(), [-4.69056])

0 comments on commit 7e722c4

Please sign in to comment.