summaryrefslogtreecommitdiff
path: root/mlp.c
blob: b22b2815f4b32f5e0a2479f65bdb5dd19a11e52a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
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;
}