This represents a small example how to use sparse grids for classification problems.
It uses the artificial Ripley dataset.
#include <string>
#include <vector>
#include <exception>
#include <limits>
#include <ostream>
getLearner creates a sparse grid classification learner.
- Parameters
-
dimension | the number of dimensions. |
- Returns
- a classification for dimension dimension
gridConfig.dim_ = dimension;
gridConfig.level_ = 3;
adaptivityConfig.noPoints_ = 0;
adaptivityConfig.numRefinements_ = 0;
solverConfig.maxIterations_ = 500;
solverConfig.eps_ = 1e-8;
regularizationConfig.lambda_ = 0.00001;
regularizationConfig.exponentBase_ = 0.25;
solverConfig, regularizationConfig);
}
main Creates a sparse grid classification learner and prints the training accuracy for the ripley dataset.
- Returns
int main(
int argc,
char** argv) {
const auto filenameTrain =
std::string("../../datasets/ripley/ripleyGarcke.train.arff");
std::cout << "Read file " << filenameTrain << "." << std::endl;
auto xTrain = dataTrain.getData();
auto yTrain = dataTrain.getTargets();
const auto dimensions = dataTrain.getDimension();
auto learner = getLearner(dimensions);
learner.train(xTrain, yTrain);
const auto accuracy = learner.getAccuracy(xTrain, yTrain);
std::cout <<
"Best config got a training acc of " <<
accuracy <<
"!" << std::endl;
}