mirror of https://github.com/davisking/dlib.git
Added a comment about picking a reasonable gamma.
--HG-- extra : convert_revision : svn%3Afdd8eb12-d10e-0410-9acb-85c331704f74/trunk%403744
This commit is contained in:
parent
05598b44fd
commit
9d09a8db3d
|
@ -28,18 +28,6 @@ int main()
|
|||
// Here we declare that our samples will be 1 dimensional column vectors.
|
||||
typedef matrix<double,1,1> sample_type;
|
||||
|
||||
// Now we are making a typedef for the kind of kernel we want to use. I picked the
|
||||
// radial basis kernel because it only has one parameter and generally gives good
|
||||
// results without much fiddling.
|
||||
typedef radial_basis_kernel<sample_type> kernel_type;
|
||||
|
||||
// Here we declare an instance of the rvm_regression_trainer object. This is the
|
||||
// object that we will later use to do the training.
|
||||
rvm_regression_trainer<kernel_type> trainer;
|
||||
// Here we set the kernel we want to use for training. The 0.05 is the gamma
|
||||
// parameter to the radial_basis_kernel.
|
||||
trainer.set_kernel(kernel_type(0.05));
|
||||
|
||||
// Now sample some points from the sinc() function
|
||||
sample_type m;
|
||||
std::vector<sample_type> samples;
|
||||
|
@ -51,6 +39,28 @@ int main()
|
|||
labels.push_back(sinc(x));
|
||||
}
|
||||
|
||||
// Now we are making a typedef for the kind of kernel we want to use. I picked the
|
||||
// radial basis kernel because it only has one parameter and generally gives good
|
||||
// results without much fiddling.
|
||||
typedef radial_basis_kernel<sample_type> kernel_type;
|
||||
|
||||
// Here we declare an instance of the rvm_regression_trainer object. This is the
|
||||
// object that we will later use to do the training.
|
||||
rvm_regression_trainer<kernel_type> trainer;
|
||||
|
||||
// Here we set the kernel we want to use for training. The radial_basis_kernel
|
||||
// has a parameter called gamma that we need to determine. As a rule of thumb, a good
|
||||
// gamma to try is 1.0/(mean squared distance between your sample points). So
|
||||
// below we are using a similar value. Note also that using an inappropriately large
|
||||
// gamma will cause the RVM training algorithm to run extremely slowly. What
|
||||
// "large" means is relative to how spread out your data is. So it is important
|
||||
// to use a rule like this as a starting point for determining the gamma value
|
||||
// if you want to use the RVM. It is also probably a good idea to normalize your
|
||||
// samples as shown in the rvm_ex.cpp example program.
|
||||
const double gamma = 2.0/compute_mean_squared_distance(samples);
|
||||
cout << "using gamma of " << gamma << endl;
|
||||
trainer.set_kernel(kernel_type(gamma));
|
||||
|
||||
// now train a function based on our sample points
|
||||
decision_function<kernel_type> test = trainer.train(samples, labels);
|
||||
|
||||
|
@ -62,6 +72,7 @@ int main()
|
|||
m(0) = 5.0; cout << sinc(m(0)) << " " << test(m) << endl;
|
||||
|
||||
// The output is as follows:
|
||||
//using gamma of 0.05
|
||||
//0.239389 0.240989
|
||||
//0.998334 0.999538
|
||||
//-0.189201 -0.188453
|
||||
|
|
Loading…
Reference in New Issue