【deep learning学习笔记】注释yusugomori的DA代码 --- dA.cpp -- 训练
说实话,具体的训练公式,我没有自己推导,姑且认为他写的代码是对的。总体上看,用bp的方法。特殊之处,在于输入层和输出层是完完全全的“同一层”。
void dA::get_corrupted_input (
int *x, // the original input 0-1 vector -- input
int *tilde_x, // the resulted 0-1 vector gotten noised -- output
double p // the p probability of noise, binomial test -- input
)
{
for(int i=0; i<n_visible; i++)
{
if(x[i] == 0)
{
// if the state is 0, do noghing
tilde_x[i] = 0;
}
else
{
// if the state is 1, add the noise of p probability on it
tilde_x[i] = binomial(1, p);
}
}
} // Encode
void dA::get_hidden_values (
int *x, // the input from visible nodes
double *y // the output of hidden nodes
)
{
for(int i=0; i<n_hidden; i++)
{
// calculated sum_j(vj * wij) + bi
y[i] = 0;
for(int j=0; j<n_visible; j++)
{
y[i] += W[i][j] * x[j];
}
y[i] += hbias[i];
// sigmod (y)
y[i] = sigmoid(y[i]);
}
} // Decode
void dA::get_reconstructed_input (
double *y, // the input from hidden nodes
double *z // the output reconstructed of visible nodes
)
{
for(int i=0; i<n_visible; i++)
{
// calculated sum_j(hj * wij) + ci
z[i] = 0;
for(int j=0; j<n_hidden; j++)
{
z[i] += W[j][i] * y[j];
}
z[i] += vbias[i];
// sigmod (z)
z[i] = sigmoid(z[i]);
}
} void dA::train (
int *x, // the input sample from visiable node
double lr, // the learning rate
double corruption_level // corruption_level is the probability of noise
)
{
// the auto-encoder networks:
// input(visible) layer --> hidden layer --> output(visible) layer
// the input layer is the same as the output layer, the two layers are totally same.
// we train it by the standard bp algorithm, from output layer to the hidden layer, and to the input layer
// Here is the whole process: int *tilde_x = new int[n_visible]; // the noise input
double *y = new double[n_hidden]; // the output of hidden layer
double *z = new double[n_visible]; // the output of output layer, reconstruction double *L_vbias = new double[n_visible]; // temp value for visible bias
double *L_hbias = new double[n_hidden]; // temp value for hidden bias double p = 1 - corruption_level; // make the input sample noise by the p probability
get_corrupted_input(x, tilde_x, p);
// calculate the output of hidden nodes by the noise input, encode
get_hidden_values(tilde_x, y);
// reconstruct the input sample from visible nodes, decode
get_reconstructed_input(y, z); // update the bias of visible nodes
for(int i=0; i<n_visible; i++)
{
// the difference between input sample and the PROBABILITY of reconstructed probability of visible node
// it's different from RBM that in RBM we calcualte the difference between input sample and
// the 0-1 state of the reconstructed visiable node
// here use the standard bp algorithm, from visible layer to hidden layer
L_vbias[i] = x[i] - z[i];
// update the value by the learning rate
vbias[i] += lr * L_vbias[i] / N;
} // update the bias of hidden nodes
for(int i=0; i<n_hidden; i++)
{
// propgate the bias from visible nodes
// here use the standard bp algorithm, from visible layer to hidden layer
L_hbias[i] = 0;
for(int j=0; j<n_visible; j++)
{
L_hbias[i] += W[i][j] * L_vbias[j];
}
L_hbias[i] *= y[i] * (1 - y[i]);
hbias[i] += lr * L_hbias[i] / N;
} // update the weight of networks
for(int i=0; i<n_hidden; i++)
{
for(int j=0; j<n_visible; j++)
{
W[i][j] += lr * (L_hbias[i] * tilde_x[j] + L_vbias[j] * y[i]) / N;
}
} delete[] L_hbias;
delete[] L_vbias;
delete[] z;
delete[] y;
delete[] tilde_x;
} void dA::reconstruct (
int *x, // the input sample -- input
double *z // the reconstructed value -- output
)
{
double *y = new double[n_hidden]; // calculate the output of hidden layer
get_hidden_values(x, y);
// reconstruct from hidden layer to visible layer
get_reconstructed_input(y, z); delete[] y;
}
【deep learning学习笔记】注释yusugomori的DA代码 --- dA.cpp -- 训练的更多相关文章
- 【deep learning学习笔记】注释yusugomori的DA代码 --- dA.h
DA就是“Denoising Autoencoders”的缩写.继续给yusugomori做注释,边注释边学习.看了一些DA的材料,基本上都在前面“转载”了.学习中间总有个疑问:DA和RBM到底啥区别 ...
- 【deep learning学习笔记】注释yusugomori的RBM代码 --- 头文件
百度了半天yusugomori,也不知道他是谁.不过这位老兄写了deep learning的代码,包括RBM.逻辑回归.DBN.autoencoder等,实现语言包括c.c++.java.python ...
- [置顶]
Deep Learning 学习笔记
一.文章来由 好久没写原创博客了,一直处于学习新知识的阶段.来新加坡也有一个星期,搞定签证.入学等杂事之后,今天上午与导师确定了接下来的研究任务,我平时基本也是把博客当作联机版的云笔记~~如果有写的不 ...
- Deep Learning 学习笔记(8):自编码器( Autoencoders )
之前的笔记,算不上是 Deep Learning, 只是为理解Deep Learning 而需要学习的基础知识, 从下面开始,我会把我学习UFDL的笔记写出来 #主要是给自己用的,所以其他人不一定看得 ...
- 【deep learning学习笔记】Recommending music on Spotify with deep learning
主要内容: Spotify是个类似酷我音乐的音乐站点.做个性化音乐推荐和音乐消费.作者利用deep learning结合协同过滤来做音乐推荐. 详细内容: 1. 协同过滤 基本原理:某两个用户听的歌曲 ...
- Neural Networks and Deep Learning学习笔记ch1 - 神经网络
近期開始看一些深度学习的资料.想学习一下深度学习的基础知识.找到了一个比較好的tutorial,Neural Networks and Deep Learning,认真看完了之后觉得收获还是非常多的. ...
- paper 149:Deep Learning 学习笔记(一)
1. 直接上手篇 台湾李宏毅教授写的,<1天搞懂深度学习> slideshare的链接: http://www.slideshare.net/tw_dsconf/ss-62245351? ...
- Deep Learning 学习笔记——第9章
总览: 本章所讲的知识点包括>>>> 1.描述卷积操作 2.解释使用卷积的原因 3.描述pooling操作 4.卷积在实践应用中的变化形式 5.卷积如何适应输入数据 6.CNN ...
- 【Deep Learning学习笔记】Dynamic Auto-Encoders for Semantic Indexing_Mirowski_NIPS2010
发表于NIPS2010 workshop on deep learning的一篇文章,看得半懂. 主要内容: 是针对文本表示的一种方法.文本表示可以进一步应用在文本分类和信息检索上面.通常,一篇文章表 ...
- 【deep learning学习笔记】最近读的几个ppt(四)
这几个ppt都是在微博上看到的,是百度的一个员工整理的. <Deep Belief Nets>,31页的一个ppt 1. 相关背景 还是在说deep learning好啦,如特征表示云云. ...
随机推荐
- 用pt-stalk定位MySQL短暂的性能问题
背景] MySQL出现短暂的3-30秒的性能问题,一般的监控工具较难抓到现场,很难准确定位问题原因. 对于这类需求,我们日常的MySQL分析工具都有些不足的地方: 1. 性能监控工具,目前粒度是分钟级 ...
- SpringMVC(九) RequestMapping请求参数
通过在控制器方法中使用@RequestParam(value="参数名",require=true/false,defaultvalue="")的方式,使在UR ...
- Servlet接口、GenericServlet类、HttpServlet类
Servlet是最顶层的接口,其提供的方法有: init(ServletConfig config):void // 初始化 getServletConfig():ServletConfig // 取 ...
- 2977 二叉堆练习1 codevs
题目描述 Description 已知一个二叉树,判断它是否为二叉堆(小根堆) 输入描述 Input Description 二叉树的节点数N和N个节点(按层输入) 输出描述 Output Descr ...
- hdu 4452 37届金华赛区 K题
题意:给一个n*n的格子,1在左上角,2在右下角,每个人有一个初始速度和方向,若遇到边缘,则朝相反方向前进,若两个人相遇则交换方向(注意方向改变后,人仍然需要移动),同时,每个人每过t1,t2时间就会 ...
- Codeforces Round #292 (Div. 1)A. Drazil and Factorial 构造
A. Drazil and Factorial 题目连接: http://codeforces.com/contest/516/problem/A Description Drazil is play ...
- spring cloud 学习(9) - turbine stream无法在eureka注册的解决办法
turbine是啥就不多解释了,初次接触的可以移步spring cloud 学习(4) - hystrix 服务熔断处理 拉到最后看一下,turbine stream默认情况下启动成功后,eureka ...
- nginx php-fpm安装配置(转)
nginx本身不能处理PHP,它只是个web服务器,当接收到请求后,如果是php请求,则发给php解释器处理,并把结果返回给客户端. nginx一般是把请求发fastcgi管理进程处理,fascgi管 ...
- ZOJ 3765 Lights (伸展树splay)
题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3765 Lights Time Limit: 8 Seconds ...
- 使用Axure RP原型设计实践01,使用概述
首先认识Axure RP Pro 7.0软件的默认界面布局.最上面的是工具栏区域,左侧上方的是网站地图区域(sitemap),左侧中部的是部件区域(Widgets),左侧下方的是模板区域(Master ...