# \dontshow{
##examples for checks: executable in < 5 sec together with the examples above not shown to users
### define ode
toy_fun = function(t,x,par_ode){
alpha=par_ode[1]
as.matrix( c( -alpha*x[1]) )
}
toy_grlNODE= function(par,grad_ode,y_p,z_p) {
alpha = par[1]
dres= c(0)
dres[1] = sum( 2*( z_p-grad_ode)*y_p*alpha ) #sum( -2*( z_p[1,2:lm]-dz1)*z1*alpha )
dres
}
t_no = c(0.1,1,2,3,4,8)
n_o = length(t_no)
y_no = matrix( c(exp(-t_no)),ncol=1 )
######################## create and initialise ode object #########################################
init_par = rep(c(0.1))
init_yode = t(y_no)
init_t = t_no
kkk = ode$new(1,fun=toy_fun,grfun=toy_grlNODE,t=init_t,ode_par= init_par, y_ode=init_yode )
##### standard gradient matching
ktype='rbf'
rkgres = rkg(kkk,(y_no),ktype)
rkgdiag = diagnostic( rkgres,1,'rkg',qq_plot=FALSE )
# }
if (FALSE) {
require(mvtnorm)
set.seed(SEED); SEED = 19537
FN_fun <- function(t, x, par_ode) {
a = par_ode[1]
b = par_ode[2]
c = par_ode[3]
as.matrix(c(c*(x[1]-x[1]^3/3 + x[2]),-1/c*(x[1]-a+b*x[2])))
}
solveOde = ode$new(sample=2,fun=FN_fun)
xinit = as.matrix(c(-1,-1))
tinterv = c(0,10)
solveOde$solve_ode(par_ode=c(0.2,0.2,3),xinit,tinterv)
n_o = max(dim(solveOde$y_ode))
noise = 0.01
y_no = t(solveOde$y_ode)+rmvnorm(n_o,c(0,0),noise*diag(2))
t_no = solveOde$t
odem = ode$new(fun=FN_fun,grfun=NULL,t=t_no,ode_par=rep(c(0.1),3),y_ode=t(y_no))
ktype = 'rbf'
rkgres = rkg(odem,y_no,ktype)
rkgdiag = diagnostic( rkgres,1,'rkg',qq_plot=FALSE )
}
Run the code above in your browser using DataLab