Skip to content

Commit

Permalink
SmolyakExperiment: Move out of experimental
Browse files Browse the repository at this point in the history
  • Loading branch information
jschueller committed May 6, 2024
1 parent ae14bb7 commit 8879794
Show file tree
Hide file tree
Showing 12 changed files with 25 additions and 38 deletions.
1 change: 1 addition & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
==== New classes ====

==== API changes ====
* SmolyakExperiment left the experimental module
* Removed deprecated method Study.printLabels
* Removed deprecated class TimerCallback
* Removed deprecated MetaModelValidation(inputSample, outputSample, metaModel) ctor
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

# %%
import openturns as ot
import openturns.experimental as otexp
import openturns.viewer as otv
from matplotlib import pylab as plt

Expand All @@ -29,7 +28,7 @@
for i in range(number_of_rows):
for j in range(number_of_columns):
level = 1 + j + i * number_of_columns
experiment = otexp.SmolyakExperiment(collection, level)
experiment = ot.SmolyakExperiment(collection, level)
nodes, weights = experiment.generateWithWeights()
sample_size = weights.getDimension()
graph = ot.Graph(
Expand Down Expand Up @@ -160,7 +159,7 @@
number_of_nodes = ot.Sample(level_max, 1)
for level in level_list:
collection = [uniform] * dimension
experiment = otexp.SmolyakExperiment(collection, level)
experiment = ot.SmolyakExperiment(collection, level)
nodes, weights = experiment.generateWithWeights()
size = nodes.getSize()
number_of_nodes[level - 1, 0] = size
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,23 +25,22 @@

# %%
import openturns as ot
import openturns.experimental as otexp
import openturns.viewer as otv
from matplotlib import pylab as plt

# %%
# In the first example, we print the indices involved in
# Smolyak-Legendre quadrature of level 3.
# The multi-indices are computed using the
# :py:meth:`openturns.experimental.SmolyakExperiment.computeCombination` method.
# :py:meth:`openturns.SmolyakExperiment.computeCombination` method.
# Actually, the multi-indices do not actually depend on the
# underlying univariate quadratures, but this is required for
# the :class:`openturns.experimental.SmolyakExperiment` class.
# the :class:`openturns.SmolyakExperiment` class.

collection = [ot.GaussProductExperiment()] * 2
level = 3
print("level = ", level)
experiment = otexp.SmolyakExperiment(collection, level)
experiment = ot.SmolyakExperiment(collection, level)
indices = experiment.computeCombination()
print(indices)

Expand All @@ -57,7 +56,7 @@
def drawSmolyakIndices(level):
# Plot Smolyak indices of given level in 2 dimensions
collection = [ot.GaussProductExperiment()] * 2
experiment = otexp.SmolyakExperiment(collection, level)
experiment = ot.SmolyakExperiment(collection, level)
indices = experiment.computeCombination()
sample = indices
graph = ot.Graph("L = %d" % (level), "k1", "k2", True)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,14 @@
"""
# %%
# The goal of this example is to see the effect of the merge algorithm in
# Smolyak's quadrature implemented in :class:`openturns.experimental.SmolyakExperiment`.
# Smolyak's quadrature implemented in :class:`openturns.SmolyakExperiment`.
# We analyse the sensitivity of the number of nodes to the relative
# and absolute tolerances.
# Then we analyse the effect of the merge algorithm on the number of nodes.

# %%
import numpy as np
import openturns as ot
import openturns.experimental as otexp
import openturns.viewer as otv
import matplotlib.pyplot as plt

Expand Down Expand Up @@ -46,7 +45,7 @@ def computeNumberOfSmolyakNodes(level, epsilon_a, epsilon_r):
ot.ResourceMap.SetAsScalar("SmolyakExperiment-MergeAbsoluteEpsilon", epsilon_a)
uniform = ot.GaussProductExperiment(ot.Uniform(0.0, 1.0))
collection = [uniform] * 2
experiment = otexp.SmolyakExperiment(collection, level)
experiment = ot.SmolyakExperiment(collection, level)
nodes, weights = experiment.generateWithWeights()
size = nodes.getSize()
return size
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
# %%
import numpy as np
import openturns as ot
import openturns.experimental as otexp
import openturns.viewer as otv
from matplotlib import pylab as plt

Expand All @@ -26,7 +25,7 @@
collection = [uniform] * 2
level = 3
print("level = ", level)
experiment = otexp.SmolyakExperiment(collection, level)
experiment = ot.SmolyakExperiment(collection, level)
nodes, weights = experiment.generateWithWeights()
print(nodes)
print(weights)
Expand Down Expand Up @@ -98,7 +97,7 @@ def g_function_py(x):
collection = [uniform] * dimension
level = 5
print("level = ", level)
experiment = otexp.SmolyakExperiment(collection, level)
experiment = ot.SmolyakExperiment(collection, level)
nodes, weights = experiment.generateWithWeights()
print("size = ", nodes.getSize())

Expand Down Expand Up @@ -178,7 +177,7 @@ def smolyakQuadrature(g_function, level):
dimension = g_function.getInputDimension()
uniform = ot.GaussProductExperiment(ot.Uniform(0.0, 1.0))
collection = [uniform] * dimension
experiment = otexp.SmolyakExperiment(collection, level)
experiment = ot.SmolyakExperiment(collection, level)
nodes, weights = experiment.generateWithWeights()
size = nodes.getSize()
g_values = g_function(nodes)
Expand Down
3 changes: 1 addition & 2 deletions python/doc/pyplots/SmolyakExperiment.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import openturns as ot
import openturns.experimental as otexp
from matplotlib import pyplot as plt
from openturns.viewer import View

Expand All @@ -9,7 +8,7 @@
experiment2 = ot.GaussProductExperiment(ot.Uniform(0.0, 1.0))
collection = [experiment1, experiment2]
level = 3
smolyak = otexp.SmolyakExperiment(collection, level)
smolyak = ot.SmolyakExperiment(collection, level)

sample = smolyak.generate()

Expand Down
2 changes: 1 addition & 1 deletion python/doc/user_manual/designs_of_experiments.rst
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ Deterministic weighted experiments
GaussProductExperiment
LowDiscrepancyExperiment
TensorProductExperiment
experimental.SmolyakExperiment
SmolyakExperiment

.. _low_discrepancy_sequence_api:

Expand Down
2 changes: 1 addition & 1 deletion python/src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -807,6 +807,7 @@ ot_add_python_module(weightedexperiment weightedexperiment_module.i
TemperatureProfileImplementation.i TemperatureProfileImplementation_doc.i.in
LowDiscrepancyExperiment.i LowDiscrepancyExperiment_doc.i.in
MonteCarloExperiment.i MonteCarloExperiment_doc.i.in
SmolyakExperiment.i SmolyakExperiment_doc.i.in
SplitterImplementation.i SplitterImplementation_doc.i.in
KFoldSplitter.i KFoldSplitter_doc.i.in
LeaveOneOutSplitter.i LeaveOneOutSplitter_doc.i.in
Expand Down Expand Up @@ -1026,7 +1027,6 @@ ot_add_python_module(experimental experimental_module.i
PointToFieldFunctionalChaosAlgorithm.i PointToFieldFunctionalChaosAlgorithm_doc.i.in
UserDefinedMetropolisHastings.i UserDefinedMetropolisHastings_doc.i.in
SamplePartition.i SamplePartition_doc.i.in
SmolyakExperiment.i SmolyakExperiment_doc.i.in
SmoothedUniformFactory.i SmoothedUniformFactory_doc.i.in
StudentCopula.i StudentCopula_doc.i.in
StudentCopulaFactory.i StudentCopulaFactory_doc.i.in
Expand Down
13 changes: 4 additions & 9 deletions python/src/SmolyakExperiment_doc.i.in
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
%feature("docstring") OT::SmolyakExperiment
"Smolyak experiment.

.. warning::
This class is experimental and likely to be modified in future releases.
To use it, import the ``openturns.experimental`` submodule.

Parameters
----------
experiments : list of :class:`~openturns.WeightedExperiment`
Expand All @@ -22,7 +18,7 @@ Smolyak experiment has a significantly lower number of nodes [petras2003]_.
This implementation uses the combination technique ([gerstner1998]_ page 215).
Smolyak quadrature involve weights which are negative ([sullivan2015]_ page 177).
The size of the experiment is only known after the nodes and weights have been computed,
that is, after the :meth:`~openturns.experimental.SmolyakExperiment.generateWithWeights` method is called.
that is, after the :meth:`generateWithWeights` method is called.

**Method**

Expand Down Expand Up @@ -124,7 +120,7 @@ for any :math:`\ell \geq 1`.
As shown by the previous equation, for a given multi-index :math:`\vect{k}`
the Smolyak quadrature requires to set the level of each marginal experiment to
an integer which depends on the multi-index.
This is done using the :meth:`~openturns.experimental.SmolyakExperiment.setLevel` method of the marginal quadrature.
This is done using the :meth:`setLevel` method of the marginal quadrature.

The following formula expresses the multivariate quadrature in terms of
combinations univariate quadratures, known as the *combination technique*.
Expand Down Expand Up @@ -217,20 +213,19 @@ Therefore,

See Also
--------
openturns.WeightedExperiment
WeightedExperiment

Examples
--------
In the following example, we create Smolyak quadrature using two Gauss-Legendre
marginal quadratures.

>>> import openturns as ot
>>> import openturns.experimental as otexp
>>> experiment1 = ot.GaussProductExperiment(ot.Uniform(0.0, 1.0))
>>> experiment2 = ot.GaussProductExperiment(ot.Uniform(0.0, 1.0))
>>> collection = [experiment1, experiment2]
>>> level = 3
>>> multivariate_experiment = otexp.SmolyakExperiment(collection, level)
>>> multivariate_experiment = ot.SmolyakExperiment(collection, level)
>>> nodes, weights = multivariate_experiment.generateWithWeights()"

// ---------------------------------------------------------------------
Expand Down
4 changes: 0 additions & 4 deletions python/src/experimental_module.i
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,5 @@
%include TruncatedOverMesh.i
%include PosteriorDistribution.i
%include UniformOrderStatistics.i

// duplicate helpers
OTDefaultCollectionConvertFunctions(WeightedExperiment)
%include SmolyakExperiment.i
%include GeneralizedExtremeValueValidation.i
%include GeneralizedParetoValidation.i
1 change: 1 addition & 0 deletions python/src/weightedexperiment_module.i
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
%include KFoldSplitter.i
%include LeaveOneOutSplitter.i
%include TensorProductExperiment.i
%include SmolyakExperiment.i

/* At last we include template definitions */
%include UncertaintyWeightedExperimentTemplateDefs.i
11 changes: 5 additions & 6 deletions python/test/t_SmolyakExperiment_std.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#! /usr/bin/env python

import openturns as ot
import openturns.experimental as otexp
import openturns.testing as ott

ot.TESTPREAMBLE()
Expand Down Expand Up @@ -112,7 +111,7 @@ def testSmolyakExperiment1():
experiment2 = ot.GaussProductExperiment(ot.Uniform(0.0, 1.0))
collection = [experiment1, experiment2]
level = 3
smolyak = otexp.SmolyakExperiment(collection, level)
smolyak = ot.SmolyakExperiment(collection, level)
nodes, weights = smolyak.generateWithWeights()
numberOfDigits = 14
nodes = roundSample(nodes, numberOfDigits)
Expand Down Expand Up @@ -197,7 +196,7 @@ def testSmolyakExperiment2():
experiment2 = ot.GaussProductExperiment(ot.Uniform(0.0, 1.0))
collection = [experiment1, experiment2]
level = 3
smolyak = otexp.SmolyakExperiment(collection, level)
smolyak = ot.SmolyakExperiment(collection, level)
nodes = smolyak.generate()
numberOfDigits = 14
nodes = roundSample(nodes, numberOfDigits)
Expand Down Expand Up @@ -239,7 +238,7 @@ def testSmolyakExperiment3():
marginalExperiment = ot.GaussProductExperiment(ot.Uniform(0.0, 1.0))
collection.append(marginalExperiment)
level = 3
smolyak = otexp.SmolyakExperiment(collection, level)
smolyak = ot.SmolyakExperiment(collection, level)
nodes, weights = smolyak.generateWithWeights()
# Check size and dimension
assert nodes.getDimension() == 3
Expand All @@ -256,7 +255,7 @@ def testSmolyakExperiment4():
experiment2 = ot.GaussProductExperiment(ot.Uniform(0.0, 1.0))
collection = [experiment1, experiment2]
level = 1
smolyak = otexp.SmolyakExperiment(collection, level)
smolyak = ot.SmolyakExperiment(collection, level)
nodes, weights = smolyak.generateWithWeights()
numberOfDigits = 14
nodes = roundSample(nodes, numberOfDigits)
Expand Down Expand Up @@ -293,7 +292,7 @@ def testSmolyakExperiment5():
experiment2 = ot.GaussProductExperiment(ot.Uniform(0.0, 1.0))
collection = [experiment1, experiment2]
level = 3
smolyak = otexp.SmolyakExperiment(collection, level)
smolyak = ot.SmolyakExperiment(collection, level)
indicesCollection = smolyak.computeCombination()
print("indicesCollection = ", indicesCollection)
expected = [[2, 1], [1, 2], [3, 1], [2, 2], [1, 3]]
Expand Down

0 comments on commit 8879794

Please sign in to comment.