forked from lgallet/XOR-NeuralNetwork-C
feat: ✨ Update error message; update makefile; Update doc
This commit is contained in:
parent
442ebdd16c
commit
8b3dd78717
10
README.md
10
README.md
@ -1 +1,11 @@
|
|||||||
# XOR Neural Network
|
# 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]
|
||||||
|
```
|
||||||
|
3
main.c
3
main.c
@ -5,7 +5,6 @@
|
|||||||
#include "main.h"
|
#include "main.h"
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
|
|
||||||
double sigmoid(double x)
|
double sigmoid(double x)
|
||||||
{
|
{
|
||||||
if(x > 20) return 1.0;
|
if(x > 20) return 1.0;
|
||||||
@ -104,7 +103,7 @@ int main(){
|
|||||||
|
|
||||||
int trainingSetOrder[] = {0,1,2,3};
|
int trainingSetOrder[] = {0,1,2,3};
|
||||||
|
|
||||||
int numEpochs = 100000;
|
int numEpochs = 1000000;
|
||||||
|
|
||||||
//training loop
|
//training loop
|
||||||
for(int epoch = 0; epoch < numEpochs; epoch++){
|
for(int epoch = 0; epoch < numEpochs; epoch++){
|
||||||
|
7
use.c
7
use.c
@ -1,3 +1,4 @@
|
|||||||
|
#include "main.h"
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
@ -24,11 +25,11 @@ int main(int argc, char *argv[]) {
|
|||||||
// Load weights and biases from CSV file
|
// Load weights and biases from CSV file
|
||||||
getvalues("weights.csv", HiddenWeights, HiddenBiases, FinalOutputWeights, FinalOutputBiases);
|
getvalues("weights.csv", HiddenWeights, HiddenBiases, FinalOutputWeights, FinalOutputBiases);
|
||||||
if (argc < 2) {
|
if (argc < 2) {
|
||||||
fprintf(stderr, "No arguments provided.\n");
|
errx(0, "No arguments provided. Usage: %s <input1> <input2>", argv[0]);
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
if (argc != 3) {
|
if (argc != 3) {
|
||||||
fprintf(stderr, "Usage: %s <input1> <input2>\n", argv[0]);
|
errx(0, "Usage: %s <input1> <input2>", argv[0]);
|
||||||
return EXIT_FAILURE;
|
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) {
|
void getvalues(char filename[], double **HiddenWeights, double *HiddenBiases, double **FinalOutputWeights, double *FinalOutputBiases) {
|
||||||
FILE *fp = fopen(filename, "r");
|
FILE *fp = fopen(filename, "r");
|
||||||
if (fp == NULL) {
|
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 i = 0; i < 2; i++) {
|
||||||
for (int j = 0; j < 2; j++) {
|
for (int j = 0; j < 2; j++) {
|
||||||
|
4
use.h
4
use.h
@ -6,13 +6,13 @@
|
|||||||
#define USE_H
|
#define USE_H
|
||||||
|
|
||||||
#define NUM_INPUTS 2
|
#define NUM_INPUTS 2
|
||||||
#define NUM_HIDDEN 2
|
#define NUM_HIDDEN 25
|
||||||
#define NUM_OUTPUTS 1
|
#define NUM_OUTPUTS 1
|
||||||
#define NUM_TRAINING_SETS 4
|
#define NUM_TRAINING_SETS 4
|
||||||
|
|
||||||
|
|
||||||
void getvalues(char filename[], double **HiddenWeights, double *HiddenBiases, double **FinalOutputWeights, double *FinalOutputBiases);
|
void getvalues(char filename[], double **HiddenWeights, double *HiddenBiases, double **FinalOutputWeights, double *FinalOutputBiases);
|
||||||
int main();
|
int main(int argc, char *argv[]);
|
||||||
|
|
||||||
|
|
||||||
#endif //USE_H
|
#endif //USE_H
|
||||||
|
Reference in New Issue
Block a user