50 bool CHomogeneousKernelMap::init(
CFeatures* features)
 
   64 void CHomogeneousKernelMap::init()
 
   66     SG_DEBUG (
"Initialising homogeneous kernel map...\n")
 
   81                         m_period = 5.86 * 
CMath::sqrt (static_cast<float64_t> (m_order))  + 3.65;
 
   83                     case HomogeneousKernelJS:
 
   84                         m_period = 6.64 * 
CMath::sqrt (static_cast<float64_t> (m_order))  + 7.24;
 
   87                         m_period = 2.38 * 
CMath::log (m_order + 0.8) + 5.6;
 
   91             case HomogeneousKernelMapWindowRectangular:
 
   94                         m_period = 8.80 * 
CMath::sqrt (m_order + 4.44) - 12.6;
 
   96                     case HomogeneousKernelJS:
 
   97                         m_period = 9.63 * 
CMath::sqrt (m_order + 1.00) - 2.93;
 
  100                         m_period = 2.00 * 
CMath::log (m_order + 0.99) + 3.52;
 
  108     m_numSubdivisions = 8 + 8*m_order;
 
  109     m_subdivision = 1.0 / m_numSubdivisions;
 
  113     int tableHeight = 2*m_order + 1 ;
 
  114     int tableWidth = m_numSubdivisions * (m_maxExponent - m_minExponent + 1);
 
  115     size_t numElements = (tableHeight * tableWidth + 2*(1+m_order));
 
  116     if (
unsigned(m_table.
vlen) != numElements) {
 
  117         SG_DEBUG (
"reallocating... %d -> %d\n", m_table.
vlen, numElements)
 
  118         m_table.vector = SG_REALLOC (
float64_t, m_table.vector, m_table.vlen, numElements);
 
  119         m_table.vlen = numElements;
 
  123     uint64_t i = 0, j = 0;
 
  124     float64_t* tablep = m_table.vector;
 
  125     float64_t* kappa = m_table.vector + tableHeight * tableWidth;
 
  126     float64_t* freq = kappa + (1+m_order);
 
  127     float64_t L = 2.0 * 
CMath::PI / m_period;
 
  130     while (i <= m_order) {
 
  132         kappa[i] = get_smooth_spectrum (j * L);
 
  134         if (kappa[i] > 0 || j >= 3*i) ++ i;
 
  138     for (exponent  = m_minExponent ;
 
  139             exponent <= m_maxExponent ; ++ exponent) {
 
  141         float64_t x, Lxgamma, Llogx, xgamma;
 
  142         float64_t sqrt2kappaLxgamma;
 
  143         float64_t mantissa = 1.0;
 
  145         for (i = 0 ; i < m_numSubdivisions;
 
  146                 ++i, mantissa += m_subdivision) {
 
  147             x = ldexp (mantissa, exponent);
 
  149             Lxgamma = L * xgamma;
 
  153             for (j = 1 ; j <= m_order; ++j) {
 
  154                 sqrt2kappaLxgamma = 
CMath::sqrt (2.0 * Lxgamma * kappa[j]);
 
  155                 *tablep++ = sqrt2kappaLxgamma * 
CMath::cos (freq[j] * Llogx);
 
  156                 *tablep++ = sqrt2kappaLxgamma * 
CMath::sin (freq[j] * Llogx);
 
  170     for (
int i = 0; i < num_vectors; ++i)
 
  173         for (
int j=0; j<transformed.
vlen; j++)
 
  174             feature_matrix(j,i) = transformed[j];
 
  179     return feature_matrix;
 
  245 CHomogeneousKernelMap::get_spectrum(float64_t omega)
 const 
  249             return (2.0 / 
CMath::PI) / (1 + 4 * omega*omega);
 
  252         case HomogeneousKernelJS:
 
  255                 (1 + 4 * omega*omega);
 
  258             throw ShogunException (
"CHomogeneousKernelMap::get_spectrum: no valid kernel has been set!");
 
  263 CHomogeneousKernelMap::sinc(float64_t x)
 const 
  265     if (x == 0.0) 
return 1.0 ;
 
  270 CHomogeneousKernelMap::get_smooth_spectrum(float64_t omega)
 const 
  272     float64_t kappa_hat = 0;
 
  274     float64_t epsilon = 1e-2;
 
  275     float64_t 
const omegaRange = 2.0 / (m_period * epsilon);
 
  276     float64_t 
const domega = 2 * omegaRange / (2 * 1024.0 + 1);
 
  279             kappa_hat = get_spectrum (omega);
 
  281         case HomogeneousKernelMapWindowRectangular:
 
  282             for (omegap = - omegaRange ; omegap <= omegaRange ; omegap += domega) {
 
  283                 float64_t win = sinc ((m_period/2.0) * omegap);
 
  285                 kappa_hat += win * get_spectrum (omegap + omega);
 
  293             throw ShogunException (
"CHomogeneousKernelMap::get_smooth_spectrum: no valid kernel has been set!");
 
  302     ASSERT (in_v.vector != NULL)
 
  304     uint64_t featureDimension = 2*m_order+1;
 
  306     SGVector<float64_t> out_v(featureDimension*in_v.vlen);
 
  308     for (
int k = 0; k < in_v.vlen; ++k) {
 
  312         float64_t mantissa = frexp (in_v[k], &exponent);
 
  313         float64_t sign = (mantissa >= 0.0) ? +1.0 : -1.0;
 
  318                 exponent <= m_minExponent ||
 
  319                 exponent >= m_maxExponent)
 
  321             for (j = 0 ; j <= m_order ; ++j) {
 
  322                 out_v[k*featureDimension+j] = 0.0;
 
  328         float64_t 
const * v1 = m_table.
vector +
 
  329             (exponent - m_minExponent) * m_numSubdivisions * featureDimension;
 
  330         float64_t 
const * v2;
 
  334         while (mantissa >= m_subdivision) {
 
  335             mantissa -= m_subdivision;
 
  336             v1 += featureDimension;
 
  339         v2 = v1 + featureDimension;
 
  340         for (j = 0 ; j < featureDimension ; ++j) {
 
  344             out_v[k*featureDimension+j] = sign * ((f2 - f1) * (m_numSubdivisions * mantissa) + f1);
 
  350 void CHomogeneousKernelMap::register_params()
 
static float64_t sin(float64_t x)
tanh(x), x being a complex128_t 
uint64_t get_order() const 
ST * get_feature_vector(int32_t num, int32_t &len, bool &dofree)
int32_t get_num_features() const 
virtual ~CHomogeneousKernelMap()
Class ShogunException defines an exception which is thrown whenever an error inside of shogun occurs...
void set_feature_matrix(SGMatrix< ST > matrix)
void set_period(float64_t p)
void set_window_type(HomogeneousKernelMapWindowType w)
virtual int32_t get_num_vectors() const 
Template class DensePreprocessor, base class for preprocessors (cf. CPreprocessor) that apply to CDen...
HomogeneousKernelMapWindowType
Type of spectral windowing function. 
static float64_t cos(float64_t x)
sinh(x), x being a complex128_t 
virtual EFeatureClass get_feature_class() const =0
HomogeneousKernelMapWindowType get_window_type() const 
HomogeneousKernelType
Type of kernel. 
all of classes and functions are contained in the shogun namespace 
The class Features is the base class of all feature objects. 
static float64_t exp(float64_t x)
virtual bool init(CFeatures *features)
static float64_t log(float64_t v)
Class which collects generic mathematical functions. 
void set_kernel_type(HomogeneousKernelType k)
void set_order(uint64_t o)
float64_t get_period() const 
static float32_t sqrt(float32_t x)
float64_t get_gamma(float64_t g) const 
void set_gamma(float64_t g)
static int32_t pow(bool x, int32_t n)
virtual SGVector< float64_t > apply_to_feature_vector(SGVector< float64_t > vector)
apply preproc on single feature vector 
virtual EFeatureType get_feature_type() const =0
virtual SGMatrix< float64_t > apply_to_feature_matrix(CFeatures *features)
HomogeneousKernelType get_kernel_type() const 
static const float64_t PI