Implementation Of McCulloch Pitts Model In Python And Implementing The Logic Gates: Code, Advantages, Disadvantages

Implementation Of McCulloch Pitts Model In Python And Implementing The Logic Gates: Code, Advantages, Disadvantages
Implementation Of McCulloch Pitts Model In Python And Implementing The Logic Gates: Code, Advantages, Disadvantages


What Is Mc Culloch Pitts Model?
  1. It is a simple neuron model.
  2. The inputs are either 0 or 1.
  3. The input is either excitatory or inhibitory.
  4. The output obtained is 0 or 1.

Code:

n=int(input("Enter the threshold value = "))

print("1.AND\n2.OR\n3.NOT\n4.EXOR\n")

m=int(input("Enter the gate = "))

def AND(x):

result=[0,0,0,1]

for i in range(-6,6):

for j in range(-6,6):

sol=[]

for k in range(4):

y=i*x[k][0]+j*x[k][1]

if(y>n or y==n):

sol.append(1)

else:

sol.append(0)

if(sol==result and m == 4):

return(i,j,result)

elif(sol == result):

return(i,j)

def OR(x):

result=[0,1,1,1]

for i in range(-6,6):

for j in range(-6,6):

sol=[]

for k in range(4):

y=i*x[k][0]+j*x[k][1]

if(y>n or y==n):

sol.append(1)

else:

sol.append(0)

if(sol==result):

return(i,j)

def NOT(x):

result=[1,0]

input1=[0,1]


for i in range(-6,-1):

sol=[]

for k in range(2):

y=i*input1[k]

if(y>n or y==n):

sol.append(1)

else:

sol.append(0)

if(sol==result):

return(i)

def XOR(x):

#  PART I k = x

for i in range(len(k)): if(k[i][1] == 0): k[i][1] = 1
else: k[i][1] = 0

i,j,result_1 = AND(k) print("\nFirst weights = ",[i,j])
# PART II

k = x

for i in range(len(k)):

if(k[i][0] == 0):

k[i][1] = 1

else:

k[i][1] = 0

i,j,result_2 = AND(k)

print("\nSecond weights = ",[i,j])

i,j = OR(result_1, result_2)

print("\nFinal output weights = ",[i,j])



x=[[0,0],[0,1],[1,0],[1,1]]

while(m < 5):

if(m==1):

i,j = AND(x)

print("The possible weights are : ",[i,j])


elif(m==2):

i,j = OR(x)

print("The possible weights are : ",[i,j])

elif(m==3):

i = NOT(x)

print("The possible weight is : ",i)

elif(m==4):

XOR(x)

print("1.AND\n2.OR\n3.NOT\n4.EXOR\n")


m=int(input("Enter the gate = "))

Advantages:
  1. It has great computational power.
  2. It is very simple model.
Disadvantages:
  1. This model is not very flexible.
  2. The Weights and thresholds are fixed.




Post a Comment

0 Comments