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

📄 networkstructure.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 : networkStructure.java//package jaNet.backprop.gui;

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

public class networkStructure extends Dialog {
    //{{DECLARE_CONTROLS
    //}}
    public TextField 				editInputSize;
    public List 					listHiddenLayers;
    public Button 					buttonNewLayer;
    public Button 					buttonDelLayer;
    public TextField 				editHiddenSize;
    public TextField 				editHActFn;
    public Button 					buttonBrowseH;
    public TextField 				editOutputSize;
    public TextField 				editOActFn;
    public Button 					buttonBrowseO;
	public Button 					buttonOk;
	public Button 					buttonCancel;


	private static BPNLayer  		allLayers[];
	private static BPNWeightPack	allWeights[];
	
	private BPNdescriptor 			bpnDes;
	private BPN 					currentBPN;
	
	private boolean					imUp;

    public networkStructure(Frame parent, BPN bpn) {
	    super(parent, "Network Structure", false);
		Label label_1;
		Label label_2;
		Label label_3;
		Label label_4;
		Label label_5;
		Label label_6;
		Label label_8;
		Label label_9;
		Separator separatorIH;
		Separator separatorHO;
		Separator separatorOB;
		int   w=0, h=0;

		// im popped up !
		imUp = true;

		// set background color
        this.setBackground(Color.lightGray);

		// setup current BPN for future modifications
		currentBPN = bpn;

		// get BPNdescriptor from bpn
		bpnDes = bpn.getBPNdescriptor();

        // main panel
	    GridBagLayout grid = new GridBagLayout();
	    int rowHeights[] = {0,5,10,25,10,20,25,5,25,20,10,20,25,5,30,5};
		int columnWidths[] = {0,5,80,75,5,40,10,200,5,80,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};
		double columnWeights[] = {0.0,0.0,0.0,0.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0};
	    grid.rowHeights = rowHeights;
	    grid.columnWidths = columnWidths;
	    grid.rowWeights = rowWeights;
	    grid.columnWeights = columnWeights;

	    for(int i=0;i<rowHeights.length;i++) h += rowHeights[i];
	    for(int i=0;i<columnWidths.length;i++) w += columnWidths[i];
	    //{{INIT_CONTROLS
        resize(insets().left + insets().right + w+50, insets().top + insets().bottom + h +50);
        //}}

    	label_1 = new Label();
    	label_1.setText("Input Layer");
    	this.add(label_1);

    	label_4 = new Label();
    	label_4.setFont(new Font("Helvetica",Font.PLAIN , 12));
    	label_4.setText("size:");
    	this.add(label_4);

    	editInputSize = new TextField(8);
    	editInputSize.setText(""+bpnDes.layerDef[0]);
    	this.add(editInputSize);

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

    	label_2 = new Label();
    	label_2.setText("Hidden Layers");
    	this.add(label_2);

    	listHiddenLayers = new List(4,false);
    	for(int i=1;i<bpnDes.layerDef.length-1;i++)
			listHiddenLayers.addItem("Hidden "+ i);
		if(bpnDes.layerDef.length>2) listHiddenLayers.select(0);
    	this.add(listHiddenLayers);

    	buttonNewLayer = new Button();
    	buttonNewLayer.setLabel("New");
    	buttonNewLayer.disable();
    	this.add(buttonNewLayer);

    	buttonDelLayer = new Button();
    	buttonDelLayer.setLabel("Del");
     	buttonDelLayer.disable();
	   	this.add(buttonDelLayer);

    	label_9 = new Label();
    	label_9.setFont(new Font("Helvetica",Font.PLAIN , 12));
    	label_9.setText("Activating Function Class");
    	this.add(label_9);

    	label_5 = new Label();
    	label_5.setFont(new Font("Helvetica",Font.PLAIN , 12));
    	label_5.setText("size:");
    	this.add(label_5);

    	editHiddenSize = new TextField(8);
    	if(bpnDes.layerDef.length>2) editHiddenSize.setText(""+bpnDes.layerDef[1]);
    	this.add(editHiddenSize);

    	editHActFn = new TextField(20);
    	if(bpnDes.layerDef.length>2) editHActFn.setText(""+bpnDes.activationFnDef[0]);
    	this.add(editHActFn);

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

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

    	label_3 = new Label();
    	label_3.setText("Output Layer");
    	this.add(label_3);

    	label_8 = new Label();
    	label_8.setFont(new Font("Helvetica",Font.PLAIN , 12));
    	label_8.setText("Activating Function Class");
    	this.add(label_8);

    	label_6 = new Label();
    	label_6.setFont(new Font("Helvetica",Font.PLAIN , 12));
    	label_6.setText("size:");
    	this.add(label_6);

    	editOutputSize = new TextField(8);
		editOutputSize.setText(""+bpnDes.layerDef[bpnDes.layerDef.length-1]);
    	this.add(editOutputSize);

    	editOActFn = new TextField(20);
		editOActFn.setText(""+bpnDes.activationFnDef[bpnDes.activationFnDef.length-2]);
    	this.add(editOActFn);

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

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

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

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

    	reset(con);
    	con.gridx = 2;
    	con.gridy = 4;
    	con.gridwidth = 8;
    	con.anchor = GridBagConstraints.CENTER;
    	con.fill = GridBagConstraints.BOTH;
    	grid.setConstraints(separatorIH, con);

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

    	reset(con);
    	con.gridx = 2;
    	con.gridy = 6;
    	con.gridwidth = 2;
    	con.gridheight = 3;
    	con.anchor = GridBagConstraints.CENTER;
    	con.fill = GridBagConstraints.BOTH;
    	grid.setConstraints(listHiddenLayers, con);

    	reset(con);
    	con.gridx = 5;
    	con.gridy = 6;
    	con.anchor = GridBagConstraints.CENTER;
    	con.fill = GridBagConstraints.HORIZONTAL;
    	grid.setConstraints(buttonNewLayer, con);

    	reset(con);
    	con.gridx = 5;
    	con.gridy = 8;
    	con.anchor = GridBagConstraints.CENTER;
    	con.fill = GridBagConstraints.HORIZONTAL;
    	grid.setConstraints(buttonDelLayer, con);

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

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

    	reset(con);
    	con.gridx = 3;
    	con.gridy = 9;
    	con.anchor = GridBagConstraints.CENTER;
    	con.fill = GridBagConstraints.HORIZONTAL;
    	grid.setConstraints(editHiddenSize, con);

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

    	reset(con);
    	con.gridx = 9;
    	con.gridy = 9;
    	con.anchor = GridBagConstraints.CENTER;
    	con.fill = GridBagConstraints.NONE;
    	grid.setConstraints(buttonBrowseH, con);

    	reset(con);
    	con.gridx = 2;
    	con.gridy = 10;
    	con.gridwidth = 8;
    	con.anchor = GridBagConstraints.CENTER;
    	con.fill = GridBagConstraints.BOTH;
    	grid.setConstraints(separatorHO, con);

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

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

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

    	reset(con);
    	con.gridx = 3;
    	con.gridy = 12;
    	con.anchor = GridBagConstraints.CENTER;
    	con.fill = GridBagConstraints.HORIZONTAL;
    	grid.setConstraints(editOutputSize, con);

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

    	reset(con);
    	con.gridx = 9;
    	con.gridy = 12;
    	con.anchor = GridBagConstraints.CENTER;
    	con.fill = GridBagConstraints.NONE;
    	grid.setConstraints(buttonBrowseO, con);
    	
		reset(con);
		con.gridx = 2;
		con.gridy = 13;
		con.gridwidth = 8;
		con.anchor = GridBagConstraints.CENTER;
		con.fill = GridBagConstraints.BOTH;
		grid.setConstraints(separatorOB, con);

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

		reset(con);
		con.gridx = 9;
		con.gridy = 14;
		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() {
    	Rectangle bounds = getParent().bounds();
    	Rectangle abounds = bounds();

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

    	super.show();
    }

    public synchronized void wakeUp() {
    	notify();
    }
    
    public boolean getConsistence(){
		return imUp;
	}

    public boolean handleEvent(Event event) {
    	if (event.id == Event.ACTION_EVENT && event.target == buttonBrowseO) {
    	    	clickedButtonBrowseO();
    	    	return true;
    	}
    	else
    	if (event.id == Event.KEY_ACTION && event.target == editOActFn) {
    	    	keyActionEditOActFn(event);
    	    	return true;
    	}
    	else
    	if (event.id == Event.ACTION_EVENT && event.target == buttonBrowseH) {
    	    	clickedButtonBrowseH();
    	    	return true;
    	}
    	else
    	if (event.id == Event.KEY_ACTION && event.target == editHActFn) {
    	    	keyActionEditHActFn(event);
    	    	return true;
    	}
    	else
    	if (event.id == Event.ACTION_EVENT && event.target == buttonDelLayer) {
    	    	clickedButtonDelLayer();
    	    	return true;
    	}
    	else
    	if (event.id == Event.ACTION_EVENT && event.target == buttonNewLayer) {
    	    	clickedButtonNewLayer();
    	    	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.target == listHiddenLayers) {
				if(event.id == Event.LIST_SELECT)
					selChangeListHiddenLayers(((Integer)event.arg).intValue());
				if(event.id == Event.LIST_DESELECT)
					listHiddenLayers.select(((Integer)event.arg).intValue());
    	    	return true;
    	}
    	else

    	if (event.id == Event.WINDOW_DESTROY) {
    	    exit();
    	    return true;
    	}
    	return super.handleEvent(event);
    }
    
    public void exit(){
		imUp = false;
		hide();
		dispose();
    }

    public void selChangeListHiddenLayers(int pos) {
		editHiddenSize.setText(""+bpnDes.layerDef[1+pos]);
    	editHActFn.setText(""+bpnDes.activationFnDef[pos]);
    }
    public void clickedButtonNewLayer() {
        // to do: put event handler code here.
    }
    public void clickedButtonDelLayer() {
        // to do: put event handler code here.
    }
    public void keyActionEditHActFn(Event ev) {
        // to do: put event handler code here.
    }
    public void clickedButtonBrowseH() {
        // to do: put event handler code here.
    }
    public void keyActionEditOActFn(Event ev) {
        // to do: put event handler code here.
    }
    public void clickedButtonBrowseO() {
        // to do: put event handler code here.
    }
    public void clickedButtonOk() {
		exit();
    }
    public void clickedButtonCancel() {
		exit();
    }
        
    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 + -