ARTIFICIAL NEURAL NETWORK

                                    ARTIFICIAL NEURAL NETWORK

In this lab we are run AI program for machine learning which solves the Binary using LED Numerical Display.

It's from Micheal Klement from the below link

(Running An Artificial Neural Network On An Arduino Uno – The DIY Life (the-diy-life.com)).

An artificial neural network is a mathematical computing model which is designed to mimic the way in which the brain reacts to sensory inputs. 


Historically important

In fact they have been around since the 80’s and while they are based on some fairly complicated mathematics, you do not need to understand the mathematics in order to understand how the network functions.

So what is an artificial neural network? In short, an artificial neural network is a segment of code which learns how to respond to inputs based on example sets of inputs and outputs. They are very powerful tools and are rapidly finding their place in facial recognition, autonomous vehicles, stock market and sports predictions and even as far as websites suggesting products which you may be interested in. Their most powerful application lies in pattern recognition, where the exact input into the network is not known. There may be too little or too much information and it is up to the network to decide how it is processed. A good example of the application of an artificial neural network is in handwriting recognition


In this example, we’re going to be building a three layer feed forward network, the three being the input layer, hidden layer and output layer as shown above.

when we compared to Truth table for LCD

we give an input of value which shows an number from 0 to 9


  • PatternCount – The number of items/row of training data in your table.
  • InputNodes – The number of neurons associated with the input data.
  • Output Nodes – The number of neurons associated with the output data.

For example 
if we wanna get a 8 LCD segments all the input hast to be 1 and if we compare with number 0 
if we change last input to 0 the 8 will change in to 0
Binary is an output.


To run the code
First connect the Arduino in the computer

Then upload the code from the link .


//Author: Ralph Heymsfeld
//28/06/2018

#include <math.h>

/**********************
 * Network Configuration - customized per network 
 **********************/

const int PatternCount = 10;
const int InputNodes = 7;
const int HiddenNodes = 8;
const int OutputNodes = 4;
const float LearningRate = 0.3;
const float Momentum = 0.9;
const float InitialWeightMax = 0.5;
const float Success = 0.0004;

const byte Input[PatternCount][InputNodes] = {
  { 1, 1, 1, 1, 1, 1, 0 },  // 0
  { 0, 1, 1, 0, 0, 0, 0 },  // 1
  { 1, 1, 0, 1, 1, 0, 1 },  // 2
  { 1, 1, 1, 1, 0, 0, 1 },  // 3
  { 0, 1, 1, 0, 0, 1, 1 },  // 4
  { 1, 0, 1, 1, 0, 1, 1 },  // 5
  { 0, 0, 1, 1, 1, 1, 1 },  // 6
  { 1, 1, 1, 0, 0, 0, 0 },  // 7 
  { 1, 1, 1, 1, 1, 1, 1 },  // 8
  { 1, 1, 1, 0, 0, 1, 1 }   // 9
}; 

const byte Target[PatternCount][OutputNodes] = {
  { 0, 0, 0, 0 },  
  { 0, 0, 0, 1 }, 
  { 0, 0, 1, 0 }, 
  { 0, 0, 1, 1 }, 
  { 0, 1, 0, 0 }, 
  { 0, 1, 0, 1 }, 
  { 0, 1, 1, 0 }, 
  { 0, 1, 1, 1 }, 
  { 1, 0, 0, 0 }, 
  { 1, 0, 0, 1 } 
};

Run the code 

output is 

Training cycle 
each time it changes and reduce the error giving the output and finally It get solved.

change the code and bring the XOR table





Modified code



#include <math.h>

/**********************
 * Network Configuration - customized per network 
 **********************/

const int PatternCount = 4;
const int InputNodes = 2;
const int HiddenNodes = 3;
const int OutputNodes = 1;
const float LearningRate = 0.3;
const float Momentum = 0.9;
const float InitialWeightMax = 0.5;
const float Success = 0.0004;

const byte Input[PatternCount][InputNodes] = {
  { 0,0 },  // 0
  { 0,1 },  // 1
  { 1,0 },  // 2
  { 1,1 },  // 3
  
}; 

const byte Target[PatternCount][OutputNodes] = {
  { 0 },  
  { 1 }, 
  { 1 }, 
  { 0 }, 
   
};

and the result you get

Training cycle is very fast when optimising.
You get solved very quick.

we change the pattern count, Input and output nodes from the previous code.

First cycle output

Initial/Untrained Outputs: 

  Training Pattern: 0
  Input 0 0   Target 0   Output 0.27673 
  Training Pattern: 1
  Input 0 1   Target 1   Output 0.27028 
  Training Pattern: 2
  Input 1 0   Target 1   Output 0.26796 
  Training Pattern: 3
  Input 1 1   Target 0   Output 0.26167 

TrainingCycle: 1  Error = 0.60655

  Training Pattern: 0
  Input 0 0   Target 0   Output 0.30410 
  Training Pattern: 1
  Input 0 1   Target 1   Output 0.29860 
  Training Pattern: 2
  Input 1 0   Target 1   Output 0.29505 
  Training Pattern: 3
  Input 1 1   Target 0   Output 0.28964 

TrainingCycle: 1000  Error = 0.00135

  Training Pattern: 0
  Input 0 0   Target 0   Output 0.01486 
  Training Pattern: 1
  Input 0 1   Target 1   Output 0.97724 
  Training Pattern: 2
  Input 1 0   Target 1   Output 0.96900 
  Training Pattern: 3
  Input 1 1   Target 0   Output 0.03147 

TrainingCycle: 2000  Error = 0.00051

  Training Pattern: 0
  Input 0 0   Target 0   Output 0.00857 
  Training Pattern: 1
  Input 0 1   Target 1   Output 0.98563 
  Training Pattern: 2
  Input 1 0   Target 1   Output 0.98122 
  Training Pattern: 3
  Input 1 1   Target 0   Output 0.01961 

TrainingCycle: 2432  Error = 0.00040

  Training Pattern: 0
  Input 0 0   Target 0   Output 0.00748 
  Training Pattern: 1
  Input 0 1   Target 1   Output 0.98719 
  Training Pattern: 2
  Input 1 0   Target 1   Output 0.98339 
  Training Pattern: 3
  Input 1 1   Target 0   Output 0.01742 

Training Set Solved! 
--------

Second Cycle 

Initial/Untrained Outputs: 

  Training Pattern: 0
  Input 0 0   Target 0   Output 0.25949 
  Training Pattern: 1
  Input 0 1   Target 1   Output 0.26417 
  Training Pattern: 2
  Input 1 0   Target 1   Output 0.26299 
  Training Pattern: 3
  Input 1 1   Target 0   Output 0.26827 

TrainingCycle: 1  Error = 0.62150

  Training Pattern: 0
  Input 0 0   Target 0   Output 0.30798 
  Training Pattern: 1
  Input 0 1   Target 1   Output 0.31376 
  Training Pattern: 2
  Input 1 0   Target 1   Output 0.31220 
  Training Pattern: 3
  Input 1 1   Target 0   Output 0.31843 

TrainingCycle: 1000  Error = 0.00131

  Training Pattern: 0
  Input 0 0   Target 0   Output 0.02251 
  Training Pattern: 1
  Input 0 1   Target 1   Output 0.97564 
  Training Pattern: 2
  Input 1 0   Target 1   Output 0.97570 
  Training Pattern: 3
  Input 1 1   Target 0   Output 0.03037 

TrainingCycle: 2000  Error = 0.00052

  Training Pattern: 0
  Input 0 0   Target 0   Output 0.01446 
  Training Pattern: 1
  Input 0 1   Target 1   Output 0.98465 
  Training Pattern: 2
  Input 1 0   Target 1   Output 0.98470 
  Training Pattern: 3
  Input 1 1   Target 0   Output 0.01886 

TrainingCycle: 2476  Error = 0.00040

  Training Pattern: 0
  Input 0 0   Target 0   Output 0.01277 
  Training Pattern: 1
  Input 0 1   Target 1   Output 0.98650 
  Training Pattern: 2
  Input 1 0   Target 1   Output 0.98654 
  Training Pattern: 3
  Input 1 1   Target 0   Output 0.01652 

Training Set Solved !
---------

The XOR problem was a big challenge in early AI. It showed we needed more complex models like multi-layer perceptrons (MLPs) with hidden layers. These hidden layers allow neural networks to understand non-linear patterns between inputs and outputs. This was a big step forward for AI. Training neural networks involves adjusting weights and biases to reduce errors over many cycles. AI is becoming more common in everyday life, helping with decisions, automating tasks, and giving personalized recommendations. As AI technology improves, it will continue to make life easier and more innovative.

Reason for No of training cycles different each time 

Initialization
learning rate
Network Architecture
Data variability
Stopping criteria






Comments

Popular posts from this blog

video editing Tr airbuds and persistence of data

week 3 Arduino basics with Microcontroller