Skip to content

Instantly share code, notes, and snippets.

View tupui's full-sized avatar

Pamphile Roy tupui

View GitHub Profile
@tupui
tupui / benford.py
Created November 19, 2020 16:04
Benford's law to measure random number generation quality
"""Benford's law to measure random number generation quality.
.. note:: This script relies on a modified version of scipy. Pull Request:
https://github.com/scipy/scipy/pull/10844
---------------------------
MIT License
Copyright (c) 2020 Pamphile Tupui ROY
@tupui
tupui / halton_convergence.py
Last active July 20, 2021 17:37
Integration convergence using Halton sequence: scrambling effect
"""Integration convergence using Halton sequence: scrambling effect.
Compute the convergence rate for integrating functions using Halton low
discrepancy sequence [1]_. We are interested in the effect of scrambling [2]_.
Two sets of functions are considered:
(i) The first set of functions are synthetic examples specifically designed
to verify the correctness of the implementation [4]_.
@tupui
tupui / sobol_convergence.py
Last active February 5, 2021 07:48
Integration convergence using Sobol' sequence: removing the first point
"""Integration convergence using Sobol' sequence: removing the first point.
Compute the convergence rate for integrating functions using Sobol' low
discrepancy sequence [1]_. We are interested in measuring the effect of
removing the first point of the sequence ([0, ...]).
Two sets of functions are considered:
(i) The first set of functions are synthetic examples specifically designed
to verify the correctness of the implementation [3]_.
@tupui
tupui / perturb_discrepancy.py
Created January 28, 2019 22:34
Compute discrepancy for an elementary perturbation of a LHS - For statsmodels
from functools import lru_cache
import numpy as np
import copy
import openturns as ot
from statsmodels.tools import sequences
dim = 2
n_samples = 20
doe_init = np.array(ot.SobolSequence(dim).generate(n_samples))
disc_init = sequences.discrepancy(doe_init)
@tupui
tupui / moment_independent_visually.py
Created December 7, 2018 16:11
Visual explanation of Moment independent sensitivity analysis
r"""Visual explanation of Moment independent sensitivity analysis.
Moment-based method are based on the whole PDF to mitigate these
issues (Borgonovo2007). Based on the unconditional PDF, a conditional PDF per
parameter is computed. The more the conditional PDF deviates from the
unconditional PDF, the more the parameter has an impact on the quantity of
interest. The same procedure can be done using the Empirical Cumulative
Density Function (ECDF), respectively with the unconditional ECDF.
This visually shows this procedure. Bins of samples (red circles) are used to
compute a conditional PDF of the output. This PDF is compared to the
@tupui
tupui / sobol_visually.py
Created December 7, 2018 16:03
Visual explanation of first order Sobol' indices
r"""Visual explanation of Sobol' indices.
Sobol' indices are metrics to express sensitivity of the output from
perturbations comming from input parameters. First order indices write
.. math:: S_{x_i} = \frac{\mathbb{V}_i(Y)}{\mathbb{V}[Y]} =
\frac{\mathbb{\mathbb{V}}[\mathbb{E}(Y|x_i)]}{\mathbb{V}[Y]}
The following is using the Ishigami function
@tupui
tupui / cosi.py
Created September 4, 2018 11:52
Cosine transformation sensitivity indices
"""Cosine transformation sensitivity indices.
Using a Discrete Cosine Transformation (DCT), it is possible to compute
first order sensitivity indices.
Reference:
Plischke E., How to compute variance-based sensitivity indicators with your
spreadsheet software, Environmental Modelling & Software,
2012. DOI: 10.1016/j.envsoft.2012.03.004
@tupui
tupui / minimum_spanning_tree.py
Created July 28, 2018 00:11
Minimum Spanning Tree applied to Design of Experiments
"""Minimum Spanning Tree.
MST is used here as a discrepancy criterion.
Comparing two different designs: the higher the mean, the better the design is
in terms of space filling.
---------------------------
MIT License
@tupui
tupui / sobol_saltelli.py
Last active January 24, 2024 13:55
Sobol' variance based sensitivity indices based on Saltelli2010 in python
"""Sobol' indices.
Compute Sobol' variance based sensitivity indices.
Use formulations from Saltelli2010.
Reference:
Saltelli et al. Variance based sensitivity analysis of model output. Design and estimator for the total sensitivity index,
Computer Physics Communications, 2010. DOI: 10.1016/j.cpc.2009.09.018
@tupui
tupui / pod.py
Created June 20, 2018 12:25
Playing with Proper Orthogonal Decomposition in python using numpy
"""Proper Orthogonal Decomposition.
Demonstrate how to use it.
---------------------------
MIT License
Copyright (c) 2018 Pamphile Tupui ROY