Skip to content

Commit

Permalink
Some code refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
mraveri committed Dec 13, 2024
1 parent f534bf9 commit eca8ba3
Show file tree
Hide file tree
Showing 54 changed files with 2,287 additions and 1,020 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ install:
# It uses Python's unittest module to discover and execute all test cases
# located in the 'tensiometer/tests' directory.
test:
@python -m unittest discover tensiometer/tests
@python -m unittest discover tensiometer/tests -p "*_test.py" -vvv -f

# Runs a specific test file using Python's unittest module.
# Usage: make test_file file=<test_filename>
Expand All @@ -35,7 +35,7 @@ coverage_report:
# The '-vvv' flag provides verbose output, and the '-f' flag stops on the first failure.
# After running the tests, it generates a coverage report.
test_with_coverage:
@coverage run -m unittest discover tensiometer/tests -vvv -f
@coverage run -m unittest discover tensiometer/tests -p "*_test.py" -vvv -f
@coverage report

########################################################################################
Expand Down
80 changes: 60 additions & 20 deletions docs/example_notebooks/example_chains_convergence_test.html

Large diffs are not rendered by default.

14 changes: 9 additions & 5 deletions docs/example_notebooks/example_chains_convergence_test.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@
"source": [
"In this notebook we show how to perform moment based tests for the quality of the posterior estimate from different MCMC chains.\n",
"\n",
"We perform these tests considering several different chains obtained with the same sampling scheme but what we discuss can be readily applied to pools of chains from different sources or to two chains obtained with different sampling settings."
"We perform these tests considering several different chains obtained with the same sampling scheme but what we discuss can be readily applied to pools of chains from different sources or to two chains obtained with different sampling settings.\n",
"\n",
"### Table of contents\n",
"1. [The short story](#short): fast summary\n",
"2. [The long story](#long): detailed explanation"
]
},
{
Expand All @@ -36,7 +40,7 @@
"import matplotlib.pyplot as plt\n",
"import numpy as np\n",
"# import the tensiometer tools that we need:\n",
"from tensiometer import utilities\n",
"from tensiometer.utilities import stats_utilities as utilities\n",
"from tensiometer import chains_convergence"
]
},
Expand Down Expand Up @@ -66,7 +70,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"## The short story\n",
"## The short story <a name=\"short\"></a>\n",
"\n",
"We start with a pool of chains. For definitness we assume that we have two. The way in which we have obtained them does not truly matter. \n",
"The only thing that matters is that they should be from the same distribution."
Expand Down Expand Up @@ -160,7 +164,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"## The long story:"
"## The long story: <a name=\"long\"></a>"
]
},
{
Expand Down Expand Up @@ -515,7 +519,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.7"
"version": "3.9.18"
}
},
"nbformat": 4,
Expand Down
72 changes: 54 additions & 18 deletions docs/example_notebooks/example_gaussian_tension.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/example_notebooks/example_gaussian_tension.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
"import IPython\n",
"import numpy as np\n",
"# tensiometer imports:\n",
"from tensiometer import utilities\n",
"from tensiometer.utilities import stats_utilities as utilities\n",
"from tensiometer import gaussian_tension"
]
},
Expand Down Expand Up @@ -573,7 +573,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.7"
"version": "3.9.15"
}
},
"nbformat": 4,
Expand Down
72 changes: 54 additions & 18 deletions docs/example_notebooks/example_measured_parameters.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/example_notebooks/example_measured_parameters.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
"import numpy as np\n",
"import seaborn as sns\n",
"# import the tensiometer tools that we need:\n",
"from tensiometer import utilities\n",
"from tensiometer.utilities import stats_utilities as utilities\n",
"from tensiometer import gaussian_tension"
]
},
Expand Down Expand Up @@ -633,7 +633,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.7"
"version": "3.9.18"
}
},
"nbformat": 4,
Expand Down
349 changes: 187 additions & 162 deletions docs/example_notebooks/example_non_gaussian_tension.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/example_notebooks/example_non_gaussian_tension.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
"\n",
"# import the tensiometer tools that we need:\n",
"import tensiometer\n",
"from tensiometer import utilities\n",
"from tensiometer.utilities import stats_utilities as utilities\n",
"from tensiometer import mcmc_tension"
]
},
Expand Down Expand Up @@ -479,7 +479,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.7"
"version": "3.9.15"
}
},
"nbformat": 4,
Expand Down
604 changes: 325 additions & 279 deletions docs/example_notebooks/example_posterior_profiles.html

Large diffs are not rendered by default.

