Compare commits

..

No commits in common. "7aa57191da9231916cf77d4bbd8f8e0d76f66a8a" and "56d59b1b5049f20c0f75912c44eed9359483a3a2" have entirely different histories.

2 changed files with 13 additions and 32 deletions

View File

@ -90,6 +90,9 @@ Matrix broadCastRows(const Matrix matrix, const unsigned int rows,
Matrix add(const Matrix matrix1, const Matrix matrix2) {
// Broadcasting nur bei Vektor und Matrix, Fehlermeldung bei zwei unpassenden
// Matrizen
const unsigned int rows1 = matrix1.rows;
const unsigned int rows2 = matrix2.rows;
const unsigned int cols1 = matrix1.cols;
@ -209,8 +212,8 @@ Matrix add(const Matrix matrix1, const Matrix matrix2) {
}
else {
printf("Fehlermeldung"); // vielleicht Fehlermeldung ändern zu
// Programmabbruch
printf(
"Fehlermeldung"); // vielleicht Fehlermeldung ändern zu Programmabbruch
Matrix error = {0, 0, NULL};
return error;
}

View File

@ -5,50 +5,28 @@
#include <stdlib.h>
#include <string.h>
/*typedef struct
{
Matrix weights;
Matrix biases;
ActivationFunctionType activation;
} Layer;
typedef struct
{
Layer *layers;
unsigned int numberOfLayers;
} NeuralNetwork;*/
/*Layer: Ebene im neuronalen Netzwerk, besteht aus mehreren Neuronen
Input-Layer: Eingabedatei
Hidden-Layer: verarbeiten die Daten
Output-Layer: Ergebnis
Gewichte: bestimmen, wie stark ein Eingangssignal auf ein Neuron wirkt
Dimension: Form der Matrizen für einen Layer*/
// speichert NeuralNetwork nn in binäre Datei->erzeugt Dateiformat
static void prepareNeuralNetworkFile(const char *path, const NeuralNetwork nn) {
FILE *f = fopen(path, "wb"); // Binärdatei zum Schreiben öffnen
FILE *f = fopen(path, "wb");
if (f == NULL)
return;
// Header ist Erkennungsstring am Anfang der Datei, loadmodel erkennt
// Dateiformat
/* 1) Header: exakt das String, ohne '\n' oder abschließendes '\0' */
const char header[] = "__info2_neural_network_file_format__";
fwrite(header, sizeof(char), strlen(header), f);
// Wenn es keine Layer gibt, 0 eintragen, LoadModel gibt 0 zurück
/* Wenn es keine Layer gibt, kein Dimensionspaar schreiben (loadModel
wird beim Lesen dann 0 zurückgeben). Aber wir können auch frühzeitig
mit einem 0-Int terminieren beides ist in Ordnung. */
if (nn.numberOfLayers == 0) {
/* optional: schreibe ein 0 als next outputDimension (nicht nötig) */
int zero = 0;
fwrite(&zero, sizeof(int), 1, f);
fclose(f);
return;
}
// Layer 0, inputDimension: Anzahl Input-Neuronen, outputDimension: Anzahl
// Output-Neuronen
/* 2) Für die erste Layer schreiben wir inputDimension und outputDimension */
/* inputDimension == weights.cols, outputDimension == weights.rows */
int inputDim = (int)nn.layers[0].weights.cols;
int outputDim = (int)nn.layers[0].weights.rows;
fwrite(&inputDim, sizeof(int), 1, f);