#load "core/std"
-#load_path "src"
-#load "neuralnet"
+#load "src/neuralnet"
use package core
train(^nn, ^mnist_data.base, ^optimizer);
}
-
-
-
-
-// Old code for printing the outputs fancily:
-/*
- {
- print_colored_array :: (arr: [] $T, color_idx: i32, color_code := 94) {
- for i: arr.count {
- if i == color_idx {
- printf("\x1b[%im", color_code);
- print(arr[i]);
- print("\x1b[0m ");
- } else {
- print(arr[i]);
- print(" ");
- }
- }
- print("\n");
- }
-
- color := 94;
- if prediction != label do color = 91;
-
- output := nn->get_output();
-
- print_colored_array(sample.output, label, color);
- print_colored_array(output, prediction, color);
-
- loss := nn->get_loss(sample.output, criterion);
- printf("Loss: %f Correct: %i / 100\n", cast(f32) loss, past_100_correct);
-
- past_100_correct = 0;
-
- // if ex % 10000 == 0 {
- // println("Saving neural network...");
- // neural_net_save(nn, "data/still_working.nn");
- // }
- }
- */
optimizer_init :: (use optim: ^Optimizer, nn: ^NeuralNet, allocator := context.allocator) {
network = nn;
- #context_scope {
- context.allocator = allocator;
-
- variables = array.make(#type ^Variable);
- variable_arrays = array.make(#type ^[] Variable);
- }
+ variables = array.make(#type ^Variable, allocator=allocator);
+ variable_arrays = array.make(#type ^[] Variable, allocator=allocator);
}
optimizer_step :: (use optim: ^Optimizer, scale: f32 = 1) {
variable.value += variable.delta * alpha;
}
}
-}
\ No newline at end of file
+}