感知器算法(c语言版)(共3页).doc
精选优质文档-倾情为你奉上#include<stdio.h>#include<time.h>#define C 1void main()int i,j,k,N1,N2,x202,s3,d20,array204,w4;/s用于记录各点坐标乘积;array用于存放将输入点变换后的点printf("感知器算法(两类别问题)n");printf("请输入第1类坐标点数N1:");scanf("%d",&N1);printf("请输入第1类各点的坐标:n");for(i=0;i<N1;i+)/scanf("%d",&arrayi0);scanf("%d%d",&xi0,&xi1);printf("请输入第2类坐标点数N2:");scanf("%d",&N2);printf("请输入第2类各点的坐标:n");for(i=0;i<N2;i+)/scanf("%d",&arrayi0);scanf("%d%d",&xi+N10,&xi+N11);/*for(i=0;i<N1;i+)/打印输出输入的点坐标;printf("输入的第1类坐标点为");printf("%d,%d ",xi0,xi1);for(i=0;i<N2;i+)/打印输出输入的点坐标;printf("输入的第2类坐标点为");printf("%d,%d ",xi+N10,xi+N21);*/printf("输入的第1类点为:n");for(j=0;j<N1;j+)arrayj0=1;arrayj1=xj0;arrayj2=xj1;arrayj3=1;printf("(%d,%d,%d)n",arrayj1,arrayj2,arrayj3);printf("输入的第2类点为:n");for(j=N1;j<(N1+N2);j+)arrayj0=2;arrayj1=(-1)*xj0;arrayj2=(-1)*xj1;arrayj3=-1;printf("(%d,%d,%d)n",arrayj1,arrayj2,arrayj3);printf("取参数C为:%dn",C);printf("初始向量为:n");w0=1;w1=0;w2=0;w3=0;printf("%d,%d,%dn",w1,w2,w3);dofor(i=0;i<(N1+N2);i+)for(j=0;j<3;j+)sj=arrayij+1*wj+1;di=s0+s1+s2;if(di<=0)for(k=0;k<3;k+)wk+1=C*arrayik+1+wk+1;for(j=(N1+N2-1);j>=0;j-)k=(dj<=0)|(dj+1<=0);while(k);/while(d0<=0)|(d1<=0)|(d2<=0)|(d3<=0);printf("优化后的向量w=:(");for(k=0;k<3;k+)printf("%d ",wk+1);printf(")n");/程序缺点:不能动态分配内存大小,导致内存使用浪费;专心-专注-专业