多层神经网络Java代码800行
這個網絡只有不到800行可以實現多層多分類任務,3層網絡測試mnist數據集10分類,最高可以達到98.48%。這個程序包含13個子程序,有6個變量和8個本地路徑。只需確保電腦已經安裝java環境,并且8個本地的路徑都正確程序就可以運行。
代碼
使用說明
一.13個子程序
二.6個變量
三.8個路徑
四.標定數據
五.極限性能測試
package cpa;import java.awt.image.BufferedImage; import java.io.File; import java.io.FileWriter; import java.io.IOException; import java.text.DecimalFormat; import java.text.ParseException; import java.util.Random; import java.util.regex.Pattern; import javax.imageio.ImageIO;public class d3n {static double ret=0.1; //學習率 ***(3) 減小static double weix=100;//權重 ***(4) 減小 static double p;/************************************************************/static int cy=1; //層數 ***(7)//1*3-0=3 2*3-1=5 3*3-2=7 4*3-3=9 cy*3-(cy-1) //static int[] tra= {0,1,2,3,4,5,6,7,8,9}; //訓練集//static int[] fen= {0,1,2,3,4,5,6,7,8,9}; //測試集/*static int shuru=28*28;static int yc=300;static int shuchu=490;*/static int[] tra= {0,2}; //訓練集static int[] fen= {0,2}; //測試集***(2)static int shuru=9*9;static int yc=30; //***(5) 減小static int shuchu=49; /**********************************************************/ static double train[][][]=new double[tra.length][5000][shuru]; static double test[][][];/***********************************************************/static FileWriter fileWriter5 ; static int [][]nr;static int [][]mr;static int [][]kr;static double[] xr;static double[] y;static double w1r [][][];static double w2r [][][];static double wf1r [][][]; static double wf2r [][][]; static double [][]fr ;static double [][]ffr;static double [][]dr;static double [][]ddr;static int z=tra.length;public static void ini( ) throws IOException, ParseException { w1r =new double[cy][1][1];w2r =new double[cy][1][1];wf1r =new double[cy][1][1];wf2r =new double[cy][1][1];fr =new double[cy][1];ffr=new double[cy][1];dr =new double[cy][1];ddr=new double[cy][1];nr=new int[cy][1];mr=new int[cy][1];kr=new int[cy][1];nr[0][0]=shuru;mr[0][0]=yc;kr[0][0]=shuchu; for(int a=1 ;a<cy ;a++){nr[a][0]=shuchu;mr[a][0]=yc;kr[a][0]=shuchu; }kr[cy-1][0]=tra.length;for(int a=0 ;a<cy ;a++){w1r[a] =new double[nr[a][0]][mr[a][0]];w2r[a] =new double[mr[a][0]][kr[a][0]];wf1r[a] =new double[nr[a][0]][mr[a][0]];wf2r[a] =new double[mr[a][0]][kr[a][0]];fr[a] =new double[mr[a][0]];ffr[a]=new double[kr[a][0]];dr[a] =new double[mr[a][0]];ddr[a]=new double[kr[a][0]];}xr =new double[nr[0][0]];y=new double[kr[cy-1][0]]; }public static void ini1( ) throws IOException, ParseException { double []bcon=new double[shuru];for( int at=1 ;at<5000;at++) {for(int v=0;v<kr[cy-1][0];v++) { String str="d:/工業/10/"+tra[v]+"/"+at+".jpg"; //***A bcon=pix(str,shuru);train[v][at]=bcon; }}/***************************************************************/test=new double[fen.length][1][shuru];for(int a=0 ;a<fen.length ;a++){String sf="b"+fen[a];String path="d:/工業/10/"+sf+"/"; //***BFile file=new File(path);File[] tempList = file.listFiles();double []con2=new double[shuru];test[a]=new double[tempList.length][shuru];System.out.println( test.length+" "+test[a].length+" * " );for (int i = 0; i < tempList.length; i++) {if (tempList[i].isFile()) {String[] b=Pattern.compile(sf).split(tempList[i].toString());/*****************************************************************/String[] b1=Pattern.compile("\\.").split(b[1]);b1[0]=b1[0].substring(1, b1[0].length()); String name=tempList[i].toString();int id=Integer.parseInt(b1[0]);con2=pix(name,shuru);test[a][i]=con2;}}} } public static double[] pix( String a,int shuru ) throws IOException, ParseException {String openf=a;BufferedImage image=ImageIO.read(new File(openf)); int k=(int) Math.pow(shuru, 0.5);double [] x=new double[k*k];double[][] pixt=new double[k][k];int count=-1;for(int i=0;i<k;i++){ for(int j=0;j<k;j++){count++;int[] rgb = new int [3];int t=(int)(28/k);int pixel = image.getRGB(i*t , j*t);rgb[0] = (pixel & 0xff0000) >> 16;rgb[1] = (pixel & 0xff00) >> 8;rgb[2] = (pixel & 0xff);pixt[i][j]=0.299*rgb[0]+0.587*rgb[1]+0.114*rgb[2];//255是白色x[count]=(pixt[i][j]/255);}}return x;}public static double sig( double a) throws IOException, ParseException {double b=1/ (1+Math.pow(Math.E , (-1)*(a) ) ) ; return b;}public static void winicy ( int [][]n ,int [][]m, double [][][] twei ,double x ) throws IOException, ParseException {for(int c=0 ;c<cy ;c++){ for(int a=0 ;a<n[c][0] ;a++){for(int b=0 ;b<m[c][0] ;b++){Random rand1 =new Random();int ti1=rand1.nextInt(98)+1; int xx=1;if(ti1%2==0){xx=-1;}x=(double)x;twei[c][a][b]=xx*((double)ti1/x);}}}}public static double[] sigmfr( double[] xr , double[] y ,double w1r [][][],double w2r [][][],double wf1r [][][],double wf2r [][][],int [][]nr,int [][]mr, int [][]kr) throws IOException, ParseException{ for(int a=0 ;a<cy ;a++){for (int w = 0; w < mr[a][0]; w++) {double tem = 0;for (int h = 0; h < nr[a][0] ; h++) {if(a==0){tem = tem + (xr[h]) * w1r[a][h][w];}if(a>0){tem = tem + (ffr[a-1][h]) * w1r[a][h][w];}}fr[a][w] = sig(tem);}for (int w = 0; w < kr[a][0]; w++) {double tem = 0;for (int h = 0; h <mr[a][0]; h++) {tem = tem + fr[a][h] * w2r[a][h][w]; }ffr[a][w] = sig(tem); }} /************************************///正向到此結束for(int a=cy-1 ;a>-1 ;a--){ if(a<cy-1){for (int h = 0; h < nr[a+1][0]; h++) {double tem = 0;for (int w = 0; w < mr[a+1][0]; w++) {tem = tem + w1r[a+1][h][w] * ffr[a][h] * (1 - ffr[a][h]) * (dr[a+1][w]);}ddr[a][h] = tem;}}for(int a1=0 ;a1<mr[a][0] ;a1++){for(int b=0 ;b<kr[a][0];b++){if(a<cy-1){wf2r[a][a1][b]=wf2r[a][a1][b]+fr[a][a1]*( ddr[a][b]);}if(a==cy-1){wf2r[a][a1][b]=wf2r[a][a1][b]+fr[a][a1]*( ffr[a][b]-y[b]);} }}for (int h = 0; h < mr[a][0] ; h++) { double tem=0;for (int w = 0; w < kr[a][0]; w++) {if(a<cy-1){tem=tem+w2r[a][h][w] *fr[a][h]*(1-fr[a][h])*( ddr[a][w]) ; }if(a==cy-1){tem=tem+w2r[a][h][w] *fr[a][h]*(1-fr[a][h])*( ffr[a][w]-y[w] ) ; } }dr[a][h]=tem;}for (int h = 0; h < nr[a][0] ; h++) { for (int w = 0; w < mr[a][0]; w++) {if(a>0){wf1r[a][h][w]=wf1r[a][h][w]+ ffr[a-1][h]*dr[a][w] ;}if(a==0){wf1r[a][h][w]=wf1r[a][h][w]+ xr[h]*dr[a][w] ;}}}}/************************************************/double [] fan= new double[kr[cy-1][0]];for (int w = 0; w < kr[cy-1][0]; w++) {fan[w]=ffr[cy-1][w] ; //h} return fan; }public static double[] tsigmfr( double[] xr , double w1r [][][],double w2r [][][],double wf1r [][][],double wf2r [][][],int [][]nr,int [][]mr, int [][]kr) throws IOException, ParseException{ for(int a=0 ;a<cy ;a++){for (int w = 0; w < mr[a][0]; w++) {double tem = 0;for (int h = 0; h < nr[a][0] ; h++) {if(a==0){tem = tem + (xr[h]) * w1r[a][h][w];}if(a>0){tem = tem + (ffr[a-1][h]) * w1r[a][h][w];}}fr[a][w] = sig(tem);}for (int w = 0; w < kr[a][0]; w++) {double tem = 0;for (int h = 0; h <mr[a][0]; h++) {tem = tem + fr[a][h] * w2r[a][h][w]; }ffr[a][w] = sig(tem); //h}}double [] fan= new double[kr[cy-1][0]];for (int w = 0; w < kr[cy-1][0]; w++) {fan[w]=ffr[cy-1][w] ; } return fan; }public static String test1( int tcount ) throws IOException, ParseException { //ini( );//ini1( );//p=1e-6;DecimalFormat df = new DecimalFormat( "0.00000000"); winicy(nr, mr, w1r ,weix ); winicy(mr, kr, w2r ,weix ); int flag=0; int count = 0;double[] jud=new double[kr[cy-1][0]];double dr=0;int batch=tra.length ;for(int at=1 ;at<5000 ; at++ ){ for(int v=0;v<batch;v++){ count++; y=new double[kr[cy-1][0]];y[v]=1;xr=train[v][at];jud=sigmfr( xr , y , w1r , w2r , wf1r , wf2r , nr,mr, kr );if(count%1000==0) {System.out.println(df.format(jud[0])+" "+df.format(jud[1])+" * " + count+" "+df.format(Math.abs(jud[0] - y[0]))+" * "+df.format(Math.abs(jud[1] - y[1]))+" * "+v +" "+tcount+" "+p+" " +dr);}int pan=0;for(int c=0;c<batch;c++){if( Math.abs(jud[c]-y[c])<p ){pan++;}}if(pan==batch){flag=1; break; }}/******************************************/for(int a=0 ;a<cy ;a++){for (int a1=0; a1<mr[a][0]; a1++) {for (int b=0; b<kr[a][0]; b++) {w2r[a][a1][b]=w2r[a][a1][b]-ret*wf2r[a][a1][b]/z;}}for (int a2=0; a2<nr[a][0]; a2++) {for (int b=0; b<mr[a][0]; b++) {w1r[a][a2][b]=w1r[a][a2][b]-ret*wf1r[a][a2][b]/z; }}}wf1r =new double[cy][1][1];wf2r =new double[cy][1][1]; for(int a=0 ;a<cy ;a++){wf1r[a] =new double[nr[a][0]][mr[a][0]];wf2r[a] =new double[mr[a][0]][kr[a][0]];} if (flag==1 ){dr=itest( );System.out.println(dr+" 正確率 "+z+" "+ tcount+" "+p );break;}if(flag==0&&at==4999){at=1;}}String fan="";for (int a = 0; a < kr[cy-1][0]; a++) {fan=fan+jud[a]+",";}fan=fan+count+","+dr+","+p;return fan;}public static double itest( ) throws IOException, ParseException { double []x2=new double[shuru];double c1=0;double c2=0;double rc1=0;for(int count =0 ;count <kr[cy-1][0] ;count++){for ( int i=0; i < test[count].length; i++) {x2= test[ count][i];double [] jud= new double[kr[cy-1][0]];jud=tsigmfr (x2 , w1r ,w2r ,wf1r ,wf2r ,nr,mr, kr );DecimalFormat df = new DecimalFormat( "0.0000000"); double max=0.0;for(int a=0 ;a<kr[cy-1][0] ;a++){if(jud[a]>max){max=jud[a];}}int pan=0;for(int a=0 ;a<kr[cy-1][0] ;a++){if(jud[a]==max){pan=fen[a]; }}String show="0";if(pan==fen[count]){c1++;show="對的";}if(pan!=fen[count]){c2++;show="錯的";}rc1=c1/(c1+c2);// System.out.println(pan+" "+ c1+" "+c2+" || "+ " * "+df.format(jud[0])+" "+df.format(jud[1])+" "+rc1+" "+rc2);}}return rc1;}public static void t31( ) throws IOException, ParseException { String str[]= new String[200];for(int a=1 ; a<200 ; a++){long sysDate1 = System.currentTimeMillis();String r=test1( a );long sysDate2 = System.currentTimeMillis(); str[a]=r +","+ (sysDate2-sysDate1);//fileWriter5.write(r +","+ (sysDate2-sysDate1) +"\r\n");//fileWriter5.flush(); }for(int a=1 ; a<200 ; a++){fileWriter5.write(str[a] +"\r\n");fileWriter5.flush(); } }public static void pauto( ) throws IOException, ParseException { ini( );ini1( );fileWriter5=new FileWriter("d:/工業/f/naf.csv"); //***CString ins=read.conv.read( "d:/工業/f/naf3gd數據/3convda.csv"); //***Dins=ins.trim();String[] id =Pattern.compile(",").split(ins); for(int a= 0 ;a<34 ;a++) //***(1) 減小{if(id[a].contains("*")){String[] xx =Pattern.compile("\\*").split(id[a]);p=Double.parseDouble(xx[0].trim() )*Double.parseDouble(xx[1].trim() ); System.out.println(id[a]+" * "+xx[0]+" * "+xx[1]+" "+p );}if ( !(id[a].contains("*")) ){p=Double.parseDouble(id[a].trim() );}long sysDate1 = System.currentTimeMillis(); t31( );long sysDate2 = System.currentTimeMillis(); fileWriter5.write((sysDate2-sysDate1) +"\r\n");fileWriter5.flush(); }}public static void r31( ) throws IOException, ParseException { ini( );FileWriter fileWriter5=new FileWriter("d:/工業/f/naf3數據處理.csv"); //***EString ins= read.conv.read( "d:/工業/f/naf.csv"); //***Fins=ins.trim();String[] id =Pattern.compile(",").split(ins); System.out.println(id.length);int count=0;int bb=4;int k=kr[cy-1][0];double d[] =new double[k+bb];int num=0;int t=k+bb;double tmax=0;for(int a=0 ;a<id.length/t-1 ;a++){ if(!id[a*t+1].trim().isEmpty() && count<199){System.out.println(id[a*t]+" "+id[a*t+1]+" "+id[a*t+2] +" "+count );for(int b=0 ;b<k+bb; b++){d[b]=d[b]+Double.parseDouble(id[a*t+b].trim()); }if( Double.parseDouble((id[a*t+3]).trim())>tmax){tmax=Double.parseDouble((id[a*t+3]).trim());}count++;}String tem="";if(count==199){ for(int b=0 ;b<k+bb; b++){if(b!=3){tem=tem+d[b]/199+",";}if(b==3){tem=tem+tmax+",";}}System.out.println( tem +" ** " +a );count=0;for(int b=0 ;b<k+bb; b++){d[b]=0; }tmax=0;}if(id[(a+1)*t+1].trim().isEmpty() ){tem=tem+ id[(a+1)*t ]+"," ;System.out.println( tem +" ** " +a );fileWriter5.write( tem +"\r\n");fileWriter5.flush();tem="";}} }public static void r31ave( ) throws IOException, ParseException { ini( );FileWriter fileWriter5=new FileWriter("d:/工業/f/naf3數據處理.csv"); //***GString ins= read.conv.read( "d:/工業/f/naf.csv"); //***Hins=ins.trim();String[] id =Pattern.compile(",").split(ins); System.out.println(id.length);int count=0;int bb=4;int k=kr[cy-1][0];double d[] =new double[k+bb];int wz=4;int t=k+bb;double tmax=0;int pnum=199;for(int a=0 ;a<id.length/t-1 ;a++){ if(!id[a*t+1].trim().isEmpty() && count<pnum){for(int b=0 ;b<k+bb; b++){d[b]=d[b]+Double.parseDouble(id[a*t+b].trim()); }System.out.println(id[a*t]+" "+id[a*t+1]+" "+id[a*t+2] +" "+count +" "+tmax );count++;}String tem="";if(count==pnum){for(int b=0 ;b<k+bb; b++){// if(b!=3){tem=tem+d[b]/pnum+",";}}System.out.println( tem +" ** " +a );count=0;for(int b=0 ;b<k+bb; b++){d[b]=0; }tmax=0;}if(id[(a+1)*t+1].trim().isEmpty() ){tem=tem+ id[(a+1)*t ]+"," ;System.out.println( tem +" ** " +a );fileWriter5.write( tem +"\r\n");fileWriter5.flush();tem=""; }}}public static void main(String[] args) throws IOException, ParseException {pauto( );//r31( );//r31ave( );}}使用說明
一.13個子程序
1.Ini()
初始化權重數組w1r,w2r;初始化權重差值數組wf1r,wf2r;初始化中間數組fr,ffr;初始化差值數組dr,ddr;初始化各層節點數nr,mr,kr;初始化輸入數組xr;初始化輸出數組y
?
2.Ini1()
將訓練集讀入數組train[][][]中,將測試集讀入test[][][]中
?
3.pix( String a,int shuru )
讀出圖片各點的像素,a是圖片的路徑,shuru用來控制輸入圖片的大小,這個不是池化過程,比如shuru=9*9是每隔3個點取一個點,shuru=7*7就是每隔4個點取一個點,shuru=28*28就是mnist的原圖不變
?
4.sig( double a)
sigmoid函數
?
5.winicy ( int [][]n ,int [][]m, double [][][] twei ,double x )
為權重賦值
?
6.sigmfr( double[] xr ,?? double[]? y? , double w1r [][][],double w2r [][][],
???????? double wf1r [][][],double wf2r [][][],int [][]nr,int [][]mr, int [][]kr)
程序的最基本步驟,正向迭代和反向傳導
?
7.tsigmfr(? double[] xr ,?? double w1r [][][],double w2r [][][],
???????? double wf1r [][][],double wf2r [][][],int [][]nr,int [][]mr, int [][]kr )
??? 用于測試,只包括正向迭代
?
8.test1( int tcount? )
主調用程序if( Math.abs(jud[c]-y[c])<p )是用輸出函數與目標函數的差值作為迭代終止條件。tcount表示調用次數。
可以用test1( 0 )的方式單次調用test1.
神經網絡最為精髓的權重共享操作就是在這步完成,w2r[a][a1][b]=w2r[a][a1][b]-ret*wf2r[a][a1][b]/z;因為這一步,對應兩組輸入的權重得以完成耦合。
當用test1(0)的單次調用方式調用程序時,需要將ini()和 ini1()程序開啟,并給p(δ)賦值
?
9.itest(? )
測試程序
?
10.t31( )
這一步是可選操作,讓test1迭代199次用來統計平均值,并記錄每次迭代數據。
?
11.pauto( )
調用t31(),并完成對主參數p(δ)的賦值,可以在得到的表格中觀察到,在δ不變的前提下,迭代次數是離散分布而且是高度特征的。
?
12.r31( )
數據處理,用于計算最大值,啟動r31()程序前要把pauto()程序關掉,//pauto().否則數據會被重寫。
?
13.r31ave( )
數據處理,取平均值,由于空格問題需要手動在naf.csv的最后一行最后一列手動的輸入一個字符,可以是任意一個字符。
比如
| 6.97E-05 | 0.999946 | 4644 | 0.984095 | 9.00E-05 | 109 |
| 7.81E-05 | 0.99995 | 3862 | 0.982107 | 9.00E-05 | 94 |
| 16859 | ? | ? | ? | ? | * |
啟動r31ave()程序前要把pauto()程序關掉,//pauto().否則數據會被重寫。
?
二.6個變量
?
| δ | 訓練集差異 | 學習率 | 權重 | 隱藏層節點數 | 卷積核數量 | 網絡層數 | ? |
| 不變 | 增加 | 減小 | 增大 | 減小 | 有最優值 | 增加 | 網絡性能增加 |
| ? | ? | ? | ? | ? | ? | ? | ? |
| δ | 訓練集差異 | 學習率 | 權重 | 隱藏層節點數 | 卷積核數量 | 網絡層數 | ? |
| 減小 | 不變 | 不變 | 不變 | 不變 | 不變 | 不變 | 網絡性能增加 |
在這個網絡中只有7個變量可以影響網絡的分類性能,其中收斂標準δ,學習率,權重和網絡層數是等效的變量,比如增加網絡層數在一定范圍內可以等效的通過減小δ來實現。隱藏層節點數需要求出效率最優值,卷積核數量需要用實驗的辦法找到最優值。但即便在這兩個最優值不知道的情況下也可以通過減小等效參數δ的辦法來單向的提高網絡性能。將δ設為1e-6幾乎總可以保證網絡有一個不錯的性能。而不必估計與之對應的迭代次數,這是這個網絡調參最為便捷的地方。
1.δ(p)…594(行)
2.訓練集和測試集…33
3.學習率…15
4.權重…16
5.隱藏層節點數…36
7.層數…20
這個網絡沒有卷積核因此只有6個參數.,
?
這個網絡只能實現奇數行網絡比如3,5,7,9,11,13。其中3到11層網絡的性能是穩定可期待的,但是13層網絡的性能并不穩定。因此有效的層數只有5個。
節點數只能用1個循環節來賦值,比如當
int shuru=9*9;
int yc=30;???????
int shuchu=49;
3層是81*30*分類數
5層是81*30*49*30*分類數
具體調參過程請參考《調參總結》
?
三.8個路徑
A…126…訓練集所在位置
B…139…測試集所在位置
C…588…測試數據輸出位置
D…589…收斂標準δ(p)的數據
E…622…處理后的數據輸出位置
F…624…與C相同
G…704…與E相同
H…706…與C相同
這8個路徑必須更改為本地路徑,否則程序不能正常運行。
訓練集的10個數字分別裝到10個文件夾里面,
測試集的10個數字也是分別裝到10個文件夾里面,但是文件夾的命名方式是b0,b1…
String sf="b"+fen[a]; …138 也可以在第138行更改這個命名規則
?
四.標定數據
?
將參數設定為
static double ret=0.1; //學習率????? ***(3)? 減小
static double weix=100;//權重????????? ***(4)? 減小?
static int cy=1; //層數 ***(7)
static int[] tra= {0,2};? //訓練集
static int[] fen= {0,2};? //測試集***(2)
static int yc=30;????? ?//***(5)? 減小
for(int a= 0 ;a<34 ;a++)??? ????? //***(1) 減小
在大約13min內可以得到如下表格的數據,迭代次數和平均準確率和最大準確率應該是高度一致的,收斂時間與機器的性能有關,有可能不同。
| 81*30*2 | ? | ? | ? | ? | ? | ? | ? | ? |
| f2[0] | f2[1] | 迭代次數n | 平均準確率p-ave | δ | 耗時ms/次 | 耗時ms/199次 | 耗時 min/199 | 最大值p-max |
| 0.522324 | 0.466338 | 4.824121 | 0.527528 | 0.5 | 17.66834 | 3516 | 0.0586 | 0.804672 |
| 0.517923 | 0.488976 | 10.60302 | 0.559235 | 0.4 | 16.8995 | 3363 | 0.05605 | 0.818588 |
| 0.480915 | 0.527382 | 32.92462 | 0.685667 | 0.3 | 17.47739 | 3478 | 0.057967 | 0.917992 |
| 0.45703 | 0.546234 | 68.78894 | 0.797262 | 0.2 | 18 | 3582 | 0.0597 | 0.963718 |
| 0.507829 | 0.48911 | 155.2965 | 0.911606 | 0.1 | 19.26131 | 3833 | 0.063883 | 0.968688 |
| 0.318766 | 0.681292 | 492.8593 | 0.960129 | 0.01 | 25.47739 | 5086 | 0.084767 | 0.977634 |
| 0.065961 | 0.934053 | 1295.281 | 0.975169 | 0.001 | 40.68342 | 8096 | 0.134933 | 0.982604 |
| 0.050842 | 0.949179 | 1368.503 | 0.975409 | 9.00E-04 | 41.07035 | 8173 | 0.136217 | 0.983101 |
| 0.035695 | 0.964281 | 1426.709 | 0.976148 | 8.00E-04 | 42.35678 | 8429 | 0.140483 | 0.983101 |
| 0.030628 | 0.969389 | 1494.201 | 0.976238 | 7.00E-04 | 43.52764 | 8662 | 0.144367 | 0.985586 |
| 0.050617 | 0.94937 | 1667.829 | 0.976875 | 6.00E-04 | 46.60804 | 9275 | 0.154583 | 0.986581 |
| 0.010398 | 0.989601 | 1749.307 | 0.977357 | 5.00E-04 | 47.70854 | 9509 | 0.158483 | 0.986581 |
| 0.015357 | 0.984639 | 1875.171 | 0.977389 | 4.00E-04 | 50.34673 | 10019 | 0.166983 | 0.985089 |
| 0.005238 | 0.994751 | 2184.286 | 0.979382 | 3.00E-04 | 56.21106 | 11186 | 0.186433 | 0.986083 |
| 0.010197 | 0.989805 | 2582.925 | 0.97974 | 2.00E-04 | 63.26131 | 12589 | 0.209817 | 0.985089 |
| 0.01012 | 0.989879 | 3498.412 | 0.981728 | 1.00E-04 | 84.22111 | 16760 | 0.279333 | 0.987078 |
| 6.47E-05 | 0.999938 | 3645.025 | 0.981758 | 9.00E-05 | 84.13568 | 16743 | 0.27905 | 0.987078 |
| 0.005083 | 0.994919 | 3840.156 | 0.982055 | 8.00E-05 | 87.79899 | 17472 | 0.2912 | 0.987575 |
| 4.83E-05 | 0.999951 | 4077.126 | 0.982707 | 7.00E-05 | 92.61307 | 18445 | 0.307417 | 0.988072 |
| 0.005068 | 0.994932 | 4212.678 | 0.982557 | 6.00E-05 | 93.86432 | 18695 | 0.311583 | 0.987575 |
| 3.61E-05 | 0.999964 | 4589.568 | 0.982902 | 5.00E-05 | 101.6683 | 20232 | 0.3372 | 0.988072 |
| 0.005054 | 0.994945 | 5167.663 | 0.983454 | 4.00E-05 | 113.1709 | 22521 | 0.37535 | 0.988072 |
| 0.005047 | 0.994953 | 5821.111 | 0.983354 | 3.00E-05 | 125.2261 | 24935 | 0.415583 | 0.988569 |
| 1.49E-05 | 0.999985 | 6976.513 | 0.983821 | 2.00E-05 | 145.2412 | 28903 | 0.481717 | 0.987575 |
| 7.47E-06 | 0.999993 | 9615.879 | 0.983631 | 1.00E-05 | 193.8141 | 38569 | 0.642817 | 0.988569 |
| 6.46E-06 | 0.999993 | 9692.05 | 0.983736 | 9.00E-06 | 194.9598 | 38797 | 0.646617 | 0.989066 |
| 5.81E-06 | 0.999994 | 10012.85 | 0.984148 | 8.00E-06 | 201.0754 | 40014 | 0.6669 | 0.988569 |
| 5.07E-06 | 0.999995 | 10419.32 | 0.983961 | 7.00E-06 | 207.5176 | 41296 | 0.688267 | 0.988072 |
| 4.29E-06 | 0.999996 | 11089.11 | 0.9844 | 6.00E-06 | 222.4523 | 44268 | 0.7378 | 0.989066 |
| 3.58E-06 | 0.999996 | 12141.85 | 0.984138 | 5.00E-06 | 240.0804 | 47776 | 0.796267 | 0.988072 |
| 0.005028 | 0.994972 | 12888.37 | 0.984478 | 4.00E-06 | 254.397 | 50625 | 0.84375 | 0.989563 |
| 2.11E-06 | 0.999998 | 13944.59 | 0.9849 | 3.00E-06 | 275.7286 | 54870 | 0.9145 | 0.989066 |
| 1.50E-06 | 0.999999 | 16152.7 | 0.98498 | 2.00E-06 | 315.6784 | 62820 | 1.047 | 0.988569 |
| 7.15E-07 | 0.999999 | 20551.51 | 0.985886 | 1.00E-06 | 395.9397 | 78792 | 1.3132 | 0.99006 |
標定表格的第5列δ列就是程序第589行的路徑D的表格,可以將標定數據表格的其他列都刪除,將δ列置于第一列就是表格3convda.csv的內容。
?
五.極限性能測試
?
使用三層的網絡不用卷積核,用mnist數據集,10分類測試網絡的實用性能
?
參數設置方案是
static double ret=0.1; //學習率????? ***(3)? 減小
static double weix=1000;//權重????????? ***(4)? 減小 ?
static int cy=1; //層數 ***(7)
static int[] tra= {0,1,2,3,4,5,6,7,8,9};? //訓練集
static int[] fen= {0,1,2,3,4,5,6,7,8,9};? //測試集
static int n=784;
static int m=300;?? //***(5)? 減小
static int k=10;???
for(int a= 60 ;a<61 ;a++)?? ????? //***(1) 減小
?
| 迭代次數n | 準確率 | δ | 耗時ms/次 | 耗時ms/199次 |
| 6802425 | 0.984858 | 1.00E-09 | 11319060 | 188.651 |
| 6730004 | 0.984156 | 1.00E-09 | 14988660 | 249.811 |
| 6249665 | 0.984456 | 1.00E-09 | 9229857 | 153.831 |
| 6290676 | 0.983654 | 1.00E-09 | 11362439 | 189.374 |
| 5129416 | 0.982852 | 1.00E-09 | 7887187 | 131.4531 |
| 4464786 | 0.982952 | 1.00E-09 | 6659705 | 110.9951 |
| 5305764 | 0.983153 | 1.00E-09 | 7999463 | 133.3244 |
| 6067846 | 0.983053 | 1.00E-09 | 9387251 | 156.4542 |
| 5218186 | 0.982551 | 1.00E-09 | 8619121 | 143.652 |
| 5327884 | 0.982952 | 1.00E-09 | 7842863 | 130.7144 |
| 4909916 | 0.983153 | 1.00E-09 | 7628994 | 127.1499 |
| 5789196 | 0.982451 | 1.00E-09 | 8916027 | 148.6005 |
| 5156298 | 0.98225 | 1.00E-09 | 7897897 | 131.6316 |
?
共測試了13組,平均需要564萬次迭代,耗時大概153min,準確率最大值98.48%。
?
總結
以上是生活随笔為你收集整理的多层神经网络Java代码800行的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 调参总结
- 下一篇: 应用化学C4H12Si类四甲基硅结构的神