require(datanugget)
require(rstiefel)
#4-dim small example
X = cbind.data.frame(rnorm(5*10^3),
rnorm(5*10^3,2,1),
rnorm(5*10^3,5,2),
rnorm(5*10^3))
#raw data is recommended to be scaled firstly to generate data nuggets for Projection Pursuit
X = as.data.frame(scale(X))
#create data nuggets
my.DN = create.DN(x = X,
R = 500,
delete.percent = .1,
DN.num1 = 500,
DN.num2 = 250,
no.cores = 0,
make.pbs = FALSE)
#refine data nuggets
my.DN2 = refine.DN(x = X,
DN = my.DN,
EV.tol = .9,
min.nugget.size = 2,
max.splits = 5,
no.cores = 0,
make.pbs = FALSE)
#get nugget centers, weights, and scales
nugg = my.DN2$`Data Nuggets`[,2:(ncol(X)+1)]
weight = my.DN2$`Data Nuggets`$Weight
scale = my.DN2$`Data Nuggets`$Scale
#spherize the data nuggets with weights to calculate the PP index
nugg_wsph <- wsph(nugg,weight)$data_wsph
#generate a random orthonormal matrix as a projection matrix to 2-dim space
proj_2d = rustiefel(4, 2)
#project data nugget centers into 2-dim space by the random projection matrix
nuggproj_2d = as.matrix(nugg_wsph)%*%proj_2d
#plot the projected data nuggets
#lighter green represents larger weights
plotNugg(nuggproj_2d, weight)
#calculate the CM index for the projected 2-dim big data
CMNugg(nuggproj_2d,weight)
Run the code above in your browser using DataLab