XCSF  1.4.7
XCSF learning classifier system
env_csv.c File Reference

CSV input file handling functions. More...

#include "env_csv.h"
#include "param.h"
Include dependency graph for env_csv.c:

Go to the source code of this file.

Macros

#define MAX_ROWS   (100000)
 Maximum number of instances. More...
 
#define MAX_COLS   (200)
 Maximum line length. More...
 
#define MAX_NAME   (200)
 Maximum file name length. More...
 
#define DELIM   (",")
 File delimiter. More...
 

Functions

static int env_csv_samples (FILE *fin)
 Returns the number of samples in a csv file. More...
 
static int env_csv_dim (FILE *fin)
 Returns the number of dimensions in a csv file. More...
 
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. More...
 
static void env_csv_read (const char *filename, double **data, int *n_samples, int *n_dim)
 Parses a specified csv file. More...
 
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. More...
 
void env_csv_init (struct XCSF *xcsf, const char *filename)
 Initialises a CSV input environment from a specified filename. More...
 
void env_csv_free (const struct XCSF *xcsf)
 Frees the csv environment. More...
 
void env_csv_reset (const struct XCSF *xcsf)
 Dummy method since no csv environment reset is necessary. More...
 
bool env_csv_is_done (const struct XCSF *xcsf)
 Returns whether the csv environment is in a terminal state. More...
 
const double * env_csv_get_state (const struct XCSF *xcsf)
 Dummy method since no state is returned by the csv environment. More...
 
double env_csv_execute (const struct XCSF *xcsf, const int action)
 Dummy method since no action is executed by the csv environment. More...
 
bool env_csv_multistep (const struct XCSF *xcsf)
 Returns whether the csv environment is a multistep problem. More...
 
double env_csv_maxpayoff (const struct XCSF *xcsf)
 Returns the maximum payoff value possible in the csv environment. More...
 

Detailed Description

CSV input file handling functions.

Author
Richard Preen rpree.nosp@m.n@gm.nosp@m.ail.c.nosp@m.om
Date
2015–2020.

Definition in file env_csv.c.

Macro Definition Documentation

◆ DELIM

#define DELIM   (",")

File delimiter.

Definition at line 30 of file env_csv.c.

◆ MAX_COLS

#define MAX_COLS   (200)

Maximum line length.

Definition at line 28 of file env_csv.c.

◆ MAX_NAME

#define MAX_NAME   (200)

Maximum file name length.

Definition at line 29 of file env_csv.c.

◆ MAX_ROWS

#define MAX_ROWS   (100000)

Maximum number of instances.

Definition at line 27 of file env_csv.c.

Function Documentation

◆ env_csv_dim()

static int env_csv_dim ( FILE *  fin)
static

Returns the number of dimensions in a csv file.

Parameters
[in]finThe csv file.
Returns
The number of dimensions.

Definition at line 54 of file env_csv.c.

References DELIM, and MAX_COLS.

Referenced by env_csv_read().

Here is the caller graph for this function:

◆ env_csv_execute()

double env_csv_execute ( const struct XCSF xcsf,
const int  action 
)

Dummy method since no action is executed by the csv environment.

Parameters
[in]xcsfThe XCSF data structure.
[in]actionThe selected action.
Returns
0.

Definition at line 230 of file env_csv.c.

◆ env_csv_free()

void env_csv_free ( const struct XCSF xcsf)

Frees the csv environment.

Parameters
[in]xcsfThe XCSF data structure.

Definition at line 177 of file env_csv.c.

References EnvCSV::test_data, EnvCSV::train_data, Input::x, and Input::y.

◆ env_csv_get_state()

const double* env_csv_get_state ( const struct XCSF xcsf)

Dummy method since no state is returned by the csv environment.

Parameters
[in]xcsfThe XCSF data structure.
Returns
0.

Definition at line 217 of file env_csv.c.

◆ env_csv_init()

void env_csv_init ( struct XCSF xcsf,
const char *  filename 
)

Initialises a CSV input environment from a specified filename.

Parameters
[in]xcsfThe XCSF data structure.
[in]filenameThe file name of the csv data.

Definition at line 160 of file env_csv.c.

References env_csv_input_read(), param_init(), EnvCSV::test_data, EnvCSV::train_data, Input::x_dim, and Input::y_dim.

Referenced by env_init().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ env_csv_input_read()

static void env_csv_input_read ( const char *  infile,
struct Input train_data,
struct Input test_data 
)
static

Parses specified csv files into training and testing data sets.

Precondition
Identical number of x and y samples.
Parameters
[in]infileThe base name of the csv files to read.
[out]train_dataThe data structure to load the training data.
[out]test_dataThe data structure to load the testing data.

Definition at line 138 of file env_csv.c.

References env_csv_read(), MAX_NAME, Input::n_samples, Input::x, Input::x_dim, Input::y, and Input::y_dim.

Referenced by env_csv_init().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ env_csv_is_done()

bool env_csv_is_done ( const struct XCSF xcsf)

Returns whether the csv environment is in a terminal state.

Parameters
[in]xcsfThe XCSF data structure.
Returns
True.

Definition at line 205 of file env_csv.c.

◆ env_csv_maxpayoff()

double env_csv_maxpayoff ( const struct XCSF xcsf)

Returns the maximum payoff value possible in the csv environment.

Parameters
[in]xcsfThe XCSF data structure.
Returns
0.

Definition at line 255 of file env_csv.c.

◆ env_csv_multistep()

bool env_csv_multistep ( const struct XCSF xcsf)

Returns whether the csv environment is a multistep problem.

Parameters
[in]xcsfThe XCSF data structure.
Returns
False.

Definition at line 243 of file env_csv.c.

◆ env_csv_read()

static void env_csv_read ( const char *  filename,
double **  data,
int *  n_samples,
int *  n_dim 
)
static

Parses a specified csv file.

Provided a file name will set the data, n_samples, and n_dim.

Parameters
[in]filenameThe name of the csv file to read.
[out]dataA data structure to store the data.
[out]n_samplesThe number of samples in the dataset.
[out]n_dimThe number of dimensions in the dataset.

Definition at line 110 of file env_csv.c.

References env_csv_dim(), env_csv_read_data(), and env_csv_samples().

Referenced by env_csv_input_read().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ env_csv_read_data()

static void env_csv_read_data ( FILE *  fin,
double **  data,
const int  n_samples,
const int  n_dim 
)
static

Reads the data from a csv file.

Parameters
[in]finThe csv file.
[out]dataThe read data.
[in]n_samplesThe number of samples.
[in]n_dimThe number of dimensions.

Definition at line 80 of file env_csv.c.

References DELIM, and MAX_COLS.

Referenced by env_csv_read().

Here is the caller graph for this function:

◆ env_csv_reset()

void env_csv_reset ( const struct XCSF xcsf)

Dummy method since no csv environment reset is necessary.

Parameters
[in]xcsfThe XCSF data structure.

Definition at line 194 of file env_csv.c.

◆ env_csv_samples()

static int env_csv_samples ( FILE *  fin)
static

Returns the number of samples in a csv file.

Parameters
[in]finThe csv file.
Returns
The number of samples.

Definition at line 38 of file env_csv.c.

References MAX_COLS.

Referenced by env_csv_read().

Here is the caller graph for this function: