Source: Deep Learning on Medium
MP Neuron is an elementary block of Deep Learning. It is a mathematical model, largely inspired from a biological neuron.
This model was given by Warren Sturgis McCulloch & Walter Pitts. They both had worked in the field of neuroscience. Due to their interest in this field, they proposed a highly simplified computational model of the neuron.
How does it work?
This model take binary inputs (i.e 0 or 1) and produce binary output. MP Neuron is divided into a series of two functions. The first function g aggregates the inputs and the function f takes decision based on this aggregation. Inputs can either excite or inhibit the neuron.
Hence the MP Neuron fires only when the sum of the inputs is greater than the threshold value (b).
The following mathematical expression represents the MP Neuron as:
The predicted output is given as
Range of bias (b)
The range of b is from 0 to n due to the following two extreme cases:
If all inputs are 0 then the aggregation of inputs is 0 hence the minimum value of b is 0.
If all inputs are 1 then the aggregation of inputs is n hence the maximum value of b is n.
The goal of this algorithm is to find the value of b for which the accuracy is maximum.
Here accuracy is given as
- Iterate over b from 0 to n
- For each iteration
Aggregate the inputs
Compare the aggregated value to b & predict output (y^)
- Output the accuracy and value of b for which accuracy is maximum.
Python implementation of MP Neuron
Loading the dataset
Here we have used sklearn library to import breast cancer dataset. The code extensively uses pandas library for data preprocessing. The code could be quite complex for someone not familiar with pandas library. However I have documented the large part of the code so that you can figure out the gist of the program.
MP Neuron Class
The code for MP Neuron class is fairly easy to understand as it doesn’t require the knowledge of pandas although you need to know numpy library.
It has three functions:
- model() — It aggregates the inputs & compares it with b. It returns 0 or 1.
- predict() — It predicts the output y^ for a particular value of b.
- fit() — This function calculates the accuracy for different values of b and then outputs the accuracy & value of b for which accuracy is maximum.
Why do we need a better model than MP Neuron?
- It works with only binary inputs and binary outputs.
- All the inputs have equal weightage.
- The model fails when the data is not linear.
Disclaimer- The content of this article is largely inspired from the Deep Learning course offered by One Fourth Labs