From 6b6080459f461e1a34659437996e969fdc246ed3 Mon Sep 17 00:00:00 2001 From: haemmerlre98889 Date: Fri, 21 Nov 2025 15:15:27 +0100 Subject: [PATCH 1/6] Haeder hinzugefuegt --- neuralNetworkTests.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/neuralNetworkTests.c b/neuralNetworkTests.c index 21ab370..35890ca 100644 --- a/neuralNetworkTests.c +++ b/neuralNetworkTests.c @@ -4,11 +4,20 @@ #include #include "unity.h" #include "neuralNetwork.h" - +//Dateischichten sind in neuralNetwork.h definiert static void prepareNeuralNetworkFile(const char *path, const NeuralNetwork nn) { - // TODO + // Datei oeffnen + FILE *fopen(const char *NeuralNetwork, const char *r); + + if (__info2_neural_network_file_format__ == NULL) return 1; + + // Dateiname: __info2_neural_network_file_format__ + + + // Datei wieder schließen! + int fclose(FILE *path); } void test_loadModelReturnsCorrectNumberOfLayers(void) -- 2.47.2 From e07287edde729e19872b6a2b7142bdb93e21d1aa Mon Sep 17 00:00:00 2001 From: haemmerlre98889 Date: Sat, 22 Nov 2025 09:50:08 +0100 Subject: [PATCH 2/6] Testdatei fertig geschrieben --- neuralNetworkTests.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/neuralNetworkTests.c b/neuralNetworkTests.c index 35890ca..6489a55 100644 --- a/neuralNetworkTests.c +++ b/neuralNetworkTests.c @@ -4,20 +4,26 @@ #include #include "unity.h" #include "neuralNetwork.h" +#include "neuralNetwork.c" //Dateischichten sind in neuralNetwork.h definiert +// Dateiname: __info2_neural_network_file_format__ static void prepareNeuralNetworkFile(const char *path, const NeuralNetwork nn) { // Datei oeffnen - FILE *fopen(const char *NeuralNetwork, const char *r); + FILE *file = fopen(path, "wb"); - if (__info2_neural_network_file_format__ == NULL) return 1; - // Dateiname: __info2_neural_network_file_format__ + if (file == NULL) + return 1; + + // header schreiben + fwrite(FILE_HEADER_STRING, sizeof(char), strlen(FILE_HEADER_STRING), file); + // Datei wieder schließen! - int fclose(FILE *path); + fclose(file); } void test_loadModelReturnsCorrectNumberOfLayers(void) -- 2.47.2 From 4a6e7a904a19ea571a83ce222a5c593216bd6780 Mon Sep 17 00:00:00 2001 From: silvana884 Date: Mon, 24 Nov 2025 20:50:58 +0100 Subject: [PATCH 3/6] Matrix.c hinzugefuegt --- .idea/editor.xml | 341 ++++++++++++++++++++++++++++++++++++++++++++ .idea/workspace.xml | 128 +++++++++++++++++ matrix.c | 130 ++++++++++++++++- 3 files changed, 593 insertions(+), 6 deletions(-) create mode 100644 .idea/editor.xml create mode 100644 .idea/workspace.xml diff --git a/.idea/editor.xml b/.idea/editor.xml new file mode 100644 index 0000000..45a9ffc --- /dev/null +++ b/.idea/editor.xml @@ -0,0 +1,341 @@ + + + + + \ No newline at end of file diff --git a/.idea/workspace.xml b/.idea/workspace.xml new file mode 100644 index 0000000..4b2931a --- /dev/null +++ b/.idea/workspace.xml @@ -0,0 +1,128 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + { + "associatedIndex": 5 +} + + + + { + "keyToString": { + "RunOnceActivity.RadMigrateCodeStyle": "true", + "RunOnceActivity.ShowReadmeOnStart": "true", + "RunOnceActivity.cidr.known.project.marker": "true", + "RunOnceActivity.git.unshallow": "true", + "RunOnceActivity.readMode.enableVisualFormatting": "true", + "cf.first.check.clang-format": "false", + "cidr.known.project.marker": "true", + "git-widget-placeholder": "main", + "last_opened_file_path": "C:/Users/Silvana/NeuronalesNetz", + "node.js.detected.package.eslint": "true", + "node.js.detected.package.tslint": "true", + "node.js.selected.package.eslint": "(autodetect)", + "node.js.selected.package.tslint": "(autodetect)", + "nodejs_package_manager_path": "npm", + "vue.rearranger.settings.migration": "true" + } +} + + + + + 1762940933833 + + + + + + + + + + file://$PROJECT_DIR$/imageInput.c + + + + + \ No newline at end of file diff --git a/matrix.c b/matrix.c index ad00628..9b27187 100644 --- a/matrix.c +++ b/matrix.c @@ -6,30 +6,148 @@ Matrix createMatrix(unsigned int rows, unsigned int cols) { - + if(rows && cols){ + Matrix matrix; + matrix.rows = rows; + matrix.cols = cols; + matrix.buffer = malloc(rows * cols * sizeof(MatrixType)); + + matrix.buffer = malloc(rows * cols * sizeof(MatrixType)); + if (!matrix.buffer) { + matrix.rows = 0; + matrix.cols = 0; + return matrix; // malloc ist fehlgeschlagen + } + + + for (int i = 0; i < (rows * cols); i++) + matrix.buffer[i] = 0; + + return matrix; + } + Matrix matrix; + matrix.rows = 0; + matrix.cols = 0; + matrix.buffer = 0; + return matrix; } + void clearMatrix(Matrix *matrix) { - + free(matrix->buffer); + matrix->buffer = NULL; + matrix->rows = 0; + matrix->cols = 0; } void setMatrixAt(MatrixType value, Matrix matrix, unsigned int rowIdx, unsigned int colIdx) { - + matrix.buffer[rowIdx * matrix.cols + colIdx] = value; } MatrixType getMatrixAt(const Matrix matrix, unsigned int rowIdx, unsigned int colIdx) { - + if(rowIdx >= matrix.rows || colIdx >= matrix.cols){ + return UNDEFINED_MATRIX_VALUE; + } + return matrix.buffer[rowIdx * matrix.cols + colIdx]; } Matrix add(const Matrix matrix1, const Matrix matrix2) { - + int rows1 = rows(matrix1); + int rows2 = rows(matrix2); + int cols1 = cols(matrix1); + int cols2 = cols(matrix2); + if((cols1 == 1 || cols2 == 1) && rows1 == rows2) //Broadcasting + { + if(cols1 == 1) //Wenn die erste Matrix der Vektor ist + { + return broadcasting(matrix1, matrix2); + } + else + { + return broadcasting(matrix2, matrix1); + } + } + else if(rows1 == rows2 && cols1 == cols2) //Addition nur moeglich, wenn beide Matrizen gleiche ANzahl an Zeilen und Spalten haben + { + Matrix addition = createMatrix(rows1, cols2); //Matrix erstellt, in die die addierten Werte geschrieben werden + MatrixType wert1; + MatrixType wert2; + for(int i = 0; i < rows1; i++){ //soll fuer jedes Element durchlaufen, sodass alle Werte von beiden Matrizen aufaddiert werden. + for(int j = 0; j < cols1; j++){ + wert1 = getMatrixAt(matrix1, i, j); + wert2 = getMatrixAt(matrix2, i, j); + MatrixType addierterWert = wert1 + wert2; + setMatrixAt(addierterWert, addition, i, j); + } + } + return addition; + } + else{ + return createMatrix(0,0); + } } +Matrix broadcasting(const Matrix vektor, const Matrix matrix) + { + int rowsM = rows(matrix); + int colsM = cols(matrix); + Matrix result = createMatrix(rowsM, colsM); + MatrixType wert; + MatrixType koordinate; + for(int i = 0; i < rowsM; i++) + { + for(int j = 0; j < colsM; j++){ + wert = getMatrixAt(matrix, i, j); + koordinate = getMatrixAt(vektor, i, 0); + setMatrixAt((koordinate + wert), result, i, j); + } + } + return result; + } + Matrix multiply(const Matrix matrix1, const Matrix matrix2) { - + int rows1 = rows(matrix1); + int cols1 = cols(matrix1); + int rows2 = rows(matrix2); + int cols2 = cols(matrix2); + if(cols1 == rows2) //Bedingung fuer Multiplikation: Spalten der ersten Matrix gleich Zeilen 2. Matrix + { + Matrix result = createMatrix(rows1, cols2); + MatrixType wert1; + MatrixType wert2; + MatrixType mul; + MatrixType add = 0; + for(int i = 0; i < rows1; i++) + { + for(int k = 0; k < cols2; k++) + { + for(int j = 0; j < cols1; j++) + { + wert1 = getMatrixAt(matrix1, i, j); + wert2 = getMatrixAt(matrix2, j, k); + mul = wert1 * wert2; + add += mul; + } + setMatrixAt(add, result, i, k); + add = 0; + } + } + return result; + } + return createMatrix(0,0); +} + +int rows(const Matrix matrix) +{ + return matrix.rows; +} + +int cols(const Matrix matrix) +{ + return matrix.cols; } \ No newline at end of file -- 2.47.2 From 58f9fd81158b8bfd22a6030eb2244ae500d87f65 Mon Sep 17 00:00:00 2001 From: silvana884 Date: Mon, 24 Nov 2025 21:34:02 +0100 Subject: [PATCH 4/6] Testen moeglich, 6 Failures --- .idea/workspace.xml | 2 +- matrix.h | 8 ++++++++ neuralNetwork.c | 2 +- neuralNetwork.h | 2 ++ neuralNetworkTests.c | 35 +++++++++++++++++++++++++++-------- 5 files changed, 39 insertions(+), 10 deletions(-) diff --git a/.idea/workspace.xml b/.idea/workspace.xml index 4b2931a..5533b38 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -20,7 +20,7 @@ - +