SepiaParam

Each SepiaParam object represents a matrix-valued parameter in the model.

class sepia.SepiaParam(val, name, val_shape=1, dist='Normal', params=None, bounds=None, mcmcStepType='Uniform', mcmcStepParam=0.1, orig_range=None, theta_fcon=None)

SepiaParam class contains current value, shape, name, and prior for a single matrix-valued parameter in the model.

Variables
  • val (numpy.ndarray) – current parameter value

  • val_shape (tuple) – shape of parameter value array

  • fixed (numpy.ndarray(dtype=bool)) – whether certain elements of the parameter should be fixed (will not be sampled)

  • name (string) – name of parameter (eg ‘betaU’, ‘theta’)

  • refVal (numpy.ndarray) – reference value, used during MCMC to store previous value in case proposal is rejected

  • prior (sepia.SepiaPrior) – encapsulates prior information for this parameter

  • mcmc (sepia.SepiaMCMC) – encapsulates MCMC information and draws for this parameter

  • orig_range (list) – range for untransformed parameter, if transformation was applied (currently applies only to ‘theta’)

Initialize SepiaParam object, which initializes the contained SepiaPrior and SepiaMCMC objects as well.

Parameters
  • val (np.ndarray/float) – starting value (if scalar, will be expanded to val_shape array)

  • name (string) – parameter name

  • val_shape (tuple) – shape of parameter array

  • dist (string) – prior distribution name in [‘Normal’, ‘Gamma’, ‘Beta’, ‘Uniform’]

  • params (list/NoneType) – list of ndarrays, params for prior, or None to use default parameters

  • bounds (list/NoneType) – list of bounds for parameter values (can be inf), or None to use default bounds

  • mcmcStepType (string) – step type for MCMC (eg ‘Uniform’, ‘BetaRho’, ‘PropMH’)

  • mcmcStepParam (numpy.ndarray/float) – step size parameter (has val_shape or scalar is expanded to that shape)

  • orig_range (list) – range for untransformed parameter (applicable for theta)

  • theta_fcon (function/NoneType) – constraint function for theta param

Raises

ValueError – if non-scalar val doesn’t match val_shape

calc_accept()

Calculate whether each draw was rejected or accepted.

Returns

numpy.ndarray – 0/1 whether accepted or not

calc_accept_rate()

Calculate acceptance rate.

Returns

numpy.ndarray of acceptance rates for each index of the parameter

get_num_samples()

Return number of samples in self.mcmc.draws.

mcmc_to_array(sampleset=None, flat=True, untransform_theta=False)

Convert internal representation of MCMC draws to an array.

Parameters
  • sampleset (int/list/NoneType) – indices of samples to use or integer for a single index

  • flat (bool) – flatten array shape of parameter?

  • untransform_theta (bool) – untransform theta to original scale? (no effect on other parameters)

Returns

MCMC draws as np.ndarray

set_val(sval)

Sets val to new value, expanding to val_shape from scalar if needed.

Parameters

sval (numpy.ndarray/float) – new value

untransform_theta(sample_array)

Untransforms an array of theta values using stored t_min and t_max.

Parameters

sample_array (numpy.ndarray) – array of theta samples, (nsamp, theta_size)

Returns

untransformed sample array