资源简介
深度学习C++源码(DBN)
代码片段和文件信息
//**********************
// Deep Learning and Applications
// Piji Li
// lipiji.sdu@gmail.com
// http://www.zhizhihu.com
//*********************/
#include
#include “deep.h“
#include “timer.h“
double sample_from_gaussian(double miu double sigma)
{
//std::default_random_engine generator;
//std::normal_distribution distribution(miu sigma);
//reutrn distribution(generator);
static double V1 V2 S;
static int phase = 0;
double X;
if (phase == 0)
{
do
{
double U1 = (double)rand() / RAND_MAX;
double U2 = (double)rand() / RAND_MAX;
V1 = 2 * U1 - 1;
V2 = 2 * U2 - 1;
S = V1 * V1 + V2 * V2;
} while(S >= 1 || S == 0);
X = V1 * sqrt(-2 * log(S) / S);
} else
X = V2 * sqrt(-2 * log(S) / S);
phase = 1 - phase;
return X * sigma + miu;
}
double sigmoid(double x)
{
return 1.0 / (1.0 + exp(-x));
}
int binomial(int n double p)
{
if(p < 0 || p > 1) return 0;
int c = 0;
double r;
for(int i=0; i {
r = rand() / (RAND_MAX + 1.0);
if (r < p) c++;
}
return c;
}
double square_error(double *v1 double *v2 int size)
{
double error = 0;
for (int i = 0; i < size; i++)
{
error += pow((v1[i] - v2[i]) 2);
}
return error;
}
int max_i_(double *x int l)
{
double max_v = x[0];
double max_i = 0;
for(int i=0; i {
if(x[i] > max_v)
{
max_v = x[i];
max_i = i;
}
}
return max_i;
}
Conf::Conf(string ftx string fty int epc int bs int *hls int k double lr int n_ly int n_lb double lbd)
{
f_train_x = ftx;
f_train_y = fty;
epoch = epc;
batch_size = bs;
hidden_layer_size = hls;
cd_k = k;
learning_rate = lr;
n_layers = n_ly;
n_labels = n_lb;
lamda = lbd;
}
Conf::~Conf(){}
Dataset::Dataset(Conf conf)
{
N = 0;
n_f = 0;
batch_index = 0;
if(conf.batch_size >= 0)
{
int Nx = 0;
int Ny = 0;
int Nf = 0; // dim of x
//read the label file
ifstream fin_y(conf.f_train_y.c_str());
if(!fin_y)
{
cout << “Error opening “ << conf.f_train_y << “ for input“ << endl;
exit(-1);
}
else
{
string s;
while(getline(fin_y s))
{
Y.push_back(atof(s.c_str()));
if(conf.batch_size > 0 && Ny >= conf.batch_size)
break;
++Ny;
}
}
fin_y.close();
// read the x file
ifstream fin_x(conf.f_train_x.c_str());
if(!fin_x)
{
cout << “Error opening “ << conf.f_train_x << “ for input“ << endl;
exit(-1);
}
else
{
string s;
while(getline(fin_x s))
{
Nf = 0;
vec
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 24422706 2013-09-02 16:11 DeepLearning_DBN\data\test_x.txt
文件 20000 2013-09-02 16:09 DeepLearning_DBN\data\test_y.txt
文件 146251039 2013-06-24 20:43 DeepLearning_DBN\data\train_x.txt
文件 180000 2013-09-02 16:11 DeepLearning_DBN\data\train_y.txt
文件 120 2013-09-23 10:03 DeepLearning_DBN\data\x.txt
文件 12 2013-09-12 22:19 DeepLearning_DBN\data\y.txt
文件 23007 2015-05-20 22:26 DeepLearning_DBN\DeepLearning_DBN\deep.cpp
文件 2125 2015-04-15 07:43 DeepLearning_DBN\DeepLearning_DBN\deep.h
文件 2190 2015-05-21 06:04 DeepLearning_DBN\DeepLearning_DBN\DeepLearning_DBN\Debug\DeepLearning_DBN.log
文件 3322 2015-05-21 06:04 DeepLearning_DBN\DeepLearning_DBN\DeepLearning_DBN\Debug\DeepLearning_DBN.tlog\cl.command.1.tlog
文件 61956 2015-05-21 06:04 DeepLearning_DBN\DeepLearning_DBN\DeepLearning_DBN\Debug\DeepLearning_DBN.tlog\CL.read.1.tlog
文件 3860 2015-05-21 06:04 DeepLearning_DBN\DeepLearning_DBN\DeepLearning_DBN\Debug\DeepLearning_DBN.tlog\CL.write.1.tlog
文件 211 2015-05-21 06:04 DeepLearning_DBN\DeepLearning_DBN\DeepLearning_DBN\Debug\DeepLearning_DBN.tlog\DeepLearning_DBN.lastbuildstate
文件 0 2015-05-20 07:24 DeepLearning_DBN\DeepLearning_DBN\DeepLearning_DBN\Debug\DeepLearning_DBN.tlog\unsuccessfulbuild
文件 394733 2015-05-21 06:04 DeepLearning_DBN\DeepLearning_DBN\DeepLearning_DBN\Debug\train.obj
文件 928768 2015-05-21 06:04 DeepLearning_DBN\DeepLearning_DBN\DeepLearning_DBN\Debug\vc120.idb
文件 520192 2015-05-21 06:04 DeepLearning_DBN\DeepLearning_DBN\DeepLearning_DBN\Debug\vc120.pdb
文件 7363 2015-05-20 22:11 DeepLearning_DBN\DeepLearning_DBN\DeepLearning_DBN\DeepLearning_DBN.vcxproj
文件 1342 2015-05-20 22:11 DeepLearning_DBN\DeepLearning_DBN\DeepLearning_DBN\DeepLearning_DBN.vcxproj.filters
文件 34537472 2015-05-21 07:24 DeepLearning_DBN\DeepLearning_DBN\DeepLearning_DBN.sdf
文件 1348 2015-05-20 20:40 DeepLearning_DBN\DeepLearning_DBN\DeepLearning_DBN.sln
..A..H. 44544 2015-05-21 07:24 DeepLearning_DBN\DeepLearning_DBN\DeepLearning_DBN.v12.suo
文件 149 2015-04-15 07:43 DeepLearning_DBN\DeepLearning_DBN\predict.cpp
文件 3714 2015-05-21 06:05 DeepLearning_DBN\DeepLearning_DBN\train.cpp
....... 2652 2015-04-15 07:43 DeepLearning_DBN\include\cmat\cmat.h
....... 1958 2015-04-15 07:43 DeepLearning_DBN\include\cmat\cmat_armadillo_openblas.h
....... 461 2015-04-15 07:43 DeepLearning_DBN\Makefile
....... 413 2015-04-15 07:43 DeepLearning_DBN\readme.txt
....... 18 2015-04-15 07:43 DeepLearning_DBN\run.sh
目录 0 2015-05-21 06:04 DeepLearning_DBN\DeepLearning_DBN\DeepLearning_DBN\Debug\DeepLearning_DBN.tlog
............此处省略73个文件信息
评论
共有 条评论