两层感知器网络实现异或问题
来源:互联网 发布:淘宝开发团队多少人 编辑:程序博客网 时间:2024/04/20 07:09
#include <stdio.h>#include <stdlib.h>//样例结构体struct sample{int A;int B;int Classs;};//f函数double f(double *weight,int A,int B){return weight[0]+weight[1]*A+weight[2]*B;}//感知器函数int sgn(double y){if (y>0.000000000001)return 1;elsereturn 0;}//步长函数double getStep(double weight,int t,int o,int x){double rate = 0.01;//学习速率return weight+rate*(t-o)*x;}//学习权值void learnWeightOfAandNonB(double *weight,struct sample *sampleColletion){int i,j;int maxTimes=500;int isRight=0;int result=0;for (i=0;i<maxTimes;++i){isRight=0;for (j=0;j<4;++j){result = sgn(f(weight,sampleColletion[j].A,sampleColletion[j].B));if (result == sampleColletion[j].Classs){isRight++;}else{weight[1] = getStep(weight[1],sampleColletion[j].Classs,result,sampleColletion[j].A);weight[2] = getStep(weight[2],sampleColletion[j].Classs,result,sampleColletion[j].B);}}if (isRight == 4){break;}}if (i == maxTimes){printf("超过最大迭代次数,程序结束------weight_AandNonB\n");exit(0);}}//学习权值void learnWeightOfAxorB(double *weight,double *weight_AandNonB,struct sample *sampleColletion){int i,j;int maxTimes=500;int isRight=0;int result=0;int tempA,tempB;for (i=0;i<maxTimes;++i){isRight=0;for (j=0;j<4;++j){tempA = sgn(f(weight_AandNonB,sampleColletion[j].A,sampleColletion[j].B));tempB = sgn(f(weight_AandNonB,sampleColletion[j].B,sampleColletion[j].A));result = sgn(f(weight,tempA,tempB));if (result == sampleColletion[j].Classs){isRight++;}else{weight[1] = getStep(weight[1],sampleColletion[j].Classs,result,tempA);weight[2] = getStep(weight[2],sampleColletion[j].Classs,result,tempB);}}if (isRight == 4){break;}}if (i == maxTimes){printf("超过最大迭代次数,程序结束------weight_AxorB\n");exit(0);}}int main(void){int i=0;double weight_AandNonB[3] ={-0.1,-0.1,-0.1};//初始化权值double weight_AxorB[3] ={-0.1,-0.1,-0.1};struct sample AandNonB[4]={{0,0,0},{0,1,0},{1,0,1},{1,1,0}};//初始化样例struct sample AxorB[4]={{0,0,0},{0,1,1},{1,0,1},{1,1,0}}; //输出原始权值printf("原始权值\nweight_AandNonB\n");for(i=0;i<3;++i){printf("%.2f\t",weight_AandNonB[i]);}printf("\nweight_AxorB\n");for(i=0;i<3;++i){printf("%.2f\t",weight_AxorB[i]);}printf("\n\n\n\n");learnWeightOfAandNonB(weight_AandNonB,AandNonB);learnWeightOfAxorB(weight_AxorB,weight_AandNonB,AxorB);//输出学习后权值printf("学习后权值\nweight_AandNonB\n");for(i=0;i<3;++i){printf("%.2f\t",weight_AandNonB[i]);}printf("\nweight_AxorB\n");for(i=0;i<3;++i){printf("%.2f\t",weight_AxorB[i]);}printf("\n\n\n");return 0;}
0 0
- 两层感知器网络实现异或问题
- Python 实现感知器模型、两层神经网络
- 单层感知器的局限性--异或问题
- 【摘要与笔记1】-单层感知器,两层神经网络与深度学习
- 路由器两层网络配置
- 单层感知器就能够实现 逻辑与运算、逻辑或运算和逻辑非运算,不能实现逻辑异或运算
- Python实现感知器
- 人工智能之感知器网络
- TensorFlow之多层感知器(MLP)
- 两层或以上的showModalDialog解决方法
- 网络层—网络层提供的两种服务
- Linux 网络层实现
- 多层感知机逼近异或逻辑
- 感知机不能表示“异或”
- 两层网络下,实现PC同时访问AC、AP操作方法。
- 网络层提供的两种服务
- 网络层提供的两种服务
- 基于BP网络解决异或问题
- 强大的iOS开发必备工具
- 2014广西教师资格面试试讲细节问题_面试试讲要注意什么问题?
- Hadoop到底能做什么?怎么用hadoop?
- 一切成功源于积累——20141206 强势上涨 每个小时 每个小时 紧紧贴着布林轨道上轨
- android jni与java之间数据传输时怎么转换
- 两层感知器网络实现异或问题
- Android之ListView原理学习与优化总结
- 算法重拾之路——动态规划基础
- android screen monitor抓取手机屏幕
- weka中文使用说明(四)
- IIS设置文件可下载,及.eps下载时变成.ps
- 12-6java面向对象之String类
- 沃兹尼亚克:乔布斯车库创业被神话
- 改变状态栏、导航栏颜色