From d148b94064e041c129f5832c316cd3f8c722f755 Mon Sep 17 00:00:00 2001 From: Michael BAUDIN Date: Sun, 30 Jun 2024 22:27:52 +0200 Subject: [PATCH] New OrthogonalProduct*Factory.getMarginal() --- .../OrthogonalFunctionFactory.cxx | 7 +- .../OrthogonalProductFunctionFactory.cxx | 32 ++- .../OrthogonalProductPolynomialFactory.cxx | 17 ++ .../openturns/OrthogonalFunctionFactory.hxx | 8 +- .../OrthogonalProductFunctionFactory.hxx | 8 + .../OrthogonalProductPolynomialFactory.hxx | 5 + lib/test/CMakeLists.txt | 1 + ...t_OrthogonalProductFunctionFactory_std.cxx | 162 ++++++++++++++ ...rthogonalProductFunctionFactory_std.expout | 9 + ...OrthogonalProductPolynomialFactory_std.cxx | 64 +++++- ...hogonalProductPolynomialFactory_std.expout | 12 ++ python/src/OrthogonalFunctionFactory_doc.i.in | 15 ++ .../OrthogonalProductFunctionFactory_doc.i.in | 34 ++- ...rthogonalProductPolynomialFactory_doc.i.in | 46 +++- python/src/orthogonalbasis_module.i | 5 +- python/test/CMakeLists.txt | 1 + ...rthogonalProductFunctionFactory_std.expout | 202 ++++++++++++++++++ .../t_OrthogonalProductFunctionFactory_std.py | 41 ++++ ..._OrthogonalProductPolynomialFactory_std.py | 21 ++ 19 files changed, 662 insertions(+), 28 deletions(-) create mode 100644 lib/test/t_OrthogonalProductFunctionFactory_std.cxx create mode 100644 lib/test/t_OrthogonalProductFunctionFactory_std.expout create mode 100644 python/test/t_OrthogonalProductFunctionFactory_std.expout create mode 100644 python/test/t_OrthogonalProductFunctionFactory_std.py diff --git a/lib/src/Uncertainty/Algorithm/OrthogonalBasis/OrthogonalFunctionFactory.cxx b/lib/src/Uncertainty/Algorithm/OrthogonalBasis/OrthogonalFunctionFactory.cxx index 41c746f2f6..889cf9dbc7 100644 --- a/lib/src/Uncertainty/Algorithm/OrthogonalBasis/OrthogonalFunctionFactory.cxx +++ b/lib/src/Uncertainty/Algorithm/OrthogonalBasis/OrthogonalFunctionFactory.cxx @@ -22,6 +22,7 @@ #include "openturns/OSS.hxx" #include "openturns/PersistentObjectFactory.hxx" #include "openturns/Exception.hxx" +#include "openturns/OrthogonalBasis.hxx" BEGIN_NAMESPACE_OPENTURNS @@ -88,13 +89,17 @@ EnumerateFunction OrthogonalFunctionFactory::getEnumerateFunction() const throw NotYetImplementedException(HERE) << "In OrthogonalFunctionFactory::getEnumerateFunction() const"; } +/* Get the function factory corresponding to marginal input indices */ +OrthogonalBasis OrthogonalFunctionFactory::getMarginal(const Indices & ) const +{ + throw NotYetImplementedException(HERE) << "In OrthogonalBasis::getMarginal() const"; +} Bool OrthogonalFunctionFactory::isOrthogonal() const { return true; } - /* String converter */ String OrthogonalFunctionFactory::__repr__() const { diff --git a/lib/src/Uncertainty/Algorithm/OrthogonalBasis/OrthogonalProductFunctionFactory.cxx b/lib/src/Uncertainty/Algorithm/OrthogonalBasis/OrthogonalProductFunctionFactory.cxx index 96ec87f142..21ce04fca4 100644 --- a/lib/src/Uncertainty/Algorithm/OrthogonalBasis/OrthogonalProductFunctionFactory.cxx +++ b/lib/src/Uncertainty/Algorithm/OrthogonalBasis/OrthogonalProductFunctionFactory.cxx @@ -32,8 +32,6 @@ BEGIN_NAMESPACE_OPENTURNS - - TEMPLATE_CLASSNAMEINIT(PersistentCollection) static const Factory > Factory_PersistentCollection_OrthogonalUniVariateFunctionFamily; @@ -53,7 +51,6 @@ OrthogonalProductFunctionFactory::OrthogonalProductFunctionFactory() // Nothing to do } - /* Constructor */ OrthogonalProductFunctionFactory::OrthogonalProductFunctionFactory(const FunctionFamilyCollection & coll) : OrthogonalFunctionFactory() @@ -62,7 +59,6 @@ OrthogonalProductFunctionFactory::OrthogonalProductFunctionFactory(const Functio buildMeasure(coll); } - /* Constructor */ OrthogonalProductFunctionFactory::OrthogonalProductFunctionFactory(const FunctionFamilyCollection & coll, const EnumerateFunction & phi) @@ -73,14 +69,12 @@ OrthogonalProductFunctionFactory::OrthogonalProductFunctionFactory(const Functio buildMeasure(coll); } - /* Virtual constructor */ OrthogonalProductFunctionFactory * OrthogonalProductFunctionFactory::clone() const { return new OrthogonalProductFunctionFactory(*this); } - /* Return the enumerate function that translate unidimensional indices into multidimensional indices */ EnumerateFunction OrthogonalProductFunctionFactory::getEnumerateFunction() const { @@ -99,13 +93,17 @@ OrthogonalProductFunctionFactory::FunctionFamilyCollection OrthogonalProductFunc return coll; } - /* Build the Function of the given index */ Function OrthogonalProductFunctionFactory::build(const UnsignedInteger index) const { return tensorizedFunctionFactory_.build(index); } +/* Build the Function of the given index */ +Function OrthogonalProductFunctionFactory::build(const Indices & indices) const +{ + return tensorizedFunctionFactory_.build(getEnumerateFunction().inverse(indices)); +} /* String converter */ String OrthogonalProductFunctionFactory::__repr__() const @@ -115,7 +113,6 @@ String OrthogonalProductFunctionFactory::__repr__() const << " measure=" << measure_; } - /* Method save() stores the object through the StorageManager */ void OrthogonalProductFunctionFactory::save(Advocate & adv) const { @@ -123,7 +120,6 @@ void OrthogonalProductFunctionFactory::save(Advocate & adv) const adv.saveAttribute("tensorizedFunctionFactory_", tensorizedFunctionFactory_); } - /* Method load() reloads the object from the StorageManager */ void OrthogonalProductFunctionFactory::load(Advocate & adv) { @@ -157,5 +153,23 @@ void OrthogonalProductFunctionFactory::buildMeasure(const FunctionFamilyCollecti measure_ = JointDistribution(distributions); } +/* Get the function factory corresponding to marginal input indices */ +OrthogonalBasis OrthogonalProductFunctionFactory::getMarginal(const Indices & indices) const +{ + OrthogonalProductFunctionFactory::FunctionFamilyCollection functionColl(getFunctionFamilyCollection()); + const UnsignedInteger size = functionColl.getSize(); + if (!indices.check(size)) + throw InvalidArgumentException(HERE) << "The indices of a marginal sample must be in the range [0, size-1] and must be different"; + // Create list of factories corresponding to input marginal indices + OrthogonalProductFunctionFactory::FunctionFamilyCollection functionMarginalCollection; + for (UnsignedInteger index = 0; index < size; ++ index) + if (indices.contains(index)) + functionMarginalCollection.add(functionColl[index]); + // Create function + const EnumerateFunction enumerateFunction(tensorizedFunctionFactory_.getEnumerateFunction()); + const EnumerateFunction marginalEnumerateFunction(enumerateFunction.getMarginal(indices)); + const OrthogonalProductFunctionFactory marginalFactory(functionMarginalCollection, marginalEnumerateFunction); + return marginalFactory; +} END_NAMESPACE_OPENTURNS diff --git a/lib/src/Uncertainty/Algorithm/OrthogonalBasis/OrthogonalProductPolynomialFactory.cxx b/lib/src/Uncertainty/Algorithm/OrthogonalBasis/OrthogonalProductPolynomialFactory.cxx index ad3560d347..43a1ad1231 100644 --- a/lib/src/Uncertainty/Algorithm/OrthogonalBasis/OrthogonalProductPolynomialFactory.cxx +++ b/lib/src/Uncertainty/Algorithm/OrthogonalBasis/OrthogonalProductPolynomialFactory.cxx @@ -304,4 +304,21 @@ Sample OrthogonalProductPolynomialFactory::getNodesAndWeights(const Indices & de return nodes; } +/* Get the function factory corresponding to the input marginal indices */ +OrthogonalBasis OrthogonalProductPolynomialFactory::getMarginal(const Indices & indices) const +{ + const UnsignedInteger size = coll_.getSize(); + if (!indices.check(size)) + throw InvalidArgumentException(HERE) << "The indices of a marginal sample must be in the range [0, size-1] and must be different"; + // Create list of factories corresponding to input marginal indices + OrthogonalProductPolynomialFactory::PolynomialFamilyCollection polynomialMarginalCollection; + for (UnsignedInteger index = 0; index < size; ++ index) + if (indices.contains(index)) + polynomialMarginalCollection.add(coll_[index]); + // Create function + const EnumerateFunction marginalEnumerateFunction(phi_.getMarginal(indices)); + const OrthogonalProductPolynomialFactory marginalFactory(polynomialMarginalCollection, marginalEnumerateFunction); + return marginalFactory; +} + END_NAMESPACE_OPENTURNS diff --git a/lib/src/Uncertainty/Algorithm/OrthogonalBasis/openturns/OrthogonalFunctionFactory.hxx b/lib/src/Uncertainty/Algorithm/OrthogonalBasis/openturns/OrthogonalFunctionFactory.hxx index 1a2145714c..1e41b09e31 100644 --- a/lib/src/Uncertainty/Algorithm/OrthogonalBasis/openturns/OrthogonalFunctionFactory.hxx +++ b/lib/src/Uncertainty/Algorithm/OrthogonalBasis/openturns/OrthogonalFunctionFactory.hxx @@ -28,6 +28,8 @@ BEGIN_NAMESPACE_OPENTURNS +class OrthogonalBasis; + /** * @class OrthogonalFunctionFactory * @@ -51,7 +53,7 @@ public: Function build(const UnsignedInteger index) const override; /** Build the Function of the given multi-indices */ - Function build(const Indices & indices) const; + virtual Function build(const Indices & indices) const; /** Return the measure upon which the basis is orthogonal */ virtual Distribution getMeasure() const; @@ -62,6 +64,10 @@ public: /** Virtual constructor */ OrthogonalFunctionFactory * clone() const override; + + /** Get the function factory corresponding to marginal input indices */ + virtual OrthogonalBasis getMarginal(const Indices & indices) const; + Bool isOrthogonal() const override; /** String converter */ diff --git a/lib/src/Uncertainty/Algorithm/OrthogonalBasis/openturns/OrthogonalProductFunctionFactory.hxx b/lib/src/Uncertainty/Algorithm/OrthogonalBasis/openturns/OrthogonalProductFunctionFactory.hxx index ffb531d07f..158a47f67b 100644 --- a/lib/src/Uncertainty/Algorithm/OrthogonalBasis/openturns/OrthogonalProductFunctionFactory.hxx +++ b/lib/src/Uncertainty/Algorithm/OrthogonalBasis/openturns/OrthogonalProductFunctionFactory.hxx @@ -27,6 +27,8 @@ #include "openturns/OrthogonalUniVariateFunctionFamily.hxx" #include "openturns/TensorizedUniVariateFunctionFactory.hxx" #include "openturns/EnumerateFunction.hxx" +#include "openturns/OrthogonalBasis.hxx" + BEGIN_NAMESPACE_OPENTURNS @@ -62,12 +64,18 @@ public: /** Build the Function of the given index */ Function build(const UnsignedInteger index) const override; + /** Build the Function of the given multi-indices */ + Function build(const Indices & indices) const override; + /** Return the enumerate function that translate unidimensional indices nto multidimensional indices */ EnumerateFunction getEnumerateFunction() const override; /** Return the collection of univariate orthogonal polynomial families */ FunctionFamilyCollection getFunctionFamilyCollection() const; + /** Get the function factory corresponding to marginal input indices */ + OrthogonalBasis getMarginal(const Indices & indices) const override; + /** Virtual constructor */ OrthogonalProductFunctionFactory * clone() const override; diff --git a/lib/src/Uncertainty/Algorithm/OrthogonalBasis/openturns/OrthogonalProductPolynomialFactory.hxx b/lib/src/Uncertainty/Algorithm/OrthogonalBasis/openturns/OrthogonalProductPolynomialFactory.hxx index 8a3d903949..da892e9d29 100644 --- a/lib/src/Uncertainty/Algorithm/OrthogonalBasis/openturns/OrthogonalProductPolynomialFactory.hxx +++ b/lib/src/Uncertainty/Algorithm/OrthogonalBasis/openturns/OrthogonalProductPolynomialFactory.hxx @@ -22,6 +22,7 @@ #define OPENTURNS_ORTHOGONALPRODUCTPOLYNOMIALFACTORY_HXX #include "openturns/OrthogonalFunctionFactory.hxx" +#include "openturns/OrthogonalProductFunctionFactory.hxx" #include "openturns/Distribution.hxx" #include "openturns/Indices.hxx" #include "openturns/Point.hxx" @@ -80,6 +81,10 @@ public: Sample getNodesAndWeights(const Indices & degrees, Point & weightsOut) const; + /** Get the function factory corresponding to the given input marginal indices */ + using OrthogonalFunctionFactory::getMarginal; + OrthogonalBasis getMarginal(const Indices & indices) const override; + /** String converter */ String __repr__() const override; String __str__(const String & offset = "") const override; diff --git a/lib/test/CMakeLists.txt b/lib/test/CMakeLists.txt index d75a495736..66e7b7d7ae 100644 --- a/lib/test/CMakeLists.txt +++ b/lib/test/CMakeLists.txt @@ -648,6 +648,7 @@ ot_check_test (LinearModelAnalysis_std) ot_check_test (LinearModelValidation_std IGNOREOUT) ot_check_test (KrigingAlgorithm_isotropic_std IGNOREOUT) ot_check_test (OrthogonalProductPolynomialFactory_std) +ot_check_test (OrthogonalProductFunctionFactory_std) if (HMAT_FOUND) ot_check_test (KrigingAlgorithm_std_hmat) diff --git a/lib/test/t_OrthogonalProductFunctionFactory_std.cxx b/lib/test/t_OrthogonalProductFunctionFactory_std.cxx new file mode 100644 index 0000000000..8da06a66c9 --- /dev/null +++ b/lib/test/t_OrthogonalProductFunctionFactory_std.cxx @@ -0,0 +1,162 @@ +// -*- C++ -*- +/** + * @brief The test file of OrthogonalProductFunctionFactory class + * + * Copyright 2005-2024 Airbus-EDF-IMACS-ONERA-Phimeca + * + * This library is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this library. If not, see . + * + */ +#include "openturns/OT.hxx" +#include "openturns/OTtestcode.hxx" + +using namespace OT; +using namespace OT::Test; + +// Compute reference function value from index and point +Point computeTripleHaarFunctionValue(const UnsignedInteger & index, const Point & point) +{ + if (point.getDimension() != 3) + throw InvalidArgumentException(HERE) << "Expected a dimension 3 point, but dimension is " << point.getDimension(); + const UnsignedInteger dimension = 3; + TensorizedUniVariateFunctionFactory::FunctionFamilyCollection functionCollection(dimension); + functionCollection[0] = HaarWaveletFactory(); + functionCollection[1] = HaarWaveletFactory(); + functionCollection[2] = HaarWaveletFactory(); + const LinearEnumerateFunction enumerate(dimension); + const TensorizedUniVariateFunctionFactory factory(functionCollection, enumerate); + const Function referenceFunction(factory.build(index)); + const Point value(referenceFunction(point)); + return value; +} + +// Compute reference function value from multi-index and point +Point computeTripleHaarFunctionValue(const Indices & indices, const Point & point) +{ + if (point.getDimension() != 3) + throw InvalidArgumentException(HERE) << "Expected a dimension 3 point, but dimension is " << point.getDimension(); + const UnsignedInteger dimension = 3; + const LinearEnumerateFunction enumerate(dimension); + const UnsignedInteger index = enumerate.inverse(indices); + const Point value(computeTripleHaarFunctionValue(index, point)); + return value; +} + +Point computeHaarFourierFunctionValue(const UnsignedInteger & index, const Point & point) +{ + if (point.getDimension() != 3) + throw InvalidArgumentException(HERE) << "Expected a dimension 3 point, but dimension is " << point.getDimension(); + const UnsignedInteger dimension = 3; + TensorizedUniVariateFunctionFactory::FunctionFamilyCollection functionCollection(dimension); + functionCollection[0] = HaarWaveletFactory(); + functionCollection[1] = HaarWaveletFactory(); + functionCollection[2] = FourierSeriesFactory(); + const LinearEnumerateFunction enumerate(dimension); + const TensorizedUniVariateFunctionFactory factory(functionCollection, enumerate); + const Function referenceFunction(factory.build(index)); + const Point value(referenceFunction(point)); + return value; +} + +// Compute reference function value from multi-index and point +Point computeHaarFourierFunctionValue(const Indices & indices, const Point & point) +{ + if (point.getDimension() != 3) + throw InvalidArgumentException(HERE) << "Expected a dimension 3 point, but dimension is " << point.getDimension(); + const UnsignedInteger dimension = 3; + const LinearEnumerateFunction enumerate(dimension); + const UnsignedInteger index = enumerate.inverse(indices); + const Point value(computeHaarFourierFunctionValue(index, point)); + return value; +} + + +int main(int, char *[]) +{ + TESTPREAMBLE; + OStream fullprint(std::cout); + setRandomGenerator(); + + + try + { + // Create the orthogonal basis + fullprint << "Create the orthogonal basis" << std::endl; + UnsignedInteger dimension = 3; + OrthogonalProductFunctionFactory::FunctionFamilyCollection functionCollection(dimension); + functionCollection[0] = HaarWaveletFactory(); + functionCollection[1] = HaarWaveletFactory(); + functionCollection[2] = HaarWaveletFactory(); + + // Create linear enumerate function + fullprint << "Create linear enumerate function" << std::endl; + LinearEnumerateFunction enumerateFunction(dimension); + OrthogonalProductFunctionFactory productBasis(functionCollection, enumerateFunction); + fullprint << productBasis.__str__() << std::endl; + fullprint << productBasis.__repr_markdown__() << std::endl; + // Test the build() method on a collection of functions + const Point center({0.5, 0.5, 0.5}); + for (UnsignedInteger i = 0; i < 10; ++ i) + { + // Test build from index + const Function function(productBasis.build(i)); + assert_almost_equal(function(center), computeTripleHaarFunctionValue(i, center)); + // Test build from multi-index + const Indices indices(enumerateFunction(i)); + const Function function2(productBasis.build(indices)); + assert_almost_equal(function2(center), computeTripleHaarFunctionValue(indices, center)); + } + + // Heterogeneous collection + fullprint << "Heterogeneous collection" << std::endl; + OrthogonalProductFunctionFactory::FunctionFamilyCollection functionCollection2(dimension); + functionCollection2[0] = HaarWaveletFactory(); + functionCollection2[1] = FourierSeriesFactory(); + functionCollection2[2] = HaarWaveletFactory(); + OrthogonalProductFunctionFactory productBasis2(functionCollection2); + fullprint << productBasis2.__str__() << std::endl; + fullprint << productBasis2.__repr_markdown__() << std::endl; + OrthogonalProductFunctionFactory::FunctionFamilyCollection functionCollection4(productBasis2.getFunctionFamilyCollection()); + assert_equal((int) functionCollection4.getSize(), 3); + + // Test getMarginal + fullprint << "Test getMarginal" << std::endl; + UnsignedInteger dimension2 = 5; + OrthogonalProductFunctionFactory::FunctionFamilyCollection functionCollection3(dimension2); + functionCollection3[0] = HaarWaveletFactory(); + functionCollection3[1] = FourierSeriesFactory(); + functionCollection3[2] = HaarWaveletFactory(); + functionCollection3[3] = HaarWaveletFactory(); + functionCollection3[4] = FourierSeriesFactory(); + OrthogonalProductFunctionFactory productBasis5(functionCollection3); + Indices indices({0, 2, 4}); + OrthogonalBasis productBasis6(productBasis5.getMarginal(indices)); + fullprint << productBasis6.__str__() << std::endl; + // Test the build() method on a collection of functions + const Point center2({0.5, 0.5, 0.5}); + for (UnsignedInteger i = 0; i < 10; ++ i) + { + // Test build from index + const Function function(productBasis6.build(i)); + assert_almost_equal(function(center2), computeHaarFourierFunctionValue(i, center2)); + } + } + catch (TestFailed & ex) + { + std::cerr << ex << std::endl; + return ExitCode::Error; + } + + return ExitCode::Success; +} diff --git a/lib/test/t_OrthogonalProductFunctionFactory_std.expout b/lib/test/t_OrthogonalProductFunctionFactory_std.expout new file mode 100644 index 0000000000..250eddf377 --- /dev/null +++ b/lib/test/t_OrthogonalProductFunctionFactory_std.expout @@ -0,0 +1,9 @@ +Create the orthogonal basis +Create linear enumerate function +class=OrthogonalProductFunctionFactory factory=class=TensorizedUniVariateFunctionFactory univariate function collection=[class=UniVariateFunctionFamily implementation=class=HaarWaveletFactory measure=class=Uniform name=Uniform dimension=1 a=0 b=1,class=UniVariateFunctionFamily implementation=class=HaarWaveletFactory measure=class=Uniform name=Uniform dimension=1 a=0 b=1,class=UniVariateFunctionFamily implementation=class=HaarWaveletFactory measure=class=Uniform name=Uniform dimension=1 a=0 b=1] enumerate function=class=LinearEnumerateFunction dimension=3 measure=class=JointDistribution name=JointDistribution dimension=3 copula=class=IndependentCopula name=IndependentCopula dimension=3 marginal[0]=class=Uniform name=Uniform dimension=1 a=0 b=1 marginal[1]=class=Uniform name=Uniform dimension=1 a=0 b=1 marginal[2]=class=Uniform name=Uniform dimension=1 a=0 b=1 +class=OrthogonalProductFunctionFactory factory=class=TensorizedUniVariateFunctionFactory univariate function collection=[class=UniVariateFunctionFamily implementation=class=HaarWaveletFactory measure=class=Uniform name=Uniform dimension=1 a=0 b=1,class=UniVariateFunctionFamily implementation=class=HaarWaveletFactory measure=class=Uniform name=Uniform dimension=1 a=0 b=1,class=UniVariateFunctionFamily implementation=class=HaarWaveletFactory measure=class=Uniform name=Uniform dimension=1 a=0 b=1] enumerate function=class=LinearEnumerateFunction dimension=3 measure=class=JointDistribution name=JointDistribution dimension=3 copula=class=IndependentCopula name=IndependentCopula dimension=3 marginal[0]=class=Uniform name=Uniform dimension=1 a=0 b=1 marginal[1]=class=Uniform name=Uniform dimension=1 a=0 b=1 marginal[2]=class=Uniform name=Uniform dimension=1 a=0 b=1 +Heterogeneous collection +class=OrthogonalProductFunctionFactory factory=class=TensorizedUniVariateFunctionFactory univariate function collection=[class=UniVariateFunctionFamily implementation=class=HaarWaveletFactory measure=class=Uniform name=Uniform dimension=1 a=0 b=1,class=UniVariateFunctionFamily implementation=class=FourierSeriesFactory measure=class=Uniform name=Uniform dimension=1 a=-3.14159 b=3.14159,class=UniVariateFunctionFamily implementation=class=HaarWaveletFactory measure=class=Uniform name=Uniform dimension=1 a=0 b=1] enumerate function=class=LinearEnumerateFunction dimension=3 measure=class=JointDistribution name=JointDistribution dimension=3 copula=class=IndependentCopula name=IndependentCopula dimension=3 marginal[0]=class=Uniform name=Uniform dimension=1 a=0 b=1 marginal[1]=class=Uniform name=Uniform dimension=1 a=-3.14159 b=3.14159 marginal[2]=class=Uniform name=Uniform dimension=1 a=0 b=1 +class=OrthogonalProductFunctionFactory factory=class=TensorizedUniVariateFunctionFactory univariate function collection=[class=UniVariateFunctionFamily implementation=class=HaarWaveletFactory measure=class=Uniform name=Uniform dimension=1 a=0 b=1,class=UniVariateFunctionFamily implementation=class=FourierSeriesFactory measure=class=Uniform name=Uniform dimension=1 a=-3.14159 b=3.14159,class=UniVariateFunctionFamily implementation=class=HaarWaveletFactory measure=class=Uniform name=Uniform dimension=1 a=0 b=1] enumerate function=class=LinearEnumerateFunction dimension=3 measure=class=JointDistribution name=JointDistribution dimension=3 copula=class=IndependentCopula name=IndependentCopula dimension=3 marginal[0]=class=Uniform name=Uniform dimension=1 a=0 b=1 marginal[1]=class=Uniform name=Uniform dimension=1 a=-3.14159 b=3.14159 marginal[2]=class=Uniform name=Uniform dimension=1 a=0 b=1 +Test getMarginal +class=OrthogonalProductFunctionFactory factory=class=TensorizedUniVariateFunctionFactory univariate function collection=[class=UniVariateFunctionFamily implementation=class=HaarWaveletFactory measure=class=Uniform name=Uniform dimension=1 a=0 b=1,class=UniVariateFunctionFamily implementation=class=HaarWaveletFactory measure=class=Uniform name=Uniform dimension=1 a=0 b=1,class=UniVariateFunctionFamily implementation=class=FourierSeriesFactory measure=class=Uniform name=Uniform dimension=1 a=-3.14159 b=3.14159] enumerate function=class=LinearEnumerateFunction dimension=3 measure=class=JointDistribution name=JointDistribution dimension=3 copula=class=IndependentCopula name=IndependentCopula dimension=3 marginal[0]=class=Uniform name=Uniform dimension=1 a=0 b=1 marginal[1]=class=Uniform name=Uniform dimension=1 a=0 b=1 marginal[2]=class=Uniform name=Uniform dimension=1 a=-3.14159 b=3.14159 diff --git a/lib/test/t_OrthogonalProductPolynomialFactory_std.cxx b/lib/test/t_OrthogonalProductPolynomialFactory_std.cxx index fca9bad692..652fc4068c 100644 --- a/lib/test/t_OrthogonalProductPolynomialFactory_std.cxx +++ b/lib/test/t_OrthogonalProductPolynomialFactory_std.cxx @@ -1,6 +1,6 @@ // -*- C++ -*- /** - * @brief The test file of FunctionalChaosAlgoritm class + * @brief The test file of OrthogonalProductPolynomialFactory class * * Copyright 2005-2024 Airbus-EDF-IMACS-ONERA-Phimeca * @@ -24,6 +24,38 @@ using namespace OT; using namespace OT::Test; +// Compute reference function value from index and point +Point computePolynomialValue(const UnsignedInteger & index, const Point & point) +{ + if (point.getDimension() != 3) + throw InvalidArgumentException(HERE) << "Expected a dimension 3 point, but dimension is " << point.getDimension(); + const UnsignedInteger dimension = 3; + const LinearEnumerateFunction enumerate(dimension); + // Compute the multi-indices using the EnumerateFunction + Indices indices(enumerate(index)); + // Then build the collection of polynomials using the collection of factories + ProductPolynomialEvaluation::PolynomialCollection polynomials(dimension); + for (UnsignedInteger i = 0; i < dimension; ++i) + { + polynomials[i] = LegendreFactory().build(indices[i]); + } + const ProductPolynomialEvaluation product(polynomials); + const Point value(product(point)); + return value; +} + +// Compute reference function value from multi-index and point +Point computePolynomialValue(const Indices & indices, const Point & point) +{ + if (point.getDimension() != 3) + throw InvalidArgumentException(HERE) << "Expected a dimension 3 point, but dimension is " << point.getDimension(); + const UnsignedInteger dimension = 3; + const LinearEnumerateFunction enumerate(dimension); + const UnsignedInteger index = enumerate.inverse(indices); + const Point value(computePolynomialValue(index, point)); + return value; +} + int main(int, char *[]) { TESTPREAMBLE; @@ -43,6 +75,18 @@ int main(int, char *[]) OrthogonalProductPolynomialFactory productBasis(polynomialCollection, enumerateFunction); fullprint << productBasis.__str__() << std::endl; fullprint << productBasis.__repr_markdown__() << std::endl; + // Test the build() method on a collection of functions + const Point center({0.5, 0.5, 0.5}); + for (UnsignedInteger i = 0; i < 10; ++ i) + { + // Test build from index + const Function polynomial(productBasis.build(i)); + assert_almost_equal(polynomial(center), computePolynomialValue(i, center)); + // Test build from multi-index + const Indices indices(enumerateFunction(i)); + const Function polynomial2(productBasis.build(indices)); + assert_almost_equal(polynomial2(center), computePolynomialValue(indices, center)); + } // Heterogeneous collection OrthogonalProductPolynomialFactory::PolynomialFamilyCollection polynomCollection2(dimension); @@ -70,6 +114,23 @@ int main(int, char *[]) OrthogonalProductPolynomialFactory productBasis4(aCollection4); fullprint << productBasis4.__str__() << std::endl; fullprint << productBasis4.__repr_markdown__() << std::endl; + + // Test getMarginal + fullprint << "Test getMarginal" << std::endl; + UnsignedInteger dimension2 = 5; + Collection marginals4(dimension2, Uniform(0.0, 1.0)); + OrthogonalProductPolynomialFactory productBasis5(marginals4); + Indices indices({0, 2, 4}); + OrthogonalBasis productBasis6(productBasis5.getMarginal(indices)); + fullprint << productBasis6.__str__() << std::endl; + // Test the build() method on a collection of functions + const Point center2({0.5, 0.5, 0.5}); + for (UnsignedInteger i = 0; i < 10; ++ i) + { + // Test build from index + const Function polynomial(productBasis6.build(i)); + assert_almost_equal(polynomial(center2), computePolynomialValue(i, center2)); + } } catch (TestFailed & ex) { @@ -77,6 +138,5 @@ int main(int, char *[]) return ExitCode::Error; } - return ExitCode::Success; } diff --git a/lib/test/t_OrthogonalProductPolynomialFactory_std.expout b/lib/test/t_OrthogonalProductPolynomialFactory_std.expout index e9e1d6ef1f..31401121d9 100644 --- a/lib/test/t_OrthogonalProductPolynomialFactory_std.expout +++ b/lib/test/t_OrthogonalProductPolynomialFactory_std.expout @@ -86,3 +86,15 @@ OrthogonalProductPolynomialFactory | 1 | LegendreFactory | | 2 | AdaptiveStieltjesAlgorithm | +Test getMarginal +OrthogonalProductPolynomialFactory +- measure=Distribution +- isOrthogonal=true +- enumerateFunction=class=LinearEnumerateFunction dimension=3 + +| Index | Type | +|-------|-----------------| +| 0 | LegendreFactory | +| 1 | LegendreFactory | +| 2 | LegendreFactory | + diff --git a/python/src/OrthogonalFunctionFactory_doc.i.in b/python/src/OrthogonalFunctionFactory_doc.i.in index 2a0f3d324a..fc8c813330 100644 --- a/python/src/OrthogonalFunctionFactory_doc.i.in +++ b/python/src/OrthogonalFunctionFactory_doc.i.in @@ -105,3 +105,18 @@ Normal(mu = 0, sigma = 1)" %enddef %feature("docstring") OT::OrthogonalFunctionFactory::getMeasure OT_OrthogonalBasis_getMeasure_doc + +// --------------------------------------------------------------------- + +%feature("docstring") OT::OrthogonalFunctionFactory::getMarginal +"Get the marginal orthogonal functions. + +Parameters +---------- +indices : sequence of int, :math:`0 \leq i < \inputDim` + List of marginal indices of the input variables. + +Returns +------- +functionFamilylist : list of :class:`~openturns.OrthogonalBasis` + The marginal orthogonal functions." diff --git a/python/src/OrthogonalProductFunctionFactory_doc.i.in b/python/src/OrthogonalProductFunctionFactory_doc.i.in index 2b74f374a2..1a27230184 100644 --- a/python/src/OrthogonalProductFunctionFactory_doc.i.in +++ b/python/src/OrthogonalProductFunctionFactory_doc.i.in @@ -29,11 +29,17 @@ OrthogonalProductPolynomialFactory Examples -------- +Create from a list of orthogonal functions. + >>> import openturns as ot ->>> from math import pi >>> funcColl = [ot.HaarWaveletFactory(), ot.FourierSeriesFactory()] ->>> dim = len(funcColl) ->>> enumerateFunction = ot.LinearEnumerateFunction(dim) +>>> productBasis = ot.OrthogonalProductFunctionFactory(funcColl) + +Set an enumerate function. + +>>> funcColl = [ot.HaarWaveletFactory(), ot.FourierSeriesFactory()] +>>> inputDimension = len(funcColl) +>>> enumerateFunction = ot.LinearEnumerateFunction(inputDimension) >>> productBasis = ot.OrthogonalProductFunctionFactory(funcColl, enumerateFunction)" // --------------------------------------------------------------------- @@ -45,3 +51,25 @@ Returns ------- polynomialFamily : list of :class:`~openturns.OrthogonalUniVariateFunctionFamily` List of orthogonal univariate function families." + +// --------------------------------------------------------------------- + +%feature("docstring") OT::OrthogonalProductFunctionFactory::getMarginal +"Get the marginal orthogonal functions. + +Parameters +---------- +indices : sequence of int, :math:`0 \leq i < \inputDim` + List of marginal indices of the input variables. + +Returns +------- +functionFamilylist : list of :class:`~openturns.OrthogonalUniVariateFunctionFamily` + The marginal orthogonal functions. + +Examples +-------- +>>> import openturns as ot +>>> funcColl = [ot.HaarWaveletFactory(), ot.FourierSeriesFactory(), ot.HaarWaveletFactory()] +>>> productBasis = ot.OrthogonalProductFunctionFactory(funcColl) +>>> marginalProduct = productBasis.getMarginal([0, 2]) # [ot.HaarWaveletFactory(), ot.HaarWaveletFactory()]" diff --git a/python/src/OrthogonalProductPolynomialFactory_doc.i.in b/python/src/OrthogonalProductPolynomialFactory_doc.i.in index 776c007c43..8c72e25a5f 100644 --- a/python/src/OrthogonalProductPolynomialFactory_doc.i.in +++ b/python/src/OrthogonalProductPolynomialFactory_doc.i.in @@ -38,19 +38,23 @@ StandardDistributionPolynomialFactory Examples -------- +Create from a collection of orthogonal polynomials. + >>> import openturns as ot ->>> # Define the model ->>> myModel = ot.SymbolicFunction(['x1','x2','x3'], ['1+x1*x2 + 2*x3^2']) ->>> # Create a distribution of dimension 3 ->>> Xdist = ot.JointDistribution([ot.Normal(), ot.Uniform(), ot.Gamma(2.75, 1.0)]) ->>> # Create the multivariate orthonormal basis ->>> polyColl = [ot.HermiteFactory(), ot.LegendreFactory(), ot.LaguerreFactory(2.75)] ->>> enumerateFunction = ot.LinearEnumerateFunction(3) ->>> productBasis = ot.OrthogonalProductPolynomialFactory(polyColl, enumerateFunction) +>>> polyColl = [ot.HermiteFactory(), ot.LegendreFactory(), ot.LaguerreFactory()] +>>> productBasis = ot.OrthogonalProductPolynomialFactory(polyColl) + +Easy way to create a multivariate orthonormal basis from a distribution. ->>> # Easier way to create the same multivariate orthonormal basis +>>> Xdist = ot.JointDistribution([ot.Normal(), ot.Uniform(), ot.Gamma(2.75, 1.0)]) >>> marginals = [Xdist.getMarginal(i) for i in range(Xdist.getDimension())] ->>> productBasis = ot.OrthogonalProductPolynomialFactory(marginals)" +>>> productBasis = ot.OrthogonalProductPolynomialFactory(marginals) + +Set an enumerate function. + +>>> polyColl = [ot.HermiteFactory(), ot.LegendreFactory(), ot.LaguerreFactory()] +>>> enumerateFunction = ot.LinearEnumerateFunction(3) +>>> productBasis = ot.OrthogonalProductPolynomialFactory(polyColl, enumerateFunction)" // --------------------------------------------------------------------- @@ -104,3 +108,25 @@ Examples 1 : [ 1 -0.774597 3.75 ] >>> print(weights[:2]) [0.138889,0.138889]" + +// --------------------------------------------------------------------- + +%feature("docstring") OT::OrthogonalProductPolynomialFactory::getMarginal +"Get the marginal orthogonal polynomials. + +Parameters +---------- +indices : sequence of int, :math:`0 \leq i < \inputDim` + List of marginal indices of the input variables. + +Returns +------- +polynomialFamilylist : list of :class:`~openturns.OrthogonalUniVariatePolynomialFamily` + The marginal orthogonal polynomials. + +Examples +-------- +>>> import openturns as ot +>>> funcColl = [ot.LegendreFactory(), ot.LaguerreFactory(), ot.HermiteFactory()] +>>> productBasis = ot.OrthogonalProductPolynomialFactory(funcColl) +>>> marginalProduct = productBasis.getMarginal([0, 2]) # [ot.LegendreFactory(), ot.HermiteFactory()]" diff --git a/python/src/orthogonalbasis_module.i b/python/src/orthogonalbasis_module.i index 361db9497d..1d8f548be8 100644 --- a/python/src/orthogonalbasis_module.i +++ b/python/src/orthogonalbasis_module.i @@ -28,6 +28,7 @@ %import weightedexperiment_module.i /* Uncertainty/Algorithm/OrthogonalBasis */ +%import func_module.i %include OrthogonalUniVariatePolynomial.i %include OrthogonalUniVariatePolynomialFactory.i %include CharlierFactory.i @@ -45,14 +46,14 @@ %include AdaptiveStieltjesAlgorithm.i %include StandardDistributionPolynomialFactory.i %include OrthogonalFunctionFactory.i -%include OrthogonalProductPolynomialFactory.i %include OrthogonalBasis.i %include OrthogonalUniVariateFunctionFactory.i %include OrthogonalUniVariateFunctionFamily.i %include OrthogonalUniVariatePolynomialFunctionFactory.i +%include OrthogonalProductFunctionFactory.i +%include OrthogonalProductPolynomialFactory.i %include FourierSeriesFactory.i %include HaarWaveletFactory.i -%include OrthogonalProductFunctionFactory.i %include SoizeGhanemFactory.i /* At last we include template definitions */ diff --git a/python/test/CMakeLists.txt b/python/test/CMakeLists.txt index 1d9615ce15..2a898f9419 100644 --- a/python/test/CMakeLists.txt +++ b/python/test/CMakeLists.txt @@ -713,6 +713,7 @@ ot_pyinstallcheck_test (OrthogonalUniVariatePolynomialFunctionFactory_std) ot_pyinstallcheck_test (FourierSeriesFactory_std) ot_pyinstallcheck_test (HaarWaveletFactory_std) ot_pyinstallcheck_test (OrthogonalProductPolynomialFactory_std) +ot_pyinstallcheck_test (OrthogonalProductFunctionFactory_std) ## Algorithm ot_pyinstallcheck_test (TaylorExpansionMoments_std) diff --git a/python/test/t_OrthogonalProductFunctionFactory_std.expout b/python/test/t_OrthogonalProductFunctionFactory_std.expout new file mode 100644 index 0000000000..13bce04af9 --- /dev/null +++ b/python/test/t_OrthogonalProductFunctionFactory_std.expout @@ -0,0 +1,202 @@ +class=OrthogonalProductFunctionFactory factory=class=TensorizedUniVariateFunctionFactory univariate function collection=[class=UniVariateFunctionFamily implementation=class=HaarWaveletFactory measure=class=Uniform name=Uniform dimension=1 a=0 b=1,class=UniVariateFunctionFamily implementation=class=HaarWaveletFactory measure=class=Uniform name=Uniform dimension=1 a=0 b=1] enumerate function=class=LinearEnumerateFunction dimension=2 measure=class=JointDistribution name=JointDistribution dimension=2 copula=class=IndependentCopula name=IndependentCopula dimension=2 marginal[0]=class=Uniform name=Uniform dimension=1 a=0 b=1 marginal[1]=class=Uniform name=Uniform dimension=1 a=0 b=1 +print() : +type = +class=ProductUniVariateFunctionEvaluation functions=[class=HaarWavelet j=0 k=0 isScaling=true a=0 m=0.5 b=1,class=HaarWavelet j=0 k=0 isScaling=true a=0 m=0.5 b=1] +
    +
  • Input dimension = 2
  • +
  • Input description = [x0,x1]
  • +
  • Output dimension = 1
  • +
  • Output description = [y0]
  • +
  • Parameter = []
  • +
