27 #define MAX_ROWS (100000)
28 #define MAX_COLS (200)
29 #define MAX_NAME (200)
42 while (fgets(line,
MAX_COLS, fin) != NULL) {
60 if (fgets(line,
MAX_COLS, fin) != NULL) {
61 const char *ptok = strtok_r(line,
DELIM, &saveptr);
62 while (ptok != NULL) {
66 ptok = strtok_r(NULL,
DELIM, &saveptr);
84 *data = malloc(
sizeof(
double) * n_dim * n_samples);
86 const char *str = NULL;
90 while (fgets(line,
MAX_COLS, fin) != NULL && i < n_samples) {
91 str = strtok_r(line,
DELIM, &saveptr);
92 (*data)[i * n_dim] = strtod(str, &endptr);
93 for (
int j = 1; j < n_dim; ++j) {
94 str = strtok_r(NULL,
DELIM, &saveptr);
95 (*data)[i * n_dim + j] = strtod(str, &endptr);
110 env_csv_read(
const char *filename,
double **data,
int *n_samples,
int *n_dim)
112 FILE *fin = fopen(filename,
"rt");
114 printf(
"Error opening file: %s. %s.\n", filename, strerror(errno));
119 if (*n_samples > 0 && *n_dim > 0) {
123 printf(
"Error reading file: %s. No samples found\n", filename);
127 printf(
"Loaded: %s: samples=%d, dim=%d\n", filename, *n_samples, *n_dim);
139 struct Input *test_data)
142 snprintf(name,
MAX_NAME,
"%s_train_x.csv", infile);
145 snprintf(name,
MAX_NAME,
"%s_train_y.csv", infile);
148 snprintf(name,
MAX_NAME,
"%s_test_x.csv", infile);
150 snprintf(name,
MAX_NAME,
"%s_test_y.csv", infile);
#define DELIM
File delimiter.
bool env_csv_multistep(const struct XCSF *xcsf)
Returns whether the csv environment is a multistep problem.
const double * env_csv_get_state(const struct XCSF *xcsf)
Dummy method since no state is returned by the csv environment.
static int env_csv_samples(FILE *fin)
Returns the number of samples in a csv file.
#define MAX_COLS
Maximum line length.
static int env_csv_dim(FILE *fin)
Returns the number of dimensions in a csv file.
static void env_csv_input_read(const char *infile, struct Input *train_data, struct Input *test_data)
Parses specified csv files into training and testing data sets.
double env_csv_execute(const struct XCSF *xcsf, const int action)
Dummy method since no action is executed by the csv environment.
bool env_csv_is_done(const struct XCSF *xcsf)
Returns whether the csv environment is in a terminal state.
void env_csv_reset(const struct XCSF *xcsf)
Dummy method since no csv environment reset is necessary.
void env_csv_init(struct XCSF *xcsf, const char *filename)
Initialises a CSV input environment from a specified filename.
#define MAX_NAME
Maximum file name length.
double env_csv_maxpayoff(const struct XCSF *xcsf)
Returns the maximum payoff value possible in the csv environment.
static void env_csv_read(const char *filename, double **data, int *n_samples, int *n_dim)
Parses a specified csv file.
static void env_csv_read_data(FILE *fin, double **data, const int n_samples, const int n_dim)
Reads the data from a csv file.
void env_csv_free(const struct XCSF *xcsf)
Frees the csv environment.
CSV input file handling functions.
void param_init(struct XCSF *xcsf, const int x_dim, const int y_dim, const int n_actions)
Initialises default XCSF parameters.
Functions for setting and printing parameters.
CSV environment data structure.
struct Input * train_data