0% found this document useful (0 votes)
1 views

SC_Practical_1

The document outlines a practical exercise to generate AND, OR, and NOT functions using a McCulloch-Pitts neural net. It includes a Python function that simulates the behavior of these logical gates based on specified weights and thresholds. The document also provides test cases for each gate type to demonstrate the functionality of the neural net.

Uploaded by

ikudi098
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
1 views

SC_Practical_1

The document outlines a practical exercise to generate AND, OR, and NOT functions using a McCulloch-Pitts neural net. It includes a Python function that simulates the behavior of these logical gates based on specified weights and thresholds. The document also provides test cases for each gate type to demonstrate the functionality of the neural net.

Uploaded by

ikudi098
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Practical No.

1
Aim:- Generate AND, OR and NOT functions using McCulloch-Pitts
neural net
def mcculloch_pitts_gate(gate_type, w1, w2=None, theta=0):

print(f"\n--- McCulloch-Pitts Net for {gate_type.upper()} function ---")

if gate_type == "and":

x1 = [1, 1, 0, 0]

x2 = [1, 0, 1, 0]

target_output = [1, 0, 0, 0]

elif gate_type == "or":

x1 = [1, 1, 0, 0]

x2 = [1, 0, 1, 0]

target_output = [1, 1, 1, 0]

elif gate_type == "not":

x1 = [1, 0]

target_output = [0, 1]

x2 = [0] * len(x1)

else:

print("Invalid gate type")

return

y = [0] * len(target_output)

con = True

while con:

zin = [(x1[i] * w1 + (x2[i] * w2 if w2 is not None else 0)) for i in range(len(target_output))]

for i in range(len(target_output)):

if zin[i] >= theta:

y[i] = 1

else:

y[i] = 0

print("Output of net =", y)

if y == target_output:

con = False
else:

print("Net is not learning. Adjust weights and threshold.")

break

print(f"McCulloch-Pitts Net for {gate_type.upper()} function")

print("Weights of neuron:")

print("w1 =", w1)

if w2 is not None:

print("w2 =", w2)

print("Threshold value =", theta)

print("Testing AND Gate:")

mcculloch_pitts_gate("and", w1=1, w2=1, theta=2)

print("\nTesting OR Gate:")

mcculloch_pitts_gate("or", w1=1, w2=1, theta=1)

print("\nTesting NOT Gate:")

mcculloch_pitts_gate("not", w1=-1, w2=None, theta=0)

Output:-

You might also like