Profile likelihood toolbox
Project description
Profile Likelihood
Profile likelihood toolbox
Installation
Using pip
Not available yet. We are working on this.
From source
git clone https://git.physics.byu.edu/yonatank/profile_likelihood.git
pip install ./profile_likelihood # Install the package
Theory
In the problem of fitting a theoretical model
$f\left(t_m, \vec{\theta}\right)
$ to the $M
$ experimentally
determined data points $y_m
$ at times $t_m
$, by assuming that the
experimental errors for the data points are independent and Gaussian
distributed with standard deviation of $\sigma
$, the probability
that a given model produced the observed data points is
P\left(\vec{y}\middle|\vec{\theta}\right) =
\prod_{m=1}^N \frac{1}{\sqrt{2\pi}\sigma}
e^{-\left(f(t_m,\vec{\theta}) - y_m\right)^2/2\sigma^2}.
The likelihood function of this model,
$L\left(\vec{\theta}\middle|\vec{y}\right)
$, is the probability of
the occurrence of the outcomes $\vec{y}
$ given a set of parameters
$\vec{\theta}
$ of the model,
$P\left(\vec{y}\middle|\vec{\theta}\right)
$. Using the equation
above, we can write
L\left(\vec{\theta}\middle|\vec{y}\right) \propto
\exp\left[ -C\left(\vec{\theta}\right) \right],
where $C\left(\vec{\theta}\right)
$ is the cost function, given by
C\left(\vec{\theta}\right) = \frac{1}{2} \sum_m
\left(\frac{y_m - f\left(t_m, \vec{\theta}\right)}
{\sigma_m} \right)^2
Suppose the model $f\left(t_m, \vec{\theta}\right)
$ has $N
$
parameters, written as $\{ \theta_0, \cdots, \theta_{N-1} \}
$. The
profile likelihood of the model for parameter $\theta_j
$ is the
possible maximum likelihood given the parameter $\theta_j
$. The
profile likelihood for parameter $\theta_j
$ is calculated by setting
$\theta_j
$ to a fixed value, then maximizing the likelihood function
(by minimizing the cost function) over the other parameters of the
model. We repeat this computation across a range of $\theta_j
$,
$\left(\theta_j^{\min}, \theta_j^{\max}\right)
$.
Basic usage
As an example, we want to run profile likelihood calculation to sum of exponential model
f(\vec{\phi}; t) = \exp(-\phi_0*t) + \exp(-\phi_1*t),
with t = [0.5, 1.1, 3.0]
and data y = [1.089, 0.717, 0.332]
.
We further want to constrain the parameters to be positive, which suggest to
work with $\theta = \log{\phi}
$ instead.
import numpy as np
from profile_likelihood import profile_likelihood
tdata = np.array([0.5, 1.1, 3.0]).reshape((-1, 1)) # Sampling time
ydata = np.array([1.089, 0.717, 0.332]) # Mock data
def residuals(theta):
"""The function, representing the model, that will be used in the
optimization process. This function takes an array of parameter and return
an array of the residuals.
"""
phi = np.exp(theta) # Undo the log transformation
pred = np.sum(np.exp(-phi * tdata), axis=1) # Model that gives predictions
return ydata - pred # Return the residual vector.
best_fit = np.array([-1.0, 1.0]) # Best-fit parameter
nparams = len(best_fit) # Number of parameters
npred = 3 # Number of predictions
# Create likelihood object
pl = profile_likelihood(residuals, nparams, npred)
# Run computation
pl.compute(best_fit)
# Access results
pl.results
For more examples, see here.
List of frequently used methods
- profile_likelihood.compute
- profile_likelihood.save_results
- profile_likelihood.save_best_results
- profile_likelihood.load_results
- profile_likelihood.plot_likelihoods
- profile_likelihood.plot_paths
- profile_likelihood.plot_likelihoods_and_paths
Contact
Yonatan Kurniawan (kurniawanyo@outlook.com)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
File details
Details for the file profile_likelihood-0.6.0.tar.gz
.
File metadata
- Download URL: profile_likelihood-0.6.0.tar.gz
- Upload date:
- Size: 9.3 MB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/34.0 requests/2.25.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.47.0 importlib-metadata/3.10.0 keyring/17.0.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.7.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 35032cf20a4f23a23baebdb6c27a11d2dcaf31967c958282ceb8a6cb6e3b51d9 |
|
MD5 | 70d27e8036b98d69dd8bb71b6c5a1df9 |
|
BLAKE2b-256 | 65547ab06ea0fceac1692a7832f0b6f1777af18fe3e3cfcaed1afb7621a78b1f |