started unlearning setup

This commit is contained in:
2026-05-31 22:22:38 +02:00
parent 770b7be936
commit e90480adbe
10 changed files with 229 additions and 5 deletions

48
OOP.py Normal file
View File

@@ -0,0 +1,48 @@
# This is from wikipedia pseudocode implementation of a single
# ThresholdLogic Unit.
# done to make me understand OOP the Python way
# no need for brackets if not inheriting
class ThresholdLogicUnit:
# define members in init
def __init__(self, threshold, weights):
self.threshold = threshold
self.weights = weights
# If a function has to make use of member variables
# it has to have self as param
def fire(self,inputs):
tots = 0
#for i in range(0,inputs.size()):
for val, weight in zip(inputs, self.weights):
if val:
tots+= weight
return tots > self.threshold
def main():
# data
weights = [0.5, -0.2, 0.8]
threshold = 1.0
# Instantiate the class
tlu = ThresholdLogicUnit(threshold, weights)
# Test
test_inputs = [1, 1, 0]
result = tlu.fire(test_inputs)
print(f"The unit fired: {result}")
# The "Guard"
if __name__ == "__main__":
main()