SHOGUN  5.0.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules
RBM.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2014, Shogun Toolbox Foundation
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7 
8  * 1. Redistributions of source code must retain the above copyright notice,
9  * this list of conditions and the following disclaimer.
10  *
11  * 2. Redistributions in binary form must reproduce the above copyright notice,
12  * this list of conditions and the following disclaimer in the documentation
13  * and/or other materials provided with the distribution.
14  *
15  * 3. Neither the name of the copyright holder nor the names of its
16  * contributors may be used to endorse or promote products derived from this
17  * software without specific prior written permission.
18 
19  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
23  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29  * POSSIBILITY OF SUCH DAMAGE.
30  *
31  * Written (W) 2014 Khaled Nasr
32  */
33 
34 #include <shogun/neuralnets/RBM.h>
35 
36 
37 #include <shogun/base/Parameter.h>
40 
41 using namespace shogun;
42 
44 {
45  init();
46 }
47 
48 CRBM::CRBM(int32_t num_hidden)
49 {
50  init();
51  m_num_hidden = num_hidden;
52 }
53 
54 CRBM::CRBM(int32_t num_hidden, int32_t num_visible,
55  ERBMVisibleUnitType visible_unit_type) : CSGObject()
56 {
57  init();
58  m_num_hidden = num_hidden;
59  add_visible_group(num_visible, visible_unit_type);
60 }
61 
63 {
67 }
68 
69 void CRBM::add_visible_group(int32_t num_units, ERBMVisibleUnitType unit_type)
70 {
72  m_num_visible += num_units;
73 
76 
78 
79  if (n==0)
81  else
84 }
85 
87 {
90 
91  for (int32_t i=0; i<m_num_params; i++)
92  m_params[i] = CMath::normal_random(0.0,sigma);
93 }
94 
95 void CRBM::set_batch_size(int32_t batch_size)
96 {
97  if (m_batch_size == batch_size) return;
98 
99  m_batch_size = batch_size;
100 
103 
104  reset_chain();
105 }
106 
108 {
109  REQUIRE(features != NULL, "Invalid (NULL) feature pointer\n");
111  "Number of features (%i) must match the RBM's number of visible units "
112  "(%i)\n", features->get_num_features(), m_num_visible);
113 
114  SGMatrix<float64_t> inputs = features->get_feature_matrix();
115 
116  int32_t training_set_size = inputs.num_cols;
117  if (gd_mini_batch_size==0) gd_mini_batch_size = training_set_size;
119 
120  for (int32_t i=0; i<m_num_visible; i++)
121  for (int32_t j=0; j<m_batch_size; j++)
122  visible_state(i,j) = inputs(i,j);
123 
125 
126  // needed for momentum
127  SGVector<float64_t> param_updates(m_num_params);
128  param_updates.zero();
129 
130  float64_t alpha = gd_learning_rate;
131 
132  SGMatrix<float64_t> buffer;
137 
138  int32_t counter = 0;
139  for (int32_t i=0; i<max_num_epochs; i++)
140  {
141  for (int32_t j=0; j < training_set_size; j += gd_mini_batch_size)
142  {
143  alpha = gd_learning_rate_decay*alpha;
144 
145  if (j+gd_mini_batch_size>training_set_size)
146  j = training_set_size-gd_mini_batch_size;
147 
148  SGMatrix<float64_t> inputs_batch(inputs.matrix+j*inputs.num_rows,
149  inputs.num_rows, gd_mini_batch_size, false);
150 
151  for (int32_t k=0; k<m_num_params; k++)
152  m_params[k] += gd_momentum*param_updates[k];
153 
154  contrastive_divergence(inputs_batch, gradients);
155 
156  for (int32_t k=0; k<m_num_params; k++)
157  {
158  param_updates[k] = gd_momentum*param_updates[k]
159  -alpha*gradients[k];
160 
161  m_params[k] -= alpha*gradients[k];
162  }
163 
164  if (counter%monitoring_interval == 0)
165  {
167  SG_INFO("Epoch %i: reconstruction Error = %f\n",i,
168  reconstruction_error(inputs_batch, buffer));
170  SG_INFO("Epoch %i: Pseudo-log-likelihood = %f\n",i,
171  pseudo_likelihood(inputs_batch,buffer));
172  }
173  counter ++;
174  }
175  }
176 }
177 
178 void CRBM::sample(int32_t num_gibbs_steps,
179  int32_t batch_size)
180 {
181  set_batch_size(batch_size);
182 
183  for (int32_t i=0; i<num_gibbs_steps; i++)
184  {
188  if (i<num_gibbs_steps-1)
190  }
191 }
192 
194  int32_t num_gibbs_steps, int32_t batch_size)
195 {
197  "Visible group index (%i) out of bounds (%i)\n", V, m_num_visible);
198 
199  sample(num_gibbs_steps, batch_size);
200 
202 
203  int32_t offset = m_visible_state_offsets->element(V);
204  for (int32_t i=0; i<m_visible_group_sizes->element(V); i++)
205  for (int32_t j=0; j<m_batch_size; j++)
206  result(i,j) = visible_state(i+offset,j);
207 
208  return new CDenseFeatures<float64_t>(result);
209 }
210 
212  int32_t E, CDenseFeatures< float64_t >* evidence, int32_t num_gibbs_steps)
213 {
215  "Visible group index (%i) out of bounds (%i)\n", E, m_num_visible);
216 
217  set_batch_size(evidence->get_num_vectors());
218 
219  SGMatrix<float64_t> evidence_matrix = evidence->get_feature_matrix();
220 
221  int32_t offset = m_visible_state_offsets->element(E);
222 
223  for (int32_t i=0; i<m_visible_group_sizes->element(E); i++)
224  for (int32_t j=0; j<m_batch_size; j++)
225  visible_state(i+offset,j) = evidence_matrix(i,j);
226 
227  for (int32_t n=0; n<num_gibbs_steps; n++)
228  {
232  if (n<num_gibbs_steps-1)
233  {
234  for (int32_t k=0; k<m_num_visible_groups; k++)
235  if (k!=E)
237  }
238 
239  for (int32_t i=0; i<m_visible_group_sizes->element(E); i++)
240  for (int32_t j=0; j<m_batch_size; j++)
241  visible_state(i+offset,j) = evidence_matrix(i,j);
242  }
243 }
244 
246  int32_t E, CDenseFeatures< float64_t >* evidence, int32_t num_gibbs_steps)
247 {
249  "Visible group index (%i) out of bounds (%i)\n", V, m_num_visible);
251  "Visible group index (%i) out of bounds (%i)\n", E, m_num_visible);
252 
253  sample_with_evidence(E, evidence, num_gibbs_steps);
254 
256 
257  int32_t offset = m_visible_state_offsets->element(V);
258  for (int32_t i=0; i<m_visible_group_sizes->element(V); i++)
259  for (int32_t j=0; j<m_batch_size; j++)
260  result(i,j) = visible_state(i+offset,j);
261 
262  return new CDenseFeatures<float64_t>(result);
263 }
264 
266 {
267  for (int32_t i=0; i<m_num_visible; i++)
268  for (int32_t j=0; j<m_batch_size; j++)
269  visible_state(i,j) = CMath::random(0.0,1.0) > 0.5;
270 }
271 
273 {
274  set_batch_size(visible.num_cols);
275 
276  if (buffer.num_rows==0)
278 
279  typedef Eigen::Map<Eigen::MatrixXd> EMatrix;
280  typedef Eigen::Map<Eigen::VectorXd> EVector;
281 
282  EMatrix V(visible.matrix, visible.num_rows, visible.num_cols);
283  EMatrix W(get_weights().matrix, m_num_hidden, m_num_visible);
284  EVector B(get_visible_bias().vector, m_num_visible);
285  EVector C(get_hidden_bias().vector, m_num_hidden);
286 
287  EVector bv_buffer(buffer.matrix, m_batch_size);
288  EMatrix wv_buffer(buffer.matrix, m_num_hidden, m_batch_size);
289 
290  bv_buffer = B.transpose()*V;
291  float64_t bv_term = bv_buffer.sum();
292 
293  wv_buffer.colwise() = C;
294  wv_buffer += W*V;
295 
296  float64_t wv_term = 0;
297  for (int32_t i=0; i<m_num_hidden; i++)
298  for (int32_t j=0; j<m_batch_size; j++)
299  wv_term += CMath::log(1.0+CMath::exp(wv_buffer(i,j)));
300 
301  float64_t F = -1.0*(bv_term+wv_term)/m_batch_size;
302 
303  for (int32_t k=0; k<m_num_visible_groups; k++)
304  {
306  {
307  int32_t offset = m_visible_state_offsets->element(k);
308 
309  for (int32_t i=0; i<m_visible_group_sizes->element(k); i++)
310  for (int32_t j=0; j<m_batch_size; j++)
311  F += 0.5*CMath::pow(visible(i+offset,j),2)/m_batch_size;
312  }
313  }
314 
315  return F;
316 }
317 
319  SGVector< float64_t > gradients,
320  bool positive_phase,
321  SGMatrix< float64_t > hidden_mean_given_visible)
322 {
323  set_batch_size(visible.num_cols);
324 
325  if (hidden_mean_given_visible.num_rows==0)
326  {
327  hidden_mean_given_visible = SGMatrix<float64_t>(m_num_hidden,m_batch_size);
328  mean_hidden(visible, hidden_mean_given_visible);
329  }
330 
331  typedef Eigen::Map<Eigen::MatrixXd> EMatrix;
332  typedef Eigen::Map<Eigen::VectorXd> EVector;
333 
334  EMatrix V(visible.matrix, visible.num_rows, visible.num_cols);
335  EMatrix PH(hidden_mean_given_visible.matrix, m_num_hidden,m_batch_size);
336 
337  EMatrix WG(get_weights(gradients).matrix, m_num_hidden, m_num_visible);
338  EVector BG(get_visible_bias(gradients).vector, m_num_visible);
339  EVector CG(get_hidden_bias(gradients).vector, m_num_hidden);
340 
341  if (positive_phase)
342  {
343  WG = -1*PH*V.transpose()/m_batch_size;
344  BG = -1*V.rowwise().sum()/m_batch_size;
345  CG = -1*PH.rowwise().sum()/m_batch_size;
346  }
347  else
348  {
349  WG += PH*V.transpose()/m_batch_size;
350  BG += V.rowwise().sum()/m_batch_size;
351  CG += PH.rowwise().sum()/m_batch_size;
352  }
353 }
354 
356  SGVector< float64_t > gradients)
357 {
358  set_batch_size(visible_batch.num_cols);
359 
360  // positive phase
361  mean_hidden(visible_batch, hidden_state);
362  free_energy_gradients(visible_batch, gradients, true, hidden_state);
363 
364  // sampling
365  for (int32_t i=0; i<cd_num_steps; i++)
366  {
367  if (i>0 || cd_persistent)
371  if (cd_sample_visible)
373  }
374 
375  // negative phase
378 
379  // regularization
380  if (l2_coefficient>0)
381  {
382  int32_t len = m_num_hidden*m_num_visible;
383  for (int32_t i=0; i<len; i++)
384  gradients[i+m_num_visible+m_num_hidden] +=
385  l2_coefficient * m_params[i+m_num_visible+m_num_hidden];
386  }
387 
388  if (l1_coefficient>0)
389  {
390  int32_t len = m_num_hidden*m_num_visible;
391  for (int32_t i=0; i<len; i++)
392  gradients[i+m_num_visible+m_num_hidden] +=
393  l1_coefficient * m_params[i+m_num_visible+m_num_hidden];
394  }
395 
396 }
397 
399  SGMatrix< float64_t > buffer)
400 {
401  set_batch_size(visible.num_cols);
402 
403  if (buffer.num_rows==0)
405 
406  mean_hidden(visible, hidden_state);
408  mean_visible(hidden_state, buffer);
409 
410  float64_t error = 0;
411 
412  int32_t len = m_num_visible*m_batch_size;
413  for (int32_t i=0; i<len; i++)
414  error += CMath::pow(buffer[i]-visible[i],2);
415 
416  return error/m_batch_size;
417 }
418 
419 
421  SGMatrix< float64_t > buffer)
422 {
423  for (int32_t k=0; k<m_num_visible_groups; k++)
425  SG_ERROR("Pseudo-likelihood is only supported for binary visible units\n");
426 
427  set_batch_size(visible.num_cols);
428 
429  if (buffer.num_rows==0)
431 
433  for (int32_t i=0; i<m_batch_size; i++)
434  indices[i] = CMath::random(0,m_num_visible-1);
435 
436 
437  float64_t f1 = free_energy(visible, buffer);
438 
439  for (int32_t j=0; j<m_batch_size; j++)
440  visible(indices[j],j) = 1.0-visible(indices[j],j);
441 
442  float64_t f2 = free_energy(visible, buffer);
443 
444  for (int32_t j=0; j<m_batch_size; j++)
445  visible(indices[j],j) = 1.0-visible(indices[j],j);
446 
447  return m_num_visible*CMath::log(1.0/(1+CMath::exp(f1-f2)));
448 }
449 
451 {
452  typedef Eigen::Map<Eigen::MatrixXd> EMatrix;
453  typedef Eigen::Map<Eigen::VectorXd> EVector;
454 
455  EMatrix V(visible.matrix, visible.num_rows, visible.num_cols);
456  EMatrix H(result.matrix, result.num_rows, result.num_cols);
457  EMatrix W(get_weights().matrix, m_num_hidden, m_num_visible);
458  EVector C(get_hidden_bias().vector, m_num_hidden);
459 
460  H.colwise() = C;
461  H += W*V;
462 
463  int32_t len = result.num_rows*result.num_cols;
464  for (int32_t i=0; i<len; i++)
465  result[i] = 1.0/(1.0+CMath::exp(-1.0*result[i]));
466 }
467 
469 {
470  typedef Eigen::Map<Eigen::MatrixXd> EMatrix;
471  typedef Eigen::Map<Eigen::VectorXd> EVector;
472 
473  EMatrix H(hidden.matrix, hidden.num_rows, hidden.num_cols);
474  EMatrix V(result.matrix, result.num_rows, result.num_cols);
475  EMatrix W(get_weights().matrix, m_num_hidden, m_num_visible);
476  EVector B(get_visible_bias().vector, m_num_visible);
477 
478  V.colwise() = B;
479  V += W.transpose()*H;
480 
481  for (int32_t k=0; k<m_num_visible_groups; k++)
482  {
483  int32_t offset = m_visible_state_offsets->element(k);
484 
486  {
487  for (int32_t i=0; i<m_visible_group_sizes->element(k); i++)
488  for (int32_t j=0; j<m_batch_size; j++)
489  result(i+offset,j) = 1.0/(1.0+CMath::exp(-1.0*result(i+offset,j)));
490  }
492  {
493  // to avoid exponentiating large numbers, the maximum activation is
494  // subtracted from all the activations and the computations are done
495  // in thelog domain
496 
497  float64_t max = result(offset,0);
498  for (int32_t i=0; i<m_visible_group_sizes->element(k); i++)
499  for (int32_t j=0; j<m_batch_size; j++)
500  if (result(i+offset,j) > max)
501  max = result(i+offset,j);
502 
503  for (int32_t j=0; j<m_batch_size; j++)
504  {
505  float64_t sum = 0;
506  for (int32_t i=0; i<m_visible_group_sizes->element(k); i++)
507  sum += CMath::exp(result(i+offset,j)-max);
508 
509  float64_t normalizer = CMath::log(sum);
510 
511  for (int32_t i=0; i<m_visible_group_sizes->element(k); i++)
512  result(i+offset,j) =
513  CMath::exp(result(i+offset,j)-max-normalizer);
514  }
515  }
516  }
517 }
518 
520 {
521  int32_t length = result.num_rows*result.num_cols;
522  for (int32_t i=0; i<length; i++)
523  result[i] = CMath::random(0.0,1.0) < mean[i];
524 }
525 
527 {
528  for (int32_t k=0; k<m_num_visible_groups; k++)
529  {
530  sample_visible(k, mean, result);
531  }
532 }
533 
534 void CRBM::sample_visible(int32_t index,
536 {
537  int32_t offset = m_visible_state_offsets->element(index);
538 
540  {
541  for (int32_t i=0; i<m_visible_group_sizes->element(index); i++)
542  for (int32_t j=0; j<m_batch_size; j++)
543  result(i+offset,j) = CMath::random(0.0,1.0) < mean(i+offset,j);
544  }
545 
547  {
548  for (int32_t i=0; i<m_visible_group_sizes->element(index); i++)
549  for (int32_t j=0; j<m_batch_size; j++)
550  result(i+offset,j) = 0;
551 
552  for (int32_t j=0; j<m_batch_size; j++)
553  {
554  int32_t r = CMath::random(0.0,1.0);
555  float64_t sum = 0;
556  for (int32_t i=0; i<m_visible_group_sizes->element(index); i++)
557  {
558  sum += mean(i+offset,j);
559  if (r<=sum)
560  {
561  result(i+offset,j) = 1;
562  break;
563  }
564  }
565  }
566  }
567 }
568 
569 
571 {
572  if (p.vlen==0)
574  m_num_hidden, m_num_visible, false);
575  else
577  m_num_hidden, m_num_visible, false);
578 }
579 
581 {
582  if (p.vlen==0)
584  m_num_hidden, false);
585  else
587  m_num_hidden, false);
588 }
589 
591 {
592  if (p.vlen==0)
594  else
595  return SGVector<float64_t>(p.vector, m_num_visible, false);
596 }
597 
598 void CRBM::init()
599 {
600  cd_num_steps = 1;
601  cd_persistent = true;
602  cd_sample_visible = false;
603  l2_coefficient = 0.0;
604  l1_coefficient = 0.0;
606  monitoring_interval = 10;
607 
608  gd_mini_batch_size = 0;
609  max_num_epochs = 1;
610  gd_learning_rate = 0.1;
612  gd_momentum = 0.9;
613 
614  m_num_hidden = 0;
615  m_num_visible = 0;
620  m_num_params = 0;
621  m_batch_size = 0;
622 
623  SG_ADD(&cd_num_steps, "cd_num_steps", "Number of CD Steps", MS_NOT_AVAILABLE);
624  SG_ADD(&cd_persistent, "cd_persistent", "Whether to use PCD", MS_NOT_AVAILABLE);
625  SG_ADD(&cd_sample_visible, "sample_visible",
626  "Whether to sample the visible units during (P)CD", MS_NOT_AVAILABLE);
627  SG_ADD(&l2_coefficient, "l2_coefficient",
628  "L2 regularization coeff", MS_NOT_AVAILABLE);
629  SG_ADD(&l1_coefficient, "l1_coefficient",
630  "L1 regularization coeff", MS_NOT_AVAILABLE);
631  SG_ADD((machine_int_t*)&monitoring_method, "monitoring_method",
632  "Monitoring Method", MS_NOT_AVAILABLE);
633  SG_ADD(&monitoring_interval, "monitoring_interval",
634  "Monitoring Interval", MS_NOT_AVAILABLE);
635 
636  SG_ADD(&gd_mini_batch_size, "gd_mini_batch_size",
637  "Gradient Descent Mini-batch size", MS_NOT_AVAILABLE);
638  SG_ADD(&max_num_epochs, "max_num_epochs",
639  "Max number of Epochs", MS_NOT_AVAILABLE);
640  SG_ADD(&gd_learning_rate, "gd_learning_rate",
641  "Gradient descent learning rate", MS_NOT_AVAILABLE);
642  SG_ADD(&gd_learning_rate_decay, "gd_learning_rate_decay",
643  "Gradient descent learning rate decay", MS_NOT_AVAILABLE);
644  SG_ADD(&gd_momentum, "gd_momentum",
645  "Gradient Descent Momentum", MS_NOT_AVAILABLE);
646 
647  SG_ADD(&m_num_hidden, "num_hidden",
648  "Number of Hidden Units", MS_NOT_AVAILABLE);
649  SG_ADD(&m_num_visible, "num_visible",
650  "Number of Visible Units", MS_NOT_AVAILABLE);
651 
652  SG_ADD(&m_num_visible_groups, "num_visible_groups",
653  "Number of Visible Unit Groups", MS_NOT_AVAILABLE);
654  SG_ADD((CSGObject**)&m_visible_group_sizes, "visible_group_sizes",
655  "Sizes of Visible Unit Groups", MS_NOT_AVAILABLE);
656  SG_ADD((CSGObject**)&m_visible_group_types, "visible_group_types",
657  "Types of Visible Unit Groups", MS_NOT_AVAILABLE);
658  SG_ADD((CSGObject**)&m_visible_state_offsets, "visible_group_index_offsets",
659  "State Index offsets of Visible Unit Groups", MS_NOT_AVAILABLE);
660 
661  SG_ADD(&m_num_params, "num_params",
662  "Number of Parameters", MS_NOT_AVAILABLE);
663  SG_ADD(&m_params, "params", "Parameters", MS_NOT_AVAILABLE);
664 }
665 
#define SG_INFO(...)
Definition: SGIO.h:118
virtual float64_t reconstruction_error(SGMatrix< float64_t > visible, SGMatrix< float64_t > buffer=SGMatrix< float64_t >())
Definition: RBM.cpp:398
int32_t get_num_features() const
virtual CDenseFeatures< float64_t > * sample_group(int32_t V, int32_t num_gibbs_steps=1, int32_t batch_size=1)
Definition: RBM.cpp:193
SGMatrix< ST > get_feature_matrix()
static float32_t normal_random(float32_t mean, float32_t std_dev)
Definition: Math.h:1095
bool cd_sample_visible
Definition: RBM.h:382
virtual void add_visible_group(int32_t num_units, ERBMVisibleUnitType unit_type)
Definition: RBM.cpp:69
#define SG_ERROR(...)
Definition: SGIO.h:129
#define REQUIRE(x,...)
Definition: SGIO.h:206
SGVector< float64_t > m_params
Definition: RBM.h:461
float64_t gd_momentum
Definition: RBM.h:427
index_t num_cols
Definition: SGMatrix.h:376
float64_t gd_learning_rate
Definition: RBM.h:410
index_t num_rows
Definition: SGMatrix.h:374
static uint64_t random()
Definition: Math.h:1019
ERBMMonitoringMethod monitoring_method
Definition: RBM.h:396
virtual void mean_visible(SGMatrix< float64_t > hidden, SGMatrix< float64_t > result)
Definition: RBM.cpp:468
index_t vlen
Definition: SGVector.h:494
virtual void contrastive_divergence(SGMatrix< float64_t > visible_batch, SGVector< float64_t > gradients)
Definition: RBM.cpp:355
virtual SGMatrix< float64_t > get_weights(SGVector< float64_t > p=SGVector< float64_t >())
Definition: RBM.cpp:570
Class SGObject is the base class of all shogun objects.
Definition: SGObject.h:115
virtual SGVector< float64_t > get_hidden_bias(SGVector< float64_t > p=SGVector< float64_t >())
Definition: RBM.cpp:580
int32_t m_num_visible
Definition: RBM.h:440
virtual int32_t get_num_vectors() const
float64_t l1_coefficient
Definition: RBM.h:388
virtual void initialize_neural_network(float64_t sigma=0.01)
Definition: RBM.cpp:86
double float64_t
Definition: common.h:50
virtual ~CRBM()
Definition: RBM.cpp:62
int32_t m_batch_size
Definition: RBM.h:443
virtual void train(CDenseFeatures< float64_t > *features)
Definition: RBM.cpp:107
virtual SGVector< float64_t > get_visible_bias(SGVector< float64_t > p=SGVector< float64_t >())
Definition: RBM.cpp:590
SGMatrix< float64_t > hidden_state
Definition: RBM.h:430
int32_t m_num_hidden
Definition: RBM.h:437
int32_t monitoring_interval
Definition: RBM.h:393
virtual void reset_chain()
Definition: RBM.cpp:265
int32_t max_num_epochs
Definition: RBM.h:401
int32_t cd_num_steps
Definition: RBM.h:372
ERBMVisibleUnitType
Definition: RBM.h:54
CDynamicArray< int32_t > * m_visible_group_types
Definition: RBM.h:449
int32_t m_num_visible_groups
Definition: RBM.h:446
#define SG_UNREF(x)
Definition: SGObject.h:55
CDynamicArray< int32_t > * m_visible_group_sizes
Definition: RBM.h:452
all of classes and functions are contained in the shogun namespace
Definition: class_list.h:18
int machine_int_t
Definition: common.h:59
virtual void sample_visible(SGMatrix< float64_t > mean, SGMatrix< float64_t > result)
Definition: RBM.cpp:526
virtual void set_batch_size(int32_t batch_size)
Definition: RBM.cpp:95
static float64_t exp(float64_t x)
Definition: Math.h:621
virtual void sample_with_evidence(int32_t E, CDenseFeatures< float64_t > *evidence, int32_t num_gibbs_steps=1)
Definition: RBM.cpp:211
float64_t gd_learning_rate_decay
Definition: RBM.h:417
float64_t l2_coefficient
Definition: RBM.h:385
static float64_t log(float64_t v)
Definition: Math.h:922
int32_t gd_mini_batch_size
Definition: RBM.h:407
SGMatrix< float64_t > visible_state
Definition: RBM.h:433
int32_t get_num_elements() const
Definition: DynamicArray.h:200
const T & element(int32_t idx1, int32_t idx2=0, int32_t idx3=0) const
Definition: DynamicArray.h:224
virtual float64_t pseudo_likelihood(SGMatrix< float64_t > visible, SGMatrix< float64_t > buffer=SGMatrix< float64_t >())
Definition: RBM.cpp:420
Matrix::Scalar max(Matrix m)
Definition: Redux.h:68
#define SG_ADD(...)
Definition: SGObject.h:84
bool cd_persistent
Definition: RBM.h:376
virtual void sample_hidden(SGMatrix< float64_t > mean, SGMatrix< float64_t > result)
Definition: RBM.cpp:519
CDynamicArray< int32_t > * m_visible_state_offsets
Definition: RBM.h:455
virtual void mean_hidden(SGMatrix< float64_t > visible, SGMatrix< float64_t > result)
Definition: RBM.cpp:450
virtual float64_t free_energy(SGMatrix< float64_t > visible, SGMatrix< float64_t > buffer=SGMatrix< float64_t >())
Definition: RBM.cpp:272
static int32_t pow(bool x, int32_t n)
Definition: Math.h:535
virtual void sample(int32_t num_gibbs_steps=1, int32_t batch_size=1)
Definition: RBM.cpp:178
int32_t m_num_params
Definition: RBM.h:458
virtual void free_energy_gradients(SGMatrix< float64_t > visible, SGVector< float64_t > gradients, bool positive_phase=true, SGMatrix< float64_t > hidden_mean_given_visible=SGMatrix< float64_t >())
Definition: RBM.cpp:318
virtual CDenseFeatures< float64_t > * sample_group_with_evidence(int32_t V, int32_t E, CDenseFeatures< float64_t > *evidence, int32_t num_gibbs_steps=1)
Definition: RBM.cpp:245

SHOGUN Machine Learning Toolbox - Documentation