【deep learning学习笔记】注释yusugomori的RBM代码 --- 头文件
2023-09-27 14:23:52 时间
百度了半天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 ); };
主要添加了函数说明、参数说明、计算说明、调用关系等。
相关文章
- Web3DGame之路,Babylonjs 和TypeScript学习笔记(二)
- 【学习笔记15】JavaScript的函数
- [吴恩达机器学习笔记]12支持向量机5SVM参数细节
- 操作系统,计算机网络,数据库刷题笔记2
- Linux学习笔记——如何使用echo指令向文件写入内容
- NLP文本分类入门学习及TextCnn实践笔记——代码实现(二)
- 《数据挖掘:理论与算法》学习笔记(二)—数据预处理(上)
- Android学习笔记——文件路径(/mnt/sdcard/...)、Uri(content://media/external/...)学习
- Web 在线文件管理器学习笔记与总结(15)剪切文件夹 (16)删除文件夹
- Thinkphp学习笔记-模板赋值
- 吴恩达机器学习笔记 —— 11 应用机器学习的建议
- 初探swift语言的学习笔记(闭包 - 匿名函数或block块代码)
- [学习笔记]Java代码中各种类型变量的内存分配机制
- JVM学习笔记(二)——Class文件结构
- SwiftUI进阶之 08 编程的最大挑战是什么 (《代码大全》学习笔记)
- SwiftUI进阶之 03 App架构应该如何设计 (《代码大全》学习笔记)
- Andrew Ng-机器学习基础笔记(下)-Python实现代码
- Andrew Ng-机器学习基础笔记(上)-Python实现代码
- 【Java】Java学习笔记-面向对象
- JAVA并发编程学习笔记之CAS操作
- HDFS学习笔记(1)初探HDFS
- 《慕客网:IOS基础入门之Foundation框架初体验》学习笔记 <三> NSArray
- 传感器技术—霍尔传感器(学习笔记九)
- Linux下汇编语言学习笔记64 ---
- Linux下汇编语言学习笔记21 ---
- c#学习笔记
- 深度学习笔记