domingo, 27 de fevereiro de 2011

Building a Neural Network with 555

It was a few months ago that I had finished my classes of Artificial Neural Networks in my postgraduate course when Jack Ganssle published his column about the “555 Contest”, and the first thing a thought after reading it was: is it possible to build an artificial neuron using 555, so you can combine them to make a complex neuron network by hardware? Well after spending some time thinking about it I’ve arrived to a conclusion that yes, 555 is flexible and powerful enough to build such modern and complex structures.

An artificial neuron is a mathematical model of a neuron cell. It is the building block to a neuron network. It can be described by 3 basic elements: weighted inputs, an adder and an activation function.

The overall sum of each input(xn) multiplied by a weight(wn) is passed as an argument of the activation function ( f(s) ), resulting in the output (y).

To begin with, I’ve chosen to implement a very simple neuron model, it is referred to in the literature as the McCulloch-Pitts model, in recognition of the pioneering work done by McCulloch and Pits in 1943. In this model the activation function is nothing more than a threshold function:

Where t is the desired threshold.

A very simple example is an implementation of an AND port. It utilizes only one neuron.


Therefore the output y will only be activated, or equal to ‘1’, only when both inputs are ‘1’. That’s because s=2 that is higher than the threshold t=1.5.

Now we are going to implement this example in hardware using 555 timer operating as monostable.

In this circuit V1 and V2, are the inputs, which 10V represents a high level and 5V a low level, and are connected to the control pin of the IC.

In the first 555, U1, the capacitor C2 will charge until it reaches the voltage set by V1, resulting in a pulse with the same duration, at the output pin. After reaching the threshold, the discharge pin will go low triggering the second 555, U2, through R5 and C5, which starts charging C3 through R3 until reach the voltage set in V2. So at each output we’ll have timing pulses proportional to the voltages applied. Theses pulses will be summed by D2 and D3, and any glitches will be filtered by C6. The summed pulse will be used to charge a RC network formed by R10 and C8. The voltage V3 sets the threshold of the activation function or when C8 will stop to charge. If the pulse is wide enough, C8 reaches the control voltage and the output pin of U3 goes low otherwise it’ll be in high state. It actually implements a NAND gate, a little bit different of the preceding example, but if you invert the output you‘ll have an AND gate.

Representing the 15V power supply voltage by VCC and t1 as the duration of the output pulse in U1 we can have the following general equations:


Putting t1 in the right side of the equation,

Similarly,


For the case showed before V1 and V2 can assume 5V ou 10V, or 1/3VCC and 2/3 Vcc, respectively (considering VCC=15V). Now we can compute substitute this values, and have:


So the product RC will work as the weights in the neuron network, changing them can change the relevance you give for such input.

For the third 555, we have this equation:

Where Vo is the voltage at the junction point of D2 and D3. And t3 is the sum of t1 and t2. When the two inputs are high, t3 must be at least 1.5 times t1H, to charge C8 enough to reach threshold and make the output low. So substituting t3 and the preceding equation:

We will make R2=R10 and C2=C8, so we can take them out of the equation, and so we have:

So since the output of the 555 generally swings from 0 to 13.5V, when powered by a 15V, and considering a 1V drop at the diode D2 and D3, a good estimate for Vo will be 12.5V:



Which gives our threshold voltage.

The diode D1 serves to isolate U1from U2 but gives an undesired effect, C2 only discharges to 0.7V, to compensate this, R2 was chosen to be slightly higher than R3 and R8.

The circuit was simulated to verify his behavior. One of the main advantages of neural networks is that minor changes in inputs values don’t affect the output. That was verified when I applied in V1=8V and V2=9V, in this case, since the two inputs are close to a high level voltage (10V) the circuit behaves as having two high levels in the output.

One drawback of this implementation is that we can’t have negative values for weights. But it’s possible to build big networks for classification, or to take complex decision in hardware.



Bibliography: Haykin, S.; Neural Networks: A comprehensive foundation; Second Edition; Prentice Hall; 1999.