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