📄 errorgraphdraw.java
字号:
//////////////////////////////////////////////////////////////////////////////////// // // Copyright (C) 1996 L. Patocchi & W.Gander//// This program is free software; you can redistribute it and/or modify it// under the terms of the GNU General Public License as published by the Free// Software Foundation; either version 2 of the License, or (at your option)// any later version.//// This program is distributed in the hope that it will be useful, but WITHOUT// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for// more details.//// You should have received a copy of the GNU General Public License along with// this program; if not, write to the Free Software Foundation, Inc., 675 Mass// Ave, Cambridge, MA 02139, USA.//// Contacts:// // Project Supervisor// W.Hett hew@info.isbiel.ch// // Authors// W.Gander gandw@info.isbiel.ch// L.Patocchi patol@info.isbiel.ch//// Documentation can be found at://// http://www.isbiel.ch/Projects/janet/index.html////////////////////////////////////////////////////////////////////////////////////////// File : errorGraphDraw.java//package jaNet.backprop.gui;import java.awt.*;import jaNet.backprop.*;public class errorGraphDraw extends Canvas{ public static final int block = 500; public int border = 10; public int leftBorder = 30; public int bottomBorder = 30; public int fontSize = 10; private double error[]; //private double lowerError[]; private int nElements; private double minVal; private double maxVal; private double minLim = 0.0; public errorGraphDraw(){ super(); clearElements(); } public void showElement(double err){ putElement(err); updateDraw(); } public void putElement(double err){ if(nElements == error.length){ double temp[] = error; error = new double[error.length + block]; System.arraycopy(temp,0,error,0,nElements); //temp = lowerError; //lowerError = new double[lowerError.length + block]; //System.arraycopy(temp,0,lowerError,0,nElements); } error[nElements] = err; //lowerError[nElements] = lowerr; if(maxVal < err)maxVal = err; //if(maxVal < lowerr) maxVal = lowerr; nElements++; } public void clearElements(){ nElements = 1; error = new double[block]; error[0] = 0.0; //lowerError = new double[block]; //lowerError[0] = 0.0; minVal = 0.0; maxVal = 1.1; } public void updateDraw(){ updateDraw(this.getGraphics()); } public void updateDraw(Graphics g){ int w = size().width; int h = size().height; int stepX = (w-border-leftBorder)/nElements; int graphH = h-border-bottomBorder; int graphY = border; int x,y; if(stepX == 0) clearElements(); // create an image to avoid flicks Image image = createImage(w, h); Graphics g2 = image.getGraphics(); g2.setFont(new Font("Helvetica",Font.PLAIN , fontSize)); g2.setColor(Color.black); g2.fillRect(0,0, w, h); g2.setColor(Color.white); g2.drawLine(leftBorder,border,leftBorder,h-(bottomBorder*3/4)); g2.drawLine(leftBorder*3/4,h-bottomBorder,w-border,h-bottomBorder); g2.setColor(Color.lightGray); x = 0; while((double)x < maxVal+0.5){ y = scale((double)x, minVal, maxVal,0,graphH); g2.drawLine(leftBorder-2,h-bottomBorder-y,w-border,h-bottomBorder-y); g2.drawString(""+x,2,h-bottomBorder-y+fontSize/2); x++; } if(minLim<maxVal){ g2.setColor(Color.red); y = scale(minLim, minVal, maxVal,0,graphH); g2.drawLine(leftBorder+1,h-bottomBorder-y,w-border,h-bottomBorder-y); g2.drawString(""+minLim,2,h-bottomBorder-y+fontSize/2); } g2.setColor(Color.yellow); for(int i=2; i<nElements; i++){ int y1 = scale(error[i-1], minVal, maxVal,0,0+graphH); int y2 = scale(error[i], minVal, maxVal,0,graphH); g2.drawLine(leftBorder+1+((i-1)*stepX),h-bottomBorder-y1,leftBorder+1+(i*stepX),h-bottomBorder-y2); } g.drawImage(image, 0,0, this); } public void paint(Graphics g){ updateDraw(g); } public void setMinLimit(double val){ minLim = val; updateDraw(); } public static int scale(double x, double xMin, double xMax, int toMin, int toMax){ return (int)((x-xMin)/(xMax-xMin)*(double)(toMax-toMin))+toMin; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -