Learning by training: Artificial Neural Networks (ANN)

Posted by: tanya Comments: 0

In this essay, akin to the way the human brain processes information, we will try to replicate using Artificial Neural Networks (ANNs). The working of a human brain by making the right connections is the idea behind ANNs which simulates the behaviour of biological systems composed of “neurons”. A neural network is a machine learning algorithm based on the model of a human neuron. The human brain consists of millions of neurons that send and process signals in the form of electrical and chemical signals. A network of simulated neurons forms neural networks.

Similarly an ANN is an information processing technique and it includes a large number of connected processing units that work together to process information and help to generate meaningful results from it.

Below we have trained a network to complete a rather simple task using backpropagation algorithm which is a type subset of a machine learning model known as reinforcement learning. 

We will use R language as it provides depth in terms of its packages and we opt for ‘neuralnet’.

#The objective is to train the network to perform a cube root transformation
#We start by randomly choosing 50 numbers within a range from 0 to 100

> traininginput <- data.frame(runif(50, min=0, max=100))
> trainingoutput <- (traininginput)^(1/3)

#Bind the data

> trainingdata <- cbind(traininginput,trainingoutput)
> colnames(trainingdata) <- c(‘Input’,’Output’)

#Train the neural network
#Going to have 1 hidden layers with 10 neurons
#Threshold is a numeric value specifying the threshold for the partial derivatives of the error function as stopping criteria

> net.sq <- neuralnet(Output~Input,trainingdata, hidden=10, threshold=0.01)

#A view of the neural network

> plot(net.sq)

Rplot

#We test the neural network on the training data

> testdata <- data.frame((1:5)^3)
> net.results <- compute(net.sq, testdata)

#A preview of the results

> print(net.results$net.result)
[,1] [1,] 0.9018869094 [2,] 1.9922174192 [3,] 3.0012337351 [4,] 4.0025262073 [5,] 4.9005253347

#Results in format of actual vs neural net predictions

> cleanoutput <- cbind(testdata,(testdata)^(1/3), data.frame(net.results$net.result))

> colnames(cleanoutput) <- c(‘Input’,’Expected Output’,’Neural Net Output’)
> print(cleanoutput)

Input Expected Output Neural Net Output
1 1 1 1.095367
2 8 2 2.001383
3 27 3 3.004811
4 64 4 4.001668
5 125 5 4.873944

In conclusion,  Neural networks perform well with linear and nonlinear data and they work even if one or few units fail to respond to network but to implement large and effective software neural networks, much more processing and storage resources need to be committed. Finally, Neural network learns from the analyzed data and hence the biggest value add is in automating repetitive tasks.

Leave a Reply

Your email address will not be published. Required fields are marked *