资源简介
深度学习,DBN模型代码,c语言,代码完整,由matlab转写过来
代码片段和文件信息
#include
#include
#include
#include “Hiddenlayer.h“
#include “RBM.h“
#include “LogisticRegression.h“
#include “DBN.h“
#include “utils.h“
void test_dbn(void);
double uniform(double min double max) {
return rand() / (RAND_MAX + 1.0) * (max - min) + min;
}
int binomial(int n double p) {
if(p < 0 || p > 1) return 0;
int i;
int c = 0;
double r;
for(i=0; i r = rand() / (RAND_MAX + 1.0);
if (r < p) c++;
}
return c;
}
double sigmoid(double x) {
return 1.0 / (1.0 + exp(-x));
}
// DBN
void DBN__construct(DBN* this int N \
int n_ins int *hidden_layer_sizes int n_outs int n_layers) {
int i input_size;
this->N = N;
this->n_ins = n_ins;
this->hidden_layer_sizes = hidden_layer_sizes;
this->n_outs = n_outs;
this->n_layers = n_layers;
this->sigmoid_layers = (Hiddenlayer *)malloc(sizeof(Hiddenlayer) * n_layers);
this->rbm_layers = (RBM *)malloc(sizeof(RBM) * n_layers);
// construct multi-layer
for(i=0; iyers; i++) {
if(i == 0) {
input_size = n_ins;
} else {
input_size = hidden_layer_sizes[i-1];
}
// construct sigmoid_layer
Hiddenlayer__construct(&(this->sigmoid_layers[i]) \
N input_size hidden_layer_sizes[i] NULL NULL);
// construct rbm_layer
RBM__construct(&(this->rbm_layers[i]) N input_size hidden_layer_sizes[i] \
this->sigmoid_layers[i].W this->sigmoid_layers[i].b NULL);
}
// layer for output using LogisticRegression
LogisticRegression__construct(&(this->log_layer) \
N hidden_layer_sizes[n_layers-1] n_outs);
}
void DBN__destruct(DBN* this) {
int i;
for(i=0; in_layers; i++) {
Hiddenlayer__destruct(&(this->sigmoid_layers[i]));
RBM__destruct(&(this->rbm_layers[i]));
}
free(this->sigmoid_layers);
free(this->rbm_layers);
}
void DBN_pretrain(DBN* this int *input double lr int k int epochs) {
int i j l m n epoch;
int *layer_input;
int prev_layer_input_size;
int *prev_layer_input;
int *train_X = (int *)malloc(sizeof(int) * this->n_ins);
for(i=0; in_layers; i++) { // layer-wise
for(epoch=0; epoch
for(n=0; nN; n++) { // input x1...xN
// initial input
for(m=0; mn_ins; m++) train_X[m] = input[n * this->n_ins + m];
// layer input
for(l=0; l<=i; l++) {
if(l == 0) {
layer_input = (int *)malloc(sizeof(int) * this->n_ins);
for(j=0; jn_ins; j++) layer_input[j] = train_X[j];
} else {
if(l == 1) prev_layer_input_size = this->n_ins;
else prev_layer_input_size = this->hidden_layer_sizes[l-2];
prev_layer_input = (int *)malloc(sizeof(int) * prev_layer_input_size);
for(j=0; jyer_input_size; j++) prev_layer_input[j] = layer_input[j];
fr
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 48205 2013-04-30 19:36 Deep_Belief_Nets\bin\Debug\Deep_Belief_Nets.exe
文件 15138 2013-03-27 08:13 Deep_Belief_Nets\DBN.c
文件 440 2013-03-27 08:13 Deep_Belief_Nets\DBN.h
文件 1273 2013-04-30 19:36 Deep_Belief_Nets\Deep_Belief_Nets.cbp
文件 559 2013-04-30 20:35 Deep_Belief_Nets\Deep_Belief_Nets.depend
文件 322 2013-04-30 20:36 Deep_Belief_Nets\Deep_Belief_Nets.layout
文件 391 2013-03-27 08:13 Deep_Belief_Nets\Hiddenla
文件 500 2013-03-27 08:13 Deep_Belief_Nets\LogisticRegression.h
文件 23535 2013-04-30 19:36 Deep_Belief_Nets\obj\Debug\DBN.o
文件 613 2013-03-27 08:13 Deep_Belief_Nets\RBM.h
文件 124 2013-03-27 08:13 Deep_Belief_Nets\utils.h
目录 0 2013-05-07 15:03 Deep_Belief_Nets\bin\Debug
目录 0 2013-05-07 15:03 Deep_Belief_Nets\obj\Debug
目录 0 2013-05-07 15:03 Deep_Belief_Nets\bin
目录 0 2013-05-07 15:03 Deep_Belief_Nets\obj
目录 0 2013-05-07 15:03 Deep_Belief_Nets
----------- --------- ---------- ----- ----
91100 16
- 上一篇:学生成绩管理系统(MFC)
- 下一篇:grpc c++
评论
共有 条评论