Skip to content

Instantly share code, notes, and snippets.

View mbaudin47's full-sized avatar
😀

Michael Baudin mbaudin47

😀
  • EDF
  • Nowhere land
View GitHub Profile
@mbaudin47
mbaudin47 / find_largest_degree.py
Last active November 26, 2025 16:42
Compute the largest polynomial degree such that the number of coefficients is lower or equal to a proportion of the sample size
"""
Let d be the dimension of the input vector.
Let n be the sample size.
Let alpha in [0, 1] a proportion of the sample size.
Compute the largest polynomial degree p such that the
number of coefficients of the polynomial chaos expansion is lower or
equal to alpha * n.
For example, the next table presents the number of coefficients
of the PCE of the Ishigami function, which has dimension 3.
@mbaudin47
mbaudin47 / sobol_convergence_with_or_not_zero.py
Created November 1, 2025 22:14
Estimate the expected value of test functions using quasi-Monte Carlo.
"""
Estimate the expected value of the test functions using quasi-Monte Carlo.
See the effect of:
- scrambling the Sobol' sequence,
- including or excluding the first Sobol' point (zero).
See:
- The first zero point should be moved back into the low discrepancy sequences
@mbaudin47
mbaudin47 / benchmark_PCE_cross_validation.py
Last active July 4, 2025 10:59
Benchmark PCE cross-validation
"""
Michaël Baudin, 2025
Benchmark the elapsed time of the cross-validation of a PCE.
Compare two methods for cross-validation:
- leave-one-out,
- K-fold.
Compare two methods for performing the CV:
- classical cross-validation, using MetaModelValidation,
@mbaudin47
mbaudin47 / benchmark_linear_least_squares.py
Created July 2, 2025 21:14
Benchmark linear least squares of polynomial chaos expansion in OpenTURNS
"""
Michaël Baudin, 2025
Benchmark the elapsed time of solving a linear least squares problem using OpenTURNS.
Uses the Ishigami function.
Compute its polynomial chaos expansion.
"""
# %%
import openturns as ot
import time
@mbaudin47
mbaudin47 / pce_marginal.py
Last active June 30, 2025 11:43
Get the output marginal of a PCE
"""
Get the (output) marginal of a PCE.
There is no FunctionalChaosResult.getMarginal()
https://github.com/openturns/openturns/issues/2985
Limitation
----------
This script involves more PCE indices than necessary i.e. the number
@mbaudin47
mbaudin47 / pce_ishigami.py
Created June 30, 2025 10:00
pce_ishigami
"""
Smallest possible script to create a FunctionalChaosResult.
Uses the Ishigami function.
"""
# %%
from openturns.usecases import ishigami_function
import openturns as ot
# %%
@mbaudin47
mbaudin47 / orthogonalMatchingPursuit.py
Last active May 7, 2025 16:09
Orthogonal Matching Pursuit
"""Implements the selection method of a polynomial chaos expansion algorithm in Python.
This implements 2 algorithms:
- Algorithm B.1 page 628 of (Lüthen, et al., 2021),
- Algorithm B.1 with with CV using Corrected Leave-One-Out or K-Fold.
TODO-List
---------
- Extend the code to multiple output dimensions.
- Early stopping of the algorithm using the K-Fold or Corrected LOO score.
"""
This script uses SALib to estimate Sobol' indices from the Beam model.
The beam model is implemented as a Python function.
Moreover, we measure the time necessary to evaluate the model and estimate
the Sobol' indices.
Output
------
N = 100000
Elapsed = 218.30088353157043 (s)
"""
This script uses OpenTURNS to estimate Sobol' indices from the Beam model implemented as an OpenTURNS's function.
Moreover, we measure the time necessary to evaluate the model and estimate the Sobol' indices.
Output
------
Elapsed = 1.0558149814605713 (s)
References
----------
@mbaudin47
mbaudin47 / export_PCE_to_Python.py
Last active December 27, 2024 16:36
Export an OpenTURNS PCE as a standalone Python code
"""
Create a polynomial chaos for the Ishigami function and export
it as a standalone Python code.
See https://github.com/openturns/openturns/blob/master/lib/src/Uncertainty/Algorithm/MetaModel/FunctionalChaos/FunctionalChaosResult.cxx
This code produces a file which content is:
from openturns import *
def pceModel(X):