Skip to content

Commit

Permalink
DOE: Improve doc
Browse files Browse the repository at this point in the history
  • Loading branch information
mbaudin47 authored Apr 23, 2024
1 parent 978263f commit 049a028
Show file tree
Hide file tree
Showing 9 changed files with 39 additions and 35 deletions.
10 changes: 7 additions & 3 deletions lib/src/Base/Func/SymbolicParserExprTk.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -229,12 +229,14 @@ SymbolicParserExprTk::ExpressionCollection SymbolicParserExprTk::allocateExpress
for (UnsignedInteger inputIndex = 0; inputIndex < inputDimension; ++ inputIndex)
{
if (!symbol_table.add_variable(inputVariablesNames_[inputIndex], stack[inputIndex]))
throw InvalidArgumentException(HERE) << "Invalid input variable: " << inputVariablesNames_[inputIndex];
throw InvalidArgumentException(HERE) << "Invalid input variable: '"
<< inputVariablesNames_[inputIndex] << "' at index: " << inputIndex;
}
for (UnsignedInteger outputIndex = 0; outputIndex < outputDimension; ++ outputIndex)
{
if (!symbol_table.add_variable(outputVariablesNames_[outputIndex], stack[inputDimension + outputIndex]))
throw InvalidArgumentException(HERE) << "Invalid output variable: " << outputVariablesNames_[outputIndex];
throw InvalidArgumentException(HERE) << "Invalid output variable: '"
<< outputVariablesNames_[outputIndex] << "' at index: " << outputIndex;
}
exprtk::parser<Scalar> parser;
parser.settings().set_max_stack_depth(ResourceMap::GetAsUnsignedInteger("SymbolicParserExprTk-MaxStackDepth"));
Expand All @@ -246,7 +248,9 @@ SymbolicParserExprTk::ExpressionCollection SymbolicParserExprTk::allocateExpress
expression.register_symbol_table(symbol_table);
if (!parser.compile(formulas_[outputIndex], expression))
{
throw InvalidArgumentException(HERE) << "Errors found when parsing expression '" << formulas_[outputIndex] << "': " << parser.error();
throw InvalidArgumentException(HERE) << "Errors found when parsing expression '"
<< formulas_[outputIndex] << "' at index: "
<< outputIndex << ": " << parser.error();
}
expressions[outputIndex] = new exprtk::expression<Scalar>(expression);
}
Expand Down
4 changes: 2 additions & 2 deletions lib/src/Base/Func/SymbolicParserImplementation.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,10 @@ void SymbolicParserImplementation::setVariables(const Description & inputVariabl
{
const String varName(inputVariablesNames[i]);
if (!std::regex_match(inputVariablesNames[i], std::regex("[a-zA-Z][0-9a-zA-Z_]*")))
throw InvalidArgumentException(HERE) << "Invalid input variable: " << varName;
throw InvalidArgumentException(HERE) << "Invalid input variable: '" << varName << "' at index:" << i;
++ varMap[varName];
if (varMap[varName] > 1)
throw InvalidArgumentException(HERE) << "Duplicate input variable: " << varName;
throw InvalidArgumentException(HERE) << "Duplicate input variable: '" << varName << "' at index:" << i;
}
inputVariablesNames_ = inputVariablesNames;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// -*- C++ -*-
/**
* @brief Abstract top-level view of an weightedExperiment plane
* @brief Abstract top-level view of a WeightedExperiment
*
* Copyright 2005-2024 Airbus-EDF-IMACS-ONERA-Phimeca
*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// -*- C++ -*-
/**
* @brief Abstract top-level view of an weightedExperiment plane
* @brief Abstract top-level view of a WeightedExperiment
*
* Copyright 2005-2024 Airbus-EDF-IMACS-ONERA-Phimeca
*
Expand Down
2 changes: 1 addition & 1 deletion lib/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -586,7 +586,7 @@ ot_check_test (GaussProductExperiment_std IGNOREOUT)
ot_check_test (ImportanceSamplingExperiment_std)
ot_check_test (LHSExperiment_std)
ot_check_test (LowDiscrepancyExperiment_std)
ot_check_test (MonteCarloExperiment_std)
ot_check_test (MonteCarloExperiment_std IGNOREOUT)
ot_check_test (TensorProductExperiment_std IGNOREOUT)
ot_check_test (SmolyakExperiment_std IGNOREOUT)

Expand Down
35 changes: 19 additions & 16 deletions lib/test/t_MonteCarloExperiment_std.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -30,22 +30,25 @@ int main(int, char *[])
OStream fullprint(std::cout);
setRandomGenerator();

try
{
Normal distribution(4);
UnsignedInteger size = 10;
MonteCarloExperiment experiment(distribution, size);
fullprint << "experiment = " << experiment << std::endl;
Point weights(0);
Sample sample(experiment.generateWithWeights(weights));
fullprint << "sample = " << sample << std::endl;
fullprint << "weights = " << weights << std::endl;
}
catch (TestFailed & ex)
{
std::cerr << ex << std::endl;
return ExitCode::Error;
}
fullprint << "Test generateWithWeights()" << std::endl;
const Normal distribution(4);
const UnsignedInteger size = 100000;
const MonteCarloExperiment experiment(distribution, size);
fullprint << "experiment = " << experiment << std::endl;
Point weights(0);
const Sample sample(experiment.generateWithWeights(weights));
assert(sample.getSize() == size);
assert(sample.getDimension() == 4);
assert(weights.getDimension() == size);
const Scalar atol = 10.0 / std::sqrt(size);
const Scalar rtol = 0.0;
const Point meanExact(distribution.getMean());
assert_almost_equal(sample.computeMean(), meanExact, rtol, atol);
const CovarianceMatrix covarianceExact(distribution.getCovariance());
assert_almost_equal(sample.computeCovariance(), covarianceExact, rtol, atol);
const Point weightsExact(size, 1.0 / size);
assert_almost_equal(weights, weightsExact, 1.e-15);


return ExitCode::Success;
}
3 changes: 0 additions & 3 deletions lib/test/t_MonteCarloExperiment_std.expout

This file was deleted.

12 changes: 6 additions & 6 deletions python/src/FunctionalChaosAlgorithm_doc.i.in
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ Available constructors:
Parameters
----------
inputSample: 2-d sequence of float
Sample of the input random vectors with size :math:`n` and dimension :math:`n_X`.
Sample of the input random vectors with size :math:`\sampleSize` and dimension :math:`\inputDim`.
outputSample: 2-d sequence of float
Sample of the output random vectors with size :math:`n` and dimension :math:`n_Y`.
Sample of the output random vectors with size :math:`\sampleSize` and dimension :math:`\outputDim`.
distribution : :class:`~openturns.Distribution`
Distribution of the random vector :math:`\vect{X}` of dimension :math:`n_X`.
Distribution of the random vector :math:`\inputRV` of dimension :math:`\inputDim`.
When the *distribution* is unspecified, the
:meth:`~openturns.MetaModelAlgorithm.BuildDistribution` static
method is evaluated on the *inputSample*.
Expand All @@ -32,9 +32,9 @@ adaptiveStrategy : :class:`~openturns.AdaptiveStrategy`
projectionStrategy : :class:`~openturns.ProjectionStrategy`
Strategy of evaluation of the coefficients :math:`a_k`
weights : sequence of float
Weights :math:`(w_i)_{i = 1, ..., n}` associated to the output
sample, where :math:`n` is the sample size.
Default values are :math:`w_i = \frac{1}{n}` for :math:`i = 1, ..., n`.
Weights :math:`(w_i)_{i = 1, ..., \sampleSize}` associated to the output
sample, where :math:`\sampleSize` is the sample size.
Default values are :math:`w_i = \frac{1}{\sampleSize}` for :math:`i = 1, ..., \sampleSize`.

See also
--------
Expand Down
4 changes: 2 additions & 2 deletions python/src/MonteCarloExperiment_doc.i.in
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ distribution : :class:`~openturns.Distribution`
Distribution :math:`\mu` with an independent copula used to generate the
set of input data.
size : positive int
Number :math:`cardI` of points that will be generated in the experiment.
Number :math:`\sampleSize` of points that will be generated in the experiment.

Notes
-----
MonteCarloExperiment is a random weighted design of experiments ([hammersley1961]_ page 51, [lemieux2009]_ page 3).
MonteCarloExperiment is a random weighted design of experiments (see [hammersley1961]_ page 51, [lemieux2009]_ page 3).
The :meth:`generate` method computes the nodes :math:`(\inputReal_i)_{i = 1, ..., \sampleSize}`
by generating independent observations from the distribution :math:`\mu`. The weights associated to the
points are all equal to :math:`w_i = \frac{1}{\sampleSize}` where :math:`\sampleSize` is the sample size.
Expand Down

0 comments on commit 049a028

Please sign in to comment.