pydygp.linlatentforcemodels.GibbsMLFMAdapGrad¶
-
class
pydygp.linlatentforcemodels.GibbsMLFMAdapGrad(*args, **kwargs)[source]¶ Extends the MLFM-AG matching model to implement conditional Gibbs sampling.
Parameters: - basis_mats : tuple of square ndarray
A tuple of square numpy array_like with the same shape.
- R : int
Number of latent forces in the model.
- 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 for the R latent forces.
Methods
__init__(*args, **kwargs)Initialize self. beta_condpdf(vecx, vecg[, gamma, logphi])beta_condpdf_mo(vecx, vecg[, gamma, logphi])fit(times, Y, **kwargs)Fit the MLFM using Adaptive Gradient Matching by maximimising the likelihood function. g_condpdf(vecx, beta[, gamma, logphi, logpsi])Conditional distribution of the latent force. g_condpdf_mo(vecx, beta[, gamma, logphi, logpsi])gibbsfit(times, Y[, sample, size, burnin])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 x_condpdf(beta, vecg, logphi, loggamma[, …])x_condpdf_mo(beta, vecg, logphi, loggamma, …)Possibility of multiple outputs -
fit(times, Y, **kwargs)¶ 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
-
g_condpdf(vecx, beta, gamma=None, logphi=None, logpsi=None, **kwargs)[source]¶ Conditional distribution of the latent force.
Parameters: - vecx : numpy array, shape (N*K, )
Vectorised state variables.
- beta : numpy array, shape (R+1, D)
-
log_likelihood(y, g, beta, logphi, loggamma, logtau, eval_gradient=False, **kwargs)¶ 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)¶ 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)