#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <math.h>
#include <conio.h>
#pragma hdrstop
void main()
{ int x[20] ;
int y[10];
int in[20]={1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1};
double v[20]={1.5,1.6,1.5,1.5,0.6,0.5,0.5,0.8,0.5,0.5,0.2,0.5,0.7,0.6,0.8,0.9,0.3,0.5,0.33,0.23};
double w[20]={0.1,0.01,0.2,0.02,0.3,0.001,0.2,0.002,0.003,0.1,0.2,0.4,0.004,0.2,0.022,0.033,0.022,0.04,0.05,0.05};
int save[20];
int i,j;
double limit1[20]={1.1,1.2,0.5,1.7,2.1,1.8,0.8,0.9,1.0,1.1,1.9,1.3,1.4,1.5,1.6,1.7,1.8,1.9,2.0,2.3};
double limit2[10]={1.1,1.4,1.3,0.7,0.6,0.9,0.1,1.3,1.4,1.33};
double S=0;
for(i=0;i<20;i++)
{S=S+w[i]*in[i];}
printf("%lf ",S);
printf("n");
for(j=0;j<20;j++)
{if(S>limit1[j])
x[j]=1;
else
x[j]=0;}
for(i=0;i<20;i++)
printf("%d ",x[i]);
printf("n");
for (i=0,j=0;i<10,j<20;i++,j++)
{if(v[j]*x[j]+v[j+1]*x[j+1]>limit2[i])
{y[i]=1;printf("y%d =%d ",i,y[i]); v[j]=v[j]+2;v[j+1]=v[j+1]+2;}
else {y[i]=0;printf("y%d=%d ",i,y[i]);} }
for(i=0;i<10;i++)
{ save[i]=y[i];}
printf("n");
for(j=0;j<20;j++)
for (i=0;i<10;i++)
{if(v[j]*x[j]+v[j+1]*x[j+1]>limit2[i])
{y[i]=1;v[j]=v[j]+2;v[j+1]=v[j+1]+2;}
else y[i]=0;}
for(i=0;i<10;i++)
{ save[i+10]=y[i];}
for(i=0;i<20;i++)
printf("%d ",save[i]);
printf("n");
S=0;
for(i=0;i<20;i++)
{S=S+w[i]*save[i];}
printf("%lf ",S);
printf("n");
for(j=0;j<20;j++)
{if(S>limit1[j])
x[j]=1;
else
x[j]=0;}
printf("x ");
for(i=0;i<20;i++)
printf(" %d ",x[i]);
printf("n");
for(j=0;j<20;j++)
for (i=0;i<10;i++)
{if(v[j]*x[j]+v[j+1]*x[j+1]>limit2[i])
{y[i]=1;v[j]=v[j]+1;v[j+1]=v[j+1]+1;}
else y[i]=0;}
for(i=0;i<10;i++)
{ save[i]=y[i];}
for(j=0;j<20;j++)
for (i=0;i<10;i++)
{if(v[j]*x[j]+v[j+1]*x[j+1]>limit2[i])
{y[i]=1;v[j]=v[j]+1;v[j+1]=v[j+1]+1;}
else y[i]=0;}
for(i=0;i<10;i++)
{ save[i+10]=y[i];}
for(i=0;i<20;i++)
printf("%d ",y[i]);
printf("n");
getch();}
пишу нейронную сеть вопрос по циклу
Код:
for (i=0,j=0;i<10,j<20;i++,j++)
{if(v[j]*x[j]+v[j+1]*x[j+1]>limit2[i])
{y[i]=1;printf("y%d =%d ",i,y[i]); v[j]=v[j]+2;v[j+1]=v[j+1]+2;}
else {y[i]=0;printf("y%d=%d ",i,y[i]);} }
{if(v[j]*x[j]+v[j+1]*x[j+1]>limit2[i])
{y[i]=1;printf("y%d =%d ",i,y[i]); v[j]=v[j]+2;v[j+1]=v[j+1]+2;}
else {y[i]=0;printf("y%d=%d ",i,y[i]);} }
полный код такой если кому интересно
Код:
насколько я понял нужно изменить шаг j на +2 вроде