SG++-Doxygen-Documentation
|
This tutorial demostrates the sparse grid density estimation
Simple Java SG++ example for the SGDE learner
-File class needed to turn stringName to actual file
-read from filePooped with Scanner class
hashNext() loops line-by-line
read single line, put in string
after loop, close scanner
Main method.
args | ignored // Two working possiblities for loading the shared object file: //java.lang.System.load("/path/to/SGpp/trunk/lib/jsgpp/libjsgpp.so"); sgpp.LoadJSGPPLib.loadJSGPPLib(); String filename = "../datasets/friedman_4d_2000.arff"; System.out.println("# loading file: " + filename); DataMatrix samples = readARFF(filename); Configure grid System.out.println("# create grid config"); RegularGridConfiguration gridConfig = new RegularGridConfiguration(); gridConfig.setDim_(samples.getNcols()); gridConfig.setLevel_(4); gridConfig.setType_(GridType.Linear); Configure adaptive refinement System.out.println("# create adaptive refinement config"); AdaptivityConfiguration adaptConfig = new AdaptivityConfiguration(); adaptConfig.setNoPoints_(5); adaptConfig.setNumRefinements_(0); Configure solver System.out.println("# create solver config"); SLESolverConfiguration solverConfig = new SLESolverConfiguration(); solverConfig.setType_(SLESolverType.CG); solverConfig.setMaxIterations_(100); solverConfig.setEps_(1e-10); solverConfig.setThreshold_(1e-10); Configure regularization System.out.println("# create regularization config"); RegularizationConfiguration regularizationConfig = new RegularizationConfiguration(); regularizationConfig.setRegType_(RegularizationType.Laplace); Configure learner System.out.println("# create learner config"); LearnerSGDEConfiguration learnerConfig = new LearnerSGDEConfiguration(); learnerConfig.setDoCrossValidation_(false); learnerConfig.setKfold_(5); learnerConfig.setLambdaStart_(1e-1); learnerConfig.setLambdaEnd_(1e-10); learnerConfig.setLambdaSteps_(5); learnerConfig.setLogScale_(true); learnerConfig.setShuffle_(true); learnerConfig.setSeed_(1234567); learnerConfig.setSilent_(false); Initialize and run learner System.out.println("# creating the learner"); LearnerSGDE learner = new LearnerSGDE(gridConfig, adaptConfig, solverConfig, regularizationConfig, learnerConfig); learner.initialize(samples); For comparison, run the sparse grid kernel-based learner KernelDensityEstimator kde = new KernelDensityEstimator(samples); DataVector x = new DataVector(3); View resulting pdf in the middle of the domain x.set(i, 0.5); } System.out.println("--------------------------------------------------------"); System.out.println(learner.getGrid().getSize() + " -> " + learner.getAlpha().sum()); System.out.println("pdf_SGDE(x) = " + learner.pdf(x) + " ~ " + kde.pdf(x) + " = pdf_KDE(x)"); System.out.println("mean_SGDE(x) = " + learner.mean() + " ~ " + kde.mean() + " = mean_KDE(x)"); System.out.println("var_SGDE(x) = " + learner.variance() + " ~ " + kde.variance() + " = var_KDE(x)"); } } |