pydygp.linlatentforcemodels.MLFMAdapGrad¶
-
class
pydygp.linlatentforcemodels.MLFMAdapGrad(basis_mats, **kwargs)[source]¶ Multiplicative latent force model (MLFM) using the adaptive gradient matching approximation.
Parameters: - basis_mats : list of square ndarray
A list of [L1,…,LD] square numpy array_like
- lf_kernels : list of kernel objects, optional
Kernels of the latent force Gaussian process objects. If None is passed, the kernel “1.0 * RBF(1.0)” is used as a defualt.
Notes
Read more in the tutorial.
-
__init__(basis_mats, **kwargs)[source]¶ Initialize self. See help(type(self)) for accurate signature.
Methods
__init__(basis_mats, **kwargs)Initialize self. fit(times, Y, **kwargs)Fit the MLFM using Adaptive Gradient Matching by maximimising the likelihood function. log_likelihood(y, g, beta, logphi, loggamma, …)Log-likelihood of the data predict_lf(tt[, return_std])Predict the latent force variables using the Laplace approximation. setup_latentforces([kernels])Initalises the latent force GPs sim(x0, tt[, beta, dt_max, latent_forces, size])Simulate the process along a set of points -
fit(times, Y, **kwargs)[source]¶ Fit the MLFM using Adaptive Gradient Matching by maximimising the likelihood function.
Parameters: - times : ndarray, shape (ndata, )
Data time points. Ordered array of size (ndata, ), where ‘ndata’ is the number of data points
- Y : ndarray, shape = (ndata, K)
Data to be fitted. Array of size (ndata, K), where ‘ndata’ is the number of data points and K is the dimension of the latent variable space.
Returns: - res_par : A
MLFMAdapGradFitResults
-
log_likelihood(y, g, beta, logphi, loggamma, logtau, eval_gradient=False, **kwargs)[source]¶ Log-likelihood of the data
Parameters: - y : array
- g : array
- beta : array
- logphi : array
- loggamma : array
- logtau : array
- eval_gradient : boolean
Returns: - res : float,
Notes
Returns the log-likelihood
\[\ln p(\mathbf{y} \mid \mathbf{g}, \boldsymbol{\beta}, \ln \boldsymbol{\phi}, \ln \boldsymbol{\gamma}, \ln \boldsymbol{\tau})\]of the vectorised data \(\mathbf{y}\). Although note the for the GP hyperparameters, temperature parameter \(oldsymbol{\gamma}\) and data precision \(boldsymbol{ au}\) that function takes as arguments the log transform of these values (and consequently returns the gradient wth respect to the log transformed parameters) to ensure a natural positivity constraints.
-
predict_lf(tt, return_std=False)[source]¶ Predict the latent force variables using the Laplace approximation.
Requires that the model has been fitted.
Parameters: - tt : array-like, shape = (n, )
Time points where the GPs are evaluated
- return_std: bool, default: False
If True, the standard deviation of the predictive distribution at the query times is returned, along with the mean.
Returns: - lf_mean : array, shape = (R, tt.size)
Mean of predictive distribution at tt
- lf_std : array, shape = (R, tt.size), optional
Standard deviation of the predictive distribution at tt. Only returned when return_std is True
-
setup_latentforces(kernels=None)¶ Initalises the latent force GPs
Parameters: - kernels : list, optional
Kernels of the latent force Gaussian process objects
-
sim(x0, tt, beta=None, dt_max=0.1, latent_forces=None, size=1)¶ Simulate the process along a set of points
Parameters: - x0 : array_like, shape (K, )
initial condition for the ode
- tt : array_like
Ordered sequence of time points for the model to be simulated at
- beta : array_like, shape (R+1, D)
- dt_max : float, defualt = 0.1
Maximum spacing of dense time points used for simulating the model.
- latent_forces : Tuple of callables, optional, default = None
Returns: - Y : array, shape(len(tt), K)
Values of the MLFM simulated at tt
- latent_forces : tuple of callables
Tuple of functions (g_1(t),…,g_R(t)) used to simulate the model.
Examples
>>> import numpy as np >>> from pydygp.linlatentforcemodels import BaseMLFM >>> struct_mats = [np.zeros((2, 2))] + [*pydygp.liealgebras.so2()] >>> tt = np.linspace(0., 5., 15) >>> mlfm = BaseMLFM(struct_mats) >>> Y, g = mlfm.sim([1., 0], tt)