4
0

fix: 🐛 Fix double print and add arguments to the program

This commit is contained in:
Louis Gallet 2024-09-27 18:54:04 +02:00
parent 82b65ae2a1
commit 442ebdd16c
Signed by: lgallet
GPG Key ID: 84D3DF1528A84511
2 changed files with 16 additions and 9 deletions

5
main.c
View File

@ -47,17 +47,14 @@ void backup_weights(char filename[], double hiddenWeights[NUM_INPUTS][NUM_HIDDEN
fprintf(fpt, "%f,", hiddenWeights[k][j]);
}
}
printf("Final Hidden Biases: \n");
for(int j = 0; j < NUM_HIDDEN; j++){
fprintf(fpt, "%f,", hiddenLayerBias[j]);
}
printf("Final Output Weights: \n");
for(int j = 0; j < NUM_OUTPUTS; j++){
for(int k = 0; k < NUM_HIDDEN; k++){
fprintf(fpt, "%f,", outputWeights[k][j]);
}
}
printf("Final Output Biases: \n");
for(int j = 0; j < NUM_OUTPUTS; j++){
fprintf(fpt, "%f,", outputLayerBias[j]);
}
@ -234,4 +231,4 @@ int main(){
return 0;
}
}

20
use.c
View File

@ -8,7 +8,7 @@ void getvalues(char filename[], double **HiddenWeights, double *HiddenBiases, do
double sigmoid(double x);
double sigmoid_derivative(double x);
int main() {
int main(int argc, char *argv[]) {
// Allocate memory for weights and biases
double **HiddenWeights = (double **)malloc(2 * sizeof(double *));
for (int i = 0; i < 2; i++) {
@ -23,11 +23,21 @@ int main() {
// Load weights and biases from CSV file
getvalues("weights.csv", HiddenWeights, HiddenBiases, FinalOutputWeights, FinalOutputBiases);
if (argc < 2) {
fprintf(stderr, "No arguments provided.\n");
return EXIT_FAILURE;
}
if (argc != 3) {
fprintf(stderr, "Usage: %s <input1> <input2>\n", argv[0]);
return EXIT_FAILURE;
}
double input1 = atof(argv[1]);
double input2 = atof(argv[2]);
// Prompt user for input values
double input1, input2;
printf("Enter two values to compute XOR: ");
scanf("%lf %lf", &input1, &input2);
// double input1, input2;
// printf("Enter two values to compute XOR: ");
// scanf("%lf %lf", &input1, &input2);
// Perform forward pass
double hiddenLayer[2];
@ -95,4 +105,4 @@ double sigmoid(double x) {
double sigmoid_derivative(double x) {
return x * (1.0 - x);
}
}