【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);};

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




原创粉丝点击
热门问题 老师的惩罚 人脸识别 我在镇武司摸鱼那些年 重生之率土为王 我在大康的咸鱼生活 盘龙之生命进化 天生仙种 凡人之先天五行 春回大明朝 姑娘不必设防,我是瞎子 放弃继承权后想反悔怎么办 上海居住证积分中社保断怎么办 换驾驶证但是身份证地址变动怎么办 驾驶证b证扣分了怎么办 c1驾证过期没审怎么办 驾照报名三年过期了怎么办 新车行驶证过期了怎么办 行驶证忘了审怎么办 摩托车驾驶证副本丢了怎么办 人被全险车撞了怎么办 被全险车撞了怎么办 驾驶证和行驶证遗失怎么办 户口迁移身份证没换驾照怎么办 户口迁回时身份证掉了怎么办 户口毕业托管身份证掉了怎么办 身份证和户口都掉了怎么办 毕业生户口迁回原籍没身份证怎么办 落户上海后怎么办医保卡 小车临时牌过期了怎么办 驾驶证地址错了一个字怎么办 驾驶证名下车辆有违章怎么办 a2如果扣12分怎么办 b2一次超速12分怎么办 b2本扣了12分怎么办 驾照扣了27分怎么办 大车一次扣12分怎么办 a2驾照扣10分怎么办 驾驶证强制降级没给驾驶证怎么办 6P升11.2卡了怎么办 b2驾照记满12分怎么办 c1驾驶证没分了怎么办 驾照扣了15分怎么办 驾驶证暂扣六个月后怎么办 醉驾交警不通知怎么办 参军后地方驾驶证年审怎么办 军人驾驶证到期身份证注销了怎么办 资格证脱审30天怎么办 驾驶证c证扣6分怎么办 驾照被扣了9分怎么办 驾驶证被扣了9分怎么办 a2驾驶本扣3分怎么办