This is the code I used in my research internship at ISAE-Supaero in which I conducted a Study on Optimisation Problems For Importance Sampling.
It contains the functions and notebooks used for the numeric findings of the final report.
More specifically, the internship was aimed at discovering if we could create importance sampling (IS) monte carlo estimators through a compromise between having a finite variance and being close to the optimal IS estimator (in the sense of the Kullback-Leibler divergence). For a more detailed explanation, check the introduction of the final report.
Most of the folders in the project are only to keep and organise the important plots, that is, those that went to the final report.
In terms of code, it is all concentrated in only three files:
IS_tools.pyholds all the important functions for the project, see it as a library if you willmain.ipynbwas used for all the main results and plot generationexpansions.ipynbwas used to expand the assymptotic expansions with Sympy
stage_recherche/
│
├── all_compare/ # Directory that holds the comparison plots between estimators
│ ├── k01/
│ ├── k04/ # The MaxR estimator was created with a max KL divergence of 0.4
│ └── k08/
│
├── CD/ # Tests of the Chaterjee and Diaconis (2018) convergence criterion
│ ├── MaxR/ # Plots for the MaxR estimator
│ ├── MinDiv/ # Plots for the MinDiv estimator
│ └── sigmaA/ # Plots for the optimal estimator
│
├── old/ # Directory for the predecessors of main.ipynb
│ ├── convergence.py
│ └── histograms.py
│
├── plots/
│ ├── assymptotes/ # Plots of the assymptotic expansions
│ ├── gifs/ # Gifs of CD estimators histograms
│
├── StdMC-vs-sigmaA/ # Same as all_compare but only between optimal IS and standard MC
│
├── README.md # Project documentation
├── expansions.ipynb # Sympy expansions
├── IS_tools.py # Definition of all non-sympy functions of the project
└── main.ipynb # Notebook that implements IS_tools functions
To run the two notebooks of this project, you need to have the following installed on your system:
- Python 3.x
- Python package manager (Preferably uv, see more in Setup)
- Julia 1.11.x
You will also need to install the required dependencies listed in the pyproject.toml file.
Be careful, only using
uv syncwill not allow most of the parts of this project to work, since part of it's backbone relies on calculating the mean and standard deviation from the truncated normal distribution which is made with JuliaDistributions.jllibrary, so do not forget to install Julia before running.
Using uv is highly recommendable once this project was created using it. To
install uv from pip is really straight forward:
pip install uvAlternatively, you can look into the uv documentation to see how to install it through a standalone installer for your OS.
Then, to install all dependencies one must simply type:
uv syncIf you don't want to use uv, you can still download the required dependencies
with your usual python package manager (pip, poetry, conda ...). For this,
refer to the dependencies part of the pyproject.toml file to see what
packages need to be downloaded.
To use the Python Julia API PyJulia that is installed on the previous step,
your computer also need to have the Julia programming language, whose
installation you can find in the official website
here.
After that, the code calls Julia from Python and ultimately makes the
calculations using the Distributions.jl library, both of which will need
installation.
First launch Julia on a terminal:
juliaThen install the packages with:
using Pkg
Pkg.add("PyCall")
Pkg.add("Distributions")