【deep learning学习笔记】注释yusugomori的RBM代码 --- 头文件
来源:互联网 发布:淘宝上买steam游戏后果 编辑:程序博客网 时间:2024/05/21 08:46
百度了半天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 nodeint n_visible;// the number of hidden nodeint n_hidden;// the weight connecting the visiable node and the hidden nodedouble **W;// the bias of hidden nodedouble *hbias;// the bias of visiable nodedouble *vbias;public:// construct the RBM by input parametersRBM (int,// Nint,// n_visibleint,// n_hiddendouble**,// Wdouble*,// hbiasdouble*// 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 nodevoid sample_h_given_v (int*,// one input sample from visiable nodes -- inputdouble*,// the output probability of hidden nodes -- outputint*// 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 nodevoid sample_v_given_h (int*,// one input sample from hidden nodes -- inputdouble*,// the output probability of visiable nodes -- outputint*// 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 -- inputdouble*,// the weight W connecting one hidden node to all visible node -- inputdouble// 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 -- inputint,// the index of visiable node in the W matrix -- inputdouble// 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 -- inputdouble*,// the output probability of visiable nodes -- outputint*,// the calculated 0-1 state of visiable node -- outputdouble*,// the output probability of reconstructed hidden node h1 -- outputint*// 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 nodedouble*// the reconstructed output by RBM model);};
主要添加了函数说明、参数说明、计算说明、调用关系等。
- 【deep learning学习笔记】注释yusugomori的RBM代码 --- 头文件
- 【deep learning学习笔记】注释yusugomori的RBM代码 --- 头文件
- 【deep learning学习笔记】注释yusugomori的RBM代码 --- cpp文件 -- 准备工作
- 【deep learning学习笔记】注释yusugomori的RBM代码 --- cpp文件 -- 模型训练
- 【deep learning学习笔记】注释yusugomori的RBM代码 --- cpp文件 -- 模型测试
- 【deep learning学习笔记】注释yusugomori的SDA代码 -- 准备工作
- 【deep learning学习笔记】注释yusugomori的LR代码 --- LogisticRegression.h
- 【deep learning学习笔记】注释yusugomori的LR代码 --- LogisticRegression.cpp
- 【deep learning学习笔记】注释yusugomori的LR代码 --- 模型测试
- 【deep learning学习笔记】注释yusugomori的DA代码 --- dA.h
- 【deep learning学习笔记】注释yusugomori的DA代码 --- dA.cpp --模型准备
- 【deep learning学习笔记】注释yusugomori的DA代码 --- dA.cpp -- 训练
- 【deep learning学习笔记】注释yusugomori的DA代码 --- dA.cpp -- 模型测试
- 【deep learning学习笔记】注释yusugomori的SDA代码 -- Sda.h
- 【deep learning学习笔记】注释yusugomori的SDA代码 -- Sda.cpp -- 模型准备
- 【deep learning学习笔记】注释yusugomori的SDA代码 -- Sda.cpp -- 模型训练与预测
- 【deep learning学习笔记】注释yusugomori的SDA代码 -- Sda.cpp -- 模型测试
- RBM Deep Learning
- 设计模式C++实现(3)——适配器模式
- Java与C之间通过JNI传递中文字符串
- Thinking in C++: static const (类中的编译时常量)
- c++ string 字符无法准确去除两边空格!
- hdu 1011 树形dp 背包
- 【deep learning学习笔记】注释yusugomori的RBM代码 --- 头文件
- 狼奔生成器之初体验
- 在gem5的full system下运行 x86编译的测试程序 running gem5 on ubuntu in full system mode in x86
- 两栈共享空间
- nyist-244
- 完全免费和开源的权限管理系统
- 反射相关的异常
- 正则表达式有用的相关网页
- Java基础之面向对象(四)--多态、Object类