Skip to content

Commit 8872adf

Browse files
author
Yusuke Sugomori
committed
clean up cpp utils
1 parent 52f8752 commit 8872adf

File tree

7 files changed

+44
-138
lines changed

7 files changed

+44
-138
lines changed

cpp/DBN.cpp

Lines changed: 2 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,12 @@
11
#include <iostream>
22
#include <math.h>
3+
#include "utils.h"
34
#include "HiddenLayer.h"
45
#include "RBM.h"
56
#include "LogisticRegression.h"
67
#include "DBN.h"
78
using namespace std;
8-
9-
10-
double uniform(double min, double max) {
11-
return rand() / (RAND_MAX + 1.0) * (max - min) + min;
12-
}
13-
14-
int binomial(int n, double p) {
15-
if(p < 0 || p > 1) return 0;
16-
17-
int c = 0;
18-
double r;
19-
20-
for(int i=0; i<n; i++) {
21-
r = rand() / (RAND_MAX + 1.0);
22-
if (r < p) c++;
23-
}
24-
25-
return c;
26-
}
27-
28-
double sigmoid(double x) {
29-
return 1.0 / (1.0 + exp(-x));
30-
}
9+
using namespace utils;
3110

3211

3312
// DBN

cpp/HiddenLayer.cpp

Lines changed: 2 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,9 @@
11
#include <iostream>
22
#include <math.h>
33
#include "HiddenLayer.h"
4+
#include "utils.h"
45
using namespace std;
5-
6-
double uniform(double min, double max) {
7-
return rand() / (RAND_MAX + 1.0) * (max - min) + min;
8-
}
9-
10-
int binomial(int n, double p) {
11-
if(p < 0 || p > 1) return 0;
12-
13-
int c = 0;
14-
double r;
15-
16-
for(int i=0; i<n; i++) {
17-
r = rand() / (RAND_MAX + 1.0);
18-
if (r < p) c++;
19-
}
20-
21-
return c;
22-
}
23-
24-
double sigmoid(double x) {
25-
return 1.0 / (1.0 + exp(-x));
26-
}
27-
6+
using namespace utils;
287

298

309
HiddenLayer::HiddenLayer(int size, int in, int out, double **w, double *bp) {

cpp/RBM.cpp

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,9 @@
11
#include <iostream>
22
#include <math.h>
3+
#include "utils.h"
34
#include "RBM.h"
45
using namespace std;
5-
6-
double uniform(double min, double max) {
7-
return rand() / (RAND_MAX + 1.0) * (max - min) + min;
8-
}
9-
10-
int binomial(int n, double p) {
11-
if(p < 0 || p > 1) return 0;
12-
13-
int c = 0;
14-
double r;
15-
16-
for(int i=0; i<n; i++) {
17-
r = rand() / (RAND_MAX + 1.0);
18-
if (r < p) c++;
19-
}
20-
21-
return c;
22-
}
23-
24-
double sigmoid(double x) {
25-
return 1.0 / (1.0 + exp(-x));
26-
}
6+
using namespace utils;
277

288

299
RBM::RBM(int size, int n_v, int n_h, double **w, double *hb, double *vb) {

cpp/SdA.cpp

Lines changed: 3 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,13 @@
11
#include <iostream>
22
#include <math.h>
3+
#include "utils.h"
4+
35
#include "HiddenLayer.h"
46
#include "dA.h"
57
#include "LogisticRegression.h"
68
#include "SdA.h"
79
using namespace std;
8-
9-
double uniform(double min, double max) {
10-
return rand() / (RAND_MAX + 1.0) * (max - min) + min;
11-
}
12-
13-
int binomial(int n, double p) {
14-
if(p < 0 || p > 1) return 0;
15-
16-
int c = 0;
17-
double r;
18-
19-
for(int i=0; i<n; i++) {
20-
r = rand() / (RAND_MAX + 1.0);
21-
if (r < p) c++;
22-
}
23-
24-
return c;
25-
}
26-
27-
double sigmoid(double x) {
28-
return 1.0 / (1.0 + exp(-x));
29-
}
10+
using namespace utils;
3011

3112

3213
// SdA

cpp/dA.cpp

Lines changed: 3 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,10 @@
11
#include <iostream>
22
#include <math.h>
3+
#include "utils.h"
4+
35
#include "dA.h"
46
using namespace std;
5-
6-
7-
double uniform(double min, double max) {
8-
return rand() / (RAND_MAX + 1.0) * (max - min) + min;
9-
}
10-
11-
int binomial(int n, double p) {
12-
if(p < 0 || p > 1) return 0;
13-
14-
int c = 0;
15-
double r;
16-
17-
for(int i=0; i<n; i++) {
18-
r = rand() / (RAND_MAX + 1.0);
19-
if (r < p) c++;
20-
}
21-
22-
return c;
23-
}
24-
25-
double sigmoid(double x) {
26-
return 1.0 / (1.0 + exp(-x));
27-
}
7+
using namespace utils;
288

299

3010
dA::dA(int size, int n_v, int n_h, double **w, double *hb, double *vb) {

cpp/utils.cpp

Lines changed: 0 additions & 25 deletions
This file was deleted.

cpp/utils.h

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#pragma once
2+
3+
#include <iostream>
4+
#include <math.h>
5+
using namespace std;
6+
7+
8+
namespace utils {
9+
10+
double uniform(double min, double max) {
11+
return rand() / (RAND_MAX + 1.0) * (max - min) + min;
12+
}
13+
14+
int binomial(int n, double p) {
15+
if(p < 0 || p > 1) return 0;
16+
17+
int c = 0;
18+
double r;
19+
20+
for(int i=0; i<n; i++) {
21+
r = rand() / (RAND_MAX + 1.0);
22+
if (r < p) c++;
23+
}
24+
25+
return c;
26+
}
27+
28+
double sigmoid(double x) {
29+
return 1.0 / (1.0 + exp(-x));
30+
}
31+
32+
}

0 commit comments

Comments
 (0)