Package: profile-likelihood
Profile LikelihoodProfile likelihood toolboxInstallationUsing pippip install profile_likelihoodFrom sourcegitclonehttps://git.physics.byu.edu/yonatank/profile_likelihood.git
pipinstall./profile_likelihood# Install the packageTheoryIn 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 isP\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 writeL\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 byC\left(\vec{\theta}\right) = \frac{1}{2} \sum_m
        \left(\frac{y_m - f\left(t_m, \vec{\theta}\right)}
			{\sigma_m} \right)^2Suppose 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 usageAs an example, we want to run profile likelihood calculation to sum of
exponential modelf(\vec{\phi}; t) = \exp(-\phi_0*t) + \exp(-\phi_1*t),witht = [0.5, 1.1, 3.0]and datay = [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.importnumpyasnpfromprofile_likelihoodimportprofile_likelihoodtdata=np.array([0.5,1.1,3.0]).reshape((-1,1))# Sampling timeydata=np.array([1.089,0.717,0.332])# Mock datadefresiduals(theta):"""The function, representing the model, that will be used in theoptimization process. This function takes an array of parameter and returnan array of the residuals."""phi=np.exp(theta)# Undo the log transformationpred=np.sum(np.exp(-phi*tdata),axis=1)# Model that gives predictionsreturnydata-pred# Return the residual vector.best_fit=np.array([-1.0,1.0])# Best-fit parameternparams=len(best_fit)# Number of parametersnpred=3# Number of predictions# Create likelihood objectpl=profile_likelihood(residuals,nparams,npred)# Run computationpl.compute(best_fit)# Access resultspl.resultsFor more examples, seehere.List of frequently used methodsprofile_likelihood.computeprofile_likelihood.save_resultsprofile_likelihood.save_best_resultsprofile_likelihood.load_resultsprofile_likelihood.plot_likelihoodsprofile_likelihood.plot_pathsprofile_likelihood.plot_likelihoods_and_pathsContactYonatan Kurniawan (kurniawanyo@outlook.com)