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

📄 layer.java

📁 利用Java实现的神经网络工具箱
💻 JAVA
字号:
/* * Layer.java 	1.0 09 Jun 2004 * * NeuralNetworkToolkit * Copyright (C) 2004 Universidade de Bras�lia * * This file is part of NeuralNetworkToolkit. * * NeuralNetworkToolkit 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. * * NeuralNetworkToolkit 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 NeuralNetworkToolkit; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 - USA. */package neuralnetworktoolkit.neuralnetwork;import java.io.Serializable;import java.util.Vector;import neuralnetworktoolkit.activationfunctions.*;/** * Class that implements some basic features of a layer. *   * @version 1.0 09 Jun 2004 *  * @author <a href="mailto:hugoiver@yahoo.com.br">Hugo Iver V. Gon�alves</a> * @author <a href="mailto:rodbra@pop.com.br">Rodrigo C. M. Coimbra</a> */public class Layer implements ILayer, Serializable {	/** Indicates that layer is normalizer or not. */	private int isNormalizer;	/** Indicates that layer is dynamic or static. */	private int isDynamic;	/** Stores neurons dynamically. */	private Vector dynamicNeurons;	/** Stores neurons statically. */	private INeuron[] staticNeurons;	/** Stores weights dynamically. */	private Vector dynamicWeights;	/** Stores weights statically. */	private Weights[] staticWeights;	/** Layer size. */	private int layerSize = 0;	/** 	 * Layer activation function (all layer neurons have the same	 * activation function, default).	 */	private IActivationFunction activationFunction;	/**	 * Creates a new layer with the specified attributes.	 * 	 * @param lastLayerSize      Preceding layer size.	 * @param size               Layer size.	 * @param normalizer         Indicates that layer is normalizer or not.	 * @param dynamic            Indicates that layer is dynamic or static.	 * @param activationFunction Layer activation function.	 */	public Layer(int lastLayerSize,				 int size,				 int dynamic,				 IActivationFunction activationFunction) {		this.isDynamic = dynamic;		this.activationFunction = activationFunction;		this.layerSize = size;		// Outer switch				// 1st Inner switch			switch (isDynamic) {			case NeuralNetwork.NOT_DYNAMIC :			{				staticNeurons = new INeuron[size];				staticWeights = new Weights[size];				for (int i = 0; i < size; i++) {					staticNeurons[i] =						new Neuron(activationFunction);					staticWeights[i] =						new Weights(								lastLayerSize,								NeuralNetwork.NOT_DYNAMIC,								NeuralNetwork.NOT_RECURRENT);					/*staticWeights[i]					 .randomicBiasAndWeightStart();*/				}			}			break;			case NeuralNetwork.DYNAMIC :			{				// TODO implement this case.			}			break;		} // end 1st Inner switch				} //Layer()	/* (non-Javadoc)	 * @see neuralnetworktoolkit.ILayer#addNeuron(neuralnetworktoolkit.INeuron)	 */	public void addNeuron(INeuron neuron) {		switch (isDynamic) {			case NeuralNetwork.NOT_DYNAMIC :				{				// TODO Implement this.				}				break;			case NeuralNetwork.DYNAMIC :				{					dynamicNeurons.addElement(neuron);				}				break;		}	} //addNeuron()	/* (non-Javadoc)	 * @see neuralnetworktoolkit.ILayer#removeNeuron(int)	 */	public void removeNeuron(int index) {		switch (isDynamic) {			case NeuralNetwork.NOT_DYNAMIC :				{				// TODO Implement this.				}				break;			case NeuralNetwork.DYNAMIC :				{					dynamicNeurons.removeElementAt(index);				}				break;		}	} //removeNeuron()	/* (non-Javadoc) 	 * @see neuralnetworktoolkit.ILayer#getNeuron(int)	 */	public INeuron getNeuron(int index) {		INeuron result = null;		switch (isDynamic) {			case NeuralNetwork.NOT_DYNAMIC :				{					result = (INeuron) staticNeurons[index];				}				break;			case NeuralNetwork.DYNAMIC :				{					result = (INeuron) dynamicNeurons.elementAt(index);				}				break;		}		return result;			} //getNeuron()	/* (non-Javadoc)	 * @see neuralnetworktoolkit.ILayer#setWeight(double, int, int)	 */	public void setWeight(double weight, int inputNeuron, int neuron) {		switch (isDynamic) {			case NeuralNetwork.NOT_DYNAMIC :				{					staticWeights[neuron].setWeight(inputNeuron, weight);				}				break;			case NeuralNetwork.DYNAMIC :				{				// TODO Implement this.				}				break;		}	} //setWeight()	/* (non-Javadoc)	 * @see neuralnetworktoolkit.ILayer#getWeight(int, int)	 */	public double getWeight(int inputNeuron, int neuron) {		// TODO Auto-generated method stub		double result = 0;		switch (isDynamic) {			case NeuralNetwork.NOT_DYNAMIC :				{					result = staticWeights[neuron].getWeight(inputNeuron);				}				break;			case NeuralNetwork.DYNAMIC :				{				// TODO Implement this.				}				break;		}		return result;			} //getWeight()	/* (non-Javadoc)	 * @see neuralnetworktoolkit.ILayer#updateWeight(double, int, int)	 */	public void updateWeight(double increment, int inputNeuron, int neuron) {		switch (isDynamic) {			case NeuralNetwork.NOT_DYNAMIC :				{					staticWeights[neuron].updateWeight(inputNeuron, increment);				}				break;			case NeuralNetwork.DYNAMIC :				{				// TODO Implement this.				}				break;		}			} //updateWeight()	/* (non-Javadoc)	 * @see neuralnetworktoolkit.ILayer#updateWeight(double, int, int)	 */	public void updateBias(double increment, int neuron) {		switch (isDynamic) {			case NeuralNetwork.NOT_DYNAMIC :				{					staticWeights[neuron].updateBias(increment);				}				break;			case NeuralNetwork.DYNAMIC :				{				// TODO Implement this.				}				break;		}			} //updateBias()	/* (non-Javadoc)	 * @see neuralnetworktoolkit.ILayer#setWeight(double, int, int)	 */	public void setBias(double value, int neuron) {		switch (isDynamic) {			case NeuralNetwork.NOT_DYNAMIC :				{					staticWeights[neuron].setBias(value);				}				break;			case NeuralNetwork.DYNAMIC :				{				// TODO Implement this.				}				break;		}			} //updateBias()		/* (non-Javadoc)	 * @see neuralnetworktoolkit.ILayer#setIsDynamic(int)	 */	public void setIsDynamic(int condition) {		isDynamic = condition;			} //setIsDynamic()	/* (non-Javadoc)	 * @see neuralnetworktoolkit.ILayer#getLayerSize()	 */	public int getLayerSize() {		return layerSize;			} //getLayerSize()	/* (non-Javadoc)	 * @see neuralnetworktoolkit.ILayer#getBias(int)	 */	public double getBias(int index) {		double result = 0;				switch (isDynamic) {			case NeuralNetwork.NOT_DYNAMIC :				{					result = staticWeights[index].getBias();				}				break;			case NeuralNetwork.DYNAMIC :				{				// TODO Implement this.				}				break;		}		return result;			} //getBias()	/* (non-Javadoc)	 * @see neuralnetworktoolkit.ILayer#getWeightSize(int)	 */	public int getWeightSize(int index) {		// TODO implement the general case.		return staticWeights[index].getSize();			} //getWeightSize()} //Layer

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -