home»research»kml»tutorial

Tutorial

Sinc regression

A common benchmark used in the kernel-machine literature is that of a toy sinc function. Here we show how to reproduce these examples with a kernel machine of your choice. First, let us define our data structure.

#include <boost/vector_property_map.hpp> 
typedef std::pair< double, double > example_type; 
typedef boost::vector_property_map< example_type > container_type; 

The example_type is an input-output pair eqn_xynh with both inputs and outputs being of type double. The container_type provides a type definition for the data container to be used by the kernel machine of choice (this could also very well be, e.g., a custom class that accesses a database on-the-fly to retrieve examples of example_type).

We let the data for one experiment consist of 50 examples eqn_wvb4, with inputs eqn_tynf uniformly distributed over [-10,10], and outputs corrupted with Gaussian noise, eqn_n9hf.

#include <boost/random/mersenne_twister.hpp> 
#include <boost/random/normal_distribution.hpp> 
#include <boost/random/variate_generator.hpp> 
#include <boost/math/special_functions/sinc.hpp> 
 
// create the random number generator N(0,0.1) 
boost::mt19937 randomness; 
typedef boost::normal_distribution<double> dist_type; 
dist_type norm_dist( 0.0, 0.1 ); 
boost::variate_generator< boost::mt19937, dist_type > noise( randomness, 
                                                             norm_dist ); 
// instantiate the data container, and fill it with (x,y)-pairs 
container_type my_data; 
for( int i=0; i<50; ++i ) { 
  double x = static_cast<double>(i) / 49.0 * 20.0 - 10.0; 
  my_data[ i ] = std::make_pair( x, boost::sinc(x) + noise() ); 
} 

To generate the outputs, we have pulled in parts from the Boost Random Number Library, and the sinc function from the Boost Math Special Functions Library. Figure 1 shows an example scatterplot of the data that we just built the generator for.

sinc_data

Figure 1: Input data generated for our first tutorial example.

See Also

Reference