Basic Likelihood tools such as functions for computing likelihoods, Latin Hypercube sampling (efficient random sampling) and other tools which don’t belong on other packages, or apply to multiple packages.
Fit a model to data generating Bayesian posterior distributions of input and outputs of the model.
Calculates the Akaike information criterion from the residual sum of squares of the best fitting run.
Parameters: |
|
---|
Finds best parameters using an optimization approach
Parameters: |
|
---|
Plot the final results of the inference
Generates a set of samples from the starting theta prior distributions for reporting purposes.
Returns: | Dictionary with (name,sample) pairs |
---|
Fit the model against data
Parameters: |
|
---|
Set the prior distributions for Phi and Theta
Parameters: |
|
---|
Bayesian Melding class
Runs the model for inference through Approximate Bayes Computation techniques. This method should be used as an alternative to the sir.
Parameters: |
|
---|
Adds a few extra uniformly distributed data points beyond the dataset range. This is done by adding from a uniform dist.
Parameters: |
|
---|---|
Returns: | Salted dataset. |
Plots the last simulated series
Parameters:
- series: Record array with the simulated series.
- idx: Integer index of the curve to plot .
- data: Dictionary with the full dataset.
- vars: List with variable names to be plotted.
- step: Step of the chain
Multiple condition filtering. Remove values in x[i], if corresponding values in cond[i] are less than limits[i][0] or greater than limits[i][1].
Parameters: |
|
---|
Updates the posteriors of the model’s output for the last t time steps. Returns two record arrays: - The posteriors of the Theta - the posterior of Phi last t values of time-series. self.L by t arrays.
Parameters: |
|
---|
Importance sampling
Returns: | returns a sample of size n |
---|
Returns the probability associated with each phi[i] on the pooled pdf of phi and q2phi.
Parameters: |
|
---|
MCMC based fitting
Parameters: |
|
---|
Runs the model through the Melding inference.model model is a callable which return the output of the deterministic model, i.e. the model itself. The model is run self.K times to obtain phi = M(theta).
Handles running the model k times keeping a temporary savefile for resuming calculation in case of interruption.
Parameters: |
|
---|---|
Returns: |
|
Setup the models Outputs, or Phi, and generate the samples from prior distributions needed for the melding replicates.
Parameters: |
|
---|
Setup the model outputs and set their prior distributions from the vectors in data. This method is to be used when the prior distributions are available in the form of a sample from an empirical distribution such as a bayesian posterior. In order to expand the samples provided, K samples are generated from a kernel density estimate of the original sample.
Parameters: |
|
---|
Setup the models inputs and generate the samples from prior distributions needed for the dists the melding replicates.
Parameters: |
|
---|
Setup the model inputs and set the prior distributions from the vectors in data. This method is to be used when the prior distributions are available in the form of a sample from an empirical distribution such as a bayesian posterior. In order to expand the samples provided, K samples are generated from a kernel density estimate of the original sample.
Parameters: |
|
---|
Run the model output through the Sampling-Importance-Resampling algorithm. Returns 1 if successful or 0 if not.
Parameters: |
|
---|
Calculates a basic fitness calculation between a model- generated time series and a observed time series. it uses a Mean square error.
Parameters: |
|
---|---|
Return: | Root mean square deviation between ´s1´ and ´s2´. |
Loops through an array with data series as columns, and Replaces NaNs with the mean of the other series.
Parameters: |
|
---|---|
Returns: | array of the same shape as obs |
Returns model results plus run number.
Parameters: |
|
---|---|
Return: |
|
Model (r,p0, n=1) Simulates the Population dynamic Model (PDM) Pt = rP0 for n time steps. P0 is the initial population size. Example model for testing purposes.
Does a single run of self.model and returns the results as a record array
Plots a record array as a panel of histograms
Return random integers from low (inclusive) to high (exclusive).
Return random integers from the “discrete uniform” distribution in the “half-open” interval [low, high). If high is None (the default), then results are from [0, low).
>>> np.random.randint(2, size=10)
array([1, 0, 0, 0, 1, 1, 0, 0, 1, 0])
>>> np.random.randint(1, size=10)
array([0, 0, 0, 0, 0, 0, 0, 0, 0, 0])
Generate a 2 x 4 array of ints between 0 and 4, inclusive:
>>> np.random.randint(5, size=(2, 4))
array([[4, 0, 2, 1],
[3, 2, 2, 0]])
random_sample(size=None)
Return random floats in the half-open interval [0.0, 1.0).
Results are from the “continuous uniform” distribution over the
stated interval. To sample multiply
the output of random_sample by (b-a) and add a:
(b - a) * random_sample() + a
>>> np.random.random_sample()
0.47108547995356098
>>> type(np.random.random_sample())
<type 'float'>
>>> np.random.random_sample((5,))
array([ 0.30220482, 0.86820401, 0.1654503 , 0.11659149, 0.54323428])
Three-by-two array of random numbers from [-5, 0):
>>> 5 * np.random.random_sample((3, 2)) - 5
array([[-3.99149989, -0.52338984],
[-2.99091858, -0.79479508],
[-1.23204345, -1.75224494]])
Seed the generator.
This method is called when RandomState is initialized. It can be called again to re-seed the generator. For details, see RandomState.
RandomState
Log-Like Bernoulli >>> Bernoulli([0,1,1,1,0,0,1,1],0.5) -5.54517744448
Log-Like Beta >>> Beta([.2,.3,.7,.6,.4],2,5) -0.434845728904
Binomial Log-Likelihood >>> Binomial([2,3],6,0.3) -2.81280615454
Categorical Log-likelihood generalization of a Bernoulli process for variables with any constant number of discrete values.
Parameters: |
|
---|
>>> Categor([1],([.3,.7],[0,1]))
-0.356674943939
Log-Like Gamma >>> Gamma([2,3,7,6,4],2,2) -11.015748357
Lognormal Log-likelihood
Parameters: |
|
---|
>>> Lognormal([0.5,1,1.2],0,0.5)
-3.15728720569
Negative Binomial Log-Likelihood >>> Negbin([2,3],6,0.3) -9.16117424315
Normal Log-like
Parameters: |
|
---|
>>> Normal([0],0,1)
-0.918938533205
Poisson Log-Likelihood function >>> Poisson([2],2) -1.30685281944
find out what it is.
Uniform Log-likelihood
Parameters: |
|
---|
>>> Uniform([1.1,2.3,3.4,4],0,5)
-6.4377516497364011
Log-Like Weibull >>> Weibull([2,1,0.3,.5,1.7],1.5,3) -7.811955373
returns the value of tau which maximizes normal loglik for a fixed (x,mu)
Module with specialized plotting functions for the Melding results
Converted from MATLAB script at http://billauer.co.il/peakdet.html Currently returns two lists of tuples, but maybe arrays would be better function [maxtab, mintab]=peakdet(v, delta, x) %PEAKDET Detect peaks in a vector % [MAXTAB, MINTAB] = PEAKDET(V, DELTA) finds the local % maxima and minima (“peaks”) in the vector V. % MAXTAB and MINTAB consists of two columns. Column 1 % contains indices in V, and column 2 the found values. % % With [MAXTAB, MINTAB] = PEAKDET(V, DELTA, X) the indices % in MAXTAB and MINTAB are replaced with the corresponding % X-values. % % A point is considered a maximum peak if it has the maximal % value, and was preceded (to the left) by a value lower by % DELTA. % Eli Billauer, 3.4.05 (Explicitly not copyrighted). % This function is released to the public domain; Any use is allowed.
Predicted total new cases in a window vs oserved.
Create violin plots on an axis
Parameters: |
|
---|
Module with specialized plotting functions for the Melding results
Converted from MATLAB script at http://billauer.co.il/peakdet.html Currently returns two lists of tuples, but maybe arrays would be better function [maxtab, mintab]=peakdet(v, delta, x) %PEAKDET Detect peaks in a vector % [MAXTAB, MINTAB] = PEAKDET(V, DELTA) finds the local % maxima and minima (“peaks”) in the vector V. % MAXTAB and MINTAB consists of two columns. Column 1 % contains indices in V, and column 2 the found values. % % With [MAXTAB, MINTAB] = PEAKDET(V, DELTA, X) the indices % in MAXTAB and MINTAB are replaced with the corresponding % X-values. % % A point is considered a maximum peak if it has the maximal % value, and was preceded (to the left) by a value lower by % DELTA. % Eli Billauer, 3.4.05 (Explicitly not copyrighted). % This function is released to the public domain; Any use is allowed.
Predicted total new cases in a window vs oserved.
Create violin plots on an axis
Parameters: |
|
---|