Skip to content

Commit 2af6ad1

Browse files
Using Latin hypercube sampler for Prior.draw (#521)
* Using Latin hypercube sampler instead for `Prior.draw` * Testing sampling that sampling does not crash in the continous integration tests --------- Co-authored-by: Tuomo Salmi <t.h.j.salmi@uva.nl> Co-authored-by: Tuomo Salmi <tuomo.salmi@helsinki.fi>
1 parent 6057991 commit 2af6ad1

16 files changed

Lines changed: 256 additions & 19 deletions

File tree

.github/workflows/ci_tests.yml

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ jobs:
3535
python=${{ matrix.python-version }}
3636
- name: mamba installs
3737
run: |
38-
micromamba install flake8 pytest
38+
micromamba install flake8 pytest h5py "ultranest>=4.0"
3939
- name: Set up GCC
4040
run: |
4141
sudo apt-get install -y gcc
@@ -49,6 +49,23 @@ jobs:
4949
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
5050
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
5151
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
52+
#- name: multinest and pymultinest install (seems working but the pytest below still cannot find the MultiNest library files)
53+
# run: |
54+
# sudo apt-get install cmake libblas-dev liblapack-dev libatlas-base-dev
55+
# sudo apt install mpich
56+
# git clone https://github.com/farhanferoz/MultiNest.git multinest
57+
# cd multinest/MultiNest_v3.12_CMake/multinest/
58+
# mkdir build
59+
# cd build
60+
# CC=gcc FC=mpif90 CXX=g++ cmake -DCMAKE_{C,CXX}_FLAGS="-O3 -march=native -funroll-loops" -DCMAKE_Fortran_FLAGS="-O3 -march=native -funroll-loops" ..
61+
# make
62+
# cd ../../../../
63+
# git clone https://github.com/JohannesBuchner/PyMultiNest.git pymultinest
64+
# cd pymultinest
65+
# python setup.py install
66+
# cd ..
67+
# export LD_LIBRARY_PATH=$(pwd)/multinest/MultiNest_v3.12_CMake/multinest/lib/:$LD_LIBRARY_PATH
68+
# echo $LD_LIBRARY_PATH
5269
- name: install X-PSI package
5370
run: |
5471
python setup.py install

CHANGELOG.rst

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,43 @@ and this project adheres to
3333
.. Attribution
3434
.. ^^^^^^^^^^^
3535
36+
37+
[v3.0.6] - 2025-05-12
38+
~~~~~~~~~~~~~~~~~~~~~
39+
40+
Summary
41+
^^^^^^^
42+
43+
* Drawing samples from prior to now use Latin hypercube sampler (LHS) to more uniformly draw samples over high-dimensions.
44+
45+
Added
46+
^^^^^
47+
48+
* Continuous integration test for sampling with UltraNest added.
49+
50+
Changed
51+
^^^^^^^
52+
53+
* `Prior.draw` modified to use `scipy.stats.qmc.LatinHypercube` instead of `numpy.random.rand` for drawing samples from prior distribution.
54+
* `Prior.estimate_hypercube_frac` modified to accept the kwarg `LHS_seed` to enable reproducible LHS.
55+
* `Prior.unit_hypercube_frac` modified to accept the kwarg `LHS_seed` to enable reproducible LHS.
56+
* `NestedSampler.__call__` accepts `LHS_seed` as a kwarg to passs to `Prior.unit_hypercube_frac`
57+
* `examples/examples_fast/Sampling.ipynb`: `runtime_params` includes a fixed `LHS_seed`.
58+
* `examples.examples_fast.Modules.main_IS_likelihood.runtime_params` includes a fixed `LHS_seed`.
59+
* `examples.examples_fast.Modules.main_IS_prior.runtime_params` includes a fixed `LHS_seed`.
60+
* `examples.examples_fast.Modules.main.runtime_params` includes a fixed `LHS_seed`.
61+
* `examples.examples_modeling_tutorial.TestRun_BB.runtime_params` includes a fixed `LHS_seed`.
62+
* `examples.examples_modeling_tutorial.TestRun_Num.runtime_params` includes a fixed `LHS_seed`.
63+
* `examples.examples_modeling_tutorial.TestRun_NumBeam.runtime_params` includes a fixed `LHS_seed`.
64+
* `examples.examples_modeling_tutorial.TestRun_PolNum_split_inference.runtime_params` includes a fixed `LHS_seed`.
65+
66+
Attribution
67+
^^^^^^^^^^^
68+
69+
Devarshi Choudhury
70+
Tuomo Salmi
71+
72+
3673
[v3.0.5] - 2025-03-19
3774
~~~~~~~~~~~~~~~~~~~~~
3875

@@ -42,7 +79,7 @@ Summary
4279
* Issues with phase bin interpolations were fixed when using the time-invariant version of the Everywhere class.
4380

4481
Fixed
45-
^^^^^^^
82+
^^^^^
4683

4784
* Phase bin interpolations are now skipped if having only one phase bin during the likelihood calculation (``xpsi/likelihoods/default_background_marginalisation.pyx``) or during the data synthesisation (``xpsi/tools/synthesise.pyx``). Previously, these resulted in errors.
4885

@@ -106,6 +143,7 @@ Changed
106143

107144
Attribution
108145
^^^^^^^^^^^
146+
109147
Devarshi Choudhury,
110148
Tuomo Salmi,
111149
Bas Dorsman

docs/source/conf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@
8080
# The short X.Y version.
8181
version = '3.0-b'
8282
# The full version, including alpha/beta/rc tags.
83-
release = '3.0.5'
83+
release = '3.0.6'
8484

8585
# The language for content autogenerated by Sphinx. Refer to documentation
8686
# for a list of supported languages.

examples/examples_fast/Modules/main.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@
155155
'evidence_tolerance': 0.1,
156156
'max_iter': 100, #-1,
157157
'seed' : 0, # Fixing the seed
158+
'LHS_seed': 42, # Fixing the LHS seed for hypercube fraction estimation
158159
'verbose': True}
159160