+ +type = +class=ProductUniVariateFunctionEvaluation functions=[class=HaarWavelet j=0 k=0 isScaling=false a=0 m=0.5 b=1,class=HaarWavelet j=0 k=0 isScaling=true a=0 m=0.5 b=1] +
    +
  • Input dimension = 2
  • +
  • Input description = [x0,x1]
  • +
  • Output dimension = 1
  • +
  • Output description = [y0]
  • +
  • Parameter = []
  • +
+ +type = +class=ProductUniVariateFunctionEvaluation functions=[class=HaarWavelet j=0 k=0 isScaling=true a=0 m=0.5 b=1,class=HaarWavelet j=0 k=0 isScaling=false a=0 m=0.5 b=1] +
    +
  • Input dimension = 2
  • +
  • Input description = [x0,x1]
  • +
  • Output dimension = 1
  • +
  • Output description = [y0]
  • +
  • Parameter = []
  • +
+ +type = +class=ProductUniVariateFunctionEvaluation functions=[class=HaarWavelet j=1 k=0 isScaling=false a=0 m=0.25 b=0.5,class=HaarWavelet j=0 k=0 isScaling=true a=0 m=0.5 b=1] +
    +
  • Input dimension = 2
  • +
  • Input description = [x0,x1]
  • +
  • Output dimension = 1
  • +
  • Output description = [y0]
  • +
  • Parameter = []
  • +
