SHOGUN  5.0.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules
RBM.h
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 #ifndef __RBM_H__
35 #define __RBM_H__
36 
37 #include <shogun/lib/config.h>
38 
39 #include <shogun/lib/common.h>
40 #include <shogun/base/SGObject.h>
41 #include <shogun/lib/SGMatrix.h>
42 #include <shogun/lib/SGVector.h>
45 
46 namespace shogun
47 {
49 {
52 };
53 
55 {
59 };
60 
122 class CRBM : public CSGObject
123 {
124 friend class CDeepBeliefNetwork;
125 
126 public:
128  CRBM();
129 
135  CRBM(int32_t num_hidden);
136 
143  CRBM(int32_t num_hidden, int32_t num_visible,
144  ERBMVisibleUnitType visible_unit_type = RBMVUT_BINARY);
145 
146  virtual ~CRBM();
147 
153  virtual void add_visible_group(int32_t num_units, ERBMVisibleUnitType unit_type);
154 
161  virtual void initialize_neural_network(float64_t sigma=0.01);
162 
167  virtual void set_batch_size(int32_t batch_size);
168 
174  virtual void train(CDenseFeatures<float64_t>* features);
175 
184  virtual void sample(int32_t num_gibbs_steps=1, int32_t batch_size=1);
185 
198  int32_t V,
199  int32_t num_gibbs_steps=1, int32_t batch_size=1);
200 
210  virtual void sample_with_evidence(
211  int32_t E, CDenseFeatures<float64_t>* evidence,
212  int32_t num_gibbs_steps=1);
213 
227  int32_t V,
228  int32_t E, CDenseFeatures<float64_t>* evidence,
229  int32_t num_gibbs_steps=1);
230 
234  virtual void reset_chain();
235 
254  virtual float64_t free_energy(SGMatrix<float64_t> visible,
256 
271  virtual void free_energy_gradients(SGMatrix<float64_t> visible,
272  SGVector<float64_t> gradients,
273  bool positive_phase = true,
274  SGMatrix<float64_t> hidden_mean_given_visible = SGMatrix<float64_t>());
275 
282  virtual void contrastive_divergence(SGMatrix<float64_t> visible_batch,
283  SGVector<float64_t> gradients);
284 
294 
309 
312  {
314  }
315 
318 
326 
334 
342 
344  virtual int32_t get_num_parameters() { return m_num_params; }
345 
346  virtual const char* get_name() const { return "RBM"; }
347 
348 protected:
350  virtual void mean_hidden(SGMatrix<float64_t> visible, SGMatrix<float64_t> result);
351 
353  virtual void mean_visible(SGMatrix<float64_t> hidden, SGMatrix<float64_t> result);
354 
356  virtual void sample_hidden(SGMatrix<float64_t> mean, SGMatrix<float64_t> result);
357 
359  virtual void sample_visible(SGMatrix<float64_t> mean, SGMatrix<float64_t> result);
360 
362  virtual void sample_visible(int32_t index,
364 
365 private:
366  void init();
367 
368 public:
372  int32_t cd_num_steps;
373 
377 
383 
386 
389 
394 
397 
401  int32_t max_num_epochs;
402 
408 
411 
418 
428 
431 
434 
435 protected:
437  int32_t m_num_hidden;
438 
440  int32_t m_num_visible;
441 
443  int32_t m_batch_size;
444 
447 
450 
453 
456 
458  int32_t m_num_params;
459 
462 };
463 
464 }
465 #endif
A Restricted Boltzmann Machine.
Definition: RBM.h:122
virtual float64_t reconstruction_error(SGMatrix< float64_t > visible, SGMatrix< float64_t > buffer=SGMatrix< float64_t >())
Definition: RBM.cpp:398
virtual int32_t get_num_parameters()
Definition: RBM.h:344
virtual CDenseFeatures< float64_t > * sample_group(int32_t V, int32_t num_gibbs_steps=1, int32_t batch_size=1)
Definition: RBM.cpp:193
bool cd_sample_visible
Definition: RBM.h:382
virtual void add_visible_group(int32_t num_units, ERBMVisibleUnitType unit_type)
Definition: RBM.cpp:69
SGVector< float64_t > m_params
Definition: RBM.h:461
float64_t gd_momentum
Definition: RBM.h:427
float64_t gd_learning_rate
Definition: RBM.h:410
virtual const char * get_name() const
Definition: RBM.h:346
ERBMMonitoringMethod monitoring_method
Definition: RBM.h:396
virtual void mean_visible(SGMatrix< float64_t > hidden, SGMatrix< float64_t > result)
Definition: RBM.cpp:468
virtual void contrastive_divergence(SGMatrix< float64_t > visible_batch, SGVector< float64_t > gradients)
Definition: RBM.cpp:355
virtual CDenseFeatures< float64_t > * visible_state_features()
Definition: RBM.h:311
virtual SGMatrix< float64_t > get_weights(SGVector< float64_t > p=SGVector< float64_t >())
Definition: RBM.cpp:570
A Deep Belief Network.
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
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
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
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
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
virtual SGVector< float64_t > get_parameters()
Definition: RBM.h:317
int32_t gd_mini_batch_size
Definition: RBM.h:407
SGMatrix< float64_t > visible_state
Definition: RBM.h:433
virtual float64_t pseudo_likelihood(SGMatrix< float64_t > visible, SGMatrix< float64_t > buffer=SGMatrix< float64_t >())
Definition: RBM.cpp:420
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
ERBMMonitoringMethod
Definition: RBM.h:48
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
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