160161

examples/examples_fast/Modules/main_IS_likelihood.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@
155155
'evidence_tolerance': 0.1,
156156
'max_iter': 100, #-1,
157157
'seed' : 0, # Fixing the seed
158+
'LHS_seed': 42, # Fixing the LHS seed for hypercube fraction estimation
158159
'verbose': True}
159160

160161

examples/examples_fast/Modules/main_IS_prior.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@
152152
'evidence_tolerance': 0.1,
153153
'max_iter': 100, #-1,
154154
'seed' : 0, # Fixing the seed
155+
'LHS_seed': 42, # Fixing the LHS seed for hypercube fraction estimation
155156
'verbose': True}
156157

157158

examples/examples_fast/Sampling.ipynb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -781,7 +781,7 @@
781781
},
782782
{
783783
"cell_type": "code",
784-
"execution_count": 20,
784+
"execution_count": null,
785785
"metadata": {
786786
"scrolled": true
787787
},
@@ -804,7 +804,8 @@
804804
"# 'wrapped_params': wrapped_params,\n",
805805
"# 'evidence_tolerance': 0.1,\n",
806806
"# 'max_iter': -1,\n",
807-
"# 'seed' : 0, # Fixing the seed \n",
807+
"# 'seed' : 0, # Fixing the seed\n",
808+
"# 'LHS_seed': 42, # Fixing the LHS seed for hypercube fraction estimation', \n",
808809
"# 'verbose': True}\n",
809810
"\n",
810811
"# xpsi.Sample.nested(likelihood, prior, **runtime_params)\n",

examples/examples_modeling_tutorial/TestRun_BB.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -435,6 +435,7 @@ def transform(self, p, **kwargs):
435435
'evidence_tolerance': 0.5,
436436
'seed': 7,
437437
'max_iter': 100,# manual termination condition for short test
438+
'LHS_seed': 42, # Fixing the LHS seed for hypercube fraction estimation
438439
'verbose': True}
439440

440441
xpsi.set_phase_interpolant('Akima')

examples/examples_modeling_tutorial/TestRun_Num.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -616,6 +616,7 @@ def transform(self, p, **kwargs):
616616
'wrapped_params': wrapped_params,
617617
'evidence_tolerance': 0.5,
618618
'seed': 7,
619+
'LHS_seed': 42, # Fixing the LHS seed for hypercube fraction estimation
619620
'max_iter': 100, # manual termination condition for short test
620621
'verbose': True}
621622

examples/examples_modeling_tutorial/TestRun_NumBeam.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -586,6 +586,7 @@ def transform(self, p, **kwargs):
586586
'wrapped_params': wrapped_params,
587587
'evidence_tolerance': 0.5,
588588
'seed': 7,
589+
'LHS_seed': 42, # Fixing the LHS seed for hypercube fraction estimation
589590
'max_iter': 100, # manual termination condition for short test
590591
'verbose': True}
591592

0 commit comments

Comments
 (0)