建立网络
package net;
import java.io.Serializable;
import java.util.Random;
import tool.gongju;
public class newnet implements Serializable{
private net[] net;
private double[][] in;
private double[][][] jieguo;
public newnet() {
net=new net[29];
for(int i=0;i<29;i++) {
net[i]=new net();
}
}
public void setin(double[][] x) {
in=new double[x.length][x[0].length];
for(int i=0;i<x.length;i++)
for(int j=0;j<x[0].length;j++)
in[i][j]=x[i][j];
}
public void setjieguo(double[][][] x) {
jieguo=new double[x.length][x[0].length][x[0][0].length];
for(int i=0;i<x.length;i++)
for(int j=0;j<x[0].length;j++)
for(int k=0;k<x[0][0].length;k++)
jieguo[i][j][k]=x[i][j][k];
}
public int output(){
int z=-1;
double max=0;
for(int i=0;i<29;i++) {
double out=net[i].output(in)[0][0];
if(out>max) {
max=out;
z=i;
}
}
return z;
}
public void bp() {
bp(0);
}
public void bp(int ii) {
for(int i=0;i<29;i++) {
net[i].bp(in, jieguo[i], ii);
}
if(ii==1)
System.out.println();
}
}
package net;
import java.io.Serializable;
import java.util.Random;
import tool.gongju;
public class net implements Serializable{
private ceng[] ceng;
public net() {
ceng=new ceng[5];
ceng[0]=new ceng(784,392);
ceng[1]=new ceng(392,196);
ceng[2]=new ceng(196,98);
ceng[3]=new ceng(98,49);
ceng[4]=new ceng(49,1);
}
public double[][] output(double[][] x){
double[][] z;
ceng[0].setL(x);
z=ceng[0].getShuchu0();
ceng[1].setL(z);
z=ceng[1].getShuchu0();
ceng[2].setL(z);
z=ceng[2].getShuchu0();
ceng[3].setL(z);
z=ceng[3].getShuchu0();
ceng[4].setL(z);
z=ceng[4].getShuchu0();
return z;
}
public void bp(double[][]x,double[][] y) {
bp(x,y,0);
}
public void bp(double[][]x,double[][] y,int i) {
double[][] z=gongju.fushu(output(x));
double[][] l4_error=gongju.juzhenjianfa(y,z);
if(i==1)
gongju.show(l4_error[0]);
double[][] l3_delta=ceng[4].getdelta(l4_error);
ceng[4].back(l4_error);
double[][] l2_delta=ceng[3].getdelta(l3_delta);
ceng[3].back(l3_delta);
double[][] l1_delta=ceng[2].getdelta(l2_delta);
ceng[2].back(l2_delta);
double[][] l0_delta=ceng[1].getdelta(l1_delta);
ceng[1].back(l1_delta);
ceng[0].back(l0_delta);
}
}