Skip to content
Closed
Changes from 1 commit
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
31faa5f
added my code in and folder
IBR-41379 Oct 10, 2023
bb40ab3
Appropriated the name of the existing program according to the repo i…
IBR-41379 Oct 10, 2023
578b159
Rename Simple_Adaline.py to simple_adaline.py
IBR-41379 Oct 10, 2023
0154cd4
Chaged the name of yhe folder according to the convention.
IBR-41379 Oct 10, 2023
c08165b
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 10, 2023
5f373c1
Update simple_adaline.py
IBR-41379 Oct 10, 2023
b3a7404
Rename Churn_Modelling.csv to churn_modelling.csv
IBR-41379 Oct 10, 2023
d5af854
Update churn_cal.py
IBR-41379 Oct 10, 2023
669cf9d
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 10, 2023
df219a0
Update simple_adaline.py
IBR-41379 Oct 10, 2023
7dd3fb5
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 10, 2023
537d850
Update churn_cal.py
IBR-41379 Oct 10, 2023
38a8a0b
Update simple_adaline.py
IBR-41379 Oct 10, 2023
e0f8aa1
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 10, 2023
52b868f
Made appropriate changes to churn_cal
IBR-41379 Oct 11, 2023
6239124
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 11, 2023
e60546a
Made some changes to pass the test
IBR-41379 Oct 11, 2023
86af749
Made changes to pass the test
IBR-41379 Oct 11, 2023
ceed900
Made changes to the file to pass the ruff test
IBR-41379 Oct 11, 2023
4156be4
Modified file according to requirement
IBR-41379 Oct 11, 2023
03e5235
Update machine_learning/decision_tree_churn/churn_cal.py
IBR-41379 Oct 11, 2023
87e3e8b
Update machine_learning/decision_tree_churn/churn_cal.py
IBR-41379 Oct 11, 2023
632be92
Apply suggestions from code review
cclauss Oct 11, 2023
b62c9b4
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 11, 2023
9800d56
Update churn_cal.py
cclauss Oct 11, 2023
94e542d
appropriate changes made to both the files
IBR-41379 Oct 11, 2023
dd0ae6b
Made appropriate changes to churn_cal
IBR-41379 Oct 11, 2023
811fdf2
Made some more appropriate changes
IBR-41379 Oct 11, 2023
266edfe
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 11, 2023
38f492c
made changes for the tests
IBR-41379 Oct 11, 2023
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
  • Loading branch information
pre-commit-ci[bot] committed Oct 10, 2023
commit 7dd3fb500925040f9f46fe18e72a26ca91f95748
78 changes: 50 additions & 28 deletions neural_network/simple_adaline.py
Original file line number Diff line number Diff line change
@@ -1,59 +1,69 @@
# This program implements the AND and OR gates using the Adaline algorithm.
def weight_change_or(weight: list[float], threshold: float, learning_rate: float) -> list[float]:
output = weight[0]*0 + weight[1]*0
def weight_change_or(
weight: list[float], threshold: float, learning_rate: float
) -> list[float]:
output = weight[0] * 0 + weight[1] * 0
if output <= threshold:
output_left = weight[0]*0 + weight[1]*1
output_left = weight[0] * 0 + weight[1] * 1
if output_left >= threshold:
output_left_down = weight[0]*1 + weight[1]*0
output_left_down = weight[0] * 1 + weight[1] * 0
if output_left_down >= threshold:
output_all = weight[0]*1 + weight[1]*1
output_all = weight[0] * 1 + weight[1] * 1
if output_all >= threshold:
return weight
else:
weight[0] = weight[0] + learning_rate*1*1
weight[1] = weight[1] + learning_rate*1*1
weight[0] = weight[0] + learning_rate * 1 * 1
weight[1] = weight[1] + learning_rate * 1 * 1
return weight_change_or(weight, threshold, learning_rate)
else:
weight[0] = weight[0] + learning_rate*1*1
weight[1] = weight[1] + learning_rate*1*0
weight[0] = weight[0] + learning_rate * 1 * 1
weight[1] = weight[1] + learning_rate * 1 * 0
return weight_change_or(weight, threshold, learning_rate)
else:
weight[0] = weight[0] + learning_rate*1*0
weight[1] = weight[1] + learning_rate*1*1
weight[0] = weight[0] + learning_rate * 1 * 0
weight[1] = weight[1] + learning_rate * 1 * 1
return weight_change_or(weight, threshold, learning_rate)
else:
threshold += learning_rate
return weight_change_or(weight, threshold, learning_rate)


