XCSF  1.4.7
XCSF learning classifier system
main.c
Go to the documentation of this file.
1 /*
2  * This program is free software: you can redistribute it and/or modify
3  * it under the terms of the GNU General Public License as published by
4  * the Free Software Foundation, either version 3 of the License, or
5  * (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program. If not, see <http://www.gnu.org/licenses/>.
14  */
15 
24 #include "clset.h"
25 #include "config.h"
26 #include "env_csv.h"
27 #include "pa.h"
28 #include "param.h"
29 #include "utils.h"
30 #include "xcs_rl.h"
31 #include "xcs_supervised.h"
32 #include "xcsf.h"
33 
34 int
35 main(int argc, char **argv)
36 {
37  if (argc < 3 || argc > 5) {
38  printf("Usage: xcsf problemType{csv|mp|maze} ");
39  printf("problem{.csv|size|maze} [config.json] [xcs.bin]\n");
40  exit(EXIT_FAILURE);
41  }
42  struct XCSF *xcsf = malloc(sizeof(struct XCSF));
43  env_init(xcsf, argv); // initialise environment and default parameters
44  if (argc > 3) { // load parameter config
45  config_read(xcsf, argv[3]);
46  } else {
47  config_read(xcsf, "default.json");
48  }
49  xcsf_init(xcsf); // initialise XCSF
50  if (argc == 5) { // reload state of a previous experiment
51  const size_t s = xcsf_load(xcsf, argv[4]);
52  printf("XCSF loaded: %d elements\n", (int) s);
53  }
54  param_print(xcsf); // print parameters used
55  if (strcmp(argv[1], "csv") == 0) { // supervised regression - csv file
56  const struct EnvCSV *env = xcsf->env;
57  xcs_supervised_fit(xcsf, env->train_data, env->test_data, true, 0,
58  xcsf->MAX_TRIALS);
59  } else { // reinforcement learning - maze or mux
61  }
62  env_free(xcsf); // clean up
63  xcsf_free(xcsf);
65  free(xcsf);
66  return EXIT_SUCCESS;
67 }
Functions operating on sets of classifiers.
void config_read(struct XCSF *xcsf, const char *filename)
Reads the specified configuration file.
Definition: config.c:50
Configuration file handling functions.
void env_init(struct XCSF *xcsf, char **argv)
Initialises a built-in problem environment.
Definition: env.c:34
static void env_free(const struct XCSF *xcsf)
Frees the environment.
Definition: env.h:106
CSV input file handling functions.
int main(int argc, char **argv)
Definition: main.c:35
Definition: __init__.py:1
Prediction array functions.
void param_print(const struct XCSF *xcsf)
Prints all XCSF parameters.
Definition: param.c:481
void param_free(struct XCSF *xcsf)
Definition: param.c:93
Functions for setting and printing parameters.
CSV environment data structure.
Definition: env_csv.h:32
struct Input * train_data
Definition: env_csv.h:33
struct Input * test_data
Definition: env_csv.h:34
XCSF data structure.
Definition: xcsf.h:85
Utility functions for random number handling, etc.
double xcs_rl_exp(struct XCSF *xcsf)
Executes a reinforcement learning experiment.
Definition: xcs_rl.c:78
Reinforcement learning functions.
double xcs_supervised_fit(struct XCSF *xcsf, const struct Input *train_data, const struct Input *test_data, const bool shuffle, const int start, const int trials)
Executes MAX_TRIALS number of XCSF learning iterations using the training data and test iterations us...
Supervised regression learning functions.
size_t xcsf_load(struct XCSF *xcsf, const char *filename)
Reads the state of XCSF from a file.
Definition: xcsf.c:114
void xcsf_init(struct XCSF *xcsf)
Initialises XCSF with an empty population.
Definition: xcsf.c:37
void xcsf_free(struct XCSF *xcsf)
Frees XCSF population sets.
Definition: xcsf.c:56
XCSF data structures.