diff --git a/PPO_Bot/PPO_Bot b/PPO_Bot/PPO_Bot new file mode 100755 index 0000000..12b7567 Binary files /dev/null and b/PPO_Bot/PPO_Bot differ diff --git a/PPO_Bot/tests/test_network b/PPO_Bot/tests/test_network new file mode 100755 index 0000000..5a70dc6 Binary files /dev/null and b/PPO_Bot/tests/test_network differ diff --git a/PPO_Bot/tests/test_state b/PPO_Bot/tests/test_state new file mode 100755 index 0000000..d3be37f Binary files /dev/null and b/PPO_Bot/tests/test_state differ diff --git a/PPO_Bot/tests/test_training b/PPO_Bot/tests/test_training new file mode 100755 index 0000000..c62ab93 Binary files /dev/null and b/PPO_Bot/tests/test_training differ diff --git a/PPO_Bot/tests/test_weights b/PPO_Bot/tests/test_weights new file mode 100755 index 0000000..e4c3214 Binary files /dev/null and b/PPO_Bot/tests/test_weights differ diff --git a/PPO_Bot/training b/PPO_Bot/training new file mode 100755 index 0000000..df1ef13 Binary files /dev/null and b/PPO_Bot/training differ diff --git a/PPO_Bot/weights/latest/actor_b1.npy b/PPO_Bot/weights/latest/actor_b1.npy new file mode 100644 index 0000000..1c10c11 Binary files /dev/null and b/PPO_Bot/weights/latest/actor_b1.npy differ diff --git a/PPO_Bot/weights/latest/actor_b2.npy b/PPO_Bot/weights/latest/actor_b2.npy new file mode 100644 index 0000000..2f1d835 Binary files /dev/null and b/PPO_Bot/weights/latest/actor_b2.npy differ diff --git a/PPO_Bot/weights/latest/actor_b3.npy b/PPO_Bot/weights/latest/actor_b3.npy new file mode 100644 index 0000000..acbb141 Binary files /dev/null and b/PPO_Bot/weights/latest/actor_b3.npy differ diff --git a/PPO_Bot/weights/latest/actor_w1.npy b/PPO_Bot/weights/latest/actor_w1.npy new file mode 100644 index 0000000..bc95bb4 Binary files /dev/null and b/PPO_Bot/weights/latest/actor_w1.npy differ diff --git a/PPO_Bot/weights/latest/actor_w2.npy b/PPO_Bot/weights/latest/actor_w2.npy new file mode 100644 index 0000000..1d68db7 Binary files /dev/null and b/PPO_Bot/weights/latest/actor_w2.npy differ diff --git a/PPO_Bot/weights/latest/actor_w3.npy b/PPO_Bot/weights/latest/actor_w3.npy new file mode 100644 index 0000000..42050b6 Binary files /dev/null and b/PPO_Bot/weights/latest/actor_w3.npy differ diff --git a/PPO_Bot/weights/latest/critic_b1.npy b/PPO_Bot/weights/latest/critic_b1.npy new file mode 100644 index 0000000..2445d45 Binary files /dev/null and b/PPO_Bot/weights/latest/critic_b1.npy differ diff --git a/PPO_Bot/weights/latest/critic_b2.npy b/PPO_Bot/weights/latest/critic_b2.npy new file mode 100644 index 0000000..df9777c Binary files /dev/null and b/PPO_Bot/weights/latest/critic_b2.npy differ diff --git a/PPO_Bot/weights/latest/critic_b3.npy b/PPO_Bot/weights/latest/critic_b3.npy new file mode 100644 index 0000000..80fdf4a Binary files /dev/null and b/PPO_Bot/weights/latest/critic_b3.npy differ diff --git a/PPO_Bot/weights/latest/critic_w1.npy b/PPO_Bot/weights/latest/critic_w1.npy new file mode 100644 index 0000000..4bc8eb7 Binary files /dev/null and b/PPO_Bot/weights/latest/critic_w1.npy differ diff --git a/PPO_Bot/weights/latest/critic_w2.npy b/PPO_Bot/weights/latest/critic_w2.npy new file mode 100644 index 0000000..f595f9b Binary files /dev/null and b/PPO_Bot/weights/latest/critic_w2.npy differ diff --git a/PPO_Bot/weights/latest/critic_w3.npy b/PPO_Bot/weights/latest/critic_w3.npy new file mode 100644 index 0000000..ccb4d77 Binary files /dev/null and b/PPO_Bot/weights/latest/critic_w3.npy differ diff --git a/PPO_Bot/weights/latest/log_std.npy b/PPO_Bot/weights/latest/log_std.npy new file mode 100644 index 0000000..e9ce775 Binary files /dev/null and b/PPO_Bot/weights/latest/log_std.npy differ diff --git a/spike/arraymancer-test/arraymancer_test.nimble b/spike/arraymancer-test/arraymancer_test.nimble new file mode 100644 index 0000000..405439a --- /dev/null +++ b/spike/arraymancer-test/arraymancer_test.nimble @@ -0,0 +1,9 @@ +# Package +version = "0.1.0" +author = "SirStone" +description = "Arraymancer viability spike — XOR perceptron" +license = "MIT" + +# Dependencies +requires "nim >= 2.0.0" +requires "arraymancer >= 0.7.0" diff --git a/spike/arraymancer-test/test_xor b/spike/arraymancer-test/test_xor new file mode 100755 index 0000000..9a0a2a5 Binary files /dev/null and b/spike/arraymancer-test/test_xor differ diff --git a/spike/arraymancer-test/test_xor.nim b/spike/arraymancer-test/test_xor.nim new file mode 100644 index 0000000..5c808db --- /dev/null +++ b/spike/arraymancer-test/test_xor.nim @@ -0,0 +1,63 @@ +import arraymancer +import std/[strformat, times] + +# XOR dataset — [4,2] inputs, [4,1] targets +let xData = [[0.0'f32, 0.0'f32], + [0.0'f32, 1.0'f32], + [1.0'f32, 0.0'f32], + [1.0'f32, 1.0'f32]].toTensor() + +let yData = [[0.0'f32], [1.0'f32], [1.0'f32], [0.0'f32]].toTensor() + +var ctx = newContext Tensor[float32] + +let l1 = ctx.init(Linear[float32], 2, 4) +let l2 = ctx.init(Linear[float32], 4, 1) + +type XorNet = object + l1: Linear[float32] + l2: Linear[float32] + +var net = XorNet(l1: l1, l2: l2) +var adam = optimizer(net, Adam, learning_rate = 0.01'f32) + +let t0 = cpuTime() + +for epoch in 1..1000: + let xVar = ctx.variable(xData) + let yVar = ctx.variable(yData) + + # Forward + let h = l1.forward(xVar).sigmoid() + let pred = l2.forward(h).sigmoid() + + # MSE loss: mean((pred - y)^2) + let diff = pred - yVar + let loss = mean(diff *. diff) + + if epoch mod 200 == 0: + echo &"Epoch {epoch:4d} loss = {loss.value[0]:.6f}" + + loss.backprop() + adam.update() + +let trainTime = cpuTime() - t0 + +# Inference (no grad) +echo "" +echo "Final predictions:" +let xVar = ctx.variable(xData) +let hInf = l1.forward(xVar).sigmoid() +let preds = l2.forward(hInf).sigmoid() + +var allCorrect = true +for i in 0..<4: + let p = preds.value[i, 0] + let rounded = if p >= 0.5'f32: 1 else: 0 + let expected = [0,1,1,0][i] + if rounded != expected: allCorrect = false + echo &" [{xData[i,0].int},{xData[i,1].int}] -> {p:.4f} (rounded: {rounded}, expected: {expected})" + +echo "" +echo &"All correct: {allCorrect}" +echo &"Training time: {trainTime:.2f}s"