SHOGUN  3.2.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
RandomKitchenSinksDotFeatures.cpp
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or modify
3  * it under the terms of the GNU General Public License as published by
4  * the Free Software Foundation; either version 3 of the License, or
5  * (at your option) any later version.
6  *
7  * Written (W) 2013 Evangelos Anagnostopoulos
8  * Copyright (C) 2013 Evangelos Anagnostopoulos
9  */
10 
13 #include <typeinfo>
14 
15 namespace shogun
16 {
17 
18 class CRKSFunctions;
19 
21  : CDotFeatures()
22 {
23  init(NULL, 0);
24 }
25 
27  CDotFeatures* dataset, int32_t K)
28 {
29  init(dataset, K);
30 }
31 
33  CDotFeatures* dataset, int32_t K, SGMatrix<float64_t> coeff)
34 {
35  init(dataset, K);
36  random_coeff = coeff;
37 }
38 
40 {
42  SGMatrix<float64_t> random_params(vec.vlen, num_samples);
43  for (index_t dim=0; dim<random_params.num_rows; dim++)
44  random_params(dim, 0) = vec[dim];
45 
46  for (index_t sample=1; sample<num_samples; sample++)
47  {
49  for (index_t dim=0; dim<random_params.num_rows; dim++)
50  random_params(dim, sample) = vec[dim];
51  }
52  return random_params;
53 }
54 
56 {
58 }
59 
62 {
63  init(orig.feats, orig.num_samples);
65 }
66 
68 {
69  SG_UNREF(feats);
70 }
71 
72 void CRandomKitchenSinksDotFeatures::init(CDotFeatures* dataset,
73  int32_t K)
74 {
75  feats = dataset;
76  SG_REF(feats);
77 
78  num_samples = K;
79 
80  SG_ADD((CSGObject** ) &feats, "feats", "Features to work on",
82  m_parameters->add(&random_coeff, "random_coeff", "Random function parameters");
83 }
84 
86 {
87  return num_samples;
88 }
89 
91  int32_t vec_idx2)
92 {
93  ASSERT(typeid(*this) == typeid(*df));
96 
97  float64_t dot_product = 0;
98  for (index_t i=0; i<num_samples; i++)
99  {
100  float64_t tmp_dot_1 = dot(vec_idx1, i);
101  float64_t tmp_dot_2 = other->dot(vec_idx2, i);
102 
103  tmp_dot_1 = post_dot(tmp_dot_1, i);
104  tmp_dot_2 = other->post_dot(tmp_dot_2, i);
105  dot_product += tmp_dot_1 * tmp_dot_2;
106  }
107  return dot_product;
108 }
109 
111  int32_t vec_idx1, const float64_t* vec2, int32_t vec2_len)
112 {
113  SG_DEBUG("entering dense_dot()\n");
114  ASSERT(vec2_len == get_dim_feature_space());
115 
116  float64_t dot_product = 0;
117  for (index_t i=0; i<num_samples; i++)
118  {
119  float64_t tmp_dot = dot(vec_idx1, i);
120  tmp_dot = post_dot(tmp_dot, i);
121  dot_product += tmp_dot * vec2[i];
122  }
123  SG_DEBUG("Leaving dense_dot()\n");
124  return dot_product;
125 }
126 
128  int32_t vec_idx1, float64_t* vec2, int32_t vec2_len, bool abs_val)
129 {
130  SG_DEBUG("Entering add_to_dense()\n");
131  ASSERT(vec2_len == get_dim_feature_space());
132 
133  for (index_t i=0; i<num_samples; i++)
134  {
135  float64_t tmp_dot = dot(vec_idx1, i);
136  tmp_dot = post_dot(tmp_dot, i);
137  if (abs_val)
138  vec2[i] += CMath::abs(alpha * tmp_dot);
139  else
140  vec2[i] += alpha * tmp_dot;
141  }
142  SG_DEBUG("Leaving add_to_dense()\n");
143 }
144 
146 {
147  return num_samples;
148 }
149 
151 {
153  return NULL;
154 }
155 
157  float64_t& value, void* iterator)
158 {
160  return false;
161 }
162 
164 {
166 }
167 
169 {
170  return F_DREAL;
171 }
172 
174 {
175  return C_DENSE;
176 }
177 
179 {
180  return feats->get_num_vectors();
181 }
182 
184 {
185  return "RandomKitchenSinksDotFeatures";
186 }
187 
189 {
191  return NULL;
192 }
193 
195 {
196  return random_coeff;
197 }
198 
200 {
201  return feats->dense_dot(vec_idx, random_coeff.get_column_vector(par_idx),
203 }
204 
206 {
207  return dot_result;
208 }
209 
210 }

SHOGUN Machine Learning Toolbox - Documentation