I have a data set I am trying to go through in order, however fscanf_s() and a function I wrote that uses fgetc() both only read 4 lines that are out of order in my data set. I terminate the loop that is utilizing the values when either 1 of my data sets is empty or when fscanf_s() or my personal function returns EOF.
I tried testing what line it cancels on but its random every time. I looked for some similar problems but most of them just said to use fgets or fgetc and then parse which I am already doing with my personal function.
double update_weights_v2(LOGISTIC_MODEL hModel, FILE* data_input, FILE* data_output) {
Model* pModel = (Model*)hModel;
int status1, status2;
double X, Y, error = 0, prediction, W1_deriv = 0, W2_deriv = 0;
int n = 0;
//X = parse_data_double(data_input, &status1);
//Y = parse_data_double(data_output, &status2);
status1 = fscanf_s(data_input, "%[^\n]lf", &X);
status2 = fscanf_s(data_output, "%[^\n]lf", &Y);
while (status1 != EOF && status2 != EOF) {
prediction = pModel->activation(X, pModel->W1, pModel->W2);
error = Y - prediction;
// df/dW1 = 1/n SUM[1->n](-2*Xi * (error))
W1_deriv += (X * error * pModel->rate);
// df/dW2 = 1/n SUM[1->n](-2 * (error))
W2_deriv += (error*pModel->rate);
// Read next data entry
//X = parse_data_double(data_input, &status1);
//Y = parse_data_double(data_output, &status2);
status1 = fscanf_s(data_input, "%[^\n]lf", &X);
status2 = fscanf_s(data_output, "%[^\n]lf", &Y);
n++;
printf("Input: %.5lf\nOutput: %.5lf\nGuess: %.5lf\nError: %.5lf\nWeight[1]: %.5lf\nWeight[2]: %.5lf\n*************************************************************\n", X, Y, prediction, error, pModel->W1, pModel->W2);
}
rewind(data_input);
rewind(data_output);
return error;
}
I expected this code to iterate through the entire data set, then reset the file so that its at the first character after every full run through the data set.