Teaching Math using Neural Networks

Teaching Math using Neural Networks



Let’s build a program, that will teach the computer to predict the output of a mathematical expression without “knowing” the exact formula.

Consider the following expression: (a+b)*2

For two inputs a and b the operation will have one distinct output.
The goal is to create a program, that will predict the output for given inputs, without knowing the formula of the expression.

For this, we will use neural networks. Artificial neural networks, like real brains, are formed from connected “neurons” all capable of carrying out a data related task, such as answering a question about the relationship between them.
Simple Neural Network Function example
Simple Neural Network Function example

To make it really simple, we will just model a single neuron, with two inputs and one output.
These first four examples are called a training set:
Inputs     Output
  2    3         10
  1    1           4
  5    2         14
12    3         30

We are going to train the neuron to work out the pattern and solve the task for custom inputs by just having the training set and without knowing what operation it performs.

Training:

We give each input a ‘weight’ which can be positive or negative number. And input with a large positive weight or a large negative weight has a strong effect on the neurons output. Before we start
We set each weight to a random number. Then we began the training process:
  1. Take the inputs from the training set, adjust them by the weights, and pass them through a special formula to calculate the neurons output.
  2. Calculate the error, which is the difference between the neurons output and the desired output in the training set example.
  3. Depending on the direction of the error, adjust the weights.
  4. Repeat this process 10,000 times.

Eventually the weights of the neuron will reach an optimum for the training set. This process is called back propagation.

For the formula, we take the weighted sum of the inputs:

Output=weight1*input1+weight2*input2

After each iteration, we need to adjust the weight based on the error (the difference of the calculated output and the real output). We use this formula for each weight:

Adjustment=0.01*error*input

This makes the adjustment proportional to the size of the error. After each adjustment the error size should get smaller and smaller.

After the 10,000 iterations, we will have optimum weights and then we can give the program our desired inputs. The program will use the weights and calculate the output using the same weighted sum as above.

No comments

Powered by Blogger.