XCSF 1.4.8
XCSF learning classifier system
Loading...
Searching...
No Matches
cl.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 "cl.h"
25#include "action.h"
26#include "condition.h"
27#include "ea.h"
28#include "loss.h"
29#include "prediction.h"
30#include "utils.h"
31
39void
40cl_init(const struct XCSF *xcsf, struct Cl *c, const double size,
41 const int time)
42{
43 c->fit = xcsf->INIT_FITNESS;
44 c->err = xcsf->INIT_ERROR;
45 c->num = 1;
46 c->exp = 0;
47 c->size = size;
48 c->time = time;
49 c->prediction = calloc(xcsf->y_dim, sizeof(double));
50 c->action = 0;
51 c->m = false;
52 c->age = 0;
53 c->mtotal = 0;
54}
55
62void
63cl_copy(const struct XCSF *xcsf, struct Cl *dest, const struct Cl *src)
64{
65 dest->cond_vptr = src->cond_vptr;
66 dest->pred_vptr = src->pred_vptr;
67 dest->act_vptr = src->act_vptr;
68 act_copy(xcsf, dest, src);
69 cond_copy(xcsf, dest, src);
70 if (xcsf->ea->pred_reset) {
71 pred_init(xcsf, dest);
72 } else {
73 pred_copy(xcsf, dest, src);
74 }
75}
76
83void
84cl_init_copy(const struct XCSF *xcsf, struct Cl *dest, const struct Cl *src)
85{
86 dest->prediction = calloc(xcsf->y_dim, sizeof(double));
87 dest->fit = src->fit;
88 dest->err = src->err;
89 dest->num = src->num;
90 dest->exp = src->exp;
91 dest->size = src->size;
92 dest->time = src->time;
93 dest->action = src->action;
94 dest->m = src->m;
95 dest->age = src->age;
96 dest->mtotal = src->mtotal;
97 dest->cond_vptr = src->cond_vptr;
98 dest->pred_vptr = src->pred_vptr;
99 dest->act_vptr = src->act_vptr;
100 act_copy(xcsf, dest, src);
101 cond_copy(xcsf, dest, src);
102 pred_copy(xcsf, dest, src);
103}
104
112void
113cl_cover(const struct XCSF *xcsf, struct Cl *c, const double *x,
114 const int action)
115{
116 cl_rand(xcsf, c);
117 cond_cover(xcsf, c, x);
118 act_cover(xcsf, c, x, action);
119 c->m = true;
120 c->action = action;
121}
122
128void
129cl_rand(const struct XCSF *xcsf, struct Cl *c)
130{
131 action_set(xcsf, c);
134 cond_init(xcsf, c);
135 pred_init(xcsf, c);
136 act_init(xcsf, c);
137}
138
146double
147cl_del_vote(const struct XCSF *xcsf, const struct Cl *c, const double avg_fit)
148{
149 if (c->exp > xcsf->THETA_DEL && c->fit < xcsf->DELTA * avg_fit * c->num) {
150 return c->size * c->num * avg_fit / (c->fit / c->num);
151 }
152 return c->size * c->num;
153}
154
161double
162cl_acc(const struct XCSF *xcsf, const struct Cl *c)
163{
164 if (c->err > xcsf->E0) {
165 const double acc = xcsf->ALPHA * pow(c->err / xcsf->E0, -(xcsf->NU));
166 return fmax(acc, DBL_EPSILON);
167 }
168 return 1;
169}
170
182void
183cl_update(const struct XCSF *xcsf, struct Cl *c, const double *x,
184 const double *y, const int set_num, const bool cur)
185{
186 ++(c->exp);
187 if (!cur) { // propagate inputs for the previous state update
188 cl_predict(xcsf, c, x);
189 }
190 const double error = (xcsf->loss_ptr)(xcsf, c->prediction, y);
191 if (c->exp * xcsf->BETA < 1) {
192 c->err = (c->err * (c->exp - 1) + error) / c->exp;
193 c->size = (c->size * (c->exp - 1) + set_num) / c->exp;
194 } else {
195 c->err += xcsf->BETA * (error - c->err);
196 c->size += xcsf->BETA * (set_num - c->size);
197 }
198 cond_update(xcsf, c, x, y);
199 pred_update(xcsf, c, x, y);
200 act_update(xcsf, c, x, y);
201}
202
210void
211cl_update_fit(const struct XCSF *xcsf, struct Cl *c, const double acc_sum,
212 const double acc)
213{
214 c->fit += xcsf->BETA * ((acc * c->num) / acc_sum - c->fit);
215}
216
222void
223cl_free(const struct XCSF *xcsf, struct Cl *c)
224{
225 free(c->prediction);
226 cond_free(xcsf, c);
227 act_free(xcsf, c);
228 pred_free(xcsf, c);
229 free(c);
230}
231
240void
241cl_print(const struct XCSF *xcsf, const struct Cl *c, const bool print_cond,
242 const bool print_act, const bool print_pred)
243{
244 char *json_str = cl_json_export(xcsf, c, print_cond, print_act, print_pred);
245 printf("%s\n", json_str);
246 free(json_str);
247}
248
256bool
257cl_match(const struct XCSF *xcsf, struct Cl *c, const double *x)
258{
259 c->m = cond_match(xcsf, c, x);
260 if (c->m) {
261 ++(c->mtotal);
262 }
263 ++(c->age);
264 return c->m;
265}
266
273double
274cl_mfrac(const struct XCSF *xcsf, const struct Cl *c)
275{
276 (void) xcsf;
277 if (c->age > 0) {
278 return (double) c->mtotal / c->age;
279 }
280 return 0;
281}
282
289bool
290cl_m(const struct XCSF *xcsf, const struct Cl *c)
291{
292 (void) xcsf;
293 return c->m;
294}
295
303int
304cl_action(const struct XCSF *xcsf, struct Cl *c, const double *x)
305{
306 c->action = act_compute(xcsf, c, x);
307 return c->action;
308}
309
317const double *
318cl_predict(const struct XCSF *xcsf, const struct Cl *c, const double *x)
319{
320 pred_compute(xcsf, c, x);
321 return c->prediction;
322}
323
330bool
331cl_subsumer(const struct XCSF *xcsf, const struct Cl *c)
332{
333 if (c->exp > xcsf->THETA_SUB && c->err < xcsf->E0) {
334 return true;
335 }
336 return false;
337}
338
346bool
347cl_general(const struct XCSF *xcsf, const struct Cl *c1, const struct Cl *c2)
348{
349 if (cond_general(xcsf, c1, c2)) {
350 return act_general(xcsf, c1, c2);
351 }
352 return false;
353}
354
361bool
362cl_mutate(const struct XCSF *xcsf, const struct Cl *c)
363{
364 const bool cm = cond_mutate(xcsf, c);
365 const bool pm = pred_mutate(xcsf, c);
366 const bool am = (xcsf->n_actions > 1) ? act_mutate(xcsf, c) : false;
367 if (cm || pm || am) {
368 return true;
369 }
370 return false;
371}
372
380bool
381cl_crossover(const struct XCSF *xcsf, const struct Cl *c1, const struct Cl *c2)
382{
383 const bool cc = cond_crossover(xcsf, c1, c2);
384 const bool pc = pred_crossover(xcsf, c1, c2);
385 const bool ac = act_crossover(xcsf, c1, c2);
386 if (cc || pc || ac) {
387 return true;
388 }
389 return false;
390}
391
398double
399cl_cond_size(const struct XCSF *xcsf, const struct Cl *c)
400{
401 return cond_size(xcsf, c);
402}
403
410double
411cl_pred_size(const struct XCSF *xcsf, const struct Cl *c)
412{
413 return pred_size(xcsf, c);
414}
415
423size_t
424cl_save(const struct XCSF *xcsf, const struct Cl *c, FILE *fp)
425{
426 size_t s = 0;
427 s += fwrite(&c->err, sizeof(double), 1, fp);
428 s += fwrite(&c->fit, sizeof(double), 1, fp);
429 s += fwrite(&c->num, sizeof(int), 1, fp);
430 s += fwrite(&c->exp, sizeof(int), 1, fp);
431 s += fwrite(&c->size, sizeof(double), 1, fp);
432 s += fwrite(&c->time, sizeof(int), 1, fp);
433 s += fwrite(&c->m, sizeof(bool), 1, fp);
434 s += fwrite(&c->age, sizeof(int), 1, fp);
435 s += fwrite(&c->mtotal, sizeof(int), 1, fp);
436 s += fwrite(c->prediction, sizeof(double), xcsf->y_dim, fp);
437 s += fwrite(&c->action, sizeof(int), 1, fp);
438 s += act_save(xcsf, c, fp);
439 s += pred_save(xcsf, c, fp);
440 s += cond_save(xcsf, c, fp);
441 return s;
442}
443
451size_t
452cl_load(const struct XCSF *xcsf, struct Cl *c, FILE *fp)
453{
454 size_t s = 0;
455 s += fread(&c->err, sizeof(double), 1, fp);
456 s += fread(&c->fit, sizeof(double), 1, fp);
457 s += fread(&c->num, sizeof(int), 1, fp);
458 s += fread(&c->exp, sizeof(int), 1, fp);
459 s += fread(&c->size, sizeof(double), 1, fp);
460 s += fread(&c->time, sizeof(int), 1, fp);
461 s += fread(&c->m, sizeof(bool), 1, fp);
462 s += fread(&c->age, sizeof(int), 1, fp);
463 s += fread(&c->mtotal, sizeof(int), 1, fp);
464 c->prediction = malloc(sizeof(double) * xcsf->y_dim);
465 s += fread(c->prediction, sizeof(double), xcsf->y_dim, fp);
466 s += fread(&c->action, sizeof(int), 1, fp);
467 action_set(xcsf, c);
470 s += act_load(xcsf, c, fp);
471 s += pred_load(xcsf, c, fp);
472 s += cond_load(xcsf, c, fp);
473 return s;
474}
475
485char *
486cl_json_export(const struct XCSF *xcsf, const struct Cl *c,
487 const bool return_cond, const bool return_act,
488 const bool return_pred)
489{
490 cJSON *json = cJSON_CreateObject();
491 cJSON_AddNumberToObject(json, "error", c->err);
492 cJSON_AddNumberToObject(json, "fitness", c->fit);
493 cJSON_AddNumberToObject(json, "accuracy", cl_acc(xcsf, c));
494 cJSON_AddNumberToObject(json, "set_size", c->size);
495 cJSON_AddNumberToObject(json, "numerosity", c->num);
496 cJSON_AddNumberToObject(json, "experience", c->exp);
497 cJSON_AddNumberToObject(json, "time", c->time);
498 cJSON_AddNumberToObject(json, "samples_seen", c->age);
499 cJSON_AddNumberToObject(json, "samples_matched", c->mtotal);
500 cJSON_AddBoolToObject(json, "current_match", c->m);
501 cJSON_AddNumberToObject(json, "current_action", c->action);
502 cJSON *p = cJSON_CreateDoubleArray(c->prediction, xcsf->y_dim);
503 cJSON_AddItemToObject(json, "current_prediction", p);
504 char *json_str = NULL;
505 if (return_cond) {
506 json_str = cond_json_export(xcsf, c);
507 cJSON *condition = cJSON_Parse(json_str);
508 cJSON_AddItemToObject(json, "condition", condition);
509 free(json_str);
510 }
511 if (return_act && xcsf->n_actions > 1) {
512 json_str = act_json_export(xcsf, c);
513 cJSON *action = cJSON_Parse(json_str);
514 cJSON_AddItemToObject(json, "action", action);
515 free(json_str);
516 }
517 if (return_pred) {
518 json_str = pred_json_export(xcsf, c);
519 cJSON *prediction = cJSON_Parse(json_str);
520 cJSON_AddItemToObject(json, "prediction", prediction);
521 free(json_str);
522 }
523 char *string = cJSON_Print(json);
524 cJSON_Delete(json);
525 return string;
526}
527
533static void
534cl_json_import_properties(struct Cl *c, const cJSON *json)
535{
536 const cJSON *item = cJSON_GetObjectItem(json, "error");
537 if (item != NULL && cJSON_IsNumber(item)) {
538 c->err = item->valuedouble;
539 }
540 item = cJSON_GetObjectItem(json, "fitness");
541 if (item != NULL && cJSON_IsNumber(item)) {
542 c->fit = item->valuedouble;
543 }
544 item = cJSON_GetObjectItem(json, "set_size");
545 if (item != NULL && cJSON_IsNumber(item)) {
546 c->size = item->valuedouble;
547 }
548 item = cJSON_GetObjectItem(json, "numerosity");
549 if (item != NULL && cJSON_IsNumber(item)) {
550 c->num = item->valueint;
551 }
552 item = cJSON_GetObjectItem(json, "experience");
553 if (item != NULL && cJSON_IsNumber(item)) {
554 c->exp = item->valueint;
555 }
556 item = cJSON_GetObjectItem(json, "time");
557 if (item != NULL && cJSON_IsNumber(item)) {
558 c->time = item->valueint;
559 }
560 item = cJSON_GetObjectItem(json, "samples_seen");
561 if (item != NULL && cJSON_IsNumber(item)) {
562 c->age = item->valueint;
563 }
564 item = cJSON_GetObjectItem(json, "samples_matched");
565 if (item != NULL && cJSON_IsNumber(item)) {
566 c->mtotal = item->valueint;
567 }
568}
569
576static void
577cl_json_import_current(const struct XCSF *xcsf, struct Cl *c, const cJSON *json)
578{
579 const cJSON *item = cJSON_GetObjectItem(json, "current_match");
580 if (item != NULL && cJSON_IsBool(item)) {
581 c->m = true ? item->type == cJSON_True : false;
582 }
583 item = cJSON_GetObjectItem(json, "current_action");
584 if (item != NULL && cJSON_IsNumber(item)) {
585 c->action = item->valueint;
586 }
587 item = cJSON_GetObjectItem(json, "current_prediction");
588 if (item != NULL && cJSON_IsArray(item)) {
589 if (cJSON_GetArraySize(item) != xcsf->y_dim) {
590 printf("Import error: current prediction length mismatch\n");
591 exit(EXIT_FAILURE);
592 }
593 for (int i = 0; i < xcsf->y_dim; ++i) {
594 const cJSON *item_i = cJSON_GetArrayItem(item, i);
595 c->prediction[i] = item_i->valuedouble;
596 }
597 }
598}
599
607void
608cl_json_import(const struct XCSF *xcsf, struct Cl *c, const cJSON *json)
609{
610 cl_init(xcsf, c, xcsf->pset.num, xcsf->time);
611 cl_rand(xcsf, c);
614 const cJSON *item = cJSON_GetObjectItem(json, "action");
615 if (item != NULL) {
616 act_json_import(xcsf, c, item);
617 }
618 item = cJSON_GetObjectItem(json, "prediction");
619 if (item != NULL) {
620 pred_json_import(xcsf, c, item);
621 }
622 item = cJSON_GetObjectItem(json, "condition");
623 if (item != NULL) {
624 cond_json_import(xcsf, c, item);
625 }
626}
void action_set(const struct XCSF *xcsf, struct Cl *c)
Sets a classifier's action functions to the implementations.
Definition action.c:35
Interface for classifier actions.
static void act_init(const struct XCSF *xcsf, struct Cl *c)
Initialises a classifier's action.
Definition action.h:221
static bool act_crossover(const struct XCSF *xcsf, const struct Cl *c1, const struct Cl *c2)
Performs classifier action crossover.
Definition action.h:148
static void act_copy(const struct XCSF *xcsf, struct Cl *dest, const struct Cl *src)
Copies the action from one classifier to another.
Definition action.h:185
static bool act_mutate(const struct XCSF *xcsf, const struct Cl *c)
Performs classifier action mutation.
Definition action.h:160
static void act_cover(const struct XCSF *xcsf, const struct Cl *c, const double *x, const int action)
Generates an action that matches the specified value.
Definition action.h:198
static size_t act_load(const struct XCSF *xcsf, struct Cl *c, FILE *fp)
Reads the action from a file.
Definition action.h:122
static size_t act_save(const struct XCSF *xcsf, const struct Cl *c, FILE *fp)
Writes the action to a file.
Definition action.h:109
static int act_compute(const struct XCSF *xcsf, const struct Cl *c, const double *x)
Computes the current classifier action using the input.
Definition action.h:173
static bool act_general(const struct XCSF *xcsf, const struct Cl *c1, const struct Cl *c2)
Returns whether the action of classifier c1 is more general than c2.
Definition action.h:135
static void act_free(const struct XCSF *xcsf, const struct Cl *c)
Frees the memory used by the classifier action.
Definition action.h:210
static void act_json_import(const struct XCSF *xcsf, struct Cl *c, const cJSON *json)
Creates an action from a cJSON object.
Definition action.h:270
static void act_update(const struct XCSF *xcsf, const struct Cl *c, const double *x, const double *y)
Updates the classifier's action.
Definition action.h:245
static char * act_json_export(const struct XCSF *xcsf, const struct Cl *c)
Returns a json formatted string representation of an action .
Definition action.h:258
double cl_pred_size(const struct XCSF *xcsf, const struct Cl *c)
Returns the size of a classifier's prediction.
Definition cl.c:411
double cl_mfrac(const struct XCSF *xcsf, const struct Cl *c)
Returns the fraction of observed inputs matched by a classifier.
Definition cl.c:274
void cl_init(const struct XCSF *xcsf, struct Cl *c, const double size, const int time)
Initialises a new classifier - but not condition, action, prediction.
Definition cl.c:40
bool cl_m(const struct XCSF *xcsf, const struct Cl *c)
Returns whether a classifier matched the most recent input.
Definition cl.c:290
double cl_cond_size(const struct XCSF *xcsf, const struct Cl *c)
Returns the size of a classifier's condition.
Definition cl.c:399
char * cl_json_export(const struct XCSF *xcsf, const struct Cl *c, const bool return_cond, const bool return_act, const bool return_pred)
Returns a json formatted string representation of a classifier.
Definition cl.c:486
void cl_rand(const struct XCSF *xcsf, struct Cl *c)
Initialises random actions, conditions and predictions.
Definition cl.c:129
void cl_update(const struct XCSF *xcsf, struct Cl *c, const double *x, const double *y, const int set_num, const bool cur)
Updates a classifier's experience, error, and set size.
Definition cl.c:183
const double * cl_predict(const struct XCSF *xcsf, const struct Cl *c, const double *x)
Computes the current classifier prediction using the input.
Definition cl.c:318
void cl_update_fit(const struct XCSF *xcsf, struct Cl *c, const double acc_sum, const double acc)
Updates the fitness of a classifier.
Definition cl.c:211
int cl_action(const struct XCSF *xcsf, struct Cl *c, const double *x)
Computes the current classifier action using the input.
Definition cl.c:304
bool cl_general(const struct XCSF *xcsf, const struct Cl *c1, const struct Cl *c2)
Returns whether classifier c1 is more general than c2.
Definition cl.c:347
void cl_init_copy(const struct XCSF *xcsf, struct Cl *dest, const struct Cl *src)
Initialises and creates a copy of one classifier from another.
Definition cl.c:84
bool cl_match(const struct XCSF *xcsf, struct Cl *c, const double *x)
Calculates whether a classifier matches an input.
Definition cl.c:257
bool cl_mutate(const struct XCSF *xcsf, const struct Cl *c)
Performs classifier mutation.
Definition cl.c:362
size_t cl_save(const struct XCSF *xcsf, const struct Cl *c, FILE *fp)
Writes a classifier to a file.
Definition cl.c:424
void cl_copy(const struct XCSF *xcsf, struct Cl *dest, const struct Cl *src)
Copies condition, action, and prediction structures.
Definition cl.c:63
size_t cl_load(const struct XCSF *xcsf, struct Cl *c, FILE *fp)
Reads a classifier from a file.
Definition cl.c:452
bool cl_crossover(const struct XCSF *xcsf, const struct Cl *c1, const struct Cl *c2)
Performs classifier crossover.
Definition cl.c:381
void cl_cover(const struct XCSF *xcsf, struct Cl *c, const double *x, const int action)
Covers the condition and action for a classifier.
Definition cl.c:113
static void cl_json_import_current(const struct XCSF *xcsf, struct Cl *c, const cJSON *json)
Sets a classifier's current properties from a cJSON object.
Definition cl.c:577
void cl_free(const struct XCSF *xcsf, struct Cl *c)
Frees the memory used by a classifier.
Definition cl.c:223
double cl_acc(const struct XCSF *xcsf, const struct Cl *c)
Returns the accuracy of a classifier.
Definition cl.c:162
void cl_json_import(const struct XCSF *xcsf, struct Cl *c, const cJSON *json)
Creates a classifier from a cJSON object.
Definition cl.c:608
double cl_del_vote(const struct XCSF *xcsf, const struct Cl *c, const double avg_fit)
Returns the deletion vote of a classifier.
Definition cl.c:147
static void cl_json_import_properties(struct Cl *c, const cJSON *json)
Sets a classifier's properties from a cJSON object.
Definition cl.c:534
bool cl_subsumer(const struct XCSF *xcsf, const struct Cl *c)
Returns whether a classifier is a potential subsumer.
Definition cl.c:331
void cl_print(const struct XCSF *xcsf, const struct Cl *c, const bool print_cond, const bool print_act, const bool print_pred)
Prints a classifier.
Definition cl.c:241
Functions operating on classifiers.
void condition_set(const struct XCSF *xcsf, struct Cl *c)
Sets a classifier's condition functions to the implementations.
Definition condition.c:41
Interface for classifier conditions.
static void cond_free(const struct XCSF *xcsf, const struct Cl *c)
Frees the memory used by the classifier condition.
Definition condition.h:264
static bool cond_mutate(const struct XCSF *xcsf, const struct Cl *c)
Performs classifier condition mutation.
Definition condition.h:229
static bool cond_crossover(const struct XCSF *xcsf, const struct Cl *c1, const struct Cl *c2)
Performs classifier condition crossover.
Definition condition.h:190
static bool cond_general(const struct XCSF *xcsf, const struct Cl *c1, const struct Cl *c2)
Returns whether classifier c1 has a condition more general than c2.
Definition condition.h:204
static size_t cond_save(const struct XCSF *xcsf, const struct Cl *c, FILE *fp)
Writes the condition to a file.
Definition condition.h:138
static void cond_json_import(const struct XCSF *xcsf, struct Cl *c, const cJSON *json)
Creates a condition from a cJSON object.
Definition condition.h:310
static char * cond_json_export(const struct XCSF *xcsf, const struct Cl *c)
Returns a json formatted string representation of a condition.
Definition condition.h:298
static void cond_copy(const struct XCSF *xcsf, struct Cl *dest, const struct Cl *src)
Copies the condition from one classifier to another.
Definition condition.h:241
static double cond_size(const struct XCSF *xcsf, const struct Cl *c)
Returns the size of the classifier condition.
Definition condition.h:163
static void cond_cover(const struct XCSF *xcsf, const struct Cl *c, const double *x)
Generates a condition that matches the current input.
Definition condition.h:253
static void cond_init(const struct XCSF *xcsf, struct Cl *c)
Initialises a classifier's condition.
Definition condition.h:275
static bool cond_match(const struct XCSF *xcsf, const struct Cl *c, const double *x)
Calculates whether the condition matches the input.
Definition condition.h:217
static size_t cond_load(const struct XCSF *xcsf, struct Cl *c, FILE *fp)
Reads the condition from a file.
Definition condition.h:151
static void cond_update(const struct XCSF *xcsf, const struct Cl *c, const double *x, const double *y)
Updates the classifier's condition.
Definition condition.h:176
Evolutionary algorithm functions.
Loss functions for calculating prediction error.
void prediction_set(const struct XCSF *xcsf, struct Cl *c)
Sets a classifier's prediction functions to the implementations.
Definition prediction.c:36
Interface for classifier predictions.
static double pred_size(const struct XCSF *xcsf, const struct Cl *c)
Returns the size of the classifier prediction.
Definition prediction.h:151
static char * pred_json_export(const struct XCSF *xcsf, const struct Cl *c)
Returns a json formatted string representation of a prediction.
Definition prediction.h:261
static void pred_json_import(const struct XCSF *xcsf, struct Cl *c, const cJSON *json)
Creates a prediction from a cJSON object.
Definition prediction.h:273
static bool pred_mutate(const struct XCSF *xcsf, const struct Cl *c)
Performs classifier prediction mutation.
Definition prediction.h:177
static void pred_compute(const struct XCSF *xcsf, const struct Cl *c, const double *x)
Computes the current classifier prediction using the input.
Definition prediction.h:189
static size_t pred_save(const struct XCSF *xcsf, const struct Cl *c, FILE *fp)
Writes the prediction to a file.
Definition prediction.h:126
static void pred_update(const struct XCSF *xcsf, const struct Cl *c, const double *x, const double *y)
Updates the classifier's prediction.
Definition prediction.h:248
static void pred_copy(const struct XCSF *xcsf, struct Cl *dest, const struct Cl *src)
Copies the prediction from one classifier to another.
Definition prediction.h:201
static bool pred_crossover(const struct XCSF *xcsf, const struct Cl *c1, const struct Cl *c2)
Performs classifier prediction crossover.
Definition prediction.h:164
static void pred_init(const struct XCSF *xcsf, struct Cl *c)
Initialises a classifier's prediction.
Definition prediction.h:223
static size_t pred_load(const struct XCSF *xcsf, struct Cl *c, FILE *fp)
Reads the prediction from a file.
Definition prediction.h:139
static void pred_free(const struct XCSF *xcsf, const struct Cl *c)
Frees the memory used by the classifier prediction.
Definition prediction.h:212
Classifier data structure.
Definition xcsf.h:45
int mtotal
Total number of times actually matched an input.
Definition xcsf.h:62
struct PredVtbl const * pred_vptr
Functions acting on predictions.
Definition xcsf.h:47
int time
Time EA last executed in a participating set.
Definition xcsf.h:57
struct ActVtbl const * act_vptr
Functions acting on actions.
Definition xcsf.h:48
double err
Error.
Definition xcsf.h:52
int action
Current classifier action.
Definition xcsf.h:60
bool m
Whether the classifier matches current input.
Definition xcsf.h:58
int age
Total number of times match testing been performed.
Definition xcsf.h:61
int num
Numerosity.
Definition xcsf.h:54
int exp
Experience.
Definition xcsf.h:55
double size
Average participated set size.
Definition xcsf.h:56
double fit
Fitness.
Definition xcsf.h:53
struct CondVtbl const * cond_vptr
Functions acting on conditions.
Definition xcsf.h:46
double * prediction
Current classifier prediction.
Definition xcsf.h:59
XCSF data structure.
Definition xcsf.h:85
Utility functions for random number handling, etc.