+ +type = +class=ProductUniVariateFunctionEvaluation functions=[class=HaarWavelet j=0 k=0 isScaling=false a=0 m=0.5 b=1,class=HaarWavelet j=0 k=0 isScaling=false a=0 m=0.5 b=1] +
    +
  • Input dimension = 2
  • +
  • Input description = [x0,x1]
  • +
  • Output dimension = 1
  • +
  • Output description = [y0]
  • +
  • Parameter = []
  • +
+ +type = +class=ProductUniVariateFunctionEvaluation functions=[class=HaarWavelet j=0 k=0 isScaling=true a=0 m=0.5 b=1,class=HaarWavelet j=1 k=0 isScaling=false a=0 m=0.25 b=0.5] +
    +
  • Input dimension = 2
  • +
  • Input description = [x0,x1]
  • +
  • Output dimension = 1
  • +
  • Output description = [y0]
  • +
  • Parameter = []
  • +
+ +type = +class=ProductUniVariateFunctionEvaluation functions=[class=HaarWavelet j=1 k=1 isScaling=false a=0.5 m=0.75 b=1,class=HaarWavelet j=0 k=0 isScaling=true a=0 m=0.5 b=1] +
    +
  • Input dimension = 2
  • +
  • Input description = [x0,x1]
  • +
  • Output dimension = 1
  • +
  • Output description = [y0]
  • +
  • Parameter = []
  • +
