Skip to content

Commit

Permalink
Make bounds argument last
Browse files Browse the repository at this point in the history
  • Loading branch information
jschueller committed Oct 11, 2024
1 parent 4788cc8 commit d2933d4
Show file tree
Hide file tree
Showing 9 changed files with 21 additions and 47 deletions.
10 changes: 5 additions & 5 deletions lib/src/MorrisExperiment.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down
9 changes: 3 additions & 6 deletions lib/src/MorrisExperimentGrid.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ static const Factory<MorrisExperimentGrid> 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
Expand All @@ -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)
{
Expand Down
10 changes: 3 additions & 7 deletions lib/src/MorrisExperimentLHS.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -38,22 +38,18 @@ static const Factory<MorrisExperimentLHS> 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 */
Expand Down
2 changes: 1 addition & 1 deletion lib/src/otmorris/MorrisExperiment.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
2 changes: 1 addition & 1 deletion lib/src/otmorris/MorrisExperimentGrid.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion lib/src/otmorris/MorrisExperimentLHS.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
15 changes: 2 additions & 13 deletions python/src/MorrisExperimentGrid_doc.i.in
Original file line number Diff line number Diff line change
@@ -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
--------
Expand Down
12 changes: 2 additions & 10 deletions python/src/MorrisExperimentLHS_doc.i.in
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
6 changes: 3 additions & 3 deletions python/test/t_Morris_bound.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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())

0 comments on commit d2933d4

Please sign in to comment.