Skip to content

Commit

Permalink
Moved FCValidation and LMValidation into experimental
Browse files Browse the repository at this point in the history
  • Loading branch information
mbaudin47 committed May 7, 2024
1 parent 5442546 commit d056915
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 13 deletions.
3 changes: 2 additions & 1 deletion python/doc/pyplots/FunctionalChaosValidation.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import openturns as ot
from openturns.viewer import View
from openturns.usecases import ishigami_function
import openturns.experimental as otexp

im = ishigami_function.IshigamiModel()
sampleSize = 500
Expand All @@ -20,6 +21,6 @@
)
chaosalgo.run()
result = chaosalgo.getResult()
validation = ot.FunctionalChaosValidation(result)
validation = otexp.FunctionalChaosValidation(result)
graph = validation.drawValidation()
View(graph)
3 changes: 2 additions & 1 deletion python/doc/pyplots/LinearModelValidation.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import openturns as ot
from openturns.viewer import View
import openturns.experimental as otexp

func = ot.SymbolicFunction(
['x1', 'x2', 'x3'],
Expand All @@ -16,6 +17,6 @@
algo.run()
result = algo.getResult()
splitter = ot.LeaveOneOutSplitter(sampleSize)
validation = ot.LinearModelValidation(result, splitter)
validation = otexp.LinearModelValidation(result, splitter)
graph = validation.drawValidation()
View(graph)
5 changes: 3 additions & 2 deletions python/src/FunctionalChaosValidation_doc.i.in
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ prevents us from using the fast analytical formulas and get an
accurate estimator of the MSE.

>>> import openturns as ot
>>> import openturns.experimental as otexp
>>> from math import pi
>>> from openturns.usecases import ishigami_function
>>> im = ishigami_function.IshigamiModel()
Expand All @@ -124,7 +125,7 @@ accurate estimator of the MSE.
Validate the polynomial chaos expansion using leave-one-out cross-validation.

>>> splitterLOO = ot.LeaveOneOutSplitter(sampleSize)
>>> validation = ot.FunctionalChaosValidation(result, splitterLOO)
>>> validation = otexp.FunctionalChaosValidation(result, splitterLOO)
>>> r2Score = validation.computeR2Score()
>>> print('R2 = ', r2Score[0])
R2 = 0.99...
Expand All @@ -134,7 +135,7 @@ and set the :math:`k` parameter.

>>> kParameter = 10
>>> splitterKF = ot.KFoldSplitter(sampleSize, kParameter)
>>> validation = ot.FunctionalChaosValidation(
>>> validation = otexp.FunctionalChaosValidation(
... result, splitterKF
... )

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

/* Uncertainty/Algorithm/Metamodel */
%include FunctionalChaosValidation.i
%include LinearModelValidation.i

// duplicate helpers
OTDefaultCollectionConvertFunctions(WeightedExperiment)
%include SmolyakExperiment.i
%include GeneralizedExtremeValueValidation.i
%include GeneralizedParetoValidation.i
2 changes: 0 additions & 2 deletions python/src/metamodel_module.i
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,12 @@
%include FunctionalChaosAlgorithm.i
%include FunctionalChaosSobolIndices.i
%include MetaModelValidation.i
%include FunctionalChaosValidation.i
%include GeneralLinearModelResult.i
%include GeneralLinearModelAlgorithm.i
%include KrigingAlgorithm.i
%include LinearModelStepwiseAlgorithm.i
%include LinearModelAlgorithm.i
%include LinearModelAnalysis.i
%include LinearModelValidation.i

/* Uncertainty/Model */
%include RandomVector.i
Expand Down
9 changes: 4 additions & 5 deletions python/test/t_FunctionalChaosValidation_std.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import openturns as ot
from openturns.usecases import ishigami_function
from openturns.testing import assert_almost_equal
import openturns.experimental as otexp


def computeMSENaiveLOO(
Expand Down Expand Up @@ -170,7 +171,7 @@ def computeMSENaiveKFold(
#
print("1. Analytical leave-one-out")
splitterLOO = ot.LeaveOneOutSplitter(sampleSize)
validationLOO = ot.FunctionalChaosValidation(
validationLOO = otexp.FunctionalChaosValidation(
chaosResult, splitterLOO
)
mseLOOAnalytical = validationLOO.computeMeanSquaredError()
Expand Down Expand Up @@ -206,13 +207,11 @@ def computeMSENaiveKFold(
#
print("2. Analytical K-Fold")
splitterKF = ot.KFoldSplitter(sampleSize, kFoldParameter)
validationKFold = ot.FunctionalChaosValidation(
validationKFold = otexp.FunctionalChaosValidation(
chaosResult, splitterKF
)
print("KFold with K = ", kFoldParameter)
assert validationKFold.getSplitter().getN() == sampleSize
# TODO: fix this
# assert validationKFold.getSplitter().getSize() == kFoldParameter

# Compute mean squared error
mseKFoldAnalytical = validationKFold.computeMeanSquaredError()
Expand Down Expand Up @@ -261,7 +260,7 @@ def computeMSENaiveKFold(

# Analytical leave-one-out
splitterLOO = ot.LeaveOneOutSplitter(sampleSize)
validationLOO = ot.FunctionalChaosValidation(
validationLOO = otexp.FunctionalChaosValidation(
chaosResult, splitterLOO
)
mseLOOAnalytical = validationLOO.computeMeanSquaredError()
Expand Down
5 changes: 3 additions & 2 deletions python/test/t_LinearModelValidation_std.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import openturns as ot
from openturns.testing import assert_almost_equal
import openturns.experimental as otexp

ot.TESTPREAMBLE()

Expand Down Expand Up @@ -29,7 +30,7 @@

# Create LOO validation
splitterLOO = ot.LeaveOneOutSplitter(sampleSize)
validationLOO = ot.LinearModelValidation(result, splitterLOO)
validationLOO = otexp.LinearModelValidation(result, splitterLOO)
print(validationLOO)

# Compute analytical LOO MSE
Expand Down Expand Up @@ -73,7 +74,7 @@

# Create KFold validation
splitterKFold = ot.KFoldSplitter(sampleSize, kFoldParameter)
validationKFold = ot.LinearModelValidation(
validationKFold = otexp.LinearModelValidation(
result, splitterKFold
)
print(validationKFold)
Expand Down

0 comments on commit d056915

Please sign in to comment.