Realization of perceptron algorithm in Java

@H_ 403_ 1 @ brief description

With the rapid development of the Internet, a (AI) B (bigdata) C (cloud) has become the core development direction at present. If the three are deeply combined  AI is the core part. Therefore, if everyone must learn to program in the future society, then for programmers, artificial intelligence is the technology they must master (the development of science and technology is really TM fast).

This article introduces and implements a simplest perceptron network in Java, which is not entangled in the derivation of formulas. It aims to provide you with the idea of learning neural network and have a general understanding of neural network.

@H_ 403_ Analysis of 1@ perceptron network model

First look at a picture

If you are a little interested in neural networks, you must be familiar with this diagram. This diagram is the structure diagram of neurons. X1 ~ XM represents input and W1 ~ WM represents synaptic weight, Σ Represents the summation node, activation function represents the activation function, and then outputs a result. The specific process is

The neuron receives the input, and each input will be multiplied by the weight on its relative path. It will sum at the summation node. Here, set the result of the summation node as Z:

z = X1 * W1 + X2 * W2 + X3 * W3 + ...... + Xm * Wm

Then, Z is passed into the activation function (here we call the activation function f) for binary pattern recognition:

It can be seen here that if the value of F (x) is greater than the threshold, the classification y = 1 is obtained, otherwise y = - 1. Note: relative to the response of biological neurons to stimulation, if the stimulation is within the acceptable range, the neurons will inhibit the stimulation (y = - 1), and if it exceeds the range, they will be excited (y = 1), and the watershed of this range is the threshold (E)

@H_ 403_ 1 @ learning

We find that if the weight and threshold are fixed, then the neural network has no significance, so we  The concept of learning is introduced. Through learning, the neural network can modify the weight and threshold, so as to dynamically modify the accuracy of pattern recognition, which is the essence of machine learning.

So how to learn? Before using the network, we need to provide a set of sample data (teacher pattern learning is adopted here). The sample data includes the input data X and the correct recognition result y '. When we input the training data X and get the pattern recognition y, we will judge. If y! = y', we will adjust the weight and threshold of the network. See the formula for adjustment, μ Indicates the learning rate (correction rate), and update indicates the value to be corrected:

When the perceptron classification result is equal to the correct classification, update = 0, the network is not adjusted; If it is not equal to the correct classification, all weights (W) and thresholds (E) will be adjusted

The above is the simplest learning process of perceptron I introduced:

Input data - > sum to get Z - > wait for the classification result by activating the function - > if the classification result is inconsistent with the correct result, adjust the network

Let's implement this simple neural network

@H_ 403_ 1@Java code implementation

What I realize here is to recognize the positive and negative of integers through neural network learning. First, define a perceptron class

Then write a function to generate training data

Finally, the main function

You can test it

@H_ 403_ 1 @ limitations

This perceptron neural network is relatively simple and suitable for linearly divisible data, such as one-dimensional positive and negative numbers, and two-dimensional coordinate quadrant classification; The data that cannot be linearly divided cannot be classified correctly, such as looking for prime numbers

The above is the whole content of this article. I hope it will be helpful to your study, and I hope you can support programming tips.

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>