bones-ai / odin-mnist-nn

A MNIST neural network written from scratch in Odin, visualised with Raylib
MIT License
158 stars 11 forks source link

General Improvements #1

Open gingerBill opened 1 month ago

gingerBill commented 1 month ago

Don't forget about array programming

https://github.com/bones-ai/odin-mnist-nn/blob/eb32f633d242f827d43407a02382af2f60426736/viz.odin#L205-L209

shape_pos = (s.start + s.end)/2

https://github.com/bones-ai/odin-mnist-nn/blob/eb32f633d242f827d43407a02382af2f60426736/train.odin#L280

clamp is already a built-in operation just like min and max. Just use clamp(x, lo, hi) anywhere.


ui_checkbox should return bool instead of taking a callback.

https://github.com/bones-ai/odin-mnist-nn/blob/eb32f633d242f827d43407a02382af2f60426736/viz.odin#L539-L557

if ui_checkbox("Rotate Cam", {30, 30}, g_flags.cam_rotate) {
    g_flags.cam_rotate = !g_flags.cam_rotate
}
if ui_checkbox("Show Connections", {30, 60}, g_flags.draw_connections) {
    g_flags.draw_connections = !g_flags.draw_connections
}
if ui_checkbox("Show Cube Lines", {30, 90}, g_flags.draw_cube_lines) {
    g_flags.draw_cube_lines = !g_flags.draw_cube_lines
}
if ui_checkbox("Show Cubes", {30, 120}, g_flags.draw_cubes) {
    g_flags.draw_cubes = !g_flags.draw_cubes
}
if ui_checkbox("Show Weight Cloud", {30, 150}, g_flags.draw_weight_cloud) {
    g_flags.draw_weight_cloud = !g_flags.draw_weight_cloud
}
if ui_checkbox("Load Test Images", {30, 180}, g_flags.load_test_imgs) {
    g_flags.load_test_imgs = !g_flags.load_test_imgs
}

https://github.com/bones-ai/odin-mnist-nn/blob/eb32f633d242f827d43407a02382af2f60426736/train.odin#L27-L30

ret = make([dynamic]MnistRecord, size)
for i := 0; ; i += 1 {
    ...

https://github.com/bones-ai/odin-mnist-nn/blob/eb32f633d242f827d43407a02382af2f60426736/train.odin#L78C4-L78C18

Typo? trian vs trian?


Possible division by zero?

https://github.com/bones-ai/odin-mnist-nn/blob/eb32f633d242f827d43407a02382af2f60426736/train.odin#L155

return f32(count) / max(f32(len(test_dataset)), 1)
bones-ai commented 1 month ago

hey, thanks for pointing these things out :)