# NOT RUN {
## generate sample data and separate them
X = aux.gensamples(n=500)
set.seed(46556)
idxselect = sample(1:500,20)
Xold = X[setdiff(1:500,idxselect),] # 80% of data for training
Xnew = X[idxselect,] # 20% of data for testing
## run PCA for train data
training = do.pca(Xold,ndim=2,preprocess="whiten")
Yold = training$Y # embedded data points
oldinfo = training$trfinfo # preprocessing information
## perform out-of-sample extension
output = oos.linproj(Xold, Yold, oldinfo, Xnew)
Ynew = output$Ynew
## let's compare via visualization
xx = c(-2,2) # range of axis 1 for compact visualization
yy = c(-2,2) # range of axis 2 for compact visualization
mm = "black=train / red=test data" # figure title
## visualize
opar <- par(no.readonly=TRUE)
plot(Yold, type="p", xlim=xx, ylim=yy, main=mm, xlab="axis 1", ylab="axis 2")
points(Ynew[,1], Ynew[,2], lwd=3, col="red")
par(opar)
# }
# NOT RUN {
# }
Run the code above in your browser using DataLab