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

📄 neuron.java

📁 神经网络源代码,实现了一个BP神经网络,可以完成基于BP的神经网络算法.
💻 JAVA
字号:
package net.openai.ai.nn.network;import java.util.*;import java.io.*;public class Neuron implements Serializable {    //  the collection of connections for this neuron    private Vector connections = null;    //  the collection of 'to' connections    private Vector connectionsTo = null;    //  the collection of 'from' connections    private Vector connectionsFrom = null;    //  the input for this neuron    private double input = 0;    //  the output for this neuron    private double output = 0;    //  the error of this neuron    private double error = 0;    //  a flag to tell whther this neuron has had it's error set    private boolean errorSet = false;    public Neuron() {	connections = new Vector();	connectionsTo = new Vector();	connectionsFrom = new Vector();    }    /**     * Gets the input for this neuron.     *     * @return double The input for this neuron.     */    public final double getInput() {	return input;    }    /**      * Sets the input for this neuron.     *     * @param input The input to be set for this neuron.     */    public final void setInput(double input) {	this.input = input;	errorSet = false;    }    /**     * Gets the output for this neuron.     *     * @return double The output for this neuron.     */    public final double getOutput() {	return output;    }    /**      * Sets the output for this neuron.     *     * @param output The output to be set for this neuron.     */    public final void setOutput(double output) {	this.output = output;    }    /**     *     * Gets a connection to a particular neuron.     * @param neuron The neuron which may be connected to this neuron.     * @return Connection to the neuron...or null if not connected.     */    public final Connection getConnectionTo(Neuron neuron) {	//  make sure we have connections at all	if(connections == null || connections.isEmpty())	    return null;	int size = connections.size();	for(int i = 0; i < size; i++) {	    Connection connection = (Connection) connections.elementAt(i);	    if(neuron == connection.getToNeuron())		return connection;	}	return null;    }    /**     *     * Gets all connections for this neuron..     * @return Vector All connections for this neuron.     */    public final Vector getConnections() {	return connections;    }    /**     *     * Gets all 'to' connections for this neuron..     * @return Vector All connections 'to' this neuron.     */    public final Vector getConnectionsTo() {	return connectionsTo;    }    /**     *     * Gets all 'from' connections for this neuron..     * @return Vector All connections 'from' this neuron.     */    public final Vector getConnectionsFrom() {	return connectionsFrom;    }    /**     *     * Add a connection from this neuron.     * @param connection The connection to add.     */    public final void addConnectionFrom(Connection connection) {	if(connection != null) {	    connection.setFromNeuron(this);	    connections.add(connection);	    connectionsFrom.add(connection);	} else {	    //  throw some specialized error.	}    }    /**      *      * Add a connection to this neuron.      * @param connection The connection to add.      */     public final void addConnectionTo(Connection connection) {         if(connection != null) {             connection.setToNeuron(this);             connections.add(connection); 	    connectionsTo.add(connection);        } else {             //  throw some specialized error.         }     }    /**     * Gets the error for this neuron.     *     * @return double The error for this neuron.     */    public final double getError() {	return error;    }    /**      * Sets the error for this neuron.     *     * @param error The error to be set for this neuron.     */    public final void setError(double error) {	this.error = error;	errorSet = true;    }    /**      * Returns a flag that tells whether this neuron has had the error     * set     *     * @return boolean - Whether this neuron has had it's error calculated.     */    public final boolean isErrorSet() {	return errorSet;    }    /**     * Returns a string rpresentation of the neuron.     *     * @return String A representation of the neuron.     */    public final String toString() {	String neuron = ("\nInput: " + input 			 + "\nOutput: " + output			 + "\nError: " + error);	return neuron;    }    }

⌨️ 快捷键说明

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