多层前馈神经元网络(三)

2014-11-24 11:30:19 · 作者: · 浏览: 17
[1] = y;
label[i*m+j][0] = label[i*m+j][1] = label[i*m+j][2] = 0;
if ( y > 4.0*(x-0.5)*(x-0.5) ) {
label[i*m+j][0] = 1;
} else if ( x < 0.5 ) {
label[i*m+j][1] = 1;
} else {
label[i*m+j][2] = 1;
}
}
}
res[0] = data;
res[1] = label;
return res;
}
public static int calculateLabel(double x, double y) {
if ( y > 4.0*(x-0.5)*(x-0.5) ) {
return 0;
} else if ( x < 0.5 ) {
return 1;
} else {
return 2;
}
}
/**
* @param args
*/
public static void main(String[] args) {
int[] num = { 2, 3, 3 };
int m = 10, n = 3;
NeuroNetwork inst = new NeuroNetwork(num.length, num);
double[][][] trainData = generateData(m);
inst.train(trainData[0], trainData[1], 1000000, 0.001, 0.8);
int t=50, success = 0; www.2cto.com
double[][][] testData = generateData(t);
for ( int i=0; i
int res = inst.predict(testData[0][i], testData[1][i]);
int ans = calculateLabel(testData[0][i][0], testData[0][i][1]);
if ( res == ans ) {
success ++;
}
System.out.printf("<%f, %f> : %d %b%n",testData[0][i][0],testData[0][i][1],res,res==ans);
}
System.out.printf("Accuracy rate is %f%n", (success+0.0)/(t*t));
}
}