CSvmLinear.cpp
Go to the documentation of this file.
1 
2 #include <shark/Data/Dataset.h>
6 
7 
8 using namespace shark;
9 using namespace std;
10 
11 
12  typedef RealVector VectorType;
13  // or:
14  // typedef CompressedRealVector VectorType;
15 
16 
17 int main(int argc, char** argv)
18 {
19  // experiment settings
20  unsigned int ell = 500; // number of training data point
21  unsigned int tests = 10000; // number of test data points
22  double C = 1.0; // regularization parameter
23 
24  // generate dataset
25  PamiToy problem; // artificial benchmark data
27  training = problem.generateDataset(ell);
29  test = problem.generateDataset(tests);
30 
31  // define the model
33 
34  // define the machine
35  LinearCSvmTrainer<VectorType> trainer(C, false);
36 
37  // train the machine
38  cout << "Algorithm: " << trainer.name() << "\ntraining ..." << flush; // Shark algorithms know their names
39  trainer.train(model, training);
40  cout << "\n number of iterations: " << trainer.solutionProperties().iterations;
41  cout << "\n dual value: " << trainer.solutionProperties().value;
42  cout << "\n training time: " << trainer.solutionProperties().seconds << " seconds\ndone." << endl;
43 
44  // evaluate
46  Data<unsigned int> output = model(training.inputs());
47  double train_error = loss.eval(training.labels(), output);
48  cout << "training error:\t" << train_error << endl;
49  output = model(test.inputs());
50  double test_error = loss.eval(test.labels(), output);
51  cout << "test error:\t" << test_error << endl;
52 }