X-Git-Url: http://git.osdn.net/view?a=blobdiff_plain;f=simplenn%2Fsrc%2Fmain%2Fjava%2FBack.java;fp=simplenn%2Fsrc%2Fmain%2Fjava%2FBack.java;h=0000000000000000000000000000000000000000;hb=112646822fccf62fd373ea76306fb74286cff14d;hp=a51126b84e581d69e9f736c05ad89dfa9b2201ba;hpb=79c1e2fca751fc18b4fd145327302b2490ed02f4;p=simplenn%2Frepo.git diff --git a/simplenn/src/main/java/Back.java b/simplenn/src/main/java/Back.java deleted file mode 100644 index a51126b..0000000 --- a/simplenn/src/main/java/Back.java +++ /dev/null @@ -1,510 +0,0 @@ -import java.applet.Applet; -import java.awt.*; -import java.awt.event.*; - -public class Back extends Applet implements MouseListener,MouseMotionListener,ActionListener{ - - Button button1,button2,button3,button4; - - int X0=10,X1=125; - int Y0=55,Y1=70,Y2=160,Y3=240,Y4=305; - - int RX0=30,RX1=60,RX2=210,RX3=260; - int RY0=225,RY1=240; - - int WIDTH=7; //入力データの幅 - int HEIGHT=11; //入力データの高さ - int INPUT=WIDTH*HEIGHT; //入力層の数(入力データ数) - int HIDDEN=16; //隠れ層の数 - int PATTERN=10; //パターンの種類 - int OUTPUT=PATTERN; //出力層の数(出力データ数) - int OUTER_CYCLES=200; //外部サイクル(一連のパターンの繰返し学習)の回数 - int INNER_CYCLES=200; //内部サイクル(同一パターンの繰返し学習)の回数 - float ALPHA=1.2f; //学習の加速係数 - float BETA=1.2f; //シグモイド曲線の傾斜 - - int[] sample_in=new int[INPUT]; //学習用入力 - int[] written_in=new int[INPUT]; //認識用手書き入力 - - float[][] weight_ih=new float[INPUT][HIDDEN]; //入力層と隠れ層の間の重み係数 - float[] thresh_h=new float[HIDDEN]; //隠れ層の閾値 - float[] hidden_out=new float[HIDDEN]; //隠れ層の出力 - - float[][] weight_ho=new float[HIDDEN][OUTPUT]; //隠れ層と出力層の間の重み係数 - float[] thresh_o=new float[OUTPUT]; //出力層の閾値 - float[] recog_out=new float[OUTPUT]; //認識出力(出力層の出力) - - int[] teach=new int[PATTERN]; //教師信号 - - - - - - boolean learning_flag; //「学習モード」フラグ - - //学習用入力データの基となるパターン - int[][] sample_array={{0,0,1,1,1,0,0, //'0' - 0,1,0,0,0,1,0, - 1,0,0,0,0,0,1, - 1,0,0,0,0,0,1, - 1,0,0,0,0,0,1, - 1,0,0,0,0,0,1, - 1,0,0,0,0,0,1, - 1,0,0,0,0,0,1, - 1,0,0,0,0,0,1, - 0,1,0,0,0,1,0, - 0,0,1,1,1,0,0}, - - {0,0,0,1,0,0,0, //'1' - 0,0,0,1,0,0,0, - 0,0,0,1,0,0,0, - 0,0,0,1,0,0,0, - 0,0,0,1,0,0,0, - 0,0,0,1,0,0,0, - 0,0,0,1,0,0,0, - 0,0,0,1,0,0,0, - 0,0,0,1,0,0,0, - 0,0,0,1,0,0,0, - 0,0,0,1,0,0,0}, - - {0,0,1,1,1,0,0, //'2' - 0,1,0,0,0,1,0, - 1,0,0,0,0,0,1, - 0,0,0,0,0,0,1, - 0,0,0,0,0,0,1, - 0,0,0,0,0,1,0, - 0,0,0,0,1,0,0, - 0,0,0,1,0,0,0, - 0,0,1,0,0,0,0, - 0,1,0,0,0,0,0, - 1,1,1,1,1,1,1}, - - {0,0,1,1,1,0,0, //'3' - 0,1,0,0,0,1,0, - 1,0,0,0,0,0,1, - 0,0,0,0,0,1,0, - 0,0,0,0,1,0,0, - 0,0,0,0,0,1,0, - 0,0,0,0,0,0,1, - 0,0,0,0,0,0,1, - 1,0,0,0,0,0,1, - 0,1,0,0,0,1,0, - 0,0,1,1,1,0,0}, - - {0,0,0,0,1,0,0, //'4' - 0,0,0,1,1,0,0, - 0,0,1,0,1,0,0, - 0,0,1,0,1,0,0, - 0,1,0,0,1,0,0, - 0,1,0,0,1,0,0, - 1,0,0,0,1,0,0, - 1,1,1,1,1,1,1, - 0,0,0,0,1,0,0, - 0,0,0,0,1,0,0, - 0,0,0,0,1,0,0}, - - {1,1,1,1,1,1,1, //'5' - 1,0,0,0,0,0,0, - 1,0,0,0,0,0,0, - 1,0,0,0,0,0,0, - 1,1,1,1,1,0,0, - 0,0,0,0,0,1,0, - 0,0,0,0,0,0,1, - 0,0,0,0,0,0,1, - 0,0,0,0,0,0,1, - 1,0,0,0,0,1,0, - 0,1,1,1,1,1,0}, - - {0,0,0,0,1,1,0, //'6' - 0,0,0,1,0,0,0, - 0,0,1,0,0,0,0, - 0,1,0,0,0,0,0, - 0,1,0,0,0,0,0, - 1,0,0,0,0,0,0, - 1,0,1,1,1,0,0, - 1,1,0,0,0,1,0, - 1,0,0,0,0,0,1, - 0,1,0,0,0,1,0, - 0,0,1,1,1,0,0}, - - {1,1,1,1,1,1,1, //'7' - 0,0,0,0,0,0,1, - 0,0,0,0,0,0,1, - 0,0,0,0,0,1,0, - 0,0,0,0,0,1,0, - 0,0,0,0,1,0,0, - 0,0,0,0,1,0,0, - 0,0,0,1,0,0,0, - 0,0,0,1,0,0,0, - 0,0,1,0,0,0,0, - 0,0,1,0,0,0,0}, - - {0,0,1,1,1,0,0, //'8' - 0,1,0,0,0,1,0, - 1,0,0,0,0,0,1, - 1,0,0,0,0,0,1, - 0,1,0,0,0,1,0, - 0,0,1,1,1,0,0, - 0,1,0,0,0,1,0, - 1,0,0,0,0,0,1, - 1,0,0,0,0,0,1, - 1,0,0,0,0,0,1, - 0,1,1,1,1,1,0}, - - {0,1,1,1,1,1,0, //'9' - 1,0,0,0,0,0,1, - 1,0,0,0,0,0,1, - 1,0,0,0,0,0,1, - 0,1,1,1,1,1,1, - 0,0,0,0,0,0,1, - 0,0,0,0,0,0,1, - 0,0,0,0,0,0,1, - 0,0,0,0,0,0,1, - 1,0,0,0,0,0,1, - 0,1,1,1,1,1,0}}; - - int[][] teach_array=new int[PATTERN][OUTPUT]; //パターンと出力すべき教師信号の比較表 - - int x_new,y_new,x_old,y_old; //手書き文字入力用座標 - - - public void init(){ - - setBackground(Color.gray); - - //ボタンの設定 - add(button1=new Button(" 再学習 ")); - add(button2=new Button(" 学習終了 ")); - add(button3=new Button("入力クリヤ")); - add(button4=new Button(" 認 識 ")); - button1.addActionListener(this); - button2.addActionListener(this); - button3.addActionListener(this); - button4.addActionListener(this); - - //マウスの設定 - addMouseListener(this); - addMouseMotionListener(this); - - //教師信号の設定 - for(int q=0;q=RX1 && x<=RX1+WIDTH*10 && y>=RY1 && y<=RY1+HEIGHT*10){ - x_old=me.getX(); - y_old=me.getY(); - written_in[(y_old-RY1)/10*WIDTH+(x_old-RX1)/10]=1; - } - } - - public void mouseClicked(MouseEvent me){} - public void mouseEntered(MouseEvent me){} - public void mouseExited(MouseEvent me){} - public void mouseReleased(MouseEvent me){} - - public void mouseDragged(MouseEvent me){ - int x=me.getX(); - int y=me.getY(); - if(!learning_flag && x>=RX1 && x<=RX1+WIDTH*10 && y>=RY1 && y<=RY1+HEIGHT*10){ - Graphics g=getGraphics(); - x_new=me.getX(); - y_new=me.getY(); - g.drawLine(x_old,y_old,x_new,y_new); - x_old=x_new; - y_old=y_new; - written_in[(y_old-RY1)/10*WIDTH+(x_old-RX1)/10]=1; - } - - } - - public void mouseMoved(MouseEvent me){} - - - - //---------- 起動時およびrepaint()で呼び出されるメソッド ---------- - - public void paint(Graphics g){ - - int i,j,k,p,q,r,x; - - String string; - - float outer_error; //外部サイクルエラー累計 - float inner_error; //内部サイクルエラー累計 - float temp_error; //隠れ層の誤差の累計 - - //学習モードの背景 - if(learning_flag){ - g.setColor(new Color(255,255,192)); - g.fillRect(5,35,590,460); - g.setColor(Color.black); - g.drawString("学習モード",500,55); - } - - //認識モードの背景 - else{ - g.setColor(new Color(192,255,255)); - g.fillRect(5,35,590,460); - g.setColor(Color.black); - g.drawString("認識モード",500,55); - } - - //学習用パターンの表示 - g.drawString("使用している学習用パターン",X0,Y0); - for(q=0;q0.99){ //99% より大は、赤で YES と表示 - g.setColor(Color.red); - string="YES"; - } - else if(recog_out[k]<0.01){ // 1% より小は、青で NO と表示 - g.setColor(Color.blue); - string="NO "; - } - else{ // 1% 以上 99% 以下は、黒で ? と表示 - g.setColor(Color.black); - string=" ? "; - } - g.drawString(string,X1+10+45*k,Y4+20*q); - } - - } - } - - //------------------------------------------------------------------- - //--------------------------- 認識モード ---------------------------- - //------------------------------------------------------------------- - else{ - g.setColor(Color.black); - g.drawString("マウスで数字を描いて下さい",RX0,RY0); - g.drawRect(RX1-1,RY1-1,WIDTH*10+2,HEIGHT*10+2); //外枠 - g.setColor(Color.gray); - for(j=1;j