01 安装 Visual studio 2017.

不具备安装这个的话,也可安装,Microsoft Visual Studio Express (or equivalent)

02 创建 C# 的 控制台程序

03 添加 Accord 库

 03  让机器学习『异或』的逻辑

不需要在代码里写出来异或的程序逻辑,告诉机器 异或的输入和输出(其实就是一个监督学习,训练的过程),机器就自己学习会了异或逻辑。

上代码:

 using System;
using Accord.Controls;
using Accord.MachineLearning.VectorMachines;
using Accord.MachineLearning.VectorMachines.Learning;
using Accord.Math;
using Accord.Statistics.Kernels;
using Accord.Math.Optimization.Losses;
using Accord.Statistics; namespace SampleApplication1
{
class Program
{
[MTAThread]
static void Main(string[] args)
{
double[][] inputs =
{
/* 1.*/ new double[] { , },
/* 2.*/ new double[] { , },
/* 3.*/ new double[] { , },
/* 4.*/ new double[] { , },
}; int[] outputs =
{
/* 1. 0 xor 0 = 0: */ ,
/* 2. 1 xor 0 = 1: */ ,
/* 3. 0 xor 1 = 1: */ ,
/* 4. 1 xor 1 = 0: */ ,
}; // Create the learning algorithm with the chosen kernel
var smo = new SequentialMinimalOptimization<Gaussian>()
{
Complexity = // Create a hard-margin SVM
}; // Use the algorithm to learn the svm
var svm = smo.Learn(inputs, outputs); // Compute the machine's answers for the given inputs
bool[] prediction = svm.Decide(inputs); // Compute the classification error between the expected
// values and the values actually predicted by the machine:
double error = new AccuracyLoss(outputs).Loss(prediction); Console.WriteLine("Error: " + error); // Show results on screen
ScatterplotBox.Show("Training data", inputs, outputs);
ScatterplotBox.Show("SVM results", inputs, prediction.ToZeroOne()); Console.ReadKey();
}
}
}

04  运行搞定

 本文的源代码:

链接:https://pan.baidu.com/s/1gfrQyPX

密码: 关注微信输入关键字: 异或

最新文章

  1. JS高级程序设计2nd部分知识要点6
  2. android 开发 drawerlayout出现退不回去的情况
  3. 使用命令行设置svn忽略列表
  4. Windows Message Codes
  5. 【转】android Camera 中添加一种场景模式
  6. (转)CentOS下用yum搭建LNMP服务器
  7. &lt;php&gt;对文件的目录、属性、路径的操作
  8. SE 2014年4月18日
  9. 移动端 微信 网易 触屏滑动回弹菜单(css版)
  10. 利用缓存、Timer间隔时间发送微信的实例,很有用的例子
  11. 修改MYSQL的默认连接时长
  12. 利用mybatis-generator自动生成数据持久化的代码
  13. ArcEngine小问题解决
  14. react 16 ssr的重构踩坑
  15. flask基础---第三篇
  16. CentOS7怎么更换yum源
  17. Ubuntu 安装 hadoop
  18. svn加锁设置
  19. java web项目中打开资源文件中文乱码
  20. DP——P2300 合并神犇

热门文章

  1. TFS在项目中Devops落地进程(上)
  2. JavaScript 面试中常见算法问题详解
  3. mybatis取数据库为null的字段
  4. 快速自检电脑是否被黑客入侵过(Windows版)
  5. maven---settings.xml配置
  6. 让ffmpeg支持10bit编码
  7. [转载] Hive与HBase的联系与区别
  8. riot.js教程【六】循环、HTML元素标签
  9. web-php绕过
  10. php将html转为图片