From 8b3dd787175b9b8f1b0bcc889c6f2a06206cb796 Mon Sep 17 00:00:00 2001 From: Louis Gallet Date: Sun, 29 Sep 2024 22:57:06 +0200 Subject: [PATCH] feat: :sparkles: Update error message; update makefile; Update doc --- README.md | 12 +++++++++++- main.c | 3 +-- use.c | 7 ++++--- use.h | 4 ++-- 4 files changed, 18 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 6431409..9aa9b2e 100644 --- a/README.md +++ b/README.md @@ -1 +1,11 @@ -# XOR Neural Network \ No newline at end of file +# XOR Neural Network +## How to use +1. Build and train the model +```bash +make all +``` +> By default the model is train on 1000000 epochs, you can change this value in the main.c file, line 106. +2. Run the model +```bash +./use [value1] [value2] +``` diff --git a/main.c b/main.c index b642158..b198bc1 100644 --- a/main.c +++ b/main.c @@ -5,7 +5,6 @@ #include "main.h" #include - double sigmoid(double x) { if(x > 20) return 1.0; @@ -104,7 +103,7 @@ int main(){ int trainingSetOrder[] = {0,1,2,3}; - int numEpochs = 100000; + int numEpochs = 1000000; //training loop for(int epoch = 0; epoch < numEpochs; epoch++){ diff --git a/use.c b/use.c index cb2350d..6aa0e29 100644 --- a/use.c +++ b/use.c @@ -1,3 +1,4 @@ +#include "main.h" #include #include #include @@ -24,11 +25,11 @@ int main(int argc, char *argv[]) { // Load weights and biases from CSV file getvalues("weights.csv", HiddenWeights, HiddenBiases, FinalOutputWeights, FinalOutputBiases); if (argc < 2) { - fprintf(stderr, "No arguments provided.\n"); + errx(0, "No arguments provided. Usage: %s ", argv[0]); return EXIT_FAILURE; } if (argc != 3) { - fprintf(stderr, "Usage: %s \n", argv[0]); + errx(0, "Usage: %s ", argv[0]); return EXIT_FAILURE; } @@ -78,7 +79,7 @@ int main(int argc, char *argv[]) { void getvalues(char filename[], double **HiddenWeights, double *HiddenBiases, double **FinalOutputWeights, double *FinalOutputBiases) { FILE *fp = fopen(filename, "r"); if (fp == NULL) { - errx(EXIT_FAILURE, "Could not open file %s", filename); + errx(EXIT_FAILURE, "Could not open file %s. Train the model first by executing ./main", filename); } for (int i = 0; i < 2; i++) { for (int j = 0; j < 2; j++) { diff --git a/use.h b/use.h index 4e8f4d7..262270b 100644 --- a/use.h +++ b/use.h @@ -6,13 +6,13 @@ #define USE_H #define NUM_INPUTS 2 -#define NUM_HIDDEN 2 +#define NUM_HIDDEN 25 #define NUM_OUTPUTS 1 #define NUM_TRAINING_SETS 4 void getvalues(char filename[], double **HiddenWeights, double *HiddenBiases, double **FinalOutputWeights, double *FinalOutputBiases); -int main(); +int main(int argc, char *argv[]); #endif //USE_H