minaskar / pocomc Goto Github PK
View Code? Open in Web Editor NEWpocoMC: A Python implementation of Preconditioned Monte Carlo for accelerated Bayesian Computation
Home Page: https://pocomc.readthedocs.io
License: GNU General Public License v3.0
pocoMC: A Python implementation of Preconditioned Monte Carlo for accelerated Bayesian Computation
Home Page: https://pocomc.readthedocs.io
License: GNU General Public License v3.0
Really excited to try out your sampler - I'm writing the CosmoSIS interface now.
One thing that would help would be being able to save derived parameters, so e.g. we can make sigma_8 - Omega_m plots after sampling in A_s without further processing. Not sure how easy that is here - it might clash with your vectorization tests.
I got these two minor warnings when I am running pytest. Please consider adjusting the testing scripts and code to remove the warnings.
platform linux -- Python 3.9.12, pytest-7.1.2, pluggy-1.0.0
rootdir: /mnt/home/wwong/Software/PublicCode/pocomc
collected 33 items
tests/test_flow.py .............. [ 42%]
tests/test_pearson.py . [ 45%]
tests/test_plotting.py ... [ 54%]
tests/test_sampler.py ..... [ 69%]
tests/test_scaler.py ..... [ 84%]
tests/test_state.py .... [ 96%]
tests/test_tools.py . [100%]
=========================================================== warnings summary ===========================================================
pocomc/scaler.py:1
/mnt/home/wwong/Software/PublicCode/pocomc/pocomc/scaler.py:1: DeprecationWarning: the imp module is deprecated in favour of importlib; see the module's documentation for alternative uses
import imp
tests/test_flow.py::FlowTestCase::test_logprob_float64
/mnt/home/wwong/Software/PublicCode/pocomc/pocomc/tools.py:239: UserWarning: Float64 data is currently unsupported, casting to Float32. Output will also have type Float32.
warnings.warn(f"Float64 data is currently unsupported, casting to Float32. Output will also have type Float32.")
-- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html
=================================================== 33 passed, 2 warnings in 58.36s
====================================================
In Basic example section of the readme, nwalkers is used in generating the prior but it is not defined. Please change it to n_particles.
Thanks for your sampler and I am excited to use it. But sometime particles could walk exceed prior bounds then rising an error. It seems like the issue of transformation between parameters.
C:\Users\Loyal.Aujust\AppData\Local\Programs\Python\Python38\lib\site-packages\pocomc\scaler.py:386: RuntimeWarning: invalid value encountered in logaddexp p = np.exp(-np.logaddexp(0, -u[:, self.mask_both])) C:\Users\Loyal.Aujust\AppData\Local\Programs\Python\Python38\lib\site-packages\numpy\linalg\linalg.py:2099: RuntimeWarning: invalid value encountered in slogdet sign, logdet = _umath_linalg.slogdet(a, signature=signature)
What is the possible reason for this issue? thanks for helping!
Two namings are used for n_particles
/nparticles
and n_dim
/ndim
in docs/build/jupyter_execute/pages/quickstart.ipynb
.
The authors claim
Regarding 1., although I do expect a speed-up coming from the reparametrization using normalizing flow, it would be better to see a demonstration of the speed-up to some degree. I know wall time demonstration is a bit annoying due to many other factors in optimizing a program, so a reduction in the total number of calls of the likelihood + benchmarking of normalizing flow would be apperciated.
Regarding 2., I don't see this parallelisation benchmark anywhere in the doc. Can the author provide a small example to show the scaling relation to some moderate number of cores (e.g. 32-128)?
I'm running an inference where my log_like function could return -np.inf even for parameters within the prior. I'm encountering this error message:
~/anaconda3/envs/python3/lib/python3.8/site-packages/pocomc/sampler.py in _resample(self, u, x, J, L, P)
615
616 assert np.all(~np.isnan(self.logw))
--> 617 assert np.all(np.isfinite(self.logw))
618 assert np.all(~np.isnan(w))
619 assert np.all(np.isfinite(w))
AssertionError:
The progress bar is: Iter: 1it [00:00, 264.16it/s, beta=1.6e-10, calls=768, ESS=0.949, logZ=-.0674, accept=0.234, N=0, scale=1]
I read the code and my impression is that is error message is entirely expected? First, self.L is initiated as -np.inf where only the in-prior samples are replaced by the likelihood:
self.L = np.full((len(self.x),), -np.inf)
self.L[finite_prior_mask] = self._log_like(self.x[finite_prior_mask])
And later self.logw is calculated as
self.logw = logw_prev + self.L * (beta - beta_prev)
Maybe pocomc requires log_like to be finite when log_prior is finite?
Hello I have been using the pococmc package to sample parameters of an ODE-based system. Occasionally, an error arises in my runs: AttributeError: 'float' object has no attribute 'item'
. This happens at different times depending on which seed I use, and sometimes doesn't happen at all. It seems like sigma is a Tensor object but is somehow incorrectly being typed as a float? Any ideas how to fix this?
Error trace example:
sampler.run(p_0, ess, gamma, int(n_dim), int(1000*n_dim), progress=True)
File "/opt/miniconda3/envs/pyPoco/lib/python3.10/site-packages/pocomc/sampler.py", line 405, in run
self.u, self.x, self.J, self.L, self.P = self._mutate(
File "/opt/miniconda3/envs/pyPoco/lib/python3.10/site-packages/pocomc/sampler.py", line 532, in _mutate
results = preconditioned_metropolis(
File "/opt/miniconda3/envs/pyPoco/lib/python3.10/site-packages/torch/autograd/grad_mode.py", line 27, in decorate_context
return func(*args, **kwargs)
File "/opt/miniconda3/envs/pyPoco/lib/python3.10/site-packages/pocomc/mcmc.py", line 167, in preconditioned_metropolis
scale=sigma.item() / (2.38 / np.sqrt(n_dim)),
AttributeError: 'float' object has no attribute 'item'
Being able to restart jobs which terminate prematurely would be extremely useful for challenging analyses, especially on HPC clusters which impose maximum time limits.
To be generally useful, restarting should work regardless of what sort of pool was used (number of cores, MPI vs. multiprocessing, etc.).
Hello @minaskar, thanks for using Zuko in pocoMC! I hope you like it ;)
I quickly checked how you were using it, and noticed a potential issue with the following.
Line 55 in 61d7e0f
Here, self.transform
is a torch.distributions.Transform
created with the current weights of self.flow
. This means that updating the parameters of the flow (self.flow
) may not affect self.transform
. Instead, it would be safer to make self.transform
a property that returns self.flow().transform
without storing it, such that they are always tied.
@property
def transform(self):
return self.flow().transform
or, equivalently,
@property
def transform(self):
return self.flow.transform()
In addition, here,
Lines 89 to 91 in 61d7e0f
you can use the call_and_ladj
method on the reverse transformation.
x, logdetj = self.transform.inv.call_and_ladj(u)
And, here,
Lines 121 to 123 in 61d7e0f
you can use the rsample_and_log_prob
method of the flow, which is faster than inv + log_prob.
x, log_p = self.flow().rsample_and_log_prob((size,))
Tell me if you have any issues.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.