Compare commits

..

5 Commits

Author SHA1 Message Date
Simon Wiesend
bbb0ea1cf5
Merge branch 'main' into neuralNetworkTests 2025-11-25 13:40:23 +01:00
Simon Wiesend
12825cc1d3
Revert "neuralNetwork fixed". The root cause has been fixed in matrix.h
This reverts commit 6ba9ba319592ac3aac15723ad549f1389b5c9718.
2025-11-25 13:38:56 +01:00
6ba9ba3195 neuralNetwork fixed 2025-11-24 08:24:37 +00:00
f4427d2892 unittests bestanden 2025-11-23 16:38:17 +00:00
84b65525a6 Funktion implementiert / nicht getestet 2025-11-23 12:04:25 +00:00

View File

@ -5,10 +5,46 @@
#include "unity.h"
#include "neuralNetwork.h"
static void writeLayer(FILE *file, const Matrix weights, const Matrix biases, unsigned int inputDim)
{
unsigned int outputDim = (unsigned int)weights.rows;
fwrite(&outputDim, sizeof(unsigned int), 1, file);
if (weights.buffer != NULL)
fwrite(weights.buffer, sizeof(MatrixType), outputDim * inputDim, file);
if (biases.buffer != NULL)
fwrite(biases.buffer, sizeof(MatrixType), outputDim, file);
}
static void prepareNeuralNetworkFile(const char *path, const NeuralNetwork nn)
{
// TODO
FILE *file = fopen(path, "wb");
if (!file) return;
const char tag[] = "__info2_neural_network_file_format__";
fwrite(tag, sizeof(char), strlen(tag), file);
if (nn.numberOfLayers == 0)
{
unsigned int zero = 0;
fwrite(&zero, sizeof(unsigned int), 1, file);
fclose(file);
return;
}
unsigned int inputDim = (unsigned int)nn.layers[0].weights.cols;
fwrite(&inputDim, sizeof(unsigned int), 1, file);
for (int i = 0; i < nn.numberOfLayers; i++)
{
writeLayer(file, nn.layers[i].weights, nn.layers[i].biases, inputDim);
inputDim = (unsigned int)nn.layers[i].weights.rows;
}
unsigned int zero = 0;
fwrite(&zero, sizeof(unsigned int), 1, file);
fclose(file);
}
void test_loadModelReturnsCorrectNumberOfLayers(void)