Unit 6: Neural Network 2

Objective

This unit is the 2nd part of Neural Network which should immediately follow the completion of Unit 5.  This is designed for students with strong calculation ability (e.g. lower secondary school) involving addition and multiplication of decimal numbers.

The objective of this unit is to learn how neural network works.  It will reinforce the concept of input neurons, output neurons, and the connections.  It also examines how weights are used to show intelligence learned during the training stage.

Teaching

For a neural network with training completed, the weights were adjusted (or changed) to a set of values that, when used in the usage stage, can imitate the decisions (actions) chosen by the trainer.  These weights will not vary anymore after the completion of training.

How does a trained neural network operate?

Weights - the trained neural network should have a set of adjusted weights.  Each connections should have a weight.

Inputs - when there is an image, for example a Red card, the computer vision in the camera will capture the pixels and determine their intensity values.  These intensity values will be converted to values in the input neurons ranged from 0 to 1.  The number of input neurons are same as the number of pixels.

Which action?  Which decision?

- based on the values of the input neurons and the weights, value of each output neuron will be calculated.  If there are 2 outputs, both output values will be calculated.

- the neural network will choose the output with the biggest value as the decision (action).

 

Activity 1 - continue unit 5 "Red Light, Green Light"

Objective:

- examine the calculation of the neural network

This activity is a continuation of the "Red Light, Green Light" in unit 5.  We will use the trained neural network to continue this activity.

In case you do not have the trained neural network from unit 5 on hand, You can follow the activity sheet in Unit 5 to train a neural network and then do the following activity.

Set to Usage stage

- off the <learning> button

- click the <self drive> and start the usage stage

What are the value of the weights for the trained neural network?

(A) Test with the Red card and calculate the values of the 2 outputs.  Which is bigger?

Work on the below diagram which shows the neural network

- Find out the values of weights w11, w21, w12, and w22 from the AlphAI screen interface.  They should be on or near the connections.  They are ranged from 0 to 1.  Note that some of them can be negative.  Record them on the worksheet below.

- Put the Red card on the stand.

- The values of the input neurons should be changed to reflect the color.  They are ranged from 0 to 1.  Note that some of them can be negative.  Record them.

- In the upper diagram, calculate O1 (output 1) by using the highlighted formula

- In the lower diagram, Calculate O2 (output 2) by using the highlighted formula

Which one is bigger?

- Are they same as the calculated values in the AlphAI screen.

- The bigger will be the decision (action) chosen by the neural network?

- Is your answer correct?

 

(B) Test with the Green card and calculate the values of the 2 outputs.  Which is bigger?

Work on the below diagram which shows the neural network

- Find out the values of weights w11, w21, w12, and w22 from the AlphAI screen interface.  Note that some of them can be negative.  Record them on the worksheet below.

- Put the Green card on the stand.

- The values of the input neurons should be changed to reflect the color.  Note that some of them can be negative.  Record them.

- In the upper diagram, calculate O1 (output 1) by using the highlighted formula

- In the lower diagram, Calculate O2 (output 2) by using the highlighted formula

Which one is bigger?

- Are they same as the calculated values in the AlphAI screen.

- The bigger will be the decision (action) chosen by the neural network?

- Is your answer correct?

 

Learning

The above calculations have shown how the neural network operates.

Based on the weights established during the training stage and the different input values for images, output values are calculated.  Then, the output with the biggest value will be chosen as the decision (action).  This is how the AI learns intelligence.

When the Red card is used as input, the 2 input values and the 4 weight values are used to calculate the 2 output values.  The 2 output values will be compared.  The biggest one will be chosen as decision.  For Red card, the correct answer is "Stop".

When the Green card is used as input, the 2 input values and the 4 weight values are used to calculate the 2 output values.  The 2 output values will be compared.  The biggest one will be chosen as decision.  For Green card, the correct answer is "Go Forward".

 

Activity 2 (extended) - follow the neural network calculation with Left/Right cards

Objective:

- examine the calculation of the neural network

Material:

2 input cards (about 8.5 cm tall) which indicate Left and Right with large black rectangle.

