Likelihood¶
This page gives the details about the code in biasd.likelihood.
Switch the log-likelihood function¶
There are two main functions that you use for BIASD in biasd.likelihood. One to calculate the log-likelihood function, and the other to calculate the log-posterior function, which relies on the log-likelihood function. However, in truth, there are several different version of the log-likehood function that all accept the same arguments and return the results. There’re two written in Python, one written in C, and one written in for CUDA. Assuming that they are compiled (i.e., C or CUDA), you can toggle between them to choose which version the log-likelihood function uses. In general, you’ll want to use the default python (numba), since it is fast and it allows you to use multiple processors because many of the functions are naturally vectorized. If you have a lot of data points, you’ll probably want to use the CUDA version, where each CUDA-core calculates the log-likelihood of a single data point. Anyway, you can toggle between the versions using
import biasd as b
# Switch to the slow, python implementation
b.likelihood.use_python_ll()
# Switch to the medium, parallelizable C version
b.likelihood.use_c_ll()
# Switch to the high-throughput CUDA version
b.likelihood.use_cuda_ll()
Finally, you can test the speed per datapoint of each of these version with
- likelihood.test_speed(n, dpoints=5000, device=0)¶
Test how fast the BIASD integral runs. Input:
n is the number of times to repeat the test
dpoints is the number of data points in each test
- Returns:
The average amount of time per data point in seconds.
If you’re ever confused about which version you’re using, you can check the biasd.likelihood.ll_version variable.
- Warning:
Changing biasd.likelihood.ll_version will not switch which likelihood function is being used.
Inference-related functions¶
- likelihood.log_likelihood(theta, data, tau, device=None, epsilon=1e-10)¶
Calculate the individual values of the log of the BIASD likelihood function at \(\Theta\)
- Input:
theta is a np.ndarray of the parameters to evaluate
data is a 1D `np.ndarray of the time series to analyze
tau is the measurement period of each data point in data
- Returns:
A 1D np.ndarray of the log-likelihood for each data point in data
- likelihood.log_posterior(theta, data, prior_dists, tau, device=0)¶
Calculate the log-posterior probability distribution at \(\Theta\)
- Input:
theta is a vector of the parameters (i.e., \(\theta\)) where to evaluate the log-posterior
data is a 1D np.ndarray of the time series to analyze
prior_dists is a biasd.distributions.parameter_collection containing the prior probability distributions for the BIASD calculation
tau is the measurement period of data
- Returns:
The summed log posterior probability distribution, \(p(\Theta \vert data) \propto p(data \vert \Theta) \cdot p(\Theta)\)