36 changes: 23 additions & 13 deletions docs/example_notebooks/example_posterior_profiles.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,25 @@
"\n",
"Marco Raveri (<[email protected]>), Cyrille Doux (<[email protected]>), Shivam Pandey (<[email protected]>)\n",
"\n",
"In this notebook we show how to obtain posterior profiles from synthetic probability models, as in [Raveri, Doux and Pandey (2024), arXiv:XXXX.XXXX](https://arxiv.org/abs/XXXX.XXXXX).\n",
"In this notebook we show how to obtain posterior profiles from synthetic probability models, as in [Raveri, Doux and Pandey (2024), arXiv:2409.09101](https://arxiv.org/abs/2409.09101).\n",
"\n",
"If you want more details on how to build normalizing flow based synthetic models for posterior distributions check out the corresponding example notebook."
"If you want more details on how to build normalizing flow based synthetic models for posterior distributions check out the corresponding example notebook.\n",
"\n",
"### Table of contents\n",
"1. [Notebook setup](#setup)\n",
"2. [Flow training](#flows)\n",
"3. [Posterior profiles](#profiles)\n",
"4. [Profile accuracy](#accuracy)\n",
"5. [Real world application](#real)\n",
" 1. [Best constrained parameters profile](#best)\n",
" 2. [Full profile triangle plot](#triangle)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Notebook setup:\n",
"## Notebook setup: <a name=\"setup\"></a>\n",
"\n",
"We start by importing everything and setting up a controlled example:"
]
Expand Down Expand Up @@ -54,7 +63,7 @@
"\n",
"# import the tensiometer tools that we need:\n",
"import tensiometer\n",
"from tensiometer import utilities\n",
"from tensiometer.utilities import stats_utilities as utilities\n",
"from tensiometer.synthetic_probability import synthetic_probability as synprob\n",
"\n",
"# getdist settings to ensure consistency of plots:\n",
Expand Down Expand Up @@ -152,7 +161,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"## Flow training:\n",
"## Flow training: <a name=\"flows\"></a>\n",
"\n",
"We now train a synthetic probability model. Note that we need a flow with good local accuracy since we are going to maximize its value.\n",
"\n",
Expand Down Expand Up @@ -218,7 +227,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"## Posterior profile:\n",
"## Posterior profile: <a name=\"profiles\"></a>\n",
"\n",
"We now want to calculate posterior profiles for our distribution. These are obtained maximizing over all parameters but the ones that are been considered.\n",
"\n",
Expand Down Expand Up @@ -355,7 +364,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"## Profile accuracy tests:\n",
"## Profile accuracy tests: <a name=\"accuracy\"></a>\n",
"\n",
"The profiler calculation is hard. As you might have seen it requires hundreds or thousands of minimization instances. \n",
"\n",
Expand Down Expand Up @@ -455,7 +464,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"## Real world application: cosmological parameter profiles\n",
"## Real world application: cosmological parameter profiles <a name=\"real\"></a>\n",
"\n",
"In this section we show a real example of a profile applied to cosmological parameter posteriors.\n",
"\n",
Expand Down Expand Up @@ -738,9 +747,10 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"### Best constrained parameters profiles\n",
"### Best constrained parameters profiles <a name=\"best\"></a>\n",
"\n",
"As discussed in XXX projection effects arise because of either true non-Gaussianities of the likelihood or because of unconstrained parameter directions. This means that if we looked at the best constrained directions (that maximize prior to posterior gain, as discussed in arXiv:2112.05737) we have a chance of minimizing projection effects. \n",
"As discussed in arXiv:2409.09101\n",
" projection effects arise because of either true non-Gaussianities of the likelihood or because of unconstrained parameter directions. This means that if we looked at the best constrained directions (that maximize prior to posterior gain, as discussed in arXiv:2112.05737) we have a chance of minimizing projection effects. \n",
"\n",
"If you are interested in how to compute best constrained parameter combinations check out the corresponding notebook."
]
Expand Down Expand Up @@ -855,7 +865,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"### Full profile triangle\n",
"### Full profile triangle <a name=\"triangle\"></a>\n",
"\n",
"By now you probably want to look at a full profile triangle plot...\n",
"\n",
Expand Down Expand Up @@ -891,7 +901,7 @@
],
"metadata": {
"kernelspec": {
"display_name": "mlg",
"display_name": "tensiometer",
"language": "python",
"name": "python3"
},
Expand All @@ -905,7 +915,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.7"
"version": "3.9.18"
}
},
"nbformat": 4,
Expand Down
889 changes: 647 additions & 242 deletions docs/example_notebooks/example_synthetic_probability.html

Large diffs are not rendered by default.

Loading

0 comments on commit eca8ba3

Please sign in to comment.