⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 layersettings.java

📁 JaNet: Java Neural Network Toolkit resume: A well documented toolkit for designing and training, a
💻 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 : layerSettings.java//package jaNet.backprop.gui;

import java.awt.*;
import jaNet.backprop.*;

public class layerSettings extends Dialog {

	public TextField 	entrySize;
	public TextField 	entryActFnClass;
	public Button 		buttonBrowse;
	public TextField 	entryBiasValue;
	public Button 		buttonOk;
	public Button 		buttonCancel;
	
	private BPNgui		dearParent = null;
	BPNdescriptor 		currentBPNd = null;
	int					currentLayer;

	int					tempSize;
	String				tempActFn;
	double				tempBias;
	
	private boolean		imVisible;

    public layerSettings(Frame parent) {
	    super(parent, "Layer Edit", false);
		Label label_1;
		Label label_2;
		Label label_3;
		Separator separator;

		dearParent = (BPNgui) parent;
		
		this.setBackground(Color.lightGray);

		// main panel
		GridBagLayout grid = new GridBagLayout();
		int rowHeights[] = {0,5,25,5,20,25,5,25,10,30,5};
		int columnWidths[] = {0,5,30,75,109,30,45,30,5};
		double rowWeights[] = {0.0,1.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,1.0};
		double columnWeights[] = {0.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,0.0};
		grid.rowHeights = rowHeights;
		grid.columnWidths = columnWidths;
		grid.rowWeights = rowWeights;
		grid.columnWeights = columnWeights;

		label_1 = new Label();
		label_1.setFont(new Font("Helvetica",Font.PLAIN + Font.BOLD , 12));
		label_1.setText("Size :");
		this.add(label_1);

		entrySize = new TextField(8);
		this.add(entrySize);

		label_2 = new Label();
		label_2.setText("Activation Fn Class :");
		this.add(label_2);

		entryActFnClass = new TextField(30);
		this.add(entryActFnClass);

		buttonBrowse = new Button();
		buttonBrowse.setLabel("Browse ...");
		this.add(buttonBrowse);

		label_3 = new Label();
		label_3.setText("Bias value :");
		this.add(label_3);

		entryBiasValue = new TextField(8);
		this.add(entryBiasValue);

		separator = new Separator(Separator.HORIZONTAL);
    	separator.perSide = 0;
    	separator.rise = Separator.IN;
		this.add(separator);

		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 = 2;
		con.anchor = GridBagConstraints.CENTER;
		con.fill = GridBagConstraints.HORIZONTAL;
		grid.setConstraints(label_1, con);

		reset(con);
		con.gridx = 4;
		con.gridy = 2;
		con.anchor = GridBagConstraints.CENTER;
		con.fill = GridBagConstraints.HORIZONTAL;
		grid.setConstraints(entrySize, con);

		reset(con);
		con.gridx = 2;
		con.gridy = 4;
		con.gridwidth = 3;
		con.anchor = GridBagConstraints.CENTER;
		con.fill = GridBagConstraints.HORIZONTAL;
		grid.setConstraints(label_2, con);

		reset(con);
		con.gridx = 2;
		con.gridy = 5;
		con.gridwidth = 3;
		con.anchor = GridBagConstraints.CENTER;
		con.fill = GridBagConstraints.HORIZONTAL;
		grid.setConstraints(entryActFnClass, con);

		reset(con);
		con.gridx = 5;
		con.gridy = 5;
		con.gridwidth = 3;
		con.anchor = GridBagConstraints.CENTER;
		con.fill = GridBagConstraints.HORIZONTAL;
		grid.setConstraints(buttonBrowse, con);

		reset(con);
		con.gridx = 2;
		con.gridy = 7;
		con.gridwidth = 2;
		con.anchor = GridBagConstraints.CENTER;
		con.fill = GridBagConstraints.HORIZONTAL;
		grid.setConstraints(label_3, con);

		reset(con);
		con.gridx = 4;
		con.gridy = 7;
		con.anchor = GridBagConstraints.CENTER;
		con.fill = GridBagConstraints.HORIZONTAL;
		grid.setConstraints(entryBiasValue, con);

		reset(con);
		con.gridx = 2;
		con.gridy = 8;
		con.gridwidth = 6;
		con.anchor = GridBagConstraints.CENTER;
		con.fill = GridBagConstraints.BOTH;
		grid.setConstraints(separator, 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.gridwidth = 2;
		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(BPNdescriptor bpnd, int layer, String title) {
    	Rectangle bounds = getParent().bounds();
    	Rectangle abounds = bounds();

    	move(bounds.x + (bounds.width - abounds.width)/ 2,
    	     bounds.y + (bounds.height - abounds.height)/2);

		setTitle(title);
		
		currentLayer 	= layer;
		currentBPNd		= bpnd;
		
		tempSize  = bpnd.layerDef[layer];
		entrySize.setText(""+tempSize);
		if(layer != 0){
			tempActFn = bpnd.activationFnDef[layer-1];
			tempBias   = bpnd.layerBias[layer][0];
			entryActFnClass.enable();
			buttonBrowse.enable();
			entryBiasValue.enable();
			entryActFnClass.setText(""+tempActFn);
			entryBiasValue.setText(""+tempBias);
		}else{
			entryActFnClass.setText("");
			entryBiasValue.setText("");
			entryActFnClass.disable();
			buttonBrowse.disable();
			entryBiasValue.disable();
		}

    	super.show();
    	imVisible = true;
    }
    
    public void hide(){
		imVisible = false;
		super.hide();
	}
	
	public boolean isVisible(){
		return imVisible;
	}

    public synchronized void wakeUp() {
    	notify();
    }

    public boolean handleEvent(Event event) {
    	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.KEY_RELEASE && event.target == entrySize) {
			String entry = entrySize.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;
				}
			}
			tempSize = value;
			return super.handleEvent(event);
    	}
    	else 
    	if (event.id == Event.KEY_RELEASE && event.target == entryActFnClass) {
			tempActFn = entryActFnClass.getText();
			return super.handleEvent(event);
    	}
    	else
    	if (event.id == Event.KEY_RELEASE && event.target == entryBiasValue) {
			String entry = entryBiasValue.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;
				}
			}
			tempBias = value;		
			return super.handleEvent(event);
    	}
    	else
    	if (event.id == Event.ACTION_EVENT && event.target == buttonBrowse) {
    	    	clickedButtonBrowse();
    	    	return true;
    	}
    	else
    	if (event.id == Event.WINDOW_DESTROY) {
    	    hide();
    	    return true;
    	}
    	return super.handleEvent(event);
    }
    public void clickedButtonBrowse() {
    }
    public void clickedButtonCancel() {
        hide();
    }
    public void clickedButtonOk() {
		if(currentLayer != 0){
			if(tempBias !=  currentBPNd.layerBias1[currentLayer]){
				dearParent.setBias(currentLayer, tempBias);
				dearParent.putOnMonitor("Bias values for layer "+currentLayer+" changed to "+tempBias+"\n");
			}
			if(tempActFn.compareTo(currentBPNd.activationFnDef[currentLayer-1]) != 0){
				dearParent.setActivationFnClass(currentLayer, tempActFn);
				dearParent.putOnMonitor("Activation Fn for layer "+currentLayer+" changed to "+tempActFn+"\n");
			}		
		}
		if(tempSize != currentBPNd.layerDef[currentLayer]){
			int newLayerDef[] 			= currentBPNd.layerDef;
			double newBias[]  			= currentBPNd.layerBias1;
			String newActFnDef[] 		= currentBPNd.activationFnDef;
			
			// update values for this layer
			newLayerDef[currentLayer] 	= tempSize;
			if(currentLayer != 0){
				newBias[currentLayer]		= tempBias;
				newActFnDef[currentLayer-1]	= tempActFn;
			}
			dearParent.createNewMainBPN(newLayerDef, newActFnDef, newBias);
		}
        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 + -