pymcmcstat.settings package¶
pymcmcstat.settings.DataStructure module¶
Created on Wed Jan 17 09:03:37 2018
@author: prmiles
-
class
pymcmcstat.settings.DataStructure.
DataStructure
[source]¶ Structure for storing data in MCMC object. The following random data sets will be referenced in examples for the different class methods:
x1 = np.random.random_sample(size = (5, 1)) y1 = np.random.random_sample(size = (5, 2)) x2 = np.random.random_sample(size = (10, 1)) y2 = np.random.random_sample(size = (10, 3))
- Attributes:
-
add_data_set
(x, y, n=None, weight=1, user_defined_object=0)[source]¶ Add data set to MCMC object.
This method must be called first before using any of the other methods within
DataStructure
.mcstat = MCMC() mcstat.data.add_data_set(x = x1, y = y1) mcstat.data.add_data_set(x = x2, y = y2)
This yields the following variables in the data structure.
- xdata (
list
): List of numpy arrays xdata[0] = x1, xdata[0].shape = (5,1)
xdata[1] = x2, xdata[1].shape = (10,1)
- xdata (
- ydata (
list
): List of numpy arrays ydata[0] = y1, ydata[0].shape = (5,2)
ydata[1] = y2, ydata[1].shape = (10,3)
- ydata (
- n (
list
): List of integers.n = [5, 10]
- shape (
list
): List of y.shape.shape = [(5,2),(10,3)]
- weight (
list
): List of weights.weight = [1, 1]
- user_defined_object (
list
): List of objects.user_defined_object = [0,0]
- Args:
- x (
ndarray
): Independent data. Recommend input as column vectors. - y (
ndarray
): Dependent data. Recommend input as column vectors. - n (
list
): List of integers denoting number of data points. - weight (
list
): Weight of each data set. - user_defined_object (User Defined): Any object can be stored in this variable.
- x (
Note
In general, it is recommended that user’s format their data as a column vector. So, if you have nds independent data points, x and y should be [nds,1] or [nds,] numpy arrays. Note if a list is sent, the code will convert it to a numpy array.
-
get_number_of_batches
()[source]¶ Get number of batches in data structure. Essentially, each time you call the
add_data_set()
method you are adding another batch. It is also equivalent to say the number of batches is equal to the length of the list ydata. For example,nb = mcstat.data.get_number_of_batches()
should return
nb = 2
becauselen(mcstat.data.ydata) = 2
.- Returns:
- nbatch (
int
): Number of batches.
- nbatch (
-
get_number_of_data_sets
()[source]¶ Get number of data sets in data structure. A data set is strictly speaking defined as the total number of columns in each element of the ydata list. For example,
nds = mcstat.data.get_number_of_data_sets()
should return
nds = 2 + 3 = 5
because the number of columns in y1 is 2 and the number of columns in y2 is 3.- Returns:
- Number of columns in ydata (
int
)
- Number of columns in ydata (
-
get_number_of_observations
()[source]¶ Get number of observations in data structure. An observation is essentially the total number of rows from each element of the ydata list. For example,
nobs = mcstat.data.get_number_of_observations()
should return
nobs = 5 + 10 = 15
because the number of rows in y1 is 5 and the number of rows in y2 is 10.- Returns:
- Number of rows in ydata (
ndarray
)
- Number of rows in ydata (
pymcmcstat.settings.ModelParameters module¶
Created on Wed Jan 17 09:13:03 2018
@author: prmiles
-
class
pymcmcstat.settings.ModelParameters.
ModelParameters
[source]¶ MCMC Model Parameters.
Example:
mcstat = MCMC() mcstat.parameters.add_model_parameter(name = 'm', theta0 = 1., minimum = -10, maximum = 10) mcstat.parameters.add_model_parameter(name = 'b', theta0 = -5., minimum = -10, maximum = 100) mcstat.parameters.display_model_parameter_settings()
This will display to screen:
Sampling these parameters: name start [ min, max] N( mu, sigma^2) m : 1.00 [-10.00, 10.00] N(0.00, inf) b : -5.00 [-10.00, 100.00] N(0.00, inf)
- Attributes:
-
add_model_parameter
(name=None, theta0=None, minimum=-inf, maximum=inf, prior_mu=array([0.]), prior_sigma=inf, sample=True, local=0, adapt=True)[source]¶ Add model parameter to MCMC simulation.
- Args:
- name (
str
): Parameter name - theta0 (
float
): Initial value - minimum (
float
): Lower parameter bound - maximum (
float
): Upper parameter bound - prior_mu (
float
): Mean value of prior distribution - prior_sigma (
float
): Standard deviation of prior distribution - sample (
bool
): Flag to turn sampling on (True) or off (False) - local (
int
): Local flag - still testing.
- name (
The default prior is a uniform distribution from minimum to maximum parameter value.
-
classmethod
setup_adaptation_indices
(parind, adapt)[source]¶ Setup adaptation parameter indices.
- Args:
- Returns:
..note:
The size of the returned arrays will equal the number of parameters being sampled.
-
classmethod
setup_adapting
(adapt, sample)[source]¶ Setup parameters being adapted.
All parameters that are not being sampled will automatically be thrown out of adaptation. This method checks that the default adaptation status is consistent.
-
pymcmcstat.settings.ModelParameters.
check_noadaptind
(no_adapt, npar)[source]¶ Check if noadaptind is None -> Empty List
-
pymcmcstat.settings.ModelParameters.
check_verbosity
(verbosity)[source]¶ Check if verbosity is None -> 0
-
pymcmcstat.settings.ModelParameters.
generate_default_name
(nparam)[source]¶ Generate generic parameter name. For example, if
nparam = 4
, then the generated name is:names = 'p_{3}'
-
pymcmcstat.settings.ModelParameters.
less_than_or_equal_to_zero
(x)[source]¶ Return result of test on number based on less than or equal to
-
pymcmcstat.settings.ModelParameters.
noadapt_display_setting
(no_adapt)[source]¶ Define display settins if index not being adapted.
-
pymcmcstat.settings.ModelParameters.
prior_display_setting
(x)[source]¶ Define display string for prior.
pymcmcstat.settings.ModelSettings module¶
Created on Wed Jan 17 09:06:51 2018
@author: prmiles
-
class
pymcmcstat.settings.ModelSettings.
ModelSettings
[source]¶ MCMC Model Settings
- Attributes:
-
define_model_settings
(sos_function=None, prior_function=None, prior_type=1, prior_update_function=None, prior_pars=None, model_function=None, sigma2=None, N=None, S20=nan, N0=None, nbatch=None)[source]¶ Define model settings.
- Args:
- sos_function: Handle for sum-of-squares function
- prior_function: Handle for prior function
- prior_type: Pending…
- prior_update_function: Pending…
- prior_pars: Pending…
- model_function: Handle for model function (needed if
sos_function
not specified) - sigma2 (
float
): List of initial error observations. - N (
int
): Number of observations - seeDataStructure
. - S20 (
float
): List of scaling parameter in observation error estimate. - N0 (
float
): List of scaling parameter in observation error estimate. - nbatch (
int
): Number of batch data sets - seeget_number_of_batches()
.
Note
Variables
sigma2, N, S20, N0
, andnbatch
converted tondarray
for subsequent processing.
pymcmcstat.settings.SimulationOptions module¶
Created on Wed Jan 17 09:08:13 2018
@author: prmiles
-
class
pymcmcstat.settings.SimulationOptions.
SimulationOptions
[source]¶ MCMC simulation options.
-
define_simulation_options
(nsimu=10000, adaptint=None, ntry=None, method='dram', printint=None, adaptend=0, lastadapt=0, burnintime=0, waitbar=1, debug=0, qcov=None, updatesigma=False, stats=0, drscale=array([5., 4., 3.]), adascale=None, savesize=0, maxmem=0, chainfile='chainfile', s2chainfile='s2chainfile', sschainfile='sschainfile', covchainfile='covchainfile', savedir=None, save_to_bin=False, skip=1, label=None, RDR=None, verbosity=1, maxiter=None, priorupdatestart=0, qcov_adjust=1e-08, burnin_scale=10, alphatarget=0.234, etaparam=0.7, initqcovn=None, doram=None, rndseq=None, results_filename=None, save_to_json=False, save_to_txt=False, json_restart_file=None)[source]¶ Define simulation options.
- Args:
- nsimu (
int
): Number of parameter samples to simulate. Default is 1e4. - adaptint (
int
): Number of interates between adaptation. Default is method dependent. - ntry (
int
): Number of tries to take before rejection. Default is method dependent. - method (
str
): Sampling method ('mh', 'am', 'dr', 'dram'
). Default is'dram'
. - printint (
int
): Printing interval. - adaptend (
int
): Obsolete. - lastadapt (
int
): Last adaptation iteration (i.e., no more adaptation beyond this point). - burnintime (
int
): - waitbar (
int
): Flag to use progress bar. Default is 1 -> on (otherwise -> off). - debug (
int
): Flag to perform debug. Default is 0 -> off. - qcov (
ndarray
): Proposal parameter covariance matrix. - updatesigma (
bool
): Flag for updating measurement error variance. Default is 0 -> off (1 -> on). - stats (
int
): Calculate convergence statistics. Default is 0 -> off (1 -> on). - drscale (
ndarray
): Reduced scale for sampling in DR algorithm. Default is [5,4,3]. - adascale (
float
): User defined covariance scale. Default is method dependent (untested). - savesize (
int
): Size of chain segments when saving to log files. Default is 0. - maxmem (
int
): Maximum memory available in mega bytes (Obsolete). - chainfile (
str
): File name forchain
log file. - sschainfile (
str
): File name forsschain
log file. - s2chainfile (
str
): File name fors2chain
log file. - covchainfile (
str
): File name forqcov
log file. - savedir (
str
): Output directory of log files. Default is current directory. - save_to_bin (
bool
): Save log files to binary. Default is False. - save_to_txt (
bool
): Save log files to text. Default is False. - skip (
int
): - label (
str
): - RDR (
ndarray
): R matrix for each stage of DR. - verbosity (
int
): Verbosity of display output. - maxiter (
int
): Obsolete. - priorupdatestart
- qcov_adjust (
float
): Adjustment scale for covariance matrix. - burnin_scale (
float
): Scale for burnin. - alphatarget (
float
): Acceptance ratio target. - etaparam (
float
): - initqcovn (
float
): Proposal covariance weight in update. - doram (
int
): Flag to perform'ram'
algorithm (Obsolete). - rndseq (
ndarray
): Random number sequence (Obsolete). - results_filename (
str
): Output file name when saving results structure with json. - save_to_json (
bool
): Save results structure to json file. Default is False. - json_restart_file (
str
): Extract parameter covariance and last sample value from saved json file.
- nsimu (
Note
For the log file names
chainfile, sschainfile, s2chainfile
andcovchainfile
do not include the extension. By specifying whether to save to text or to binary, the appropriate extension will be added.
-