3 using namespace shogun;
15 register_parameters();
19 :
CDotFeatures(), m_multi_index(NULL), m_multinomial_coefficients(NULL),
20 m_normalization_values(NULL)
36 register_parameters();
121 float64_t* vec2 = pf->m_feat->get_feature_vector(vec_idx2, len2, do_free2);
132 out2*=vec2[m_multi_index[cnt]];
138 pf->m_feat->free_feature_vector(vec2, len2, do_free2);
155 for (
int j=0; j<vec2_len; j++)
186 for (
int j=0; j<vec2_len; j++)
197 vec2[j]+=alpha*output;
208 for (
int i=0; i<num_vec; i++)
228 SG_ERROR(
"Error allocating mem \n");
241 exponents[feat_idx] = degree;
243 exponents[feat_idx] = 0;
245 for (j=0; j<feat_idx+1; j++)
246 for (i=0; i<exponents[j]; i++)
251 exponents[feat_idx] = 0;
255 for (k=0; k<=degree; k++)
257 exponents[feat_idx] = k;
271 SG_ERROR(
"Error allocating mem \n");
335 for (i=0; i<len; i++)
338 ret *=
bico2(n, exps[i]);
348 static float64_t cof[6]={76.18009172947146, -86.50532032941677,
349 24.01409824083091, -1.231739572450155,
350 0.1208650973866179e-2,-0.5395239384953e-5};
355 tmp -= (x+0.5)*log(tmp);
356 ser=1.000000000190015;
357 for (j=0;j<=5;j++) ser += cof[j]/++y;
358 return -tmp+log(2.5066282746310005*ser/x);
365 if (n < 0)
SG_ERROR(
"Negative factorial in routine factln\n");
366 if (n <= 1)
return 0.0;
367 if (n <= 100)
return a[n] ? a[n] : (a[n]=
gammln(n+1.0));
368 else return gammln(n+1.0);
381 void CPolyFeatures::register_parameters()
384 "Features in original space.");
388 "Dimensions of the input space.");
390 "Dimensions of the feature space of the polynomial kernel.");
397 "Flattened matrix of all multi indices that sum do the"
398 " degree of the polynomial kernel.");
402 &multinomial_coefficients_length,
"multinomial_coefficients",
403 "Multinomial coefficients for all multi-indices.");
407 &normalization_values_length,
"normalization_values",
408 "Norm of each training example.");
void store_normalization_values()
virtual int32_t get_dim_feature_space() const
virtual EFeatureType get_feature_type()=0
int32_t bico2(int32_t n, int32_t k)
ST * get_feature_vector(int32_t num, int32_t &len, bool &dofree)
virtual EFeatureType get_feature_type()
int32_t bico(int32_t n, int32_t k)
void store_multinomial_coefficients()
virtual int32_t get_num_vectors() const
int32_t m_output_dimensions
#define SG_NOTIMPLEMENTED
virtual float64_t dot(int32_t vec_idx1, CDotFeatures *df, int32_t vec_idx2)
virtual void free_feature_iterator(void *iterator)
virtual bool get_next_feature(int32_t &index, float64_t &value, void *iterator)
void free_feature_vector(ST *feat_vec, int32_t num, bool dofree)
Features that support dot products among other operations.
EFeatureClass
shogun feature class
float32_t * m_normalization_values
void add_to_dense_vec(float64_t alpha, int32_t vec_idx1, float64_t *vec2, int32_t vec2_len, bool abs_val)
void add(bool *param, const char *name, const char *description="")
Class SGObject is the base class of all shogun objects.
CFeatures * duplicate() const
virtual EFeatureClass get_feature_class()=0
void enumerate_multi_index(const int32_t feat_idx, uint16_t **index, uint16_t *exponents, const int32_t degree)
float64_t * m_multinomial_coefficients
virtual int32_t get_size()
virtual int32_t get_nnz_features_for_vector(int32_t num)
float64_t factln(int32_t n)
virtual void * get_feature_iterator(int32_t vector_index)
EFeatureType
shogun feature type
virtual int32_t get_num_vectors() const
float64_t dense_dot(int32_t vec_idx1, const float64_t *vec2, int32_t vec2_len)
int32_t calc_feature_space_dimensions(int32_t N, int32_t D)
void add_vector(bool **param, index_t *length, const char *name, const char *description="")
CSimpleFeatures< float64_t > * m_feat
The class Features is the base class of all feature objects.
int32_t m_input_dimensions
float64_t gammln(float64_t xx)
implement DotFeatures for the polynomial kernel
virtual EFeatureClass get_feature_class()
static float32_t sqrt(float32_t x)
x^0.5
#define SG_MALLOC(type, len)
int32_t get_num_features()
static T abs(T a)
return the absolute value of a number
int32_t multinomialcoef(int32_t *exps, int32_t len)