+ +type = +class=ProductUniVariateFunctionEvaluation functions=[class=HaarWavelet j=1 k=0 isScaling=false a=0 m=0.25 b=0.5,class=HaarWavelet j=0 k=0 isScaling=false a=0 m=0.5 b=1] +
    +
  • Input dimension = 2
  • +
  • Input description = [x0,x1]
  • +
  • Output dimension = 1
  • +
  • Output description = [y0]
  • +
  • Parameter = []
  • +
+ +type = +class=ProductUniVariateFunctionEvaluation functions=[class=HaarWavelet j=0 k=0 isScaling=false a=0 m=0.5 b=1,class=HaarWavelet j=1 k=0 isScaling=false a=0 m=0.25 b=0.5] +
    +
  • Input dimension = 2
  • +
  • Input description = [x0,x1]
  • +
  • Output dimension = 1
  • +
  • Output description = [y0]
  • +
  • Parameter = []
  • +
+ +type = +class=ProductUniVariateFunctionEvaluation functions=[class=HaarWavelet j=0 k=0 isScaling=true a=0 m=0.5 b=1,class=HaarWavelet j=1 k=1 isScaling=false a=0.5 m=0.75 b=1] +
    +
  • Input dimension = 2
  • +
  • Input description = [x0,x1]
  • +
  • Output dimension = 1
  • +
  • Output description = [y0]
  • +
  • Parameter = []
  • +
