commit c256f2913f4f21db9bfe3908bcd2df4705e3111b Author: hasslesstech Date: Fri Sep 12 18:53:55 2025 +0300 initial commit diff --git a/train.py b/train.py new file mode 100644 index 0000000..146dce3 --- /dev/null +++ b/train.py @@ -0,0 +1,39 @@ +import tensorflow as tf +import numpy as np + +x = np.array([ + [0, 0, 0], + [0, 0, 1], + [0, 1, 0], + [0, 1, 1], + [1, 0, 0], + [1, 0, 1], + [1, 1, 0], + [1, 1, 1], +]) + +y = np.array([sum(i) % 2 for i in x]) + +model = tf.keras.Sequential([ + tf.keras.layers.Input(shape = (3,)), + tf.keras.layers.Dense(3, activation = "tanh"), + tf.keras.layers.Dense(1, activation = "sigmoid") +]) + +model.compile( + optimizer = tf.keras.optimizers.Adam(learning_rate = 0.05), + loss = "binary_crossentropy", + metrics = ["accuracy"] +) + +for _ in range(100): + model.fit(x, y, epochs = 10, verbose = 0) + loss, accuracy = model.evaluate(x, y, verbose = 0) + + print(f"\rAchieved accuracy={accuracy}, loss={loss}", end = '') + + if accuracy == 1.0: + print() + break + +model.save_weights("mod1_final.weights.h5") diff --git a/verify.py b/verify.py new file mode 100644 index 0000000..2c60208 --- /dev/null +++ b/verify.py @@ -0,0 +1,34 @@ +import tensorflow as tf +import numpy as np + +x = np.array([ + [0, 0, 0], + [0, 0, 1], + [0, 1, 0], + [0, 1, 1], + [1, 0, 0], + [1, 0, 1], + [1, 1, 0], + [1, 1, 1], +]) + +y = np.array([sum(i) % 2 for i in x]) + +model = tf.keras.Sequential([ + tf.keras.layers.Input(shape = (3,)), + tf.keras.layers.Dense(3, activation = "tanh"), + tf.keras.layers.Dense(1, activation = "sigmoid") +]) + +model.compile( + optimizer = tf.keras.optimizers.Adam(learning_rate = 0.05), + loss = "binary_crossentropy", + metrics = ["accuracy"] +) + +model.load_weights("mod1_final.weights.h5") + +prediction = model.predict(x) + +for i, o, t in zip(x, prediction, y): + print(f"i = {i}, o = {round(o[0])}, t = {t} : {'Good' if t == round(o[0]) else 'Bad'}")