const std = @import("std");
const SimpleNetwork = @import("network.zig").SimpleNetwork;

pub fn main() !void {
    var net = SimpleNetwork.init(1234);

    const inputs = [_][2]f32{
        .{ 0.0, 0.0 },
        .{ 0.0, 1.0 },
        .{ 1.0, 0.0 },
        .{ 1.0, 1.0 },
    };

    const targets = [_]f32{ 0.0, 1.0, 1.0, 0.0 };

    const lr: f32 = 0.5;

    std.debug.print("--- TRAINING XOR (2 LAYERS) ---\n", .{});

    var epoch: usize = 0;
    while (epoch < 10000) : (epoch += 1) {
        var total_loss: f32 = 0.0;

        for (inputs, 0..) |inp, i| {
            total_loss += net.train(inp, targets[i], lr);
        }

        if (epoch % 1000 == 0) {
            std.debug.print("Epoca {d}: Loss = {d:.6}\n", .{ epoch, total_loss / 4.0 });
        }
    }

    std.debug.print("\n--- TEST XOR ---\n", .{});
    for (inputs) |inp| {
        const out = net.forward(inp);
        const bit: u8 = if (out > 0.5) 1 else 0;
        std.debug.print("In: {d:.0},{d:.0} -> Out: {d:.4} -> {d}\n", .{ inp[0], inp[1], out, bit });
    }
}
