## generate simulated data
library(FastGaSP)
library(rstiefel)
d = 5 # number of latent factors
k = 20 # length of observation at each time step
n = 500 # number time step
noise_level = 1 # variance of noise
U = rustiefel(k, k) # factor loading matrix
z = matrix(NA, d, n)
sigma_2 = runif(d, 0.5, 1)
rho = runif(d, 0.95, 1)
for(l in 1:d){
R = matrix(NA, n, n)
diag(R) = 1
for(ir in 1:n){
for(ic in 1:n){
R[ir, ic] = rho[l]^(abs(ir-ic)) * R[ir, ir]
}
}
R = (sigma_2[l]/(1-rho[l]^2) )* R
z[l, ] = t(chol(R)) %*% rnorm(n)
}
signal = U[,1:d] %*% z
y = signal + matrix(rnorm(n*k,mean=0,sd=sqrt(noise_level)),k,n)
##constucting the fmou.model
fmou.model=fmou(output=y, d=d, est_U0=TRUE, est_sigma0_2=TRUE)
## estimate the parameters
em_alg <- fit.fmou(fmou.model, M=500)
## root mean square error (RMSE) of predictive mean of observations
sqrt(mean((em_alg$mean_obs-signal)^2))
## standard deviation of (truth) mean of observations
sd(signal)
## estimated variance of noise
em_alg$sigma0_2
Run the code above in your browser using DataLab