JAVA Back Propagation Neural Network

Source: Internet
Author: User

From Quantums blog

I haven't written anything for a long time. Just remember it ~~ It would be a waste of time to forget the record ~

The following figure shows the back-propagation neural network written in JAVA. It is object-oriented and abstracts the neurons and links into objects.

In fact, this is no longer a novelty. For classification regression, neural networks are a choice but not necessarily the best choice.

Similar evolutionary computing has the same problems, such as GA genetic algorithm.

After NN iterative learning, it is difficult to understand the meaning of each neuron weight. Therefore, some people proposed how to extract neural network rules and crop network neurons.

The next step is the most valuable

1. Calculate the delta rule, generally using the gradient descent method and so on (there is a good book "Optimization Theory and Method" about a lot of Newton's method of the fastest descent method, etc)

2. Activate the function. In fact, the ultimate goal is to make the data bid and design the standard method in the book of neural networks. In fact, you can also develop one by yourself through this idea.

3. Of course, it is the entire data structure model of NN, simulating the information transmission process of brain nerves.

The main function of the following code uses the DEMO

Package cn. isto. ai. algorithm. nn;
Import java. util. HashMap;
Import java. util. Random;
Import java. util. Set;
Import java. util. Map. Entry;

/**
* JAVA back-propagation neural network
* @ Author kj021320, codeby 2008.12.10
*
*/
Public class JavaBackPropagationNeuralNetwork {
/**
* Neuron
*/
Public class Neuron {
HashMap <Integer, Link> target = new HashMap <Integer, Link> (); // connects
HashMap <Integer, Link> source = new HashMap <Integer, Link> (); //
Double data = 0.0;
Public Link sourceGet (int index ){
Return source. get (index );
}
Public Link targetGet (int index ){
Return target. get (index );
}
Public boolean targetContains (Link l ){
Return target. containsValue (l );
}
Public boolean sourceContains (Link l ){
Return source. containsValue (l );
}
Public Link sourceLink (int index, Link l ){
If (l. linker! = This ){
L. setLinker (this );
}
Return source. put (index, l );
}
Public Link targetLink (int index, Link l ){
If (l. owner! = This ){
L. setOwner (this );
}
Return target. put (index, l );
}
}

/**
* Neural chains
*/
Public class Link {
Neuron owner;
Public void setOwner (Neuron o ){
Owner = o;
If (! O.tar getContains (this )){
O.targetLink(o.tar get. size (), this );
}
}
Public Link (){
Weight = rand (-1, 1 );
}
Public void setLinker (Neuron o ){
Linker = o;
If (! O. sourceContains (this )){
O. sourceLink (o. source. size (), this );
}
}
@ Override
Public String toString (){
Return super. toString () + "weight:" + weight;
}
Neuron linker;
Double weight;
}

Random random = new Random ();
{
Random. setSeed (System. nanoTime ());
}
Neuron [] inputnode; // input-layer Neuron
Neuron [] hiddennode; // hidden layer Neuron
Neuron [] outputnode; // output layer Neuron
Double learnrate; // learning speed
Double threshold; // threshold, error tolerance

Private final int inputCount;
Private final int hiddenCount;
Private final int outputCount;
/**
*
* @ Param input: number of neurons in the input layer
* @ Param hidden number of neurons in the hidden layer
* @ Param output: number of neurons in the output layer
*/
Public JavaBackPropagationNeuralNetwork (int input, int hidden, int output ){
InputCount = input;
HiddenCount = hidden;
OutputCount = output;
Build ();
}
Public void reBuildNeuralNetwork (){
Build ();
}
Private void build (){
Inputnode = new Neuron [inputCount + 1];
Hiddennode = new Neuron [hiddenCount];
Outputnode = new Neuron [outputCount];
InitNeurons (inputnode );
InitNeurons (hiddennode );
InitNeurons (outputnode );
MakeLink (inputnode, hiddennode );
MakeLink (hiddennode, outputnode );
}
/**
* Method of thinking
* @ Param inputs floating point numbers that match the number of neurons in the feed-forward layer-1 ~ Between 1
* @ Return

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.