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

📄 weights.java

📁 利用Java实现的神经网络工具箱
💻 JAVA
字号:
/* * Weights.java	1.0 10 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;/** * Class that implements the data structure that stores the neural * network weights information. <br><b>Dynamic and recurrent cases * stay unimplemented!<b> *  * @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 Weights implements Serializable {	/** Indicates that weights list is dynamic or static. */	private int      isDynamic;	/** Indicates that weigths list is recurrent or not. */	private int      isRecurrent;	/** Weights list size. */	private int      size                     = 0;	/** Stores not recurrent weights list dynamically. */	private Vector   dynamicWeigths;	/** Stores recurrent weights list dynamically. */	private Vector   dynamicRecurrentWeights;	/** <i>Bias</i> term value. */	private double   bias;	/** Stores not recurrent weights list statically. */	private double[] staticWeights;	/** Stores recurrent weights list statically. */ 	private double[] staticRecurrentWeights;	/**	 * Creates a new weights list with the specified attributes.	 * 	 * @param size      Weights list size.	 * @param dynamic   Indicates that the weights list is dynamic or static.	 * @param recurrent Indicates that the weights list is recurrent or not.	 */	public Weights(int size, int dynamic, int recurrent) {		this.isDynamic = dynamic;		this.isRecurrent = recurrent;		this.size = size;		//	Outer switch		switch (isDynamic) {			case NeuralNetwork.NOT_DYNAMIC :				{					// 1st Inner switch						switch (isDynamic) {						case NeuralNetwork.NOT_RECURRENT :							{								staticWeights = new double[size];							}							break;						case NeuralNetwork.RECURRENT :							{								// TODO implement this case.							}							break;					} // end 1st Inner switch					}				break;			case NeuralNetwork.DYNAMIC :				{ // TODO implement the dynamic case.					// 2nd Inner switch						switch (isDynamic) {						case NeuralNetwork.NOT_RECURRENT :							{								// TODO Implement this.							}							break;						case NeuralNetwork.RECURRENT :							{								//	TODO implement this case.							}							break;					} // end 2nd Inner switch				}				break;		} // end Outer switch	} //Weights()	/**	 * Returns the weight at index.	 * 	 * @param index Weight index.	 * 	 * @return Weight value.	 */	public double getWeight(int index) {		// TODO Implement dynamic case.		return staticWeights[index];			} //getWeight()	/**	 * Sets the weight value at index.	 * 	 * @param index     Weight index to be seted.	 * @param newWeight New weight value.	 */	public void setWeight(int index, double newWeight) {		// TODO Implement dynamic case.		staticWeights[index] = newWeight;			} //setWeight()	/**	 * Updates the weight value at index.	 * 	 * @param index     Weight index to be updated.	 * @param increment Value to be incremented at weight value.	 */	public void updateWeight(int index, double increment) {		// TODO Implement dynamic case.		staticWeights[index] = staticWeights[index] + increment;			} //updateWeight()	/**	 * Sets initial weights with random values.	 */	/*public void randomicWeightStart() {		switch (isDynamic) {			case NeuralNetwork.NOT_DYNAMIC :				{					for (int i = 0; i < staticWeights.length; i++) {						staticWeights[i] = Math.random() * 10;					}				}				break;			case NeuralNetwork.DYNAMIC :				{					// TODO Implement this case.				}				break;		}	} //randomicWeightStart()*/	/**	 * Updates <i>bias</i> term with an increment value.	 * 	 * @param increment Value to increment <i>bias</i>.	 */	public void updateBias(double increment){		bias = bias + increment;			} //updateBias()	/**	 * Sets the wished initial weights value.	 * 	 * @param weight Initial weights value to be seted.	 */	public void startWeights(int weight) {		switch (isDynamic) {			case NeuralNetwork.NOT_DYNAMIC :				{					for (int i = 0; i < staticWeights.length; i++)						staticWeights[i] = weight;									}				break;			case NeuralNetwork.DYNAMIC :				{					// TODO Implement this.				}				break;		}	} //startWeights()	/**	 * Sets initial values (randomically) to <i>bias</i> term and weights.	 */	/*public void randomicBiasAndWeightStart() {		bias = Math.random() - 0.5;		switch (isDynamic) {			case NeuralNetwork.NOT_DYNAMIC :				{					for (int i = 0; i < staticWeights.length; i++)						staticWeights[i] = (Math.random() - 0.5) * 10;									}				break;			case NeuralNetwork.DYNAMIC :				{				}				break;		}	} //randomicBiasAndWeightStart()*/	/**	 * Sets initial <i>bias</i> term with a random value.	 */	/*public void randomicStartBias() {		bias = Math.random() * 10;			} //randomicStartBias()*/			/**	 * Sets the wished initial <i>bias</i> term value.	 * 	 * @param bias Initial <i>bias</i> value to be seted.	 */	public void startBias(double bias) {		this.bias = bias;			} //startBias()	/**	 * Sets weights list to be dynamic or static.	 * 	 * @param condition Indicates that list is dynamic or static.	 */	public void setIsDynamic(int condition) {		isDynamic = condition;			} //setIsDynamic()	/**	 * Returns <i>bias</i> term value.	 * 	 * @return <i>Bias</i> term value.	 */	public double getBias() {		return bias;			} //getBias()	/**	 * Sets <i>bias</i> term value.	 * 	 * @param bias Value to be seted.	 */	public void setBias(double bias) {		this.bias = bias;			} //setBias()	/**	 * Returns weights list size.	 * 	 * @return Weights list size.	 */	public int getSize() {		return size;			} //getSize()} //Weights

⌨️ 快捷键说明

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