-
Notifications
You must be signed in to change notification settings - Fork 1
/
RBM.h
70 lines (49 loc) · 1.55 KB
/
RBM.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#ifndef RBM_H
#define RBM_H
#include <iostream>
#include <ctime>
#include <cmath>
#include <vector>
#include <fstream>
#include <cstdlib>
#include <string>
using namespace std;
class RBM{
private:
int num_visible_unit;
int num_hidden_unit;
float* input_RBM;
float* first_sample_h;
float* first_probability_h;
float* nth_sample_v;
float* nth_probability_v;
float* nth_sample_h;
float* nth_probability_h;
float* weight_RBM;
float* hBias_weight;
float* vBias_weight;
float* accum_weight;
float* accum_hBias_weight;
float* accum_vBias_weight;
public:
RBM(){};
~RBM();
float* Get_Weight(){ return weight_RBM;}
float* Get_Bias_Weight() {return hBias_weight;}
void Allocate_RBM(int num_visible_unit, int num_hidden_unit);
void Init_RBM();
void Deallocate_RBM();
void Contrastive_Divergence(float* v0Input, int cd_k);
void Gibbs_Sampling(float* hInput);
void Positive_Phase_DBN(float* vInput, float* sample);
float* Negative_Phase_DBN(float* hInput); // for test
float* Positive_Phase_first(float* vInput);
void Positive_Phase(float* vInput);
void Negative_Phase(float* hInput);
float Activation(float net){return 1.0 / (1.0 + exp(-net));} // sigmoid
void Update_Weight(float learningRate);
void Update_Weight_Batch(float learningRate);
int Sample_Binary_State(float probability);
void Reconstruct(float* vInput, float* reconstructed_v); // for test
};
#endif