Skip to content

Commit

Permalink
DeconditionedDistribution
Browse files Browse the repository at this point in the history
  • Loading branch information
jschueller committed Oct 11, 2024
1 parent 923a967 commit 4e105ff
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 10 deletions.
18 changes: 10 additions & 8 deletions lib/src/InverseFORM.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,18 @@
#include <openturns/StandardEvent.hxx>
#include <openturns/LinearFunction.hxx>
#include <openturns/ComposedDistribution.hxx>
#include <openturns/ConditionalDistribution.hxx>
#include <openturns/CompositeRandomVector.hxx>
#include <openturns/ThresholdEvent.hxx>
#include <openturns/ComposedFunction.hxx>
#include <openturns/SpecFunc.hxx>

#if OPENTURNS_VERSION >= 102400
#include <openturns/DeconditionedDistribution.hxx>
#else
#include <openturns/ConditionalDistribution.hxx>
#define DeconditionedDistribution ConditionalDistribution
#endif

using namespace OT;

namespace OTROBOPT {
Expand Down Expand Up @@ -228,17 +234,13 @@ Function InverseFORM::getG(const Scalar p)
newFunction.setParameter(params);
RandomVector antecedent(event_.getImplementation()->getAntecedent().getImplementation()->clone());
const Distribution distribution(antecedent.getDistribution());
#if OPENTURNS_VERSION >= 102300
const JointDistribution * p_joint = dynamic_cast<JointDistribution *>(distribution.getImplementation().get());
#else
const ComposedDistribution * p_joint = dynamic_cast<ComposedDistribution *>(distribution.getImplementation().get());
#endif
if (p_joint)
{
ComposedDistribution::DistributionCollection distributionCollection(p_joint->getDistributionCollection());
for (UnsignedInteger i = 0; i < distributionCollection.getSize(); ++ i)
{
if (distributionCollection[i].getImplementation()->getClassName() == "ConditionalDistribution")
if (distributionCollection[i].getImplementation()->getClassName() == "DeconditionedDistribution")
{
DistributionImplementation::PointWithDescriptionCollection parametersCollection(distributionCollection[i].getParametersCollection());
for (UnsignedInteger j = 0; j < parametersCollection.getSize(); ++ j)
Expand All @@ -253,12 +255,12 @@ Function InverseFORM::getG(const Scalar p)
}
}
}
const ConditionalDistribution * p_conditional = dynamic_cast<ConditionalDistribution *>(distributionCollection[i].getImplementation().get());
const DeconditionedDistribution * p_conditional = dynamic_cast<DeconditionedDistribution *>(distributionCollection[i].getImplementation().get());
if (p_conditional)
{
Distribution conditioning(p_conditional->getConditioningDistribution());
conditioning.setParametersCollection(parametersCollection);
ConditionalDistribution newConditional(p_conditional->getConditionedDistribution(), conditioning);
DeconditionedDistribution newConditional(p_conditional->getConditionedDistribution(), conditioning);
distributionCollection[i] = newConditional;
ComposedDistribution newDistribution(distributionCollection);
antecedent = RandomVector(newDistribution);
Expand Down
8 changes: 6 additions & 2 deletions lib/test/t_InverseFORM_sphere.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
#include "openturns/OTtestcode.hxx"
#include "otrobopt/OTRobOpt.hxx"

#if OPENTURNS_VERSION < 102400
#define DeconditionedDistribution ConditionalDistribution
#endif

using namespace OT;
using namespace OT::Test;
using namespace OTROBOPT;
Expand Down Expand Up @@ -29,7 +33,7 @@ int main()

ComposedDistribution::DistributionCollection coll;
coll.add(Beta(0.117284, 0.117284, 2.9, 3.1));//R
ConditionalDistribution eDist(LogNormal(L0, 0.1, 0.), eParams);
DeconditionedDistribution eDist(LogNormal(L0, 0.1, 0.), eParams);

coll.add(eDist);//e
coll.add(WeibullMin(3.16471, 9.21097, 0.0));//p
Expand Down Expand Up @@ -62,7 +66,7 @@ int main()
// FORM must yield the same probability on the limit state with parameter set to the optimum
eColl[0] = Dirac(result.getParameter()[0]);
eParams = ComposedDistribution(eColl);
eDist = ConditionalDistribution(LogNormal(result.getParameter()[0], 0.1, 0.0), eParams);
eDist = DeconditionedDistribution(LogNormal(result.getParameter()[0], 0.1, 0.0), eParams);
coll[1] = eDist;
myDistribution = ComposedDistribution(coll);
vect = RandomVector(myDistribution);
Expand Down

0 comments on commit 4e105ff

Please sign in to comment.