Skip to content
Snippets Groups Projects
Commit 9198cb36 authored by David Métivier's avatar David Métivier
Browse files

up readme and website

parent aee6e54e
No related branches found
No related tags found
No related merge requests found
Pipeline #297361 passed
......@@ -2,55 +2,86 @@
[[_TOC_]]
A set of R and Julia scripts for the application of Approximate Bayesian Computation with Deep Learning and Conformal Prediction.
This repository is an add-on of: Meili Baragatti, Bertrand Cloez, David Métivier, Isabelle Sanchez. Approximate Bayesian Computation with Deep Learning and Conformal prediction.
This repository contains the Supplementary Material for the paper, an add-on to: *Approximate Bayesian Computation with Deep Learning and Conformal Prediction* by Meili Baragatti, Bertrand Cloez, David Métivier, and Isabelle Sanchez.
[https://doi.org/10.48550/arXiv.2406.04874](https://doi.org/10.48550/arXiv.2406.04874). 2024
The following links give the codes used to obtain and reproduce the results of the article. The codes are in Julia for the MA(2), Lotka-Volterra and Phytoplankton dynamics in lake examples, and in R for the Gaussian Field 2D example.
The following links provide the code used to obtain and reproduce the results of the article. The code is written in Julia for the MA(2), Lotka-Volterra, and Phytoplankton dynamics in a lake examples, and in R for the 2D Gaussian Field example.
- [2D Gaussian Field example](https://mistea.pages.mia.inra.fr/codes_articles/abcdconformal/R/GaussianFields/Comparaison_ABCD_conv2d_conformal.html) (1 parameter)
- [MA(2) example](https://mistea.pages.mia.inra.fr/codes_articles/abcdconformal/julia/MA2/ABC_Conformal_MA2.html) (2 parameters) → A well-known toy Bayesian example.
- [Discrete Lotka-Volterra example](https://mistea.pages.mia.inra.fr/codes_articles/abcdconformal/julia/LoktaVolterra/ABC_Conformal_LV.html) (3 parameters) → A very challenging case for some extreme parameter values.
- [Phytoplankton dynamics in a lake with a toy model example](https://mistea.pages.mia.inra.fr/codes_articles/abcdconformal/julia/Lake_norm/ABC_Conformal_Lake.html) (9 parameters) → A high-dimensional example.
- [Gaussian Field example](https://mistea.pages.mia.inra.fr/codes_articles/abcdconformal/R/GaussianFields/Comparaison_ABCD_conv2d_conformal.html) (1 parameter)
- [MA(2) example](https://mistea.pages.mia.inra.fr/codes_articles/abcdconformal/julia/MA2/ABC_Conformal_MA2.html) (2 parameters) -> Well known toy Bayesian example.
- [Discrete Lotka-Volterra example](https://mistea.pages.mia.inra.fr/codes_articles/abcdconformal/julia/LoktaVolterra/ABC_Conformal_LV.html) (3 parameters) -> Very challenging for some extreme parameters.
- [Phytoplankton dynamics in Lake with a toy model example](https://mistea.pages.mia.inra.fr/codes_articles/abcdconformal/julia/Lake_norm/ABC_Conformal_Lake.html) (9 parameters) -> High dimensional example.
We are also making the R code available for the MA(2) and Lotka-Volterra examples. The R code is located in the `/R` folder, while the Julia code is in the `/julia` folder.
But we are also making the R codes available, for the MA(2) and Lotka-Volterra examples (the R codes are in the /R folder, while the Julia codes are in the /Julia folder).
You can view all the `html`-rendered reports (in both R and Julia) on the following [website](https://mistea.pages.mia.inra.fr/codes_articles/abcdconformal).
You can visualize ALL the html reports (in R and Julia) in the following [web site](https://mistea.pages.mia.inra.fr/codes_articles/abcdconformal).
Please note that our method was first developed in R, and the examples were later transferred and reworked in Julia. As a result, the Julia code is more sophisticated than the R code, and the results obtained with Julia are sometimes superior to those obtained with R. The speed of Julia allows the examples to be run on much larger datasets than with R.
Please note that our method was first developed in R, and the examples were then transferred and reworked in Julia. As a consequence, the Julia codes are more sophisticated than the R codes, and the results obtained with Julia are sometimes better than those obtained with R. Indeed, the speed of Julia enables the examples to be run on much larger datasets than with R.
---
# License
GPL-3 License INRAE MISTEA 2024-2025
---
# Authors
An article written by:
* @meili.baragatti Institut Agro [web site](https://meilibaragatti.fr/index.php)
* @celine.casenave INRAE MISTEA [web site](https://celinecasenave-mistea-0b1b9f08fc382922ea661dfdcf78e4e0b5910757b.pages.mia.inra.fr/)
* @bertrand.cloez INRAE MISTEA [web site](https://sites.google.com/view/bertrandcloez)
* @david.metivier INRAE MISTEA [web site](https://davidmetivier.mistea.inrae.fr/)
* @isabelle.sanchez INRAE MISTEA [web site](https://mistea.pages.mia.inra.fr/isabellesanchez/)
- **Meili Baragatti** (Institut Agro) – [Website](https://meilibaragatti.fr/index.php)
- **Céline Casenave** (INRAE MISTEA) – [Website](https://celinecasenave-mistea-0b1b9f08fc382922ea661dfdcf78e4e0b5910757b.pages.mia.inra.fr/)
- **Bertrand Cloez** (INRAE MISTEA) – [Website](https://sites.google.com/view/bertrandcloez)
- **David Métivier** (INRAE MISTEA) – [Website](https://davidmetivier.mistea.inrae.fr/)
- **Isabelle Sanchez** (INRAE MISTEA) – [Website](https://mistea.pages.mia.inra.fr/isabellesanchez/)
---
# Installation
## For Julia Quarto notebooks
## For Julia Quarto Notebooks
**Please take care to check the versions of Julia (> 1.10) and Quarto (> 1.6).**
### Settings
Download the `Project.toml` and `Manifest.toml` and datasets and pretrained models if available. Activate and instantiate the environment.
If you are not familiar with Julia, we recommend downloading the latest version using the command line provided on the [official Julia website](https://julialang.org/downloads/).
**Please ensure that you are using Julia (> 1.10) and Quarto (> 1.6).**
For each example, download the `Project.toml` and `Manifest.toml` files (as well as datasets and pretrained models if available) into the associated folder. Then, activate and instantiate the environment in the correct folder:
```julia
cd(@__DIR__) # cd inside the notebook folder where is stored the `Project.toml` (and `Manifest.toml`)
cd(@__DIR__) # Navigate to the notebook folder where `Project.toml` and `Manifest.toml` are stored
import Pkg
Pkg.activate(".") # activate the environment (you can specify another path if needed)
Pkg.pkg"registry add https://github.com/dmetivie/LocalRegistry" # see comment bellow
Pkg.instantiate() # => install all pkgs listed
Pkg.activate(".") # Activate the environment (you can specify another path if needed)
Pkg.pkg"registry add https://github.com/dmetivie/LocalRegistry" # To access ABCMethods.jl and ConcreteDropoutLayer.jl
Pkg.instantiate() # Install all listed packages
```
Then you can run cell by cell the code or use Quarto render function (for example: `quarto render .\julia\Lake_norm\ABC_Conformal_Lake.qmd --to html`) to run the whole notebook at once.
> [!WARNING]
> In Julia, the first time you execute a command, it might take some time. This is particularly true when installing and precompiling all required packages.
For this project, we developed two packages that are not yet in the official Julia registry
- [ABCMethods.jl](https://github.com/dmetivie/ABCMethods.jl): ABC methods used in the paper.
- [ConcreteDropoutLayer.jl](https://github.com/dmetivie/ConcreteDropoutLayer.jl): `Lux.jl` version of the Concrete Dropout layer. Inspired by this [Python version](https://github.com/aurelio-amerio/ConcreteDropout).
The line `Pkg.pkg"registry add https://github.com/dmetivie/LocalRegistry"` (only needed once) tells your package manager where to find these two packages.
### GPUs and reproducibility
> [!WARNING]
> We trained all the Neural Network models (ABC-CNN and ABC-Conformal) with the [`Lux.jl`](https://lux.csail.mit.edu/stable/) deep learning package using GPUs with the extansion `LuxCuda.jl` on NVIDIA GPUs. This significantly improved training times (by at least 20x for larger applications).
> 1) Make sure you do have compatible GPUs or consult the [Lux GPU page](https://lux.csail.mit.edu/stable/#Want-GPU-Support?) to use other type of models. If you do not have GPUs just comment out the line `using LuxCUDA` and set `dev = cpu_device()`.
> 2) Despite trying our best to make the notebooks 100% reproducible from scratch -- providing the `Manifest.toml` of packages version, setting the initial random seed and configuring `Lux.jl` to “seed” its layers -- GPU operations can still exhibit some non-determinism (e.g. [PyTorch doc](https://pytorch.org/docs/stable/generated/torch.use_deterministic_algorithms.html#torch.use_deterministic_algorithms) for discussion and reference about this) due to optimizations that prioritize speed over reproducibility. As a result, training the models across different sessions, software versions, GPUs, or computers may yield slightly varying outcomes.
To accelerate notebooks, we provide in for the [Discrete Lotka-Volterra example](https://mistea.pages.mia.inra.fr/codes_articles/abcdconformal/julia/LoktaVolterra/ABC_Conformal_LV.html) and [Lake toy model example](https://mistea.pages.mia.inra.fr/codes_articles/abcdconformal/julia/Lake_norm/ABC_Conformal_Lake.html) the pre-trained neural networks models as well as the datasets (even if they are fast to regenerate).
The code to train them from scratch is also provided.
In the [MA(2) example](https://mistea.pages.mia.inra.fr/codes_articles/abcdconformal/julia/MA2/ABC_Conformal_MA2.html), we do not provide this pretrained model as it is the most lightweight example.
### Running the notbooks
You can run cell by cell the code or use Quarto render function (for example: `quarto render julia/Lake_norm/ABC_Conformal_Lake.qmd --to html`) to run the whole notebook at once.
We tested it works on Linux and Windows. However, we did notice on one of our other computers an error when using Quarto render function `ERROR: Malt.TerminatedWorkerException()` that we could not yet debug. If you encounter this, try deactivating the GPU package or running the notebook cell by cell.
## For R with R markdown notebooks
......@@ -88,7 +119,7 @@ ABCDconformal
|-> GaussianFields: contains codes for GaussianFields example
|-> Concrete_Dropout_YGal_fix_tf_2_David.R
|-> Spatial_Concrete_Dropout_YGal_tf_2_fix.R
|-> Julia
|-> julia
|-> MA2: contains codes for MA2 example
|-> LoktaVoltera: contains codes for Lokta Voltera
|-> Lake_norm
......
......@@ -14,9 +14,20 @@
<h1 class="text-center text-primary mb-4">
Notebooks for "Approximate Bayesian Computation with Deep Learning and Conformal Prediction" paper
</h1>
<!-- R Notebooks Section -->
<h2 class="text-secondary">R Notebooks</h2>
<p>This page contains the Supplementary Material for the paper, an
add-on to: <em>Approximate Bayesian Computation with Deep Learning and
Conformal Prediction</em> by Meili Baragatti, Bertrand Cloez, David
Métivier, and Isabelle Sanchez.<br />
<a href="https://doi.org/10.48550/arXiv.2406.04874">https://doi.org/10.48550/arXiv.2406.04874</a>.
2024
</p>
<p>The following links provide the code used to obtain and reproduce the
results of the article. The code is written in Julia for the MA(2),
Lotka-Volterra, and Phytoplankton dynamics in a lake examples, and in R
for the 2D Gaussian Field example. The GitLab repository containing all the files can be accessed <a
href="https://forgemia.inra.fr/mistea/codes_articles/abcdconformal">here</a> </p>
<!-- Julia Notebooks Section -->
<h2 class="text-secondary mt-4">Julia Quarto Notebooks</h2>
<table class="table table-striped table-hover">
<thead class="table-dark">
<tr>
......@@ -26,22 +37,108 @@
</thead>
<tbody>
<tr>
<td><a href="https://mistea.pages.mia.inra.fr/codes_articles/abcdconformal/R/GaussianFields/Comparaison_ABCD_conv2d_conformal.html">Gaussian Fields</a></td>
<td>Gaussian Field example. One parameter to estimate.</td>
<td><a
href="https://mistea.pages.mia.inra.fr/codes_articles/abcdconformal/julia/MA2/ABC_Conformal_MA2.html">MA(2)</a>
</td>
<td>MA(2) time series model. Well known toy Bayesian example with 2 parameters.</td>
</tr>
<tr>
<td><a href="https://mistea.pages.mia.inra.fr/codes_articles/abcdconformal/R/MA2/MA2_last-one.html">MA(2)</a></td>
<td>MA(2) time series model. Well known toy Bayesian example with two parameters.</td>
<td><a
href="https://mistea.pages.mia.inra.fr/codes_articles/abcdconformal/julia/LoktaVolterra/ABC_Conformal_LV.html">Discrete
Lotka-Volterra</a></td>
<td>ABC-based inference for predator-prey dynamics with 3 parameters. Very challenging for some
extreme parameters.</td>
</tr>
<tr>
<td><a href="https://mistea.pages.mia.inra.fr/codes_articles/abcdconformal/R/LoktaVolterra/Lokta_Volterra_last-one.html">Discrete Lotka-Volterra</a></td>
<td>ABC-based inference for predator-prey dynamics. Very challenging for some extreme parameters. Three parameters.</td>
<td><a
href="https://mistea.pages.mia.inra.fr/codes_articles/abcdconformal/julia/Lake_norm/ABC_Conformal_Lake.html">Phytoplankton
Dynamics</a></td>
<td>Toy model of phytoplankton dynamics in a lake. "High" dimensional example with 9 parameters.
</td>
</tr>
</tbody>
</table>
<h3 id="settings">Settings</h3>
<p>If you are not familiar with Julia, we recommend downloading the
latest version using the command line provided on the <a href="https://julialang.org/downloads/">official
Julia website</a>.</p>
<p><strong>Please ensure that you are using Julia (&gt; 1.10) and Quarto
(&gt; 1.6).</strong></p>
<p>For each example, download the <code>Project.toml</code> and
<code>Manifest.toml</code> files (as well as datasets and pretrained
models if available) into the associated folder. Then, activate and
instantiate the environment in the correct folder (see notebooks for more details).
</p>
<p>For this project, we developed two packages that are not yet in the
official Julia registry</p>
<ul>
<li><a href="https://github.com/dmetivie/ABCMethods.jl">ABCMethods.jl</a>: ABC
methods used in the paper.</li>
<li><a href="https://github.com/dmetivie/ConcreteDropoutLayer.jl">ConcreteDropoutLayer.jl</a>:
<code>Lux.jl</code> version of the Concrete Dropout layer. Inspired by
this <a href="https://github.com/aurelio-amerio/ConcreteDropout">Python
version</a>.
</li>
The line
<code>Pkg.pkg"registry add https://github.com/dmetivie/LocalRegistry"</code>
(only needed once) tells your package manager where to find these two
packages.
</ul>
<h3 id="gpus-and-reproducibility">GPUs and reproducibility</h3>
<p>We trained all the Neural Network models (ABC-CNN and ABC-Conformal)
with the <a href="https://lux.csail.mit.edu/stable/"><code>Lux.jl</code></a> deep
learning package using GPUs with the extansion <code>LuxCuda.jl</code>
on NVIDIA GPUs. This significantly improved training times (by at least
20x for larger applications).</p>
<ol>
<li>
<p>Make sure you do have compatible GPUs or consult the <a
href="https://lux.csail.mit.edu/stable/#Want-GPU-Support?">Lux GPU
page</a> to use other type of models. If you do not have GPUs just
comment out the line <code>using LuxCUDA</code> and set
<code>dev = cpu_device()</code>.
</p>
</li>
<li>
<p>Despite trying our best to make the notebooks 100% reproducible
from scratch -- providing the <code>Manifest.toml</code> of packages
version, setting the initial random seed and configuring
<code>Lux.jl</code> to “seed” its layers -- GPU operations can still
exhibit some non-determinism (e.g. <a
href="https://pytorch.org/docs/stable/generated/torch.use_deterministic_algorithms.html#torch.use_deterministic_algorithms">PyTorch
doc</a> for discussion and reference about this) due to optimizations
that prioritize speed over reproducibility. As a result, training the
models across different sessions, software versions, GPUs, or computers
may yield slightly varying outcomes.
</p>
</li>
</ol>
<p>To accelerate notebooks, we provide in for the <a
href="https://mistea.pages.mia.inra.fr/codes_articles/abcdconformal/julia/LoktaVolterra/ABC_Conformal_LV.html">Discrete
Lotka-Volterra example</a> and <a
href="https://mistea.pages.mia.inra.fr/codes_articles/abcdconformal/julia/Lake_norm/ABC_Conformal_Lake.html">Lake
toy model example</a> the pre-trained neural networks models as well as
the datasets (even if they are fast to regenerate). The code to train
them from scratch is also provided. In the <a
href="https://mistea.pages.mia.inra.fr/codes_articles/abcdconformal/julia/MA2/ABC_Conformal_MA2.html">MA(2)
example</a>, we do not provide this pretrained model as it is the most
lightweight example.</p>
<h3 id="running-the-notbooks">Running the notbooks</h3>
<p>You can run cell by cell the code or use Quarto render function (for
example:
<code>quarto render julia/Lake_norm/ABC_Conformal_Lake.qmd --to html</code>)
to run the whole notebook at once.
</p>
<p>We tested it works on Linux and Windows. However, we did notice on
one of our other computers an error when using Quarto render function
<code>ERROR: Malt.TerminatedWorkerException()</code> that we could not
yet debug. If you encounter this, try deactivating the GPU package or
running the notebook cell by cell.
</p>
<!-- Julia Notebooks Section -->
<h2 class="text-secondary mt-4">Julia Notebooks</h2>
<!-- R Notebooks Section -->
<h2 class="text-secondary">R Markdown Notebooks</h2>
<table class="table table-striped table-hover">
<thead class="table-dark">
<tr>
......@@ -51,24 +148,68 @@
</thead>
<tbody>
<tr>
<td><a href="https://mistea.pages.mia.inra.fr/codes_articles/abcdconformal/julia/MA2/ABC_Conformal_MA2.html">MA(2)</a></td>
<td>MA(2) time series model. Well known toy Bayesian example with two parameters.</td>
<td><a
href="https://mistea.pages.mia.inra.fr/codes_articles/abcdconformal/R/GaussianFields/Comparaison_ABCD_conv2d_conformal.html">Gaussian
Fields</a></td>
<td>Gaussian Field example. Only 1 parameter to estimate. Only example with ABC Random Forest</td>
</tr>
<tr>
<td><a href="https://mistea.pages.mia.inra.fr/codes_articles/abcdconformal/julia/LoktaVolterra/ABC_Conformal_LV.html">Discrete Lotka-Volterra</a></td>
<td>ABC-based inference for predator-prey dynamics. Very challenging for some extreme parameters. Three parameters.</td>
<td><a
href="https://mistea.pages.mia.inra.fr/codes_articles/abcdconformal/R/MA2/MA2_last-one.html">MA(2)</a>
(not in the paper)</td>
<td>MA(2) time series model. Well known toy Bayesian example with two parameters.</td>
</tr>
<tr>
<td><a href="https://mistea.pages.mia.inra.fr/codes_articles/abcdconformal/julia/Lake_norm/ABC_Conformal_Lake.html">Phytoplankton Dynamics</a></td>
<td>Toy model of phytoplankton dynamics in a lake. High dimensional example.</td>
<td><a
href="https://mistea.pages.mia.inra.fr/codes_articles/abcdconformal/R/LoktaVolterra/Lokta_Volterra_last-one.html">Discrete
Lotka-Volterra</a> (not in the paper)</td>
<td>ABC-based inference for predator-prey dynamics with 3 parameters. Very challenging for some
extreme parameters.</td>
</tr>
</tbody>
</table>
<p>We are also making the R code available for the MA(2) and
Lotka-Volterra examples.
Please note that our method was first developed in R, and the
examples were later transferred and reworked in Julia. As a result, the
Julia code is more sophisticated than the R code, and the results
obtained with Julia are sometimes superior to those obtained with R. The
speed of Julia allows the examples to be run on much larger datasets
than with R.</p>
<p><b>Installation instructions</b> Please clone or download the repository and consider the R project
ABCDconformal.Rproj. R software (version &gt;=
4.1.2), the {reticulate v1.28} package and the following R packages:
<code>
library(cowplot)
library(tidyr)
library(plyr)
library(dplyr)
library(ggplot2)
library(GillespieSSA2)
library(bigmemory)
library(bigalgebra)
library(keras)
library(DT)
library(sf)
library(gstat)
library(spdep)
library(foreach)
library(abcrf)</code>
</p>
<p>It is very important to install <strong>version 1.28 of
reticulate</strong> to be able to use our code. You can see our session
info in all our HTML reports.</p>
</div>
<footer class="text-center mt-4 mb-4">
<p>&copy; 2025 Meili Baragatti, Bertrand Cloez, David Métivier, Isabelle Sanchez, <a href="https://mistea.montpellier.hub.inrae.fr/">UMR MISTEA</a></p>
<p>&copy; <b>GPL-3 License INRAE UMR MISTEA 2024-2025</b> Meili Baragatti, Bertrand Cloez, David Métivier,
Isabelle Sanchez</p>
<p> <a href="https://mistea.montpellier.hub.inrae.fr/"><img
src="https://mistea.montpellier.hub.inrae.fr/var/hub_internet_c24_umr_mistea/storage/images/_aliases/inra_logo/configuration-graphique/haut/mistea-logo/35301-1-fre-FR/Mistea-Logo.png"
alt="MISTEA logo" width="250" /></a></p>
</footer>
</body>
</html>
</html>
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment