An Interactive Simulation of The McCulloch Pitts Model Using Processing 3

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 4

An interactive simulation of the McCulloch Pitts

model using Processing 3


- Satyam Singh
- Chinmay Samudra
- Priyank Singh
- Anurag Gupta
This micro project was developed by the members of Group 8 (see above for the
names) as part of the NNFL course.
The aim of this project is to develop a software that would aid teaching the
McCulloch Pitts model to kids. We hope this project will help generate interest in
Neural Networks amongst school kids. While developing this software, we wanted
it not only to be easy to use but also easy to modify so that kids can modify in on
their own and experiment with it. Also, we didn’t want to restrict its functionality.
The above considerations convinced the developers to choose Processing 3 as the
platform on which the software should be developed. Processing 3 is relatively easy
to use as it has predefined functions that do all the heavy work associated with
generating the canvas, rendering etc. there by allowing the user to concentrate on
the software and utilizing his/her creativity to the fullest. Also, since the code inside
processing is actually written in JAVA, it does not restrict the user as far as
functionality is concerned. The code is written assuming that it will be modified and
experimented upon by many kids. Therefore, we have used an object-oriented
coding approach while developing this software.

To understand what the software is about, the user need only press the run button
on the processing editor. A canvas is generated and one can see the XOR gate being
simulated. There are 2 input nodes, a layer of 2 neurons fully connected to the 2
input nodes and another neuron connected to the first layer of neurons. The
connections between the neuron can be seen as blue coloured lines. These have
been referred to as “rods” in the code. Neurons in the same layer have the same
colour. Each neuron has a certain number of blocks stacked inside it. The number
of blocks denote the threshold. One can think of the blocks as forming a “wall” that
will only allow the signal to continue if the net height of the incoming green blocks
when stacked up is higher than or equal to the height of the “wall”. The red blocks
and green blocks can be thought of like anti-particles. When a red block and a green
block collide, they nullify each other and therefore their net height is zero.
Mathematically, a red block can be thought of as a negative number while a green
block can be thought of as a positive number.

Figure 1: Screenshot of the program running

If and when a neuron fires, it generates one green block else it does not generate
anything. This depicts the nature of the transfer function. It is one when the net
input is higher than the wall and is zero otherwise. One can recognize this as the
hard limit transfer function. When the neuron fires, the output one is immediately
multiplied by the weight of the connection. We can therefore see 2 blocks coming
out of the neurons in layer 1 whenever they fire. This is because the weight
associated with the connection between any neuron in layer one to the neuron in
layer 2 is 2. Also note that a red block can only be emitted when the connection
between 2 neurons has a negative weight.
The figure above is a screenshot of the software in action. The inputs are 1 and 0
respectively as seen in the figure. We can see that since the net number of green
boxes arriving at the first neuron in the first layer is equal to the threshold i.e.
height of green boxes is equal to height of the wall, the signal is allowed to transmit
further. Two boxes are emitted by this neuron because of the reasons mentioned
earlier. We can also see that since there is a negative connection between input
one and neuron 2 of layer 1, a red box reaches the aforementioned neuron. This
“signal” is not allowed to pass since the number of net green boxes is less than the
threshold. Going further, we can see that the output has also emitted a green box.
This indicates that the output is one. The output is correct since a XOR gate output
is 1 for dissimilar inputs.
Although we have implemented a XOR gate in this case, one may implement any
logical function using this software. As stated earlier, it is our hope that kids will try
to implement their favourite logical function using our software. Let us have a look
at the code to get a brief overview of what each part does. We have initially defined
a couple of Integer and Boolean global variables. The Boolean variables act as flags
for checking certain conditions. As an example, the Boolean variable “touching”
acts as a flag and becomes true whenever the block touches the neuron. Several
global arrays too are defined. These are of types circle, rod and block. These arrays
hold the objects as and when they are created. A couple of variables of type colour
are defined which hold the colours (rgb values) of the various elements. The reader
may be unfamiliar with the 2 internal functions of processing 3 called setup() and
draw() that are used in the code. These functions are actually very simple functions.
The function setup that returns void runs once when the program is run. The
function draw which also returns void, keeps on running once called until it is not
told to stop. We have used the setup function in a way that allows us to reset the
initial state of the global variables. This is achieved by the function mouseClicked().
This function is called whenever the mouse is clicked. This function first reinitializes
the arrays and then calls the setup() function. This helps “reset” the system as if
the program is run again. The keyPressed() function is called whenever any key is
pressed and it stores the key pressed in a variable called “key”. The developers have
used this variable to take the input value. The key ‘A’ corresponds to ‘1’ for the first
input neuron. The key ‘S’ corresponds to ‘0’ for the first input neuron. Similarly, the
keys ‘D’ and ‘F’ corresponds to ‘1’ and ‘0’ respectively for the second input neuron.
This is where the actual power of processing (and hence our software) can be seen.
The user need not develop his own functions for i/o operations. Since the mouse
can be clicked or key can be pressed at any time and not at any specific point of
time during the program execution, this can be a huge burden for the programmer
to handle if he were to do this in a conventional way. However, Processing’s
predefined functions make this process very easy. Information about all the
functions is freely available online at https://processing.org/.

This exercise helped us in not only understanding the McCulloch Pitts model
thoroughly but also made us stimulate our creative powers to come up with a way
interactive and interesting enough for kids. This process also resulted in us putting
an effort to understand and implement the Processing 3 platform which will help
us for future work as well. This was a new kind of an assignment for us, very
different from the routine and mundane ones we’re used to. We would like to
thank Dr. Basabdatta Bhattacharya for giving us an opportunity to work on this. We
sincerely hope this actually does help some kids to understand the M&P model
which is a very basic building block in the world of Neural Networks.

You might also like