📄 stoprules.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 : stopRules.java//package jaNet.backprop.gui;
import java.awt.*;
public class stopRules extends Dialog {
CheckboxGroup groupStopRule;
Checkbox checkMaxSessions;
Checkbox checkMinError;
TextField editMaxSessions;
TextField editMinError;
Checkbox checkMaxSMinE;
Button buttonOk;
Button buttonCancel;
private BPNgui dearParent;
private int tempMode ;
private int tempMaxS ;
private double tempMinE ;
public stopRules(Frame parent) {
super(parent, "BPN Stop Rules", false);
Separator separator1;
// this is my parent
dearParent = (BPNgui) parent;
this.setBackground(Color.lightGray);
GridBagLayout grid = new GridBagLayout();
int rowHeights[] = {0,5,30,30,5,30,30,30,5,30,5};
int columnWidths[] = {0,5,20,100,5,100,20,5};
double rowWeights[] = {0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0};
double columnWeights[] = {0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0};
grid.rowHeights = rowHeights;
grid.columnWidths = columnWidths;
grid.rowWeights = rowWeights;
grid.columnWeights = columnWeights;
groupStopRule= new CheckboxGroup();
checkMaxSessions=new Checkbox("stop at max learning sessions",groupStopRule, true);
this.add(checkMaxSessions);
editMaxSessions = new TextField(20);
this.add(editMaxSessions);
checkMinError=new Checkbox("stop at minimal error",groupStopRule, false);
this.add(checkMinError);
editMinError = new TextField(20);
this.add(editMinError);
checkMaxSMinE=new Checkbox("both",groupStopRule, false);
checkMaxSMinE.setLabel("both");
this.add(checkMaxSMinE);
separator1 = new Separator(Separator.HORIZONTAL);
separator1.perSide = 0;
separator1.rise = Separator.IN;
this.add(separator1);
buttonOk = new Button();
buttonOk.setLabel("OK");
this.add(buttonOk);
buttonCancel = new Button();
buttonCancel.setLabel("Cancel");
this.add(buttonCancel);
// Geometry management
GridBagConstraints con = new GridBagConstraints();
reset(con);
con.gridx = 2;
con.gridy = 2;
con.gridwidth = 5;
con.anchor = GridBagConstraints.WEST;
con.fill = GridBagConstraints.NONE;
grid.setConstraints(checkMaxSessions, con);
reset(con);
con.gridx = 3;
con.gridy = 3;
con.gridwidth = 4;
con.anchor = GridBagConstraints.CENTER;
con.fill = GridBagConstraints.HORIZONTAL;
grid.setConstraints(editMaxSessions, con);
reset(con);
con.gridx = 2;
con.gridy = 5;
con.gridwidth = 5;
con.anchor = GridBagConstraints.WEST;
con.fill = GridBagConstraints.NONE;
grid.setConstraints(checkMinError, con);
reset(con);
con.gridx = 3;
con.gridy = 6;
con.gridwidth = 4;
con.anchor = GridBagConstraints.CENTER;
con.fill = GridBagConstraints.HORIZONTAL;
grid.setConstraints(editMinError, con);
reset(con);
con.gridx = 2;
con.gridy = 7;
con.gridwidth = 5;
con.anchor = GridBagConstraints.WEST;
con.fill = GridBagConstraints.NONE;
grid.setConstraints(checkMaxSMinE, con);
reset(con);
con.gridx = 2;
con.gridy = 8;
con.gridwidth = 5;
con.anchor = GridBagConstraints.CENTER;
con.fill = GridBagConstraints.BOTH;
grid.setConstraints(separator1, con);
reset(con);
con.gridx = 3;
con.gridy = 9;
con.anchor = GridBagConstraints.CENTER;
con.fill = GridBagConstraints.HORIZONTAL;
grid.setConstraints(buttonOk, con);
reset(con);
con.gridx = 5;
con.gridy = 9;
con.anchor = GridBagConstraints.CENTER;
con.fill = GridBagConstraints.HORIZONTAL;
grid.setConstraints(buttonCancel, con);
// Resize behavior management and parent heirarchy
setLayout(grid);
addNotify();
pack();
}
public synchronized void show(int mode, int maxS, double minE) {
Rectangle bounds = getParent().bounds();
Rectangle abounds = bounds();
tempMode = mode;
tempMaxS = maxS;
tempMinE = minE;
editMaxSessions.setText(""+maxS);
editMinError.setText(""+minE);
checkMaxSessions.setState(false);
checkMinError.setState(false);
checkMaxSMinE.setState(false);
switch(mode){
case BPNgui.MAXS:
checkMaxSessions.setState(true);
editMinError.disable();
editMaxSessions.enable();
break;
case BPNgui.MINE:
checkMinError.setState(true);
editMinError.enable();
editMaxSessions.disable();
break;
case BPNgui.BOTH:
checkMaxSMinE.setState(true);
editMinError.enable();
editMaxSessions.enable();
break;
}
move(bounds.x + (bounds.width - abounds.width)/ 2,
bounds.y + (bounds.height - abounds.height)/2);
super.show();
}
public synchronized void wakeUp() {
notify();
}
public synchronized boolean handleEvent(Event event) {
if (event.id == Event.ACTION_EVENT && event.target == checkMaxSMinE) {
checkMaxSMinE.setState(true);
editMinError.enable();
editMaxSessions.enable();
tempMode = BPNgui.BOTH;
return true;
}
else
if (event.id == Event.KEY_RELEASE && event.target == editMinError) {
String entry = editMinError.getText();
double value = 0.0;
try{
value = Double.valueOf(entry).doubleValue();
}catch(NumberFormatException nfe){
if(entry.compareTo("") != 0){
dearParent.todo = ""+nfe;
return super.handleEvent(event);
}else{
value = 0.0;
}
}
tempMinE = value;
return super.handleEvent(event);
}
else
if (event.id == Event.ACTION_EVENT && event.target == checkMinError) {
checkMinError.setState(true);
editMinError.enable();
editMaxSessions.disable();
tempMode = BPNgui.MINE;
return true;
}
else
if (event.id == Event.KEY_RELEASE && event.target == editMaxSessions) {
String entry = editMaxSessions.getText();
int value = 0;
try{
value = Integer.parseInt(entry);
}catch(NumberFormatException nfe){
if(entry.compareTo("") != 0){
dearParent.todo = ""+nfe;
return super.handleEvent(event);
}else{
value = 0;
}
}
tempMaxS = value;
return super.handleEvent(event);
}
else
if (event.id == Event.ACTION_EVENT && event.target == checkMaxSessions) {
checkMaxSessions.setState(true);
editMinError.disable();
editMaxSessions.enable();
tempMode = BPNgui.MAXS;
return true;
}
else
if (event.id == Event.ACTION_EVENT && event.target == buttonOk) {
clickedButtonOk();
return true;
}
else
if (event.id == Event.ACTION_EVENT && event.target == buttonCancel) {
clickedButtonCancel();
return true;
}
else
if (event.id == Event.WINDOW_DESTROY) {
hide();
return true;
}
return super.handleEvent(event);
}
public void clickedButtonOk() {
if(dearParent.maxSesStop != tempMaxS){
dearParent.setMaximalSessionStop(tempMaxS);
dearParent.putOnMonitor("Maximal Sessions changed to "+tempMaxS+"\n");
}
if(dearParent.minErrStop != tempMinE){
dearParent.setMinimalErrorStop(tempMinE);
dearParent.putOnMonitor("Minimal Error changed to "+tempMinE+"\n");
}
if(dearParent.curLearnStopMode != tempMode){
dearParent.curLearnStopMode = tempMode;
switch(tempMode){
case BPNgui.MAXS:
dearParent.putOnMonitor("Training will stop only after "+tempMaxS+" learning sessions\n");
break;
case BPNgui.MINE:
dearParent.putOnMonitor("Training will stop only when error reaches minimal value "+tempMinE+"\n");
break;
case BPNgui.BOTH:
dearParent.putOnMonitor("Training will stop after "+tempMaxS+" learning sessions or\nwhen error reaches minimal value "+tempMinE+"\n");
break;
}
}
this.hide();
}
public void clickedButtonCancel() {
this.hide();
}
private void reset(GridBagConstraints con) {
con.gridx = GridBagConstraints.RELATIVE;
con.gridy = GridBagConstraints.RELATIVE;
con.gridwidth = 1;
con.gridheight = 1;
con.weightx = 0;
con.weighty = 0;
con.anchor = GridBagConstraints.CENTER;
con.fill = GridBagConstraints.NONE;
con.insets = new Insets(0, 0, 0, 0);
con.ipadx = 0;
con.ipady = 0;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -