## Not run: ------------------------------------
#
# # We generate samples from a time-varying graph
# # and try to recover the true model from the sampled data
#
# # We sample from a graph with 400 time steps, in which one parameter smoothly changes from 1 to 0
# # and another parameter from 0 to 1
#
# # specify time-varying graph
# p <- 4 # 4 nodes
# n <- 600 # number of time steps
# graph <- matrix(0, p, p)
# k <- 15 # steepness of sigmoid function
# sigm_in <- 1/ (1+ exp(-k*(seq(0,1,length=n)-.5))) # sigmoid curve
# sigm_de <- 1/ (1+ exp(k*(seq(0,1,length=n)-.5)))
# graphs <- array(dim=c(p, p, n))
# graphs[,,1:n] <- graph
# graphs[1,2,] <- graphs[2,1,] <- - sigm_in
# graphs[3,4,] <- graphs[4,3,] <- - sigm_de
#
# # specify type and thresholds
# type <- c('g', 'g', 'c', 'c') # two Gaussian, two Binary
# lev <- c(1, 1, 2, 2)
# # zero means (Gaussians) and thresholds (Binary)
# thresh <- list(0, 0 , c(0, 0), c(0, 0))
# # same means/thresholds at all time steps
# threshs <- list(); for(nIter in 1:n) threshs[[nIter]] <- thresh
#
# # sample
# set.seed(1)
# data <- tv.mgmsampler(type, lev, graphs, threshs)
#
# ## 3.3 Estimation of time-varying Mixed Graphical Models
#
# # estimate
# tv.obj <- tv.mgmfit(data = data,
# type = type,
# lev = lev,
# tsteps = 50,
# bandwidth = .8/n^(1/3),
# gam = 0,
# d = 2)
#
#
# # visual check
#
# plot(tv.obj$wadj[2,1,], xlab = 'Estimated time points', ylab = 'Edge weight',
# type = 'l', col = 'red', ylim=c(0,1), lwd=2, yaxt='n')
# lines(tv.obj$wadj[3,4,], col='blue', lwd=2)
# axis(side = 2, at = round(seq(0,1,length=5), 2), las=2)
# # true parameters
# tsteps <- 50
# lines( 1/ (1+ exp(-k*(seq(0,1,length=tsteps)-.5))) , col='red', lty=2)
# lines( 1/ (1+ exp(k*(seq(0,1,length=tsteps)-.5))), col='blue', lty=2)
#
# legend(38,.55, c('(2,1) true', '(2,1) estimated', '(3,4) true', '(3,4) estimated'), lty=c(2,1,2,1),
# col = c('red', 'red', 'blue', 'blue'), lwd=c(2,2, 2, 2))
#
#
## ---------------------------------------------
Run the code above in your browser using DataLab