sampler

samplermcmc.sampler

class m3c2.sampler.PTSampler(Nchains, loglik, logpi, param_dic, **kwargs)[source]

A parallel tempering MCMC.

adjust_temp(ims, ratio, betas)[source]

Adjust temperature ladder.

run_mcmc(niter, pSwap=1, adapt=1000, adapt_tN=10, n0_swap=2500, printN=2000, adapt_t0=1000.0, adapt_nu=100.0, outdir='./', multiproc=True, seeds=None, nproc=None)[source]

Run ptMCMC using multiprocessing.

Args: niter: number of mcmc iteration pSwap: probability of swapping chains n0_swap: number of iteration before starting swap adapt: number of iteration before updating covariance, modes adapt_tN: number of iteration before adjusting temperature ladder adapt_t0: temperature adaptation lag adapt_nu: temperature adaptation time printN: number of iteration before printing convergence info outdir: directory where to save chain data multiproc: enabling/disabling multiprocessing nproc: number of processes

Returns: list of Chain objects: see output files to get accumulated points and statistics.

swap(num, ims, y0, Ly0, y1, Ly1)[source]

Perform chain swap.

swap_elligibility(num, ims, Ly0, Ly1)[source]

Check if two chains can swap given their current log-lik Ly0 and Ly1.

class m3c2.sampler.Sampler(Nchains, loglik, logpi, param_dic, **kwargs)[source]

A multi chains MCMC

resume(filenames, thin=1, adapt=1000)[source]

Resume chains from previous run.

Data files contains series of point and their associated log-likelihood and log-prob as an (npt x npars+2) array

run_mcmc(niter, adapt=1000, printN=2000, outdir='./', multiproc=True, seeds=None, nproc=None)[source]

Run MCMC using multiprocessing.

Args: niter: number of mcmc iteration adapt: number of iteration before updating covariance, modes printN: number of iteration before printing convergence info outdir: directory where to save chain data multiproc: enabling/disabling multiprocessing nproc: number of processes

Returns: list of Chain objects: see output files to get accumulated points and statistics.

save_to_disk(ims, num=None, stats=False, debug=False)[source]

Save chain data (points and associated likelihood) to numpy file.

Data files contains series of point and their associated likelihood as an (npt x npars+1) array

set_proposals(p=None, priors=None)[source]

Set list of proposals for each chain.

p takes the form of a dictionary (or list of dictionaries, one for each chain), with keys corresponding to proposal function and values to probabilty of using it.

set_starting_point(pars_sampl)[source]

Initialize chain data with a first sample.

m3c2.sampler.set_temperature(dim, nTemp, Tmax=None)[source]

Set initial temperature ladder.