###############################################################################
# run the simulations for boosting/FAMM of models with functional historical effects
# to plot the models: data / true and estimated coefficients 
# code based on code by Fabian Scheipl 
# author: Sarah Brockhaus
###############################################################################


rm(list=ls())

print(R.Version()$version.string)

## library(refundDevel) 
library(refund)
library(FDboost)
library(splines)

# setwd("../")
# path <- getwd()
# 
# source(paste0(getwd(),"/Code/boosting4.R"))    # functions for simulations
# 
# pathResults <- paste0(path, "/results/")
# pathModels <- paste0(path, "/models/")

source("boosting4.R")
pathResults <- NULL
pathModels <- NULL

getwd()


doStabsel <- FALSE

###################################### M=30

set.seed(18102012)

arginS <- "smooth"
penaltyS <- "ps"

set1 <-  makeSettings(
  dgpsettings=list(M=c(30), 
                   ni=c(1),
                   p=c(0.8),
                   Gy=c(27),
                   Gx=c(100),
                   snrEps=c(2),
                   snrE=c(0),
                   snrB=c(2),
                   scenario=c(2),
                   k=c(0, 1, 2),
                   type=c("lines"), 
                   balanced=c(TRUE),
                   nuisance=c(0),  # 10
                   a=c("pen1coef4", "pen2coef4"),
                   regularS=c(TRUE), 
                   regularT=c(FALSE),
                   rep=1),
  algorithms=list(addNoise=c(FALSE),
                  centerX=c(TRUE),
                  penaltyS=c("ps"),
                  diffPen=c(1),
                  inS=c("smooth"))
)

length(set1)

usecores <- 5
options(cores=usecores)
res1 <- try(doSim(settings=set1, cores=usecores))

save(res1, file=paste(pathResults, "res1plot.Rdata", sep=""))


set.seed(18102012)

arginS <- "smooth"
penaltyS <- "ps"

set2 <- makeSettings(
  dgpsettings=list(M=c(30), 
                   ni=c(1),
                   p=c(0.8),
                   Gy=c(27),
                   Gx=c(100),
                   snrEps=c(2),
                   snrE=c(0),
                   snrB=c(2),
                   scenario=c(2),
                   k=c(5, 10),
                   type=c("bsplines"),
                   balanced=c(TRUE),
                   nuisance=c(0),  # 10
                   a=c("pen1coef4", "pen2coef4"),
                   regularS=c(TRUE), 
                   regularT=c(FALSE),
                   rep=1),
  algorithms=list(addNoise=c(FALSE),
                  centerX=c(TRUE),
                  penaltyS=c("ps"),
                  diffPen=c(1),
                  inS=c("smooth"))
)

length(set2)

usecores <- 5
options(cores=usecores)

# boosting on set2
res2 <- try(doSim(settings=set2, cores=usecores))
#res2
save(res2, file=paste(pathResults, "res2plot.Rdata", sep=""))



set.seed(18102012)

arginS <- "smooth"
penaltyS <- "ps"

set3 <-  makeSettings(
  dgpsettings=list(M=c(30), 
                   ni=c(1),
                   p=c(0.8),
                   Gy=c(27),
                   Gx=c(100),
                   snrEps=c(2),
                   snrE=c(0),
                   snrB=c(2),
                   scenario=c(2),
                   k=c(5, 10),
                   type=c("local", "end"), ##, "start"
                   balanced=c(TRUE),
                   nuisance=c(0),  # 10
                   a=c("pen1coef4", "pen2coef4"),
                   regularS=c(TRUE), 
                   regularT=c(FALSE),
                   rep=1),
  algorithms=list(addNoise=c(FALSE),
                  centerX=c(TRUE),
                  penaltyS=c("ps"),
                  diffPen=c(1),
                  inS=c("smooth"))
)

length(set3)

usecores <- 5
options(cores=usecores)

# boosting on set3
res3 <- try(doSim(settings=set3, cores=usecores))
#res3
save(res3, file=paste(pathResults, "res3plot.Rdata", sep=""))



print(sessionInfo())