+ +type = +class=ProductUniVariateFunctionEvaluation functions=[class=HaarWavelet j=2 k=0 isScaling=false a=0 m=0.125 b=0.25,class=HaarWavelet j=0 k=0 isScaling=true a=0 m=0.5 b=1] +
    +
  • Input dimension = 2
  • +
  • Input description = [x0,x1]
  • +
  • Output dimension = 1
  • +
  • Output description = [y0]
  • +
  • Parameter = []
  • +
+ +type = +class=ProductUniVariateFunctionEvaluation functions=[class=HaarWavelet j=1 k=1 isScaling=false a=0.5 m=0.75 b=1,class=HaarWavelet j=0 k=0 isScaling=false a=0 m=0.5 b=1] +
    +
  • Input dimension = 2
  • +
  • Input description = [x0,x1]
  • +
  • Output dimension = 1
  • +
  • Output description = [y0]
  • +
  • Parameter = []
  • +
+ +type = +class=ProductUniVariateFunctionEvaluation functions=[class=HaarWavelet j=1 k=0 isScaling=false a=0 m=0.25 b=0.5,class=HaarWavelet j=1 k=0 isScaling=false a=0 m=0.25 b=0.5] +
    +
  • Input dimension = 2
  • +
  • Input description = [x0,x1]
  • +
  • Output dimension = 1
  • +
  • Output description = [y0]
  • +
  • Parameter = []
  • +
