diff --git a/prototypes/ga_gun_spike/ga_spike.nim b/prototypes/ga_gun_spike/ga_spike.nim deleted file mode 100644 index bdb5e6d..0000000 --- a/prototypes/ga_gun_spike/ga_spike.nim +++ /dev/null @@ -1,111 +0,0 @@ -## ga_spike.nim — throwaway GA neuroevolution spike: evolve ANN to predict sin(x) -## Validates: population init, fitness eval, truncation selection, gaussian -## mutation on all weights, single-elite preservation, champion tracking. -## Issue #66. - -import std/[math, random, algorithm, strformat] - -const - InputDim = 10 # sliding window of 10 past sin values - HiddenDim = 4 - OutputDim = 1 - NumWeights = (InputDim * HiddenDim + HiddenDim) + # W1 + b1 - (HiddenDim * OutputDim + OutputDim) # W2 + b2 = 49 - PopSize = 200 - Generations = 200 - TopFrac = 0.2 # keep top 20% - Sigma = 0.01 # gaussian mutation sigma on ALL weights - EvalPoints = 50 # fitness eval sample size - -type Individual = object - weights: seq[float64] - fitness: float64 - -proc forward(w: seq[float64]; input: array[InputDim, float64]): float64 = - ## 10->4->1 tanh ANN, flat weight layout: W1[40], b1[4], W2[4], b2[1] - var hidden: array[HiddenDim, float64] - for h in 0..= 0.1 — evolution did not converge" - echo "PASS: assert avgErr < 0.1" diff --git a/spike/arraymancer-test/arraymancer_test.nimble b/spike/arraymancer-test/arraymancer_test.nimble deleted file mode 100644 index 405439a..0000000 --- a/spike/arraymancer-test/arraymancer_test.nimble +++ /dev/null @@ -1,9 +0,0 @@ -# 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 deleted file mode 100755 index 9a0a2a5..0000000 Binary files a/spike/arraymancer-test/test_xor and /dev/null differ diff --git a/spike/arraymancer-test/test_xor.nim b/spike/arraymancer-test/test_xor.nim deleted file mode 100644 index 5c808db..0000000 --- a/spike/arraymancer-test/test_xor.nim +++ /dev/null @@ -1,63 +0,0 @@ -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"