A 3rd card is used to keep the wheel at stop state if it is not "Left" or "Right".

Setup:

(1) the robot is put on top of small solid blocks which can allow the wheels running freely in the air without moving.

(2) the robot (the camera) is put 4 to 5 cm in front of a stand (or a wall).

AI Parameters

See appendix A1

Start the experiment

Switch on and connect the robot to your PC.  Press the <Connection> button.

With the the AI parameters set up correctly, the following neural network will be shown.

Label the Output

Start Training

- click the <reset learning> button once

- click the <learning> button

- put the card "Left" on the stand.  Look at the camera on the computer screen.  If it is detected correctly, click the output 5 times according to the labeled chart (left turn).

- put the card "right" on the stand.  Look at the camera on the computer screen.  If it is detected correctly, click the output 5 times according to the labeled chart (right turn).

- put the card "stop" on the stand.  Click the output 5 times according to the labeled chart (stop).

Testing

- Keep the <learning> button ON.  We will fine-tune the training when we do the testing.

- Click the <self drive> button.  The robot will used the learned intelligence to recognize (test) the card

- test with card "left".  Does it work?  If not, you may need to train with the card "left" several more times.

- test with card "right".  Does it work?  If not, you may need to train with the card "right" several more times.

- test with card "stop".  Does it work?  If not, you may need to train with the card "stop" several more times.

- You need enough and balanced training to make the intelligence work.  Usually you are required to need several rounds of training to adjust the result to become correct for this activity.

- Are the result correct?

- Test and train with the cards many times until it works correctly.

 

(A) Work with the "Left" card and calculate the values of the 3 outputs.  Which is bigger?

- Extract the 2 values of inputs and 6 values of weights from the screen and fill into the below diagram.

- Calculate the 3 values of output.  

- Compare.  Which is the biggest?

(B) Work with the "Right" card and calculate the values of the 3 outputs.  Which is bigger?

- Extract the 2 values of inputs and 6 values of weights from the screen and fill into the below diagram.

- Calculate the 3 values of output.  

- Compare.  Which is the biggest?

(C) Work with the "All Black" card and calculate the values of the 3 outputs.  Which is bigger?

- Extract the 2 values of inputs and 6 values of weights from the screen and fill into the below diagram.

- Calculate the 3 values of output.  

- Compare.  Which is the biggest?

Learning

The above calculations have shown how the neural network operates.

Based on the weights established during the training stage and the different input values for images, output values are calculated.  Then, the output with the biggest value will be chosen as the decision (action).  This is how the AI uses learned intelligence to make decision.

When the "Left" card is used as input, the 2 input values and the 6 weight values are used to calculate the 3 output values.  The 3 output values will be compared.  The biggest one will be chosen as decision.  For the "Left" card, the correct answer is "Turn Left".

When the "Right" card is used as input, the 2 input values and the 6 weight values are used to calculate the 3 output values.  The 3 output values will be compared.  The biggest one will be chosen as decision.  For the "Right" card, the correct answer is "Turn Right".

When the "All Black" card is used as input, the 2 input values and the 6 weight values are used to calculate the 3 output values.  The 3 output values will be compared.  The biggest one will be chosen as decision.  For the "All Black" card, the correct answer is "Stop".

Neural network algorithm will adjust the weights to imitate the trainer's decisions based on the training data.  Once the weights are established and tested correct, intelligence has been built.  We can use the trained AI to help making decisions for new inputs.

 

Discussion

Has learning been achieved?  Has the robot gained intelligence after training?

How many input neurons are there?

How many output neurons are there?

Can you draw the neural network with all connections shown?

What are the numbers on the connections?

Further discussion and work

- Learning is achieved during training, the weights are optimized which present occurrence of learning.  Discuss.

- For Advanced students, can you verify the relationship of the numbers (inputs, weights and outputs).

Appendix A

Sensors (Input) - Camera 2 x 1

Sensors (Input) - Gray Scale

Actions (Output) - left turn, right turn, and stop

Labeled Output

AI Setting

Visualization