+ +type = +class=ProductUniVariateFunctionEvaluation functions=[class=HaarWavelet j=0 k=0 isScaling=false a=0 m=0.5 b=1,class=HaarWavelet j=1 k=1 isScaling=false a=0.5 m=0.75 b=1] +
    +
  • Input dimension = 2
  • +
  • Input description = [x0,x1]
  • +
  • Output dimension = 1
  • +
  • Output description = [y0]
  • +
  • Parameter = []
  • +
+ +type = +class=ProductUniVariateFunctionEvaluation functions=[class=HaarWavelet j=0 k=0 isScaling=true a=0 m=0.5 b=1,class=HaarWavelet j=2 k=0 isScaling=false a=0 m=0.125 b=0.25] +
    +
  • Input dimension = 2
  • +
  • Input description = [x0,x1]
  • +
  • Output dimension = 1
  • +
  • Output description = [y0]
  • +
  • Parameter = []
  • +
+ +type = +class=ProductUniVariateFunctionEvaluation functions=[class=HaarWavelet j=2 k=1 isScaling=false a=0.25 m=0.375 b=0.5,class=HaarWavelet j=0 k=0 isScaling=true a=0 m=0.5 b=1] +
    +
  • Input dimension = 2
  • +
  • Input description = [x0,x1]
  • +
  • Output dimension = 1
  • +
  • Output description = [y0]
  • +
  • Parameter = []
  • +
