说实话,具体的训练公式,我没有自己推导,姑且认为他写的代码是对的。总体上看,用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. 002.Git日常基础使用

    一 获取git仓库 1.1 初始化仓库 [root@git ~]# cd /mystudy/ [root@git mystudy]# git init [root@git mystudy]# git ...

  2. JAVA 图形界面开发基础详解

    与C的win32一样,JAVA也有自己的图形界面开发,将在此篇博客中对基础部分进行讲解. 1.Java提供的图形界面类有哪些? Java提供了两套图形界面 (1)AWT组建(基础) AWT组件是jdk ...

  3. Redis高可用之主从复制实践(四)

    0.Redis目录结构 1)Redis介绍及部署在CentOS7上(一) 2)Redis指令与数据结构(二) 3)Redis客户端连接以及持久化数据(三) 4)Redis高可用之主从复制实践(四) 5 ...

  4. python 修改文件中的内容

    在python的文件操作中,是没有办法对文件中具体某行或者某个位置的内容进行局部的修改的,如果需要对文件的某一行内容进行修改,可以先将文件中的所有的内容全部读取出来,再进行内容判断,是否是需要修改的内 ...

  5. leetcode 岛屿的个数 python

      岛屿的个数     给定一个由 '1'(陆地)和 '0'(水)组成的的二维网格,计算岛屿的数量.一个岛被水包围,并且它是通过水平方向或垂直方向上相邻的陆地连接而成的.你可以假设网格的四个边均被水包 ...

  6. windows10 卸载 Docker 和 DockerNAT

    删除docker程序 记事本新建脚本文件 a.ps1,内容如下: $ErrorActionPreference = "SilentlyContinue" kill -force - ...

  7. 在JavaScript中什么时候使用==是正确的?

    在JavaScript中什么情况下使用==是正确的?简而言之:没有.这篇文章来看五种情况下总是使用===,并且解释为什么不用==. JavaScript有两种操作符用来比较两个值是否相等 [1]: 严 ...

  8. 喵哈哈村的魔法考试 Round #3 (Div.2) 题解

    A 题解:保证一个三角形的话,得两边之和大于第三边才行,所以都拿来判一判就好了. #include <iostream> using namespace std; int main(){ ...

  9. WorldFinal11 (2/11)

    WorldFinal 11 Trash Removal 题意 给你一个多边形,问这个多边形至少需要多宽的长度,才能把这个多边形放进去. 数据范围100 题解 数据范围只有100,暴力枚举两点,然后算最 ...

  10. logstash高速入口

    原文地址:http://logstash.net/docs/1.4.2/tutorials/getting-started-with-logstash 英语水平有限,假设有错误请各位指正 简单介绍 L ...