

#for i=1

library(fda)




#waveform

casose <-c('we1.txt','we2.txt','we3.txt','we4.txt','we5.txt','we6.txt','we7.txt','we8.txt','we9.txt','we10.txt','we11.txt','we12.txt','we13.txt','we14.txt','we15.txt','we16.txt','we17.txt','we18.txt','we19.txt','we20.txt','we21.txt','we22.txt','we23.txt','we24.txt','we25.txt','we26.txt','we27.txt','we28.txt','we29.txt','we30.txt','we31.txt','we32.txt','we33.txt','we34.txt','we35.txt','we36.txt','we37.txt','we38.txt','we39.txt','we40.txt','we41.txt','we42.txt','we43.txt','we44.txt','we45.txt')

casose <- c(casose,'we46.txt','we47.txt','we48.txt','we49.txt','we50.txt')



casost <-c('wt1.txt','wt2.txt','wt3.txt','wt4.txt','wt5.txt','wt6.txt','wt7.txt','wt8.txt','wt9.txt','wt10.txt','wt11.txt','wt12.txt','wt13.txt','wt14.txt','wt15.txt','wt16.txt','wt17.txt','wt18.txt','wt19.txt','wt20.txt','wt21.txt','wt22.txt','wt23.txt','wt24.txt','wt25.txt','wt26.txt','wt27.txt','wt28.txt','wt29.txt','wt30.txt','wt31.txt','wt32.txt','wt33.txt','wt34.txt','wt35.txt','wt36.txt','wt37.txt','wt38.txt','wt39.txt','wt40.txt','wt41.txt','wt42.txt','wt43.txt','wt44.txt','wt45.txt')

casost <- c(casost,'wt46.txt','wt47.txt','wt48.txt','wt49.txt','wt50.txt')




#points to FDA, coefficient basis

numbase=32#;%12,32,64,256
mibspline15=create.bspline.basis(c(1,21), numbase,6);
miLfdobj = int2Lfd(2);  
la = 1#;   %tb. 1
mifdPar = fdPar(mibspline15, miLfdobj, la);



ese=c()

K=3

i=1

we=read.table(casose[i])


 ex=we[,1:101]
 #nombre=['wt' num2str(i) '.txt'];
#wt=load(nombre);
#tex=wt(:,1:101);


nla=c(0.01 ,0.1,1,10,100)

 ti=seq(1,21,by=0.2)

fSmoothStats=c()
for (laa in nla) {
mifdPar = fdPar(mibspline15, miLfdobj, laa);

fSmooth <- smooth.basisPar(ti, t(ex), mibspline15,lambda=laa)
fSmoothStats=c( fSmoothStats,sum(fSmooth$gcv))
}


i=1 GCV is minimized with lambda
> fSmoothStats
[1] 529.1563 513.0826 504.4113 498.1286 499.7708

#for all i

mi=c()
for (i in 1:50){

we=read.table(casose[i])


 ex=we[,1:101]
 #nombre=['wt' num2str(i) '.txt'];
#wt=load(nombre);
#tex=wt(:,1:101);


nla=c(0.01 ,0.1,1,10,100)

 ti=seq(1,21,by=0.2)

fSmoothStats=c()
for (laa in nla) {
mifdPar = fdPar(mibspline15, miLfdobj, laa);

fSmooth <- smooth.basisPar(ti, t(ex), mibspline15,lambda=laa)
fSmoothStats=c( fSmoothStats,sum(fSmooth$gcv))
mi[i]=which.min(fSmoothStats)
}

}

> mi
 [1] 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
[39] 4 4 4 4 4 4 4 4 4 4 4 4
