学习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和 ...
随机推荐
- Linux基础之网络协议
互联网通信原理 从物理层面来说,每台计算机在一开始都是彼此孤立的,为了实现信息的交流与共享,计算机之间必须要建立通信网络.例如人与人之间的交流,他们必须要共用一套语言系统,才能交流成功.计算机之间也是 ...
- 【转载】HTTP 请求头与请求体
原文地址: https://segmentfault.com/a/1190000006689767 HTTP Request HTTP 的请求报文分为三个部分 请求行.请求头和请求体,格式如图:一个典 ...
- C# 获得固定年月日
/// <summary> /// 获得固定年月日,时和分不固定 : 2019-01-01 00:00:00 /// </summary> /// <returns> ...
- day13-迭代器、三元表达式、列表推导式、字典生成式、生成器与递归
目录 迭代器 可迭代对象 迭代器对象 for循环原理 三元表达式(三目表达式) 列表推导式 字典生成式 zip()方法 生成器 生成器表达式 递归 递归的两个阶段 迭代器 迭代器即迭代的工具,迭代是一 ...
- node里读取命令行参数
一.process.env process.env属性返回一个包含用户环境信息的对象. 最常见的需求,前端需要根据不同的环境(dev,prd),来调用不同的后端接口.如果用webpack,是这么做的: ...
- xcode构建webdriverAgent时报错Messaging unqualified id的解决办法
在使用xcode构建webdriverAgent时,提示build failed,报错信息为:semantic issue:Messaging unqualified id,可以参考以下解决方案 xc ...
- PAT_A1066#Root of AVL Tree
Source: PAT A1066 Root of AVL Tree (25 分) Description: An AVL tree is a self-balancing binary search ...
- maven常用dos命令
在平常的开发中可能会经常切换开发中的一些工具,有时就会对一些常用的命令给忘记了 这里特别记录下来方便以后使用: 1.查看maven版本:mvn -c 2.一件构建启动Tomcat:mvn tomcat ...
- [forward]警惕UNIX下的LD_PRELOAD环境变量
From: https://blog.csdn.net/haoel/article/details/1602108 警惕UNIX下的LD_PRELOAD环境变量 前言 也许这个话题并不新鲜,因为LD_ ...
- How To:python pip install
官方网站 https://pypi.python.org/pypi/pip/ 下载需要的版本 wget https://pypi.python.org/packages/source/p/pi ...