-
Notifications
You must be signed in to change notification settings - Fork 62
/
deep.h
117 lines (102 loc) · 2.08 KB
/
deep.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
//**********************
// Deep Learning and Applications
// Piji Li
// http://www.zhizhihu.com
//*********************/
#ifndef DEEP_H
#define DEEP_H
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <iostream>
#include <fstream>
#include <vector>
using namespace std;
double sample_from_gaussian(double miu, double sigma);
class Conf
{
public:
string f_train_x;
string f_train_y;
string f_test_x;
string f_test_y;
int epoch;
int batch_size;
int *hidden_layer_size;
int cd_k;
double learning_rate;
int n_layers;
int n_labels; //num of classes
double lamda; // penalty factor
Conf(string, string, int, int, int*, int, double, int, int, double);
~Conf();
};
class Dataset
{
public:
int N;
int n_f;
//double **X;
//double *Y;
vector<vector<double> > X;
vector<double> Y;
int batch_index;
Dataset(Conf);
~Dataset();
void reloadx(Conf, char*, vector<vector<double> >&);
};
class RBM
{
public:
int n_samples;
int n_visible;
int n_hidden;
double **W;
double *hbias;
double *vbias;
double error;
double lamda;
double momentum;
RBM(int, int, int, double**, double*, double*, double, double);
~RBM();
void train(double*, double, int);
void activate_hidden(double*, double*, int*, int, int);
void activate_visible(int*, double*, int*, int, int);
};
class LR
{
public:
int n_samples;
int n_features;
int n_labels;
double lamda;
double **W;
double *b;
LR(Dataset, Conf);
LR(int, int, int, double);
~LR();
void train(double*, int*, double);
void softmax(double*);
void predict(double*, double*);
};
class DBN
{
public:
int n_samples;
int n_features;
int n_layers;
int n_labels;
int *hidden_layer_size;
double lamda;
double alpha;
RBM **rbm_layers;
LR *lr_layer;
DBN(Dataset, Conf);
~DBN();
void pretrain(Dataset, Conf);
void finetune(Dataset, Conf);
int predict(double*, double*, int);
};
#endif //DEEP_H