StarVine
starvine.uvar.uvmodels.uv_base.UVmodel Class Reference

Univariate parameterized model base class. More...

Inheritance diagram for starvine.uvar.uvmodels.uv_base.UVmodel:
starvine.uvar.uvmodels.uv_beta.UVBeta starvine.uvar.uvmodels.uv_gamma.UVGamma starvine.uvar.uvmodels.uv_gauss.UVGauss

Public Member Functions

def __init__ (self, paramsString, momtype, bounds, args, kwargs)
 
def setupGMM (self, data, w=1.0, nMoM=None)
 General Method of Moments setup. More...
 
def fitKDE (self, data, args)
 Fit gaussian kernel density fn to data.
 
def setLogPrior (self, logPriorFn)
 Set log of prior distribution

\[ ln(P(\theta)) \]

. More...

 
def setupMCMC (self, nwalkers, params, data, wgts=None, args)
 Initilize the MCMC sampler. More...
 
def fitMCMC (self, iters, pos=None)
 Execute MCMC model parameter fitting. More...
 
def fitMLE (self, data, params0, weights=None, args, kwargs)
 Generic maximum (log)likelyhood estimate of paramers. More...
 

Public Attributes

 nParams
 
 nMomentConditions
 
 internalGMM
 
 kde
 
 logPriorFn
 
 walker_pos
 
 nwalkers
 
 sampler
 

Private Member Functions

def _pdf (self, x, args)
 Pure virtual pdf model function. More...
 
def _logPosterior (self, params, data, wgts)
 Posterior distribution $ F(model|data) \propto P(model)*P(data|model) $

\[ ln(P(model)*P(data|model)) == P(ln(model)) + P(ln(data|model)) \]

.

 
def _paramCheck (input_f)
 Parameter bounds checker. More...
 
def _loglike (self, params, data, wgts)
 

Detailed Description

Univariate parameterized model base class.

Extends the capabilities of the rv_continuous base class of the scipy.stats module with the GMM capabilites of statmodels.sandbox.regression.gmm (general method of moments fitting).

With the combined capability of scipy and statmodels, it is easy to obtain maximum likelyhood and MoM estimators for univariate model parameters.

Methods inherited from scipy.stats.rv_continuous:

rvs(*args, **kwds)  Random variates of given type.
pdf(x, *args, **kwds)  Probability density function at x of the given RV.
logpdf(x, *args, **kwds)  Log of the probability density function at x of the given RV.
cdf(x, *args, **kwds)  Cumulative distribution function of the given RV.
logcdf(x, *args, **kwds)  Log of the cumulative distribution function at x of the given RV.
sf(x, *args, **kwds)  Survival function (1 - cdf) at x of the given RV.
logsf(x, *args, **kwds)  Log of the survival function of the given RV.
ppf(q, *args, **kwds)  Percent point function (inverse of cdf) at q of the given RV.
isf(q, *args, **kwds)  Inverse survival function (inverse of sf) at q of the given RV.
moment(n, *args, **kwds)  n-th order non-central moment of distribution.
stats(*args, **kwds)  Some statistics of the given RV.
entropy(*args, **kwds)  Differential entropy of the RV.
expect([func, args, loc, scale, lb, ub, ...])  Calculate expected value of a
    function with respect to the distribution.
median(*args, **kwds)  Median of the distribution.
mean(*args, **kwds)  Mean of the distribution.
std(*args, **kwds)  Standard deviation of the distribution.
var(*args, **kwds)  Variance of the distribution.
interval(alpha, *args, **kwds)  Confidence interval with equal areas around the median.
__call__(*args, **kwds)  Freeze the distribution for the given arguments.
fit(data, *args, **kwds)  Return MLEs for shape, location, and scale parameters from data.
fit_loc_scale(data, *args)  Estimate loc and scale parameters from data using 1st and 2nd moments.
nnlf(theta, x)  Return negative loglikelihood function.

Member Function Documentation

§ _loglike()

def starvine.uvar.uvmodels.uv_base.UVmodel._loglike (   self,
  params,
  data,
  wgts 
)
private
Parameters
paramsarray-like model parameters
datanp_array input data
wgtsnp_array input data weights

§ _paramCheck()

def starvine.uvar.uvmodels.uv_base.UVmodel._paramCheck (   input_f)
private

Parameter bounds checker.

Returns
Typical function value if params are in bounds, -inf if out of bounds

§ _pdf()

def starvine.uvar.uvmodels.uv_base.UVmodel._pdf (   self,
  x,
  args 
)
private

Pure virtual pdf model function.

Note: the number of paramers is "infered" from the signature of the _pdf OR _cdf methods.

§ fitMCMC()

def starvine.uvar.uvmodels.uv_base.UVmodel.fitMCMC (   self,
  iters,
  pos = None 
)

Execute MCMC model parameter fitting.

Must call setupMCMC before calling this method.

Parameters
itersint number of MCMC iterations
posInitial position of walkers

§ fitMLE()

def starvine.uvar.uvmodels.uv_base.UVmodel.fitMLE (   self,
  data,
  params0,
  weights = None,
  args,
  kwargs 
)

Generic maximum (log)likelyhood estimate of paramers.

Parameters
dataInput data to fit to
params0Initial guess for model parameters
weightsInput data weights

Note: compare to scipy's model.fit() method results. Scipy's model.fit() method does not allow for weights :(

§ setLogPrior()

def starvine.uvar.uvmodels.uv_base.UVmodel.setLogPrior (   self,
  logPriorFn 
)

Set log of prior distribution

\[ ln(P(\theta)) \]

.

Parameters
logPriorFnfunction logPrior

§ setupGMM()

def starvine.uvar.uvmodels.uv_base.UVmodel.setupGMM (   self,
  data,
  w = 1.0,
  nMoM = None 
)

General Method of Moments setup.

Parameters
dataInput univariate data
wData weights

Example General Method of Moments use:

>>> my_uvmodel = UVmodel(...)
>>> params0 = np.array([2.0, 1.0])
>>> my_uvmodel.internalGMM.fit(params0, maxiter=2, optim_method='nm', wargs=dict(centered=False))

§ setupMCMC()

def starvine.uvar.uvmodels.uv_base.UVmodel.setupMCMC (   self,
  nwalkers,
  params,
  data,
  wgts = None,
  args 
)

Initilize the MCMC sampler.

Parameters
nwalkersint Number of walkers
paramslist of doubles Model parameter list
datanp_array data array
wgtsnp_array data weights

The documentation for this class was generated from the following file: