//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的更多相关文章

  1. TensorFlow学习笔记7-深度前馈网络(多层感知机)

    深度前馈网络(前馈神经网络,多层感知机) 神经网络基本概念 前馈神经网络在模型输出和模型本身之间没有反馈连接;前馈神经网络包含反馈连接时,称为循环神经网络. 前馈神经网络用有向无环图表示. 设三个函数 ...

  2. Reading | 《DEEP LEARNING》

    目录 一.引言 1.什么是.为什么需要深度学习 2.简单的机器学习算法对数据表示的依赖 3.深度学习的历史趋势 最早的人工神经网络:旨在模拟生物学习的计算模型 神经网络第二次浪潮:联结主义connec ...

  3. ACM学习历程—HDU 3915 Game(Nim博弈 && xor高斯消元)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3915 题目大意是给了n个堆,然后去掉一些堆,使得先手变成必败局势. 首先这是个Nim博弈,必败局势是所 ...

  4. ACM学习历程—UESTC 1219 Ba Gua Zhen(dfs && 独立回路 && xor高斯消元)

    题目链接:http://acm.uestc.edu.cn/#/problem/show/1219 题目大意是给了一张图,然后要求一个点通过路径回到这个点,使得xor和最大. 这是CCPC南阳站的一道题 ...

  5. ACM学习历程—BZOJ 2115 Xor(dfs && 独立回路 && xor高斯消元)

    题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=2115 题目大意是求一条从1到n的路径,使得路径xor和最大. 可以发现想枚举1到n的所有路 ...

  6. ACM学习历程—HDU 5536 Chip Factory(xor && 字典树)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5536 题目大意是给了一个序列,求(si+sj)^sk的最大值. 首先n有1000,暴力理论上是不行的. ...

  7. ACM学习历程—HDU 3949 XOR(xor高斯消元)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3949 题目大意是给n个数,然后随便取几个数求xor和,求第k小的.(重复不计算) 首先想把所有xor的 ...

  8. ACM学习历程—POJ 3764 The xor-longest Path(xor && 字典树 && 贪心)

    题目链接:http://poj.org/problem?id=3764 题目大意是在树上求一条路径,使得xor和最大. 由于是在树上,所以两个结点之间应有唯一路径. 而xor(u, v) = xor( ...

  9. ACM学习历程—SGU 275 To xor or not to xor(xor高斯消元)

    题目链接:http://acm.sgu.ru/problem.php?contest=0&problem=275 这是一道xor高斯消元. 题目大意是给了n个数,然后任取几个数,让他们xor和 ...

随机推荐

  1. CSS——伪类

    在a标签中运用最多: 1.a:link {color: #FF0000} /* 未访问的链接 */ 2.a:visited {color: #00FF00} /* 已访问的链接 */ 3.a:hove ...

  2. Prime算法生成最小生成树

    虽说是生成树,但我只将生成的边输出了.至于怎么用这些边来创建树...我不知道_(:з」∠)_ //Prime方法生成最小生成树 void GraphAdjacencyListWeight::Gener ...

  3. #1003 Max Sum

    http://acm.hdu.edu.cn/showproblem.php?pid=1003 给你一串数列,让你求出其中 一段连续的子数列 并且 该子数列所有数字之和最大,输出该子数列的和.起点与终点 ...

  4. 5.C#编写Redis访问类

    那么通过前面几篇博文,服务端的安装和配置应该没什么问题了,接下来的问题是如何通过代码来访问Redis. 这里我们使用的库为: StackExchange.Redis GitHub:https://gi ...

  5. R语言数据重塑

    使用cbind()函数连接多个向量来创建数据帧.此外,使用rbind()函数合并两个数据帧   使用merge()函数合并两个数据帧.数据帧必须具有相同的列名称,在其上进行合并   melt()拆分数 ...

  6. lsof command not found 解决

    有些centos 没有 lsof命令,需要安装 yum install lsof -y 使用: lsof -i:端口号

  7. SpringMVC知识点总结一(非注解方式的处理器与映射器配置方法)

    一.SpringMVC处理请求原理图(参见以前博客) 1.  用户发送请求至前端控制器DispatcherServlet 2.  DispatcherServlet收到请求调用HandlerMappi ...

  8. html 报告页面 v1.2 批量数据生成表格

    html 报告页面 v1.2 批量数据生成表格 上代码: <!DOCTYPE html> <html lang="en"> <head> < ...

  9. POJ 1088 滑雪(简单的记忆化dp)

    题目 又一道可以称之为dp的题目,虽然看了别人的代码,但是我的代码写的还是很挫,,,,,, //看了题解做的简单的记忆化dp #include<stdio.h> #include<a ...

  10. HDU1465 不容易系列之一&&HDU4535吉哥系列故事——礼尚往来

    HDU1465不容易系列之一 Problem Description 大家常常感慨,要做好一件事情真的不容易,确实,失败比成功容易多了!做好“一件”事情尚且不易,若想永远成功而总从不失败,那更是难上加 ...