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

3
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]); fprintf(fpt, "%f,", hiddenWeights[k][j]);
} }
} }
printf("Final Hidden Biases: \n");
for(int j = 0; j < NUM_HIDDEN; j++){ for(int j = 0; j < NUM_HIDDEN; j++){
fprintf(fpt, "%f,", hiddenLayerBias[j]); fprintf(fpt, "%f,", hiddenLayerBias[j]);
} }
printf("Final Output Weights: \n");
for(int j = 0; j < NUM_OUTPUTS; j++){ for(int j = 0; j < NUM_OUTPUTS; j++){
for(int k = 0; k < NUM_HIDDEN; k++){ for(int k = 0; k < NUM_HIDDEN; k++){
fprintf(fpt, "%f,", outputWeights[k][j]); fprintf(fpt, "%f,", outputWeights[k][j]);
} }
} }
printf("Final Output Biases: \n");
for(int j = 0; j < NUM_OUTPUTS; j++){ for(int j = 0; j < NUM_OUTPUTS; j++){
fprintf(fpt, "%f,", outputLayerBias[j]); fprintf(fpt, "%f,", outputLayerBias[j]);
} }

18
use.c
View File

@ -8,7 +8,7 @@ void getvalues(char filename[], double **HiddenWeights, double *HiddenBiases, do
double sigmoid(double x); double sigmoid(double x);
double sigmoid_derivative(double x); double sigmoid_derivative(double x);
int main() { int main(int argc, char *argv[]) {
// Allocate memory for weights and biases // Allocate memory for weights and biases
double **HiddenWeights = (double **)malloc(2 * sizeof(double *)); double **HiddenWeights = (double **)malloc(2 * sizeof(double *));
for (int i = 0; i < 2; i++) { for (int i = 0; i < 2; i++) {
@ -23,11 +23,21 @@ int main() {
// 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) {
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 // Prompt user for input values
double input1, input2; // double input1, input2;
printf("Enter two values to compute XOR: "); // printf("Enter two values to compute XOR: ");
scanf("%lf %lf", &input1, &input2); // scanf("%lf %lf", &input1, &input2);
// Perform forward pass // Perform forward pass
double hiddenLayer[2]; double hiddenLayer[2];