📄 networkparameters.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 : networkParameters.java//package jaNet.backprop.gui;import java.awt.*;import jaNet.backprop.*;public class networkParameters extends Dialog { public TextField editLearningRate; public TextField editMomentum; public TextField editInitMin; public TextField editInitMax; public TextField editDomainMin; public TextField editDomainMax; private BPN currentBPN; private BPNgui dearParent; private double tempMomentum; private double tempLearningRate; private double tempMinInit; private double tempMaxInit; private double tempMinDomain; private double tempMaxDomain; private double origMinDomain; private double origMaxDomain; public Button buttonOk; public Button buttonCancel; public networkParameters(Frame parent) { super(parent, "BPN Learning Parameters", false); Label label_3; Label label_4; Label label_5; Label label_1; Label label_2; Label labelLearningRate; Label labelMomentum; Label labelDomainRange; Separator separator1; Separator separator2; Separator separator3; // this is my parent dearParent = (BPNgui) parent; this.setBackground(Color.lightGray); // main panel GridBagLayout grid = new GridBagLayout(); int rowHeights[] = {0, 5, 20,25, 5, 20,25, 5, 20,25,25, 5, 20,25,25, 5,30,5}; int columnWidths[] = {0,5,100,100,100,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,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}; grid.rowHeights = rowHeights; grid.columnWidths = columnWidths; grid.rowWeights = rowWeights; grid.columnWeights = columnWeights; labelLearningRate = new Label(); labelLearningRate.setFont(new Font("Helvetica",Font.PLAIN + Font.BOLD , 12)); labelLearningRate.setText("Learning Rate"); this.add(labelLearningRate); editLearningRate = new TextField(20); this.add(editLearningRate); labelMomentum = new Label(); labelMomentum.setFont(new Font("Helvetica",Font.PLAIN + Font.BOLD , 12)); labelMomentum.setText("Momentum"); this.add(labelMomentum); editMomentum = new TextField(20); this.add(editMomentum); buttonOk = new Button(); buttonOk.setLabel("OK"); this.add(buttonOk); buttonCancel = new Button(); buttonCancel.setLabel("Cancel"); this.add(buttonCancel); separator1 = new Separator(Separator.HORIZONTAL); separator1.perSide = 0; separator1.rise = Separator.IN; this.add(separator1); label_3 = new Label(); label_3.setFont(new Font("Helvetica",Font.PLAIN + Font.BOLD , 12)); label_3.setText("Init weights"); this.add(label_3); label_4 = new Label(); label_4.setText("min"); this.add(label_4); editInitMin = new TextField(20); this.add(editInitMin); label_5 = new Label(); label_5.setText("max"); this.add(label_5); editInitMax = new TextField(20); this.add(editInitMax); labelDomainRange = new Label(); labelDomainRange.setFont(new Font("Helvetica",Font.PLAIN + Font.BOLD , 12)); labelDomainRange.setText("Domain range for unit values"); this.add(labelDomainRange); editDomainMin = new TextField(20); this.add(editDomainMin); editDomainMax = new TextField(20); this.add(editDomainMax); label_1 = new Label(); label_1.setText("min"); this.add(label_1); label_2 = new Label(); label_2.setText("max"); this.add(label_2); separator2 = new Separator(Separator.HORIZONTAL); separator2.perSide = 0; separator2.rise = Separator.IN; this.add(separator2); separator3 = new Separator(Separator.HORIZONTAL); separator3.perSide = 0; separator3.rise = Separator.IN; this.add(separator3); // Geometry management GridBagConstraints con = new GridBagConstraints(); reset(con); con.gridx = 2; con.gridy = 2; con.gridwidth = 3; con.anchor = GridBagConstraints.CENTER; con.fill = GridBagConstraints.HORIZONTAL; grid.setConstraints(labelLearningRate, con); reset(con); con.gridx = 2; con.gridy = 3; con.gridwidth = 3; con.anchor = GridBagConstraints.CENTER; con.fill = GridBagConstraints.HORIZONTAL; grid.setConstraints(editLearningRate, con); reset(con); con.gridx = 2; con.gridy = 5; con.gridwidth = 3; con.anchor = GridBagConstraints.CENTER; con.fill = GridBagConstraints.HORIZONTAL; grid.setConstraints(labelMomentum, con); reset(con); con.gridx = 2; con.gridy = 6; con.gridwidth = 3; con.anchor = GridBagConstraints.CENTER; con.fill = GridBagConstraints.HORIZONTAL; grid.setConstraints(editMomentum, con); reset(con); con.gridx = 2; con.gridy = 7; con.gridwidth = 3; con.anchor = GridBagConstraints.CENTER; con.fill = GridBagConstraints.BOTH; grid.setConstraints(separator1, con); reset(con); con.gridx = 2; con.gridy = 8; con.gridwidth = 3; con.anchor = GridBagConstraints.CENTER; con.fill = GridBagConstraints.HORIZONTAL; grid.setConstraints(label_3, con); reset(con); con.gridx = 2; con.gridy = 9; con.anchor = GridBagConstraints.CENTER; con.fill = GridBagConstraints.HORIZONTAL; grid.setConstraints(label_4, con); reset(con); con.gridx = 3; con.gridy = 9; con.gridwidth = 2; con.anchor = GridBagConstraints.CENTER; con.fill = GridBagConstraints.HORIZONTAL; grid.setConstraints(editInitMin, con); reset(con); con.gridx = 2; con.gridy = 10; con.anchor = GridBagConstraints.CENTER; con.fill = GridBagConstraints.HORIZONTAL; grid.setConstraints(label_5, con); reset(con); con.gridx = 3; con.gridy = 10; con.gridwidth = 2; con.anchor = GridBagConstraints.CENTER; con.fill = GridBagConstraints.HORIZONTAL; grid.setConstraints(editInitMax, con); reset(con); con.gridx = 2; con.gridy = 11; con.gridwidth = 3; con.anchor = GridBagConstraints.CENTER; con.fill = GridBagConstraints.BOTH; grid.setConstraints(separator2, con); reset(con); con.gridx = 2; con.gridy = 12; con.gridwidth = 3; con.anchor = GridBagConstraints.CENTER; con.fill = GridBagConstraints.HORIZONTAL; grid.setConstraints(labelDomainRange, con); reset(con); con.gridx = 2; con.gridy = 13; con.anchor = GridBagConstraints.CENTER; con.fill = GridBagConstraints.HORIZONTAL; grid.setConstraints(label_1, con); reset(con); con.gridx = 3; con.gridy = 13; con.gridwidth = 2; con.anchor = GridBagConstraints.CENTER; con.fill = GridBagConstraints.HORIZONTAL; grid.setConstraints(editDomainMin, con); reset(con); con.gridx = 2; con.gridy = 14; con.anchor = GridBagConstraints.CENTER; con.fill = GridBagConstraints.HORIZONTAL; grid.setConstraints(label_2, con); reset(con); con.gridx = 3; con.gridy = 14; con.gridwidth = 2; con.anchor = GridBagConstraints.CENTER; con.fill = GridBagConstraints.HORIZONTAL; grid.setConstraints(editDomainMax, con); reset(con); con.gridx = 2; con.gridy = 15; con.gridwidth = 3; con.anchor = GridBagConstraints.CENTER; con.fill = GridBagConstraints.BOTH; grid.setConstraints(separator3, con); reset(con); con.gridx = 2; con.gridy = 16; con.anchor = GridBagConstraints.CENTER; con.fill = GridBagConstraints.HORIZONTAL; grid.setConstraints(buttonOk, con); reset(con); con.gridx = 4; con.gridy = 16; 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(BPN bpn, double minDomain, double maxDomain) { tempMomentum = bpn.getMomentum(); tempLearningRate = bpn.getLearningRate(); tempMinInit = bpn.getInitMin(); tempMaxInit = bpn.getInitMax(); tempMinDomain = minDomain; tempMaxDomain = maxDomain; origMinDomain = tempMinDomain; origMaxDomain = tempMaxDomain; editMomentum.setText(""+tempMomentum); editLearningRate.setText(""+tempLearningRate); editInitMin.setText(""+tempMinInit); editInitMax.setText(""+tempMaxInit); editDomainMin.setText(""+tempMinDomain); editDomainMax.setText(""+tempMaxDomain); currentBPN = bpn; move(50, 50); super.show(); } public boolean handleEvent(Event event) { if (event.id == Event.KEY_RELEASE && event.target == editMomentum) { String entry = editMomentum.getText(); double value = 0.0; try{ value = Double.valueOf(entry).doubleValue(); }catch(NumberFormatException nfe){ if(entry.compareTo("") != 0){ //dearParent.todo = ""+nfe; }else{ value = 0.0; } } tempMomentum = value; return super.handleEvent(event); }else if (event.id == Event.KEY_RELEASE && event.target == editLearningRate) { String entry = editLearningRate.getText(); double value = 0.0; try{ value = Double.valueOf(entry).doubleValue(); }catch(NumberFormatException nfe){ if(entry.compareTo("") != 0){ //dearParent.todo = ""+nfe; }else{ value = 0.0; } } tempLearningRate = value; return super.handleEvent(event); }else if (event.id == Event.KEY_RELEASE && event.target == editInitMin) { String entry = editInitMin.getText(); double value = 0.0; try{ value = Double.valueOf(entry).doubleValue(); }catch(NumberFormatException nfe){ if(entry.compareTo("") != 0){ //dearParent.todo = ""+nfe; }else{ value = 0.0; } } tempMinInit = value; return super.handleEvent(event); }else if (event.id == Event.KEY_RELEASE && event.target == editInitMax) { String entry = editInitMax.getText(); double value = 0.0; try{ value = Double.valueOf(entry).doubleValue(); }catch(NumberFormatException nfe){ if(entry.compareTo("") != 0){ //dearParent.todo = ""+nfe; }else{ value = 0.0; } } tempMaxInit = value; return super.handleEvent(event); }else if (event.id == Event.KEY_RELEASE && event.target == editDomainMin) { String entry = editDomainMin.getText(); double value = 0.0; try{ value = Double.valueOf(entry).doubleValue(); }catch(NumberFormatException nfe){ if(entry.compareTo("") != 0){ //dearParent.todo = ""+nfe; }else{ value = 0.0; } } tempMinDomain = value; return super.handleEvent(event); }else if (event.id == Event.KEY_RELEASE && event.target == editDomainMax) { String entry = editDomainMax.getText(); double value = 0.0; try{ value = Double.valueOf(entry).doubleValue(); }catch(NumberFormatException nfe){ if(entry.compareTo("") != 0){ //dearParent.todo = ""+nfe; }else{ value = 0.0; } } tempMaxDomain = value; return super.handleEvent(event); }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(tempLearningRate != currentBPN.getLearningRate()){ dearParent.putOnMonitor("Learning Rate changed to "+tempLearningRate+"\n"); currentBPN.setLearningRate(tempLearningRate); } if(tempMomentum != currentBPN.getMomentum()){ dearParent.putOnMonitor("Momentum changed to "+tempMomentum+"\n"); currentBPN.setMomentum(tempMomentum); } if(tempMinInit != currentBPN.getInitMin()){ dearParent.putOnMonitor("Init Min changed to "+tempMinInit+"\n"); currentBPN.setInitMin(tempMinInit); } if(tempMaxInit != currentBPN.getInitMax()){ dearParent.putOnMonitor("Init Max changed to "+tempMaxInit+"\n"); currentBPN.setInitMax(tempMaxInit); } if(tempMaxDomain != origMaxDomain){ dearParent.putOnMonitor("Domain Max range changed to "+tempMaxDomain+"\n"); dearParent.setDomainRange(tempMinDomain, tempMaxDomain); } if(tempMinDomain != origMinDomain){ dearParent.putOnMonitor("Domain Min range changed to "+tempMinDomain+"\n"); dearParent.setDomainRange(tempMinDomain, tempMaxDomain); } 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 + -