说实话,具体的训练公式,我没有自己推导,姑且认为他写的代码是对的。总体上看,用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 -- 训练的更多相关文章

  1. 【deep learning学习笔记】注释yusugomori的DA代码 --- dA.h

    DA就是“Denoising Autoencoders”的缩写.继续给yusugomori做注释,边注释边学习.看了一些DA的材料,基本上都在前面“转载”了.学习中间总有个疑问:DA和RBM到底啥区别 ...

  2. 【deep learning学习笔记】注释yusugomori的RBM代码 --- 头文件

    百度了半天yusugomori,也不知道他是谁.不过这位老兄写了deep learning的代码,包括RBM.逻辑回归.DBN.autoencoder等,实现语言包括c.c++.java.python ...

  3. [置顶] Deep Learning 学习笔记

    一.文章来由 好久没写原创博客了,一直处于学习新知识的阶段.来新加坡也有一个星期,搞定签证.入学等杂事之后,今天上午与导师确定了接下来的研究任务,我平时基本也是把博客当作联机版的云笔记~~如果有写的不 ...

  4. Deep Learning 学习笔记(8):自编码器( Autoencoders )

    之前的笔记,算不上是 Deep Learning, 只是为理解Deep Learning 而需要学习的基础知识, 从下面开始,我会把我学习UFDL的笔记写出来 #主要是给自己用的,所以其他人不一定看得 ...

  5. 【deep learning学习笔记】Recommending music on Spotify with deep learning

    主要内容: Spotify是个类似酷我音乐的音乐站点.做个性化音乐推荐和音乐消费.作者利用deep learning结合协同过滤来做音乐推荐. 详细内容: 1. 协同过滤 基本原理:某两个用户听的歌曲 ...

  6. Neural Networks and Deep Learning学习笔记ch1 - 神经网络

    近期開始看一些深度学习的资料.想学习一下深度学习的基础知识.找到了一个比較好的tutorial,Neural Networks and Deep Learning,认真看完了之后觉得收获还是非常多的. ...

  7. paper 149:Deep Learning 学习笔记(一)

     1. 直接上手篇 台湾李宏毅教授写的,<1天搞懂深度学习> slideshare的链接: http://www.slideshare.net/tw_dsconf/ss-62245351? ...

  8. Deep Learning 学习笔记——第9章

    总览: 本章所讲的知识点包括>>>> 1.描述卷积操作 2.解释使用卷积的原因 3.描述pooling操作 4.卷积在实践应用中的变化形式 5.卷积如何适应输入数据 6.CNN ...

  9. 【Deep Learning学习笔记】Dynamic Auto-Encoders for Semantic Indexing_Mirowski_NIPS2010

    发表于NIPS2010 workshop on deep learning的一篇文章,看得半懂. 主要内容: 是针对文本表示的一种方法.文本表示可以进一步应用在文本分类和信息检索上面.通常,一篇文章表 ...

  10. 【deep learning学习笔记】最近读的几个ppt(四)

    这几个ppt都是在微博上看到的,是百度的一个员工整理的. <Deep Belief Nets>,31页的一个ppt 1. 相关背景 还是在说deep learning好啦,如特征表示云云. ...

随机推荐

  1. 学习linux-基础-操作系统结构

    操作系统结构图 物理层: CPU:( Central Processing Unit)是一块超大规模的集成电路,是一台计算机的运算核心(Core)和控制核心( Control Unit).它的功能主要 ...

  2. [代码审计]phpshe开源商城后台两处任意文件删除至getshell

    0x00 背景 这套系统审了很久了,审计的版本是1.6,前台审不出个所以然来.前台的限制做的很死. 入库的数据都是经过mysql_real_escape_string,htmlspecialchars ...

  3. WEP自动破解工具wesside-ng

    WEP自动破解工具wesside-ng   wesside-ng是aircrack-ng套件提供的一个概念验证工具.该工具可以自动扫描无线网络,发现WEP加密的AP.然后,尝试关联该AP.关联成功后, ...

  4. Redis五大类型操作使用以及订阅发布功能

    redis是一个key-value存储系统.和Memcached类似,它支持存储的value类型相对更多,包括string(字符串).list(链表).set(集合).zset(sorted set ...

  5. linux安装project lemon测评机

    (写下备用) 机子:xubuntu 16.04 LTS 1.下载lemon github地址:https://github.com/Sojiv/Project_lemon 这里download zip ...

  6. android 静音

    语音朗读 静音,设置变量识别好了. android插件下载开发. 实际可以这样, 保存应用的图标,名称,包名,下载地址. 插件作为apk.  或许希望apk不在桌面有图标.也可以.但是也没必要. 当下 ...

  7. ZJOI2019day1退役记

    ZJOI2019day1退役记 每天都在划水,考场上心态炸了,也没什么好说的. 有人催我更退役记,等成绩出来了再更更吧,成绩出来也没心情更了,落差好大,还打不过文化课选手 虽然被卡常数卡到心态爆炸,但 ...

  8. git指南目录

    git指南目录 发表回复 蓝色表示未阅读,棕色表示阅读过,绿色表示阅读过但不太理解 1. 起步 1.1 关于版本控制 1.2 Git 简史 1.3 Git 基础 1.4 安装 Git 1.5 初次运行 ...

  9. HTML解析利器HtmlAgilityPack

    一个.NET下的HTML解析类库HtmlAgilityPack.HtmlAgilityPack是一个支持用XPath来解析HTML的类库,在花了一点时间学习了解HtmlAgilityPack的API和 ...

  10. Spartan6 slave SelectMap configuration fails owing to JTAG?

    http://forums.xilinx.com/t5/Configuration/Spartan6-slave-SelectMap-configuration-fails-owing-to-JTAG ...