+ +type = +class=ProductUniVariateFunctionEvaluation functions=[class=HaarWavelet j=2 k=0 isScaling=false a=0 m=0.125 b=0.25,class=HaarWavelet j=0 k=0 isScaling=false a=0 m=0.5 b=1] +
    +
  • Input dimension = 2
  • +
  • Input description = [x0,x1]
  • +
  • Output dimension = 1
  • +
  • Output description = [y0]
  • +
  • Parameter = []
  • +
+ +type = +class=ProductUniVariateFunctionEvaluation functions=[class=HaarWavelet j=1 k=1 isScaling=false a=0.5 m=0.75 b=1,class=HaarWavelet j=1 k=0 isScaling=false a=0 m=0.25 b=0.5] +
    +
  • Input dimension = 2
  • +
  • Input description = [x0,x1]
  • +
  • Output dimension = 1
  • +
  • Output description = [y0]
  • +
  • Parameter = []
  • +
+ +type = +class=ProductUniVariateFunctionEvaluation functions=[class=HaarWavelet j=1 k=0 isScaling=false a=0 m=0.25 b=0.5,class=HaarWavelet j=1 k=1 isScaling=false a=0.5 m=0.75 b=1] +
    +
  • Input dimension = 2
  • +
  • Input description = [x0,x1]
  • +
  • Output dimension = 1
  • +
  • Output description = [y0]
  • +
  • Parameter = []
  • +
