学习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和 ...
随机推荐
- Tomcat8 连接池
1.所有的tomcat项目共用一个连接池配置 1.1 修改conf->context.xml文件,在Context节点下配置 <Resource name="jdbc/myDat ...
- CAD读取属性块
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 3 ...
- C# 泛基
1 你有时候希望在父类规定一些行为,让子类无法修改,但是这些实现是依赖一个子类才能获取的值,你又不可能知道所有的子类 ,没办法替它在父类里面初始化,这时候就需要在父类里面定义一个每个子类一个的,但又是 ...
- Codeforces Round #467 Div.2题解
A. Olympiad time limit per test 1 second memory limit per test 256 megabytes input standard input ou ...
- 最小生成树算法Kruskal详解
要讲Kruskal,我们先来看下面一组样例. 4 5 1 2 3 1 4 5 2 4 7 2 3 6 3 4 8 14 画出来更直观一些,就是上面的这张图. 智商只要不是0的(了解最小生成树是什么的童 ...
- 解决高分屏/高DPI下GNOME3/Linux字体和按钮太小的问题
更改系统设置就好了. 我的设备是Surface Pro,12英寸,分辨率2736x1824,在虚拟机里安装CentOS 7后字特别小,标题栏的最小化/最大化/关闭按钮也很小,眼睛受不了的. 更改两个设 ...
- 11.best fields策略(dis_max参数设置)
主要知识点 常规multi-field搜索结果分析 dis_max参数设置 一.为帖子数据增加content字段 POST /forum/article/_bulk { "u ...
- Problem 63
Problem 63 https://projecteuler.net/problem=63 Powerful digit counts The 5-digit number, 16807=75, i ...
- 解决WP程序 重复打开出现 “正在加载...” 字样 解决方案
在开发winphone程序时候 我们经常遇到调试.在调试的时候 可能会重复打开 debug一下.可是有时候 经常遇到 "正在加载...."字样.而且很慢.效率很低. 测试发现 在 ...
- 牛刀小试MySQL学习—MySQL 双主
双主其实说白了也是一个replication,只是推出一些新的拓扑结构 主-主的复制有两种模式: 主动-主动模式下的主-主复制(Master-Master in Active-Active Mod ...