SHOGUN  4.2.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
DeepBeliefNetwork.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 __DEEPBELIEFNETWORK_H__
35 #define __DEEPBELIEFNETWORK_H__
36 
37 #include <shogun/lib/config.h>
38 
39 #include <shogun/lib/common.h>
40 #include <shogun/base/SGObject.h>
41 #include <shogun/neuralnets/RBM.h>
42 #include <lib/SGMatrixList.h>
43 
44 namespace shogun
45 {
46 template <class T> class SGVector;
47 template <class T> class SGMatrix;
48 template <class T> class SGMatrixList;
49 template <class T> class CDenseFeatures;
50 template <class T> class CDynamicArray;
51 class CDynamicObjectArray;
52 class CNeuralNetwork;
53 class CNeuralLayer;
54 
91 {
92 public:
95 
101  CDeepBeliefNetwork(int32_t num_visible_units,
102  ERBMVisibleUnitType unit_type = RBMVUT_BINARY);
103 
104  virtual ~CDeepBeliefNetwork();
105 
111  virtual void add_hidden_layer(int32_t num_units);
112 
118  virtual void initialize_neural_network(float64_t sigma = 0.01);
119 
124  virtual void set_batch_size(int32_t batch_size);
125 
131  virtual void pre_train(CDenseFeatures<float64_t>* features);
132 
139  virtual void pre_train(int32_t index, CDenseFeatures<float64_t>* features);
140 
147  virtual void train(CDenseFeatures<float64_t>* features);
148 
162  CDenseFeatures<float64_t>* features, int32_t i=-1);
163 
175  int32_t num_gibbs_steps=1, int32_t batch_size=1);
176 
178  virtual void reset_chain();
179 
193  CNeuralLayer* output_layer=NULL, float64_t sigma = 0.01);
194 
201  virtual SGMatrix<float64_t> get_weights(int32_t index,
203 
210  virtual SGVector<float64_t> get_biases(int32_t index,
212 
213  virtual const char* get_name() const { return "DeepBeliefNetwork"; }
214 
215 protected:
217  virtual void down_step(int32_t index, SGVector<float64_t> params,
219  bool sample_states = true);
220 
222  virtual void up_step(int32_t index, SGVector<float64_t> params,
224  bool sample_states = true);
225 
227  virtual void wake_sleep(SGMatrix<float64_t> data,
228  CRBM* top_rbm,
229  SGMatrixList<float64_t> sleep_states,
230  SGMatrixList<float64_t> wake_states,
231  SGMatrixList<float64_t> psleep_states,
232  SGMatrixList<float64_t> pwake_states,
233  SGVector<float64_t> gen_params,
234  SGVector<float64_t> rec_params,
235  SGVector<float64_t> gen_gradients,
236  SGVector<float64_t> rec_gradients);
237 
238 private:
239  void init();
240 
241 public:
246 
251 
256 
261 
266 
271 
276 
281 
286 
291 
296 
301 
305  int32_t cd_num_steps;
306 
311 
315  int32_t max_num_epochs;
316 
322 
325 
332 
342 
343 protected:
346 
348  int32_t m_num_layers;
349 
352 
355 
357  int32_t m_batch_size;
358 
361 
363  int32_t m_num_params;
364 
367 
372 
376 };
377 
378 }
379 #endif
A Restricted Boltzmann Machine.
Definition: RBM.h:122
virtual void wake_sleep(SGMatrix< float64_t > data, CRBM *top_rbm, SGMatrixList< float64_t > sleep_states, SGMatrixList< float64_t > wake_states, SGMatrixList< float64_t > psleep_states, SGMatrixList< float64_t > pwake_states, SGVector< float64_t > gen_params, SGVector< float64_t > rec_params, SGVector< float64_t > gen_gradients, SGVector< float64_t > rec_gradients)
virtual void train(CDenseFeatures< float64_t > *features)
virtual CDenseFeatures< float64_t > * transform(CDenseFeatures< float64_t > *features, int32_t i=-1)
SGMatrixList< float64_t > m_states
SGVector< int32_t > pt_gd_mini_batch_size
SGVector< int32_t > m_bias_index_offsets
virtual const char * get_name() const
CDynamicArray< int32_t > * m_layer_sizes
A generic multi-layer neural network.
virtual void pre_train(CDenseFeatures< float64_t > *features)
SGVector< float64_t > pt_gd_momentum
virtual void down_step(int32_t index, SGVector< float64_t > params, SGMatrix< float64_t > input, SGMatrix< float64_t > result, bool sample_states=true)
Base class for neural network layers.
Definition: NeuralLayer.h:87
SGVector< int32_t > pt_monitoring_interval
ERBMVisibleUnitType m_visible_units_type
SGVector< int32_t > m_weights_index_offsets
virtual void up_step(int32_t index, SGVector< float64_t > params, SGMatrix< float64_t > input, SGMatrix< float64_t > result, bool sample_states=true)
SGVector< float64_t > m_params
A Deep Belief Network.
Class SGObject is the base class of all shogun objects.
Definition: SGObject.h:115
SGVector< float64_t > pt_gd_learning_rate
virtual void add_hidden_layer(int32_t num_units)
double float64_t
Definition: common.h:50
virtual void set_batch_size(int32_t batch_size)
SGVector< float64_t > pt_gd_learning_rate_decay
SGVector< bool > pt_cd_persistent
SGVector< float64_t > pt_l1_coefficient
ERBMVisibleUnitType
Definition: RBM.h:54
SGVector< int32_t > pt_monitoring_method
SGVector< float64_t > pt_l2_coefficient
all of classes and functions are contained in the shogun namespace
Definition: class_list.h:18
virtual CNeuralNetwork * convert_to_neural_network(CNeuralLayer *output_layer=NULL, float64_t sigma=0.01)
virtual CDenseFeatures< float64_t > * sample(int32_t num_gibbs_steps=1, int32_t batch_size=1)
SGVector< bool > pt_cd_sample_visible
virtual SGMatrix< float64_t > get_weights(int32_t index, SGVector< float64_t > p=SGVector< float64_t >())
virtual void initialize_neural_network(float64_t sigma=0.01)
SGVector< int32_t > pt_max_num_epochs
virtual SGVector< float64_t > get_biases(int32_t index, SGVector< float64_t > p=SGVector< float64_t >())
SGVector< int32_t > pt_cd_num_steps

SHOGUN Machine Learning Toolbox - Documentation