require(datanugget)
require(rstiefel)
#4-dim small example
X = cbind.data.frame(rnorm(5*10^3),
rnorm(5*10^3),
rnorm(5*10^3),
rnorm(5*10^3))
#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
#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)%*%proj_2d
#plot the projected data nuggets
#lighter green represents larger weights
plotNugg(nuggproj_2d, weight)
#project raw large data into 2-dim space using the same projection matrix
rawproj_2d = as.matrix(X)%*%proj_2d
#plot projected raw large dataset
plot(rawproj_2d)
#estimated density for 2-dim projected data based on the data nuggets
est_nugg = nuggKDE(nuggproj_2d, weight, scale)
#plot the estimated density values
image(est_nugg)
Run the code above in your browser using DataLab