def weight_change_and(weight: list[float], threshold: float, learning_rate: float) -> list[float]:
output = weight[0]*0 + weight[1]*0
def weight_change_and(
weight: list[float], threshold: float, learning_rate: float
) -> list[float]:
output = weight[0] * 0 + weight[1] * 0
if output <= threshold:
output_left = weight[0]*0 + weight[1]*1
output_left = weight[0] * 0 + weight[1] * 1
if output_left <= threshold:
output_left_down = weight[0]*1 + weight[1]*0
output_left_down = weight[0] * 1 + weight[1] * 0
if output_left_down <= threshold:
output_all = weight[0]*1 + weight[1]*1
output_all = weight[0] * 1 + weight[1] * 1
if output_all >= threshold:
return weight
else:
weight[0] = weight[0] + (learning_rate*1*1)
weight[1] = weight[1] + (learning_rate*1*1)
weight[0] = weight[0] + (learning_rate * 1 * 1)
weight[1] = weight[1] + (learning_rate * 1 * 1)
return weight_change_and(weight, threshold, learning_rate)
else:
weight[0] = weight[0] - (learning_rate*1*1)
weight[1] = weight[1] - (learning_rate*1*0)
weight[0] = weight[0] - (learning_rate * 1 * 1)
weight[1] = weight[1] - (learning_rate * 1 * 0)
return weight_change_and(weight, threshold, learning_rate)
else:
weight[0] = weight[0] - (learning_rate*1*0)
weight[1] = weight[1] - (learning_rate*1*1)
weight[0] = weight[0] - (learning_rate * 1 * 0)
weight[1] = weight[1] - (learning_rate * 1 * 1)
return weight_change_and(weight, threshold, learning_rate)
else:
threshold += learning_rate
return weight_change_and(weight, threshold, learning_rate)


def and_gate(weight: list[float], input_a: int, input_b: int, threshold: float, learning_rate: float) -> int:
def and_gate(
weight: list[float],
input_a: int,
input_b: int,
threshold: float,
learning_rate: float,
) -> int:
"""
This function implements the AND gate using the Adaline algorithm.

Expand All @@ -68,14 +78,20 @@ def and_gate(weight: list[float], input_a: int, input_b: int, threshold: float,
int: The output of the AND gate.
"""
weight = weight_change_and(weight, threshold, learning_rate)
output = weight[0]*input_a + weight[1]*input_b
output = weight[0] * input_a + weight[1] * input_b
if output >= threshold:
return 1
else:
return 0


def or_gate(weight: list[float], input_a: int, input_b: int, threshold: float, learning_rate: float) -> int:
def or_gate(
weight: list[float],
input_a: int,
input_b: int,
threshold: float,
learning_rate: float,
) -> int:
"""
This function implements the OR gate using the Adaline algorithm.

Expand All @@ -90,7 +106,7 @@ def or_gate(weight: list[float], input_a: int, input_b: int, threshold: float, l
int: The output of the OR gate.
"""
weight = weight_change_or(weight, threshold, learning_rate)
output = weight[0]*input_a + weight[1]*input_b
output = weight[0] * input_a + weight[1] * input_b
if output >= threshold:
return 1
else:
Expand All @@ -104,5 +120,11 @@ def or_gate(weight: list[float], input_a: int, input_b: int, threshold: float, l
input_a, input_b = input("Input the value of A and B:").split()
input_a = int(input_a)
input_b = int(input_b)
print("\nThe output of OR is:", or_gate(weight, input_a, input_b, threshold, learning_rate))
print("\nThe output of AND is:", and_gate(weight2, input_a, input_b, threshold, learning_rate))
print(
"\nThe output of OR is:",
or_gate(weight, input_a, input_b, threshold, learning_rate),
)
print(
"\nThe output of AND is:",
and_gate(weight2, input_a, input_b, threshold, learning_rate),
)