+ +type = +class=ProductUniVariateFunctionEvaluation functions=[class=HaarWavelet j=0 k=0 isScaling=false a=0 m=0.5 b=1,class=HaarWavelet j=2 k=0 isScaling=false a=0 m=0.125 b=0.25] +
    +
  • Input dimension = 2
  • +
  • Input description = [x0,x1]
  • +
  • Output dimension = 1
  • +
  • Output description = [y0]
  • +
  • Parameter = []
  • +
+ diff --git a/python/test/t_OrthogonalProductFunctionFactory_std.py b/python/test/t_OrthogonalProductFunctionFactory_std.py new file mode 100644 index 0000000000..b516bee502 --- /dev/null +++ b/python/test/t_OrthogonalProductFunctionFactory_std.py @@ -0,0 +1,41 @@ +#! /usr/bin/env python + +import openturns as ot + +ot.TESTPREAMBLE() + +dimension = 2 + +# Create the orthogonal basis +enumerateFunction = ot.LinearEnumerateFunction(dimension) +productBasis = ot.OrthogonalProductFunctionFactory( + [ot.HaarWaveletFactory(), ot.HaarWaveletFactory()], enumerateFunction +) +print(productBasis) +print("print() :") +for i in range(20): + p = productBasis.build(i) + print("type = ", type(p)) + print(p) + print(p._repr_html_()) + +# Test build from multi-index +for i in range(20): + index = enumerateFunction(i) + termBasis2 = productBasis.build(index) + +# Test getMarginal +enumerateFunction = ot.LinearEnumerateFunction(5) +productBasis = ot.OrthogonalProductPolynomialFactory( + [ + ot.LegendreFactory(), + ot.HermiteFactory(), + ot.LegendreFactory(), + ot.HermiteFactory(), + ot.HermiteFactory(), + ], + enumerateFunction, +) +productBasisMarginal = productBasis.getMarginal([0, 2, 4]) +for i in range(20): + function = productBasisMarginal.build(i) diff --git a/python/test/t_OrthogonalProductPolynomialFactory_std.py b/python/test/t_OrthogonalProductPolynomialFactory_std.py index efae7efb9f..41e87e1a8d 100755 --- a/python/test/t_OrthogonalProductPolynomialFactory_std.py +++ b/python/test/t_OrthogonalProductPolynomialFactory_std.py @@ -18,3 +18,24 @@ print("type = ", type(p)) print(p) print(p._repr_html_()) + +# Test build from multi-index +for i in range(20): + index = enumerateFunction(i) + termBasis2 = productBasis.build(index) + +# Test getMarginal +enumerateFunction = ot.LinearEnumerateFunction(5) +productBasis = ot.OrthogonalProductPolynomialFactory( + [ + ot.LegendreFactory(), + ot.HermiteFactory(), + ot.LegendreFactory(), + ot.HermiteFactory(), + ot.HermiteFactory(), + ], + enumerateFunction, +) +productBasisMarginal = productBasis.getMarginal([0, 2, 4]) +for i in range(20): + function = productBasisMarginal.build(i)