summaryrefslogtreecommitdiff
path: root/mlp.c
diff options
context:
space:
mode:
authorroot <root@annapurna.annapurna.fitness>2025-07-09 15:17:00 +0200
committerroot <root@annapurna.annapurna.fitness>2025-07-09 15:17:00 +0200
commitd51d905f4b593ba472fc73d91ea6a909cde98c0e (patch)
tree136d45b7277a6837c0d11d7f0598a22c1f9ce215 /mlp.c
initial commitHEADmaster
Diffstat (limited to 'mlp.c')
-rw-r--r--mlp.c88
1 files changed, 88 insertions, 0 deletions
diff --git a/mlp.c b/mlp.c
new file mode 100644
index 0000000..b22b281
--- /dev/null
+++ b/mlp.c
@@ -0,0 +1,88 @@
+#include <stdio.h>
+#include <stdint.h>
+#include <stdlib.h>
+#include <arpa/inet.h>
+
+float leaky_relu(float input);
+float relu(float input);
+void print_numbers(char *file_location);
+float softmax(int num_inputs, float *inputs_list);
+
+struct neuron
+
+int main(void)
+{
+ char *file_location = "/home/sp1ral/Schreibtisch/MNIST/train-images.idx3-ubyte";
+ print_numbers(file_location);
+ return 0;
+}
+
+float leaky_relu(float input)
+{
+ float leak = input / 10;
+ float output = leak > input ? leak : input;
+ return output;
+}
+
+float relu(float input)
+{
+ float output = input > 0 ? input : 0;
+ return output;
+}
+
+void print_numbers(char *file_location)
+{
+ FILE *f;
+ f = fopen(file_location, "r");
+
+ int32_t magic_number, num_items;
+
+ fread(&magic_number, 1, sizeof(magic_number), f);
+ fread(&num_items, 1, sizeof(num_items), f);
+
+ magic_number = ntohl(magic_number);
+ num_items = ntohl(num_items);
+
+ int32_t width_image, height_image;
+
+ fread(&width_image, 1, sizeof(width_image), f);
+ fread(&height_image, 1, sizeof(height_image), f);
+
+ width_image = ntohl(width_image);
+ height_image = ntohl(height_image);
+
+ printf("Magic number -> %d\n", magic_number);
+ printf("Number of items -> %d\n", num_items);
+ printf("Width image -> %d\n", width_image);
+ printf("Height image -> %d\n", height_image);
+ printf("\n");
+
+ char line[28];
+ char pixel;
+ for (int item_num = 0; item_num < num_items; item_num++) {
+ for (int i = 0; i < 28; i++) {
+ fread(&line, 1, sizeof(line), f);
+ for (int j = 0; j < 28; j++) {
+ pixel = line[j];
+ if (pixel) {
+ printf("1");
+ } else {
+ printf("0");
+ }
+ }
+ printf("\n");
+ }
+ printf("\n");
+ }
+
+ fclose(f);
+}
+
+float softmax(int num_inputs, float *inputs_list)
+{
+ float sum;
+ for (int input_num = 0; input_num < num_inputs; input_num++) {
+ sum += inputs_list[input_num];
+ }
+ return sum / inputs->num_inputs;
+}