Getting started with neural networks

In this chapter, we will introduce neural networks and find out what they were designed for. This chapter serves as a foundation for subsequent chapters, while this one shows the basic concepts of neural networks. In this chapter, we will cover the following topics:





  • Artificial neurons





  • Weights and biases





  • Activation functions





  • Layers of neurons





  • Neural network implementation in Java





Uncovering neural networks

First, the term "neural networks" can create a snapshot of the brain in your mind, in particular for those who have previously become familiar with it. This is actually true, we think of the brain as a large and natural neural network. However, what can we say about artificial neural networks ( ANNs )? Well, it starts with the antonym natural and the first thought that comes to our minds is a picture of an artificial brain or a robot that takes into account the term “ artificial". In this case, we are also dealing with the creation of a structure similar and inspired by the human brain; therefore it is called artificial intelligence. So a reader who has no past experience with ANN may now think that the book teaches how to build intelligent systems, including an artificial brain that can emulate human consciousness using Java programs, right? Of course we will not cover the creation of artificial thinking machines as in the Matrix trilogy; however, this book will explain several incredible abilities and what these structures can do. We will provide the reader with Java source codes with the definition and creation of the basic neural network structures, take advantage of all the advantages of the Java programming language.





Why artificial neural networks?

, . (NN) ANN , NN ,

. , ANN? .





1940- Warren McCulloch Walter Pits , . , . McCulloch Pits , . , , , , , . , , , .





, McCulloch Pits , . , ; , , , . , , .





, ANN , , , , , . ANN , , .





,





,













, ANN — , . , , . , .





, . ( ), ( ), ( ), :





, .





, — , . , (inputs) (output), , . ,   , :





, , . , .





. , , . , , .





:





  • (Sygmoid)





  • (Hyberbolic tangent)





  • (Hard limiting threshold)





  • (linear)





,

:





— (weights)

, , , , . , , (weights) (output), . , inputs , (weights) . , , , — .





, .





, ; , , , . , , . , :





, . 3 :

1. Input layer;

2. Hidden layer;

3. Output layer;

,

,

.





/ . , .





, , . . , . , 2 :





1. :

1.1 (monolayer) ;

1.2 (multilayer) ;

2. :

2.1 (Feedforward networks);

2.2 (Feedback networks);





, . . : , Adaline( ), , (Elman) .





, , , :





– . , . , , , , , .





(feedforward networks)

. – feedforward, ; , , , . – feedforward .





(Feedback networks)

, , , , – feedback-. :





– , , , . , , . feedback – , (Elman) (Hopfield), , .





, . , . . , , . :





, , (supervised learning), , , ( ). , « », .





!

Java. Java — -   , 1990- Sun Microsystems, Oracle 2010-. , Java , . - , Java, . — - , — , , car(, ) my car(, — ). Java ( ), - (). , — . :





  • : , , .





  • : , ((public) ), ((private) (protected)), .





  • : , ; , - . , , .





  • : , , .





, , , . , , , , , : , . . / , .





, , . , - , / . . , 6 , :





: Neuron









private ArrayList listOfWeightIn





ArrayList





private ArrayList listOfWeightOut





ArrayList









public double initNeuron()





listOfWeightIn, listOfWeightOut





:





:





public ArrayList getListOfWeightIn()





ListOfWeightIn





:





: , ListOfWeightIn





public void setListOfWeightIn(ArrayList listOfWeightIn)





ListOfWeightIn





: ,





:





public ArrayList getListOfWeightOut()





ListOfWeightOut





:





: , ListOfWeightOut





public void setListOfWeightOut(ArrayList listOfWeightOut)





ListOfWeightOut





: ,





:





: Neuron.java





 





: Layer





: .









private ArrayList listOfNeurons





ArrayList Neuron





private int numberOfNeuronsInLayer





, .









public ArrayList getListOfNeurons()





listOfNeurons





:





: listOfNeurons





public void setListOfNeurons(ArrayList listOfNeurons)





listOfNeurons





: listOfNeurons





:





public int getNumberOfNeuronsInLayer()





numberOfNeuronsInLayer





:





: numberOfNeuronsInLayer





public void setNumberOfNeuronsInLayer(int numberOfNeuronsInLayer)





numberOfNeuronsInLayer





: numberOfNeuronsInLayer





:





: Layer.java





 





: InputLayer





: Layer

















public void initLayer(InputLayer inputLayer)









: InputLayer





:





public void printLayer(InputLayer inputLayer)









: InputLayer





:





: InputLayer.java





 





: HiddenLayer





: Layer

















public ArrayList initLayer( HiddenLayer hiddenLayer, ArrayList listOfHiddenLayers, InputLayer inputLayer, OutputLayer outputLayer )





()





: HiddenLayer, HiddenLayer, InputLayer, OutputLayer





:





public void printLayer(ArrayList listOfHiddenLayers)





()





: HiddenLayer





:





: HiddenLayer.java





 





: OutputLayer





: Layer

















public void initLayer(OutputLayer outputLayer)









: OutputLayer





:





public void printLayer(OutputLayer outputLayer)









: OutputLayer





:





: OutputLayer.java





 





: NeuralNet





: ( , , ). : .









private InputLayer inputLayer





InputLayer





private HiddenLayer hiddenLayer





HiddenLayer





private ArrayList listOfHiddenLayer





ArrayList HiddenLayer.





private OutputLayer outputLayer





OutputLayer





private int numberOfHiddenLayers





,









public void initNet()





.





:





:





public void printNet()





. .





:





:





: NeuralNet.java





(UML). UML , , , , , / . : , .





, NeuralNet, n. n ( ), initNet () printNet () n, , . , :





public class NeuralNetTest {
    public static void main(String[] args) {
        NeuralNet n = new NeuralNet();
        n.initNet();
        n.printNet();
    }
}
      
      



, , , . , , :





In this chapter, we saw an introduction to neural networks, what they are, what they are used for, and their basic concepts. We also saw a very simple implementation of a neural network in the Java programming language, in which we applied the theoretical concepts of the neural network in practice, coding each of the neural network elements. It is important to understand the basic concepts before we move on to advanced concepts. The same is true for the Java code. In the next chapter, we will dive deeper into the neural network training process and explore the different types of slopes with simple examples.





From the translator

Original book: Neural Network Programming with Java








All Articles