学习XOR
//f(x;W,c,w,b)=w*max{0, W*x+c}+b
#include <iostream>
#include <vector>
#include <algorithm>
template <class T>
double tanh(T& z) {
double ret;
ret = (exp(z)-exp((-1)*z))/(exp(z)+exp((-1)*z));
return ret;
}
template <class T>
double sigmoid(T& z) {
return 1.0f/(1.0f+exp((-1)*z));
}
int main() {
int w[][2]={{1, 1}, {1,1}};
int bias[]={0, -1};
int weights[] = {1, -2};
int x[][2]={{0, 0}, {0, 1}, {1, 0}, {1, 1}};
int c[][2]={{0, 0}, {0, 0}, {0, 0}, {0, 0}};
/*x[4][2] * w[2][2] = c[4][2]*/
for(size_t i=0;i<4;++i) {
for(size_t j=0;j<2;++j) {
int sum = 0;
for(size_t k=0;k<2;++k) {
sum += x[i][k] * w[k][j];
}
c[i][j] = sum;
}
}
for(size_t i=0;i<4;++i) {
for(size_t j=0;j<2;++j) {
std::cout<<c[i][j]<<" ";
}
std::cout<<std::endl;
}
std::cout<<"add bias, rectified linear unit:\n";
for(size_t i=0;i<4;++i) {
for(size_t j=0;j<2;++j) {
c[i][j] = c[i][j] + bias[j];
c[i][j] = std::max(c[i][j], 0);
std::cout<<c[i][j]<<" ";
}
std::cout<<std::endl;
}
for(size_t i=0;i<4;++i) {
for(size_t j=0;j<1;++j) {
int sum=0;
for(size_t k=0;k<2;++k) {
sum += c[i][k] * weights[k];
}
c[i][j] = sum;
}
}
std::cout<<"the XOR result:\n";
for(size_t i=0; i<4; ++i) {
for(size_t j=0;j<2;++j) {
std::cout<<x[i][j]<<" ";
}
std::cout<<c[i][0]<<"\n";
}
return 0;
}
With the input patterns (0,0) and (1,1) located on opposite corners of the unit square, and likewise
for the other two input patterns (0,1) and (1,0), it is clear that we cannot construct a straight line
for a decision boundary so that (0,0) and (0,1) lie in one dicision region and (0,1) and (1,0) lie in the
other decision region. In other words, the singlelayer perceptron cannot solve the XOR problem.
学习XOR的更多相关文章
- TensorFlow学习笔记7-深度前馈网络(多层感知机)
深度前馈网络(前馈神经网络,多层感知机) 神经网络基本概念 前馈神经网络在模型输出和模型本身之间没有反馈连接;前馈神经网络包含反馈连接时,称为循环神经网络. 前馈神经网络用有向无环图表示. 设三个函数 ...
- Reading | 《DEEP LEARNING》
目录 一.引言 1.什么是.为什么需要深度学习 2.简单的机器学习算法对数据表示的依赖 3.深度学习的历史趋势 最早的人工神经网络:旨在模拟生物学习的计算模型 神经网络第二次浪潮:联结主义connec ...
- ACM学习历程—HDU 3915 Game(Nim博弈 && xor高斯消元)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3915 题目大意是给了n个堆,然后去掉一些堆,使得先手变成必败局势. 首先这是个Nim博弈,必败局势是所 ...
- ACM学习历程—UESTC 1219 Ba Gua Zhen(dfs && 独立回路 && xor高斯消元)
题目链接:http://acm.uestc.edu.cn/#/problem/show/1219 题目大意是给了一张图,然后要求一个点通过路径回到这个点,使得xor和最大. 这是CCPC南阳站的一道题 ...
- ACM学习历程—BZOJ 2115 Xor(dfs && 独立回路 && xor高斯消元)
题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=2115 题目大意是求一条从1到n的路径,使得路径xor和最大. 可以发现想枚举1到n的所有路 ...
- ACM学习历程—HDU 5536 Chip Factory(xor && 字典树)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5536 题目大意是给了一个序列,求(si+sj)^sk的最大值. 首先n有1000,暴力理论上是不行的. ...
- ACM学习历程—HDU 3949 XOR(xor高斯消元)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3949 题目大意是给n个数,然后随便取几个数求xor和,求第k小的.(重复不计算) 首先想把所有xor的 ...
- ACM学习历程—POJ 3764 The xor-longest Path(xor && 字典树 && 贪心)
题目链接:http://poj.org/problem?id=3764 题目大意是在树上求一条路径,使得xor和最大. 由于是在树上,所以两个结点之间应有唯一路径. 而xor(u, v) = xor( ...
- ACM学习历程—SGU 275 To xor or not to xor(xor高斯消元)
题目链接:http://acm.sgu.ru/problem.php?contest=0&problem=275 这是一道xor高斯消元. 题目大意是给了n个数,然后任取几个数,让他们xor和 ...
随机推荐
- 学习随笔-Java WebService
webService 可以将应用程序转换成网络应用程序.是简单的可共同操作的消息收发框架. 基本的webService平台是 XML 和 HTTP. HTTP 是最常用的互联网协议: XML 是 we ...
- Java_Web三大框架之Hibernate配置文件(二)
下面介绍一下编写Hibernate的配置文件,使用Hibernate操作数据库. 开始部署:下载需要的jar包 下载Hibernate Hibernat ...
- Objective-C在ARC下结合GCD的单例模式和宏模版
单例模式在iOS开发过程中经常用到,苹果提供过objective c单例的比较官方的写法: static MyGizmoClass *sharedGizmoManager = nil; + (MyGi ...
- Python3:numpy模块中的argsort()函数
Python3:numpy模块中的argsort()函数 argsort函数是Numpy模块中的函数: >>> import numpy >>> help(nu ...
- adjtimex和时钟的几个概念tick,freq,ppm,jiffies
adjtimex使用 今天遇到一个ntp的同步问题.服务器上配置好了ntpd,在启动前也手动进行过同步,但是过段时间ntpq查询发现服务器即便能选出同步服务器,但是系统的时间偏差越来越大. 服务器上实 ...
- MySQL详细操作
一.用户管理 -- 创建用户 create user "用户名"@"IP地址" identified by "密码"; "; &q ...
- Python OS & sys模块
os模块(* * * *) os模块是与操作系统交互的一个接口 os.getcwd() 获取当前工作目录,即当前python脚本工作的目录路径 os.chdir("dirname" ...
- Lucas小记
组合数学全忘了 记笔记记笔记 做个简单题 代码 from bzoj4403 #include <stdio.h> #define p 1000003 typedef long long l ...
- Curious Cupid
There are K different languages in the world. Each person speaks one and only one language. There ar ...
- Istio是啥?一文带你彻底了解!
原标题:Istio是啥?一文带你彻底了解! " 如果你比较关注新兴技术的话,那么很可能在不同的地方听说过 Istio,并且知道它和 Service Mesh 有着牵扯. 这篇文章可以作为了解 ...