Distributions

This page gives the details about the code in biasd.distributions.

Some standard probability distributions

synopsis:

Contains probability distributions for use with BIASD prior and posterior distributions

class distributions.beta(alpha, beta)

The beta distribution is often used for probabilities or fractions.

It is \(p(x\vert\alpha ,\beta) = \frac{ x^{\alpha-1}(1-x)^{\beta-1}}{B(\alpha ,\beta)}\)

class distributions.gamma(alpha, beta)

The gamma distribution is often used for compounded times.

It is \(p(x\vert\alpha ,\beta) = \frac{ \beta^\alpha x^{\alpha - 1} e^{-\beta x} }{\Gamma(\alpha)}\)

Parameters are alpha (shape), and beta (rate)

class distributions.loguniform(a, b)

The uniform distribution is useful limiting ranges Parameters are a (lower bound), and b (upper bound)

It is \(p(x\vert a , b) = \frac{x^{-1}}{\ln b - \ln a}\)

class distributions.normal(mu, sigma)

The normal/Gaussian distribution is useful for everything Parameters are mean, and the standard deviation

It is \(p(x\vert\mu ,\sigma) = \frac{ 1}{\sqrt{2\pi\sigma^2}}e^{\frac{-1}{2}\left(\frac{x-\mu}{\sigma}\right)^2}\)

class distributions.uniform(a, b)

The uniform distribution is useful limiting ranges Parameters are a (lower bound), and b (upper bound)

It is \(p(x\vert a , b) = \frac{1}{b-a}\)

Convert between distributions

distributions.convert_distribution(this, to_this_type_string)

Converts this distribution to to_this_type_string distribution

Input:
  • this is a biasd.distribution._distribution

  • to_this_type_string is a string of ‘beta’, ‘gamma’, ‘normal’, or ‘uniform’

Returns:
  • a biasd.distribution._distribution

Example:

from biasd import distributions as bd
import numpy as np
import matplotlib.pyplot as plt

n = bd.normal(.5,.01)
x = np.linspace(0,1,10000)
c = bd.convert_distribution(n,'gamma')
cc = bd.convert_distribution(n,'uniform')
ccc = bd.convert_distribution(n,'beta')
plt.plot(x,n.pdf(x))
plt.plot(x,c.pdf(x))
plt.plot(x,cc.pdf(x))
plt.plot(x,ccc.pdf(x))
plt.yscale('log')
plt.show()

Distributions can be collected for priors or posteriors

class distributions.parameter_collection(e1, e2, sigma, k1, k2)

A collection of distribution functions that are used for the BIASD two-state model as parameters for Bayesian inference. parameter_collection’s are used as priors for BIASD.

Input:
  • e1 is the probability distribution for \(\epsilon_1\)

  • e2 is the probability distribution for \(\epsilon_2\)

  • sigma is the probability distribution for \(\sigma\)

  • k1 is the probability distribution for \(k_1\)

  • k2 is the probability distribution for \(k_2\)

Collections can be visualized

class distributions.viewer(data)

Allows you to view BIASD parameter probability distributions

Input:
  • parameter_collection is a biasd.distributions.parameter_collection

Example:

from biasd import distributions as bd

# Make the parameter_collection
e1 = bd.normal(5.,1.)
e2 = bd.beta(95.,5.)
sigma = bd.gamma(5.,100.)
k1 = bd.gamma(1.,1.)
k2 = bd.uniform(-1,1.)
d = bd.parameter_collection(e1,e2,sigma,k1,k2)

# Start the viewer
v = bd.viewer(d)

Finally, you can easily generate a few useful collections using

synopsis:

Contains probability distributions for use with BIASD prior and posterior distributions

distributions.guess_prior(y, tau=1.0)

Generate a guess for the prior probability distribution for BIASD. This approach uses a Gaussian mixture model to learn both states and the noise, then it idealizes the trace, and calculates the transition probabilities. Rate constants are then calculated, and an attempt is made to correct these with virtual states.

Input:
  • y is a numpy.ndarray of the time series

  • tau is the measurement period of the time series (i.e., inverse acquisition rate)

Returns:
  • a guessed biasd.distributions.parameter_collection

distributions.uninformative_prior(data_range, timescale)

Generate an uninformative prior probability distribution for BIASD.

Input:
  • data_range is a list or array of the [lower,upper] bounds of the data

  • timescale is the frame rate (the prior will be centered here +/- 3 decades)

Returns:
  • a flat biasd.distributions.parameter_collection