Markov-Chain Monte-Carlo¶
-
class
fitr.inference.mcmc.
MCMC
(generative_model=None, name='FitrMCMCModel')¶ Uses Markov-Chain Monte-Carlo (via PyStan) to estimate models
Attributes: - name : str
Name of the model being fit
- generative_model : GenerativeModel object
Methods
fit(self, data, chains=4, n_iterations=2000, warmup=None, thin=1, seed=None, init=’random’, sample_file=None, algorithm=’NUTS’, control=None, n_jobs=-1, compile_verbose=False, sampling_verbose=False) Runs the MCMC Inference procedure with Stan __initresults(self) (Private) method to initialize MCMCFitResult object -
fit
(data, chains=4, n_iterations=2000, warmup=None, thin=1, seed=None, init='random', sample_file=None, algorithm='NUTS', control=None, n_jobs=-1, compile_verbose=False, sampling_verbose=False)¶ Runs the MCMC Inference procedure with Stan
Parameters: - data : dict
Subject level data
- chains : int > 0
Number of chains in sampler
- n_iter : int
How many iterations each chain should run (includes warmup)
- warmup : int > 0, iter//2 by default
Number of warmup iterations.
- thin : int > 0
Period for saving samples
- seed : int or np.random.RandomState, optional
Positive integer to initialize random number generation
- sample_file : str
File name specifying where samples for all parameters and other saved quantities will be written. If None, no samples will be written
- algorithm : {‘NUTS’, ‘HMC’, ‘Fixed_param’}, optional
Which of Stan’s algorithms to implement
- control : dict, optional
Dictionary of parameters to control sampler’s behaviour (see PyStan documentation for details)
- n_jobs : int, optional
Sample in parallel. If -1, all CPU cores are used. If 1, no parallel computing is used
- compile_verbose : bool
Whether to print output from model compilation
- sampling_verbose : bool
Whether to print intermediate output from model sampling
Returns: - ModelFitResult
Instance containing model fitting results
References
[1] PyStan API documentation (https://pystan.readthedocs.io)