首页 技术 正文
技术 2022年11月6日
0 收藏 992 点赞 486 浏览 3601 个字

百度了半天yusugomori,也不知道他是谁。不过这位老兄写了deep learning的代码,包括RBM、逻辑回归、DBN、autoencoder等,实现语言包括c、c++、java、python等。是学习的好材料。代码下载地址:https://github.com/yusugomori/DeepLearning。不过这位老兄不喜欢写注释,而且这些模型的原理、公式什么的,不了解的话就看不懂代码。我从给他写注释开始,边看资料、边理解它的代码、边给他写上注释。

工具包中RBM的实现包含了两个文件,RBM.h和RBM.cpp。RBM.h添加注释后,如下:

class RBM
{
public:
// the number of training sample
int N;
// the number of visiable node
int n_visible;
// the number of hidden node
int n_hidden;
// the weight connecting the visiable node and the hidden node
double **W;
// the bias of hidden node
double *hbias;
// the bias of visiable node
double *vbias;public:
// construct the RBM by input parameters
RBM (int,// N
int,// n_visible
int,// n_hidden
double**,// W
double*,// hbias
double*// vbias
);
// destructor, release all the memory of parameters
~RBM ();
// CD-k algorithm to train RBM
void contrastive_divergence (int*,// one input sample
double,// the learning rate
int// the k of CD-k, it is usually 1
);// these the functions of Gibbs sample // sample the hidden node given the visiable node, 'sample' means calculating
// 1. the output probability of the hidden node given the input of visiable node
// and the weight of current RBM; 2. the 0-1 state of hidden node by a binomial
// distribution given the calculated output probability of this hidden node
void sample_h_given_v (int*,// one input sample from visiable nodes -- input
double*,// the output probability of hidden nodes -- output
int*// the calculated 0-1 state of hidden node -- output
);
// sample the visiable node given the hidden node, 'sample' means calculating
// 1. the output probability of the visiable node given the input of hidden node
// and the weight of current RBM; 2. the 0-1 state of visiable node by a binomial
// distribution given the calculated output probability of this visiable node
void sample_v_given_h (int*,// one input sample from hidden nodes -- input
double*,// the output probability of visiable nodes -- output
int*// the calculated 0-1 state of visiable node -- output
);
// 'propup' -- probability up. It's called by the 'sample_x_given_x' function and the reconstruct funciton
//To calculate the probability in 'upper' node given the input from 'lower' node in RBM
// note: what is the 'up' and 'down'? the visiable node is below (down) the hidden node.
// 'probability up' means calculating the probability of hidden node given the visiable node
// return value: the output probability of the hidden node given the input of visiable node
// and the weight of current RBM
// the probability is : p (hi|v) = sigmod ( sum_j(vj * wij) + bi)
double propup (int*,// one input sample from visiable node -- input
double*,// the weight W connecting one hidden node to all visible node -- input
double// the bias for this hidden node -- input
);
// 'propdown' -- probability down. It's called by the 'sample_x_given_x' function and the reconstruct funciton
//To calculate the probability in 'lower' node given the input from 'upper' node in RBM
// note: what is the 'up' and 'down'? the visiable node is below (down) the hidden node.
// 'probability down' means calculating the probability of visiable node given the hidden node
// return value: the output probability of the visiable node given the input of hidden node
// and the weight of current RBM
// the probability is : p (vi|h) = sigmod ( sum_j(hj * wij) + ci)
double propdown (int*,// one input sample from hidden node -- input
int,// the index of visiable node in the W matrix -- input
double// the bias for this visible node -- input
);
// 'gibbs_hvh' -- gibbs sample firstly from hidden node to visible node, then sample
// from visiable node to hidden node. It is called by contrastive_divergence.
void gibbs_hvh (int*,// one input sample from hidden node, h0 -- input
double*,// the output probability of visiable nodes -- output
int*,// the calculated 0-1 state of visiable node -- output
double*,// the output probability of reconstructed hidden node h1 -- output
int*// the calculated 0-1 state of reconstructed hidden node h1 -- output
);
// reconstruct the input visiable node by the trained RBM (so as to varify the RBM model)
void reconstruct (int*,// one input sample from visiable node
double*// the reconstructed output by RBM model
);
};

主要添加了函数说明、参数说明、计算说明、调用关系等。

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,086
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,561
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,410
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,183
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,820
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,903