Question

Give an example of neural network using matrices please and explain it

Give an example of neural network using matrices please and explain it

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Really the use of matrices in representing the neural network and perform calculation will allow us to express the work we need to do concisely and easily.

Let us begin by visualising the simplest of all the network which consist of one input with two neurons and one output.

I think the above calculation we have done already and really doesn’t need matrices. Hmm… let try a bit more complex by making the output layer with two neuron.

Now instead of going through each node and multiply with the weights with input and passing to next layer, we can simply represent using the below matrix notation where:

A bit more with 3 layers with 3 neurons each and this time let’s use code to compute the output. Below is the network we are trying to solve:

Instead of assigning all the weights, let’s see in matrices form:

Input -> Hidden layer (W x I = H)

The Input layer is multiple with weight matrices which gives the output of the Hidden Layer.

Code:

// Define matrix I
double[,] I_Array = {{ 0.2},
{ 0.1},
{0.3}};

Matrix<double> I = Matrix<double>.Build.DenseOfArray(I_Array);


// Define weight matrics between Input and Hidden layer
double[,] W_IH_Array = {{ 0.6,0.4,0.1},
{ 0.5,0.3,0.1},
{0.2,0.9,0.7}};

Matrix<double> W_IH = Matrix<double>.Build.DenseOfArray(W_IH_Array);


//Multiple W x I to get output for the hidden layer
Matrix<double> H = W_IH * I;
H.Dump();

And below is the result of the Hidden layer:

Hidden -> Output Layer (W x H = Y)

Code:

// Define weight matrics between Input and Hidden layer
double[,] W_HY_Array = {{ 0.2,0.4,0.9},
{ 0.6,0.2,0.1},
{0.7,0.4,0.7}};

Matrix<double> W_HY = Matrix<double>.Build.DenseOfArray(W_HY_Array);
//Multiple W x H to get output for the final outout layer
Matrix<double> Y = W_HY * H;
Y.Dump();

Below is the result of the output layer

That it, so easy in just a few lines of code we simply calculated the output of the 3 layered neural networks.

Add a comment
Know the answer?
Add Answer to:
Give an example of neural network using matrices please and explain it
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT