From d2933d4f3d6abdddeb6d14dc71167d317b0a7f1c Mon Sep 17 00:00:00 2001 From: Julien Schueller Date: Fri, 11 Oct 2024 17:19:19 +0200 Subject: [PATCH] Make bounds argument last --- lib/src/MorrisExperiment.cxx | 10 +++++----- lib/src/MorrisExperimentGrid.cxx | 9 +++------ lib/src/MorrisExperimentLHS.cxx | 10 +++------- lib/src/otmorris/MorrisExperiment.hxx | 2 +- lib/src/otmorris/MorrisExperimentGrid.hxx | 2 +- lib/src/otmorris/MorrisExperimentLHS.hxx | 2 +- python/src/MorrisExperimentGrid_doc.i.in | 15 ++------------- python/src/MorrisExperimentLHS_doc.i.in | 12 ++---------- python/test/t_Morris_bound.py | 6 +++--- 9 files changed, 21 insertions(+), 47 deletions(-) diff --git a/lib/src/MorrisExperiment.cxx b/lib/src/MorrisExperiment.cxx index ab72b0b..c3aec55 100644 --- a/lib/src/MorrisExperiment.cxx +++ b/lib/src/MorrisExperiment.cxx @@ -55,15 +55,15 @@ MorrisExperiment::MorrisExperiment(const Point & delta, const UnsignedInteger N) } /** Constructor using a p-level grid and intervals*/ -MorrisExperiment::MorrisExperiment(const Point & delta, const Interval & interval, const UnsignedInteger N) +MorrisExperiment::MorrisExperiment(const Point & delta, const UnsignedInteger N, const Interval & bounds) : WeightedExperimentImplementation(N * (delta.getSize() + 1)) - , interval_(interval) + , interval_(bounds) , delta_ (delta) , N_(N) { - if (delta.getSize() != interval.getDimension()) - throw InvalidArgumentException(HERE) << "Levels and interval should be of same size. Here, level's size=" << delta.getSize() - << ", interval's size=" << interval.getDimension(); + if (delta.getSize() != bounds.getDimension()) + throw InvalidArgumentException(HERE) << "Levels and bounds should be of same size. Here, level's size=" << delta.getSize() + << ", bounds's size=" << bounds.getDimension(); } /* Virtual constructor method */ diff --git a/lib/src/MorrisExperimentGrid.cxx b/lib/src/MorrisExperimentGrid.cxx index 0f31a85..9ff384c 100644 --- a/lib/src/MorrisExperimentGrid.cxx +++ b/lib/src/MorrisExperimentGrid.cxx @@ -39,7 +39,7 @@ static const Factory Factory_MorrisExperimentGrid; /** Constructor using a p-level grid - Uniform(0,1)^d */ MorrisExperimentGrid::MorrisExperimentGrid(const Indices & levels, const UnsignedInteger N) - : MorrisExperiment(Point(levels.getSize()), Interval(levels.getSize()), N) + : MorrisExperiment(Point(levels.getSize()), N, Interval(levels.getSize())) , jumpStep_(levels.getSize(), 0) { // Compute step @@ -54,13 +54,10 @@ MorrisExperimentGrid::MorrisExperimentGrid(const Indices & levels, const Unsigne } /** Constructor using a p-level grid and intervals*/ -MorrisExperimentGrid::MorrisExperimentGrid(const Indices & levels, const Interval & interval, const UnsignedInteger N) - : MorrisExperiment(Point(levels.getSize()), interval, N) +MorrisExperimentGrid::MorrisExperimentGrid(const Indices & levels, const UnsignedInteger N, const Interval & bounds) + : MorrisExperiment(Point(levels.getSize()), N, bounds) , jumpStep_(levels.getSize(), 0) { - if (levels.getSize() != interval.getDimension()) - throw InvalidArgumentException(HERE) << "Levels and interval should be of same size. Here, level's size=" << levels.getSize() - << ", interval's size=" << interval.getDimension(); // Set levels/delta for (UnsignedInteger k = 0; k < levels.getSize(); ++k) { diff --git a/lib/src/MorrisExperimentLHS.cxx b/lib/src/MorrisExperimentLHS.cxx index 77aaaea..b3236b4 100644 --- a/lib/src/MorrisExperimentLHS.cxx +++ b/lib/src/MorrisExperimentLHS.cxx @@ -38,22 +38,18 @@ static const Factory Factory_MorrisExperimentLHS; /** Constructor using Sample, which is supposed to be an LHS design - Uniform(0,1)^d*/ MorrisExperimentLHS::MorrisExperimentLHS(const Sample & lhsDesign, const UnsignedInteger N) - : MorrisExperiment(Point(lhsDesign.getDimension(), 1.0 / lhsDesign.getSize()), Interval(lhsDesign.getDimension()), N) + : MorrisExperiment(Point(lhsDesign.getDimension(), 1.0 / lhsDesign.getSize()), N, Interval(lhsDesign.getDimension())) , experiment_(lhsDesign) { // Nothing to do } /** Constructor using Sample, which is supposed to be an LHS design */ -MorrisExperimentLHS::MorrisExperimentLHS(const Sample & lhsDesign, const Interval & interval, const UnsignedInteger N) - : MorrisExperiment((interval.getUpperBound() - interval.getLowerBound()) / lhsDesign.getSize(), interval, N) +MorrisExperimentLHS::MorrisExperimentLHS(const Sample & lhsDesign, const UnsignedInteger N, const Interval & bounds) + : MorrisExperiment((bounds.getUpperBound() - bounds.getLowerBound()) / lhsDesign.getSize(), N, bounds) , experiment_(lhsDesign) { - ; - if (experiment_.getDimension() != interval_.getDimension()) - throw InvalidArgumentException(HERE) << "Levels and design should have same dimension. Here, design's dimension=" << lhsDesign.getDimension() - << ", interval's size=" << interval_.getDimension(); } /* Virtual constructor method */ diff --git a/lib/src/otmorris/MorrisExperiment.hxx b/lib/src/otmorris/MorrisExperiment.hxx index dc151c1..33e58e6 100644 --- a/lib/src/otmorris/MorrisExperiment.hxx +++ b/lib/src/otmorris/MorrisExperiment.hxx @@ -49,7 +49,7 @@ public: MorrisExperiment(); /** Standard constructors */ - MorrisExperiment(const OT::Point & delta, const OT::Interval & interval, const OT::UnsignedInteger N); + MorrisExperiment(const OT::Point & delta, const OT::UnsignedInteger N, const OT::Interval & bounds); MorrisExperiment(const OT::Point & delta, const OT::UnsignedInteger N); diff --git a/lib/src/otmorris/MorrisExperimentGrid.hxx b/lib/src/otmorris/MorrisExperimentGrid.hxx index 4814148..9dc4deb 100644 --- a/lib/src/otmorris/MorrisExperimentGrid.hxx +++ b/lib/src/otmorris/MorrisExperimentGrid.hxx @@ -44,7 +44,7 @@ public: MorrisExperimentGrid(const OT::Indices & levels, const OT::UnsignedInteger N); /** Constructor using a p-level grid and intervals*/ - MorrisExperimentGrid(const OT::Indices & levels, const OT::Interval & interval, const OT::UnsignedInteger N); + MorrisExperimentGrid(const OT::Indices & levels, const OT::UnsignedInteger N, const OT::Interval & bounds); /** Virtual constructor method */ MorrisExperimentGrid * clone() const override; diff --git a/lib/src/otmorris/MorrisExperimentLHS.hxx b/lib/src/otmorris/MorrisExperimentLHS.hxx index 08439ff..40b3f41 100644 --- a/lib/src/otmorris/MorrisExperimentLHS.hxx +++ b/lib/src/otmorris/MorrisExperimentLHS.hxx @@ -44,7 +44,7 @@ public: MorrisExperimentLHS(const OT::Sample & lhsDesign, const OT::UnsignedInteger N); /** Constructor using Sample, which is supposed to be an LHS design */ - MorrisExperimentLHS(const OT::Sample & lhsDesign, const OT::Interval & interval, const OT::UnsignedInteger N); + MorrisExperimentLHS(const OT::Sample & lhsDesign, const OT::UnsignedInteger N, const OT::Interval & bounds); /** Virtual constructor method */ MorrisExperimentLHS * clone() const override; diff --git a/python/src/MorrisExperimentGrid_doc.i.in b/python/src/MorrisExperimentGrid_doc.i.in index 6ca701d..68cbc83 100644 --- a/python/src/MorrisExperimentGrid_doc.i.in +++ b/python/src/MorrisExperimentGrid_doc.i.in @@ -1,25 +1,14 @@ %feature("docstring") OTMORRIS::MorrisExperimentGrid "MorrisExperimentGrid builds experiments for the Morris method starting from full p-levels grid experiments. -Available constructors: - - MorrisExperimentGrid(levels, N) - - MorrisExperimentGrid(levels, interval, N) - Parameters ---------- levels : :py:class:`openturns.Indices` Number of levels for a regular grid N : int Number of trajectories -interval : :py:class:`openturns.Interval` - Bounds of the domain - -Notes ------ -With first constructor, we consider that initial experiment is a regular grid defined in :math:`[0,1]^d`. -With second constructor, we consider that initial distribution model is uniform with bounds given by the interval argument. Also, the initial experiment is of type regular. +bounds : :py:class:`openturns.Interval`, optional + Bounds of the domain, by default it is defined on :math:`[0,1]^d`. Examples -------- diff --git a/python/src/MorrisExperimentLHS_doc.i.in b/python/src/MorrisExperimentLHS_doc.i.in index d1456b1..2cb52e4 100644 --- a/python/src/MorrisExperimentLHS_doc.i.in +++ b/python/src/MorrisExperimentLHS_doc.i.in @@ -1,25 +1,17 @@ %feature("docstring") OTMORRIS::MorrisExperimentLHS "MorrisExperimentLHS builds experiments for the Morris method using a centered LHS design as input starting. -Available constructors: - - MorrisExperimentLHS(lhsDesign, N) - - MorrisExperimentLHS(lhsDesign, interval, N) - Parameters ---------- lhsDesign : :py:class:`openturns.Sample` Initial design -interval : :py:class:`openturns.Interval` - Bounds of the domain N : int Number of trajectories +bounds : :py:class:`openturns.Interval`, optional + Bounds of the domain, by default it is defined on :math:`[0,1]^d`. Notes ----- -With the first constructor, we fix the initial design which could be an LHS, an optimal LHS defined using uniform marginals. -With the second constructor LHS design and bounds are required. The lhs sample must be centered, ie from :py:class:`openturns.LHSExperiment` with randomShift=False. The method consists in generating trajectories (paths) by randomly selecting their initial points from the lhs design. diff --git a/python/test/t_Morris_bound.py b/python/test/t_Morris_bound.py index c89efe6..0864c38 100644 --- a/python/test/t_Morris_bound.py +++ b/python/test/t_Morris_bound.py @@ -24,11 +24,11 @@ levels = [level_number] * dim # set the bounds of the grid experiment -bound = ot.Interval( +bounds = ot.Interval( [marginal.computeQuantile(0.01)[0] for marginal in list_marginals], [marginal.computeQuantile(0.99)[0] for marginal in list_marginals], ) -experiment = otmorris.MorrisExperimentGrid(levels, bound, trajectories) +experiment = otmorris.MorrisExperimentGrid(levels, trajectories, bounds) experiment.setJumpStep(ot.Indices([jump_step] * dim)) # create and compute the design of experiments @@ -38,7 +38,7 @@ output_sample = poutre(input_sample) # run the Morris analysis -morris = otmorris.Morris(input_sample, output_sample, bound) +morris = otmorris.Morris(input_sample, output_sample, bounds) print("E(|EE|) = ", morris.getMeanAbsoluteElementaryEffects()) print("E(EE) = ", morris.getMeanElementaryEffects()) print("V(|EE|)^{1/2} = ", morris.getStandardDeviationElementaryEffects())