XCSF  1.4.7
XCSF learning classifier system
cond_gp.h
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 #pragma once
25 
26 #include "condition.h"
27 #include "gp.h"
28 #include "xcsf.h"
29 
33 struct CondGP {
34  struct GPTree gp;
35 };
36 
37 void
39 
40 char *
41 cond_gp_param_json_export(const struct XCSF *xcsf);
42 
43 char *
44 cond_gp_param_json_import(struct XCSF *xcsf, cJSON *json);
45 
46 bool
47 cond_gp_crossover(const struct XCSF *xcsf, const struct Cl *c1,
48  const struct Cl *c2);
49 
50 bool
51 cond_gp_general(const struct XCSF *xcsf, const struct Cl *c1,
52  const struct Cl *c2);
53 
54 bool
55 cond_gp_match(const struct XCSF *xcsf, const struct Cl *c, const double *x);
56 
57 bool
58 cond_gp_mutate(const struct XCSF *xcsf, const struct Cl *c);
59 
60 void
61 cond_gp_copy(const struct XCSF *xcsf, struct Cl *dest, const struct Cl *src);
62 
63 void
64 cond_gp_cover(const struct XCSF *xcsf, const struct Cl *c, const double *x);
65 
66 void
67 cond_gp_free(const struct XCSF *xcsf, const struct Cl *c);
68 
69 void
70 cond_gp_init(const struct XCSF *xcsf, struct Cl *c);
71 
72 void
73 cond_gp_print(const struct XCSF *xcsf, const struct Cl *c);
74 
75 void
76 cond_gp_update(const struct XCSF *xcsf, const struct Cl *c, const double *x,
77  const double *y);
78 
79 double
80 cond_gp_size(const struct XCSF *xcsf, const struct Cl *c);
81 
82 size_t
83 cond_gp_save(const struct XCSF *xcsf, const struct Cl *c, FILE *fp);
84 
85 size_t
86 cond_gp_load(const struct XCSF *xcsf, struct Cl *c, FILE *fp);
87 
88 char *
89 cond_gp_json_export(const struct XCSF *xcsf, const struct Cl *c);
90 
91 void
92 cond_gp_json_import(const struct XCSF *xcsf, struct Cl *c, const cJSON *json);
93 
97 static struct CondVtbl const cond_gp_vtbl = {
103 };
void cond_gp_print(const struct XCSF *xcsf, const struct Cl *c)
Prints a tree-GP condition.
Definition: cond_gp.c:181
void cond_gp_cover(const struct XCSF *xcsf, const struct Cl *c, const double *x)
Generates a GP tree that matches the current input.
Definition: cond_gp.c:79
static struct CondVtbl const cond_gp_vtbl
Tree GP condition implemented functions.
Definition: cond_gp.h:97
void cond_gp_copy(const struct XCSF *xcsf, struct Cl *dest, const struct Cl *src)
Copies a tree-GP condition from one classifier to another.
Definition: cond_gp.c:63
size_t cond_gp_save(const struct XCSF *xcsf, const struct Cl *c, FILE *fp)
Writes a tree-GP condition to a file.
Definition: cond_gp.c:210
bool cond_gp_general(const struct XCSF *xcsf, const struct Cl *c1, const struct Cl *c2)
Dummy general function.
Definition: cond_gp.c:166
char * cond_gp_json_export(const struct XCSF *xcsf, const struct Cl *c)
Returns a json formatted string representation of a tree-GP condition.
Definition: cond_gp.c:242
void cond_gp_param_defaults(struct XCSF *xcsf)
Initialises default tree GP condition parameters.
Definition: cond_gp.c:286
bool cond_gp_crossover(const struct XCSF *xcsf, const struct Cl *c1, const struct Cl *c2)
Performs sub-tree crossover with two tree-GP conditions.
Definition: cond_gp.c:145
size_t cond_gp_load(const struct XCSF *xcsf, struct Cl *c, FILE *fp)
Reads a tree-GP condition from a file.
Definition: cond_gp.c:226
bool cond_gp_mutate(const struct XCSF *xcsf, const struct Cl *c)
Mutates a tree-GP condition with the self-adaptive rate.
Definition: cond_gp.c:130
char * cond_gp_param_json_import(struct XCSF *xcsf, cJSON *json)
Sets the tree GP parameters from a cJSON object.
Definition: cond_gp.c:274
void cond_gp_free(const struct XCSF *xcsf, const struct Cl *c)
Frees the memory used by a tree-GP condition.
Definition: cond_gp.c:48
bool cond_gp_match(const struct XCSF *xcsf, const struct Cl *c, const double *x)
Calculates whether a GP tree condition matches an input.
Definition: cond_gp.c:113
double cond_gp_size(const struct XCSF *xcsf, const struct Cl *c)
Returns the size of a tree-GP condition.
Definition: cond_gp.c:195
void cond_gp_json_import(const struct XCSF *xcsf, struct Cl *c, const cJSON *json)
Creates a tree GP condition from a cJSON object.
Definition: cond_gp.c:307
void cond_gp_init(const struct XCSF *xcsf, struct Cl *c)
Creates and initialises a tree-GP condition.
Definition: cond_gp.c:35
void cond_gp_update(const struct XCSF *xcsf, const struct Cl *c, const double *x, const double *y)
Dummy update function.
Definition: cond_gp.c:96
char * cond_gp_param_json_export(const struct XCSF *xcsf)
Returns a json formatted string of the tree GP parameters.
Definition: cond_gp.c:262
Interface for classifier conditions.
An implementation of GP trees based upon TinyGP.
Definition: __init__.py:1
Classifier data structure.
Definition: xcsf.h:45
Tree GP condition data structure.
Definition: cond_gp.h:33
struct GPTree gp
GP tree.
Definition: cond_gp.h:34
Condition interface data structure.
Definition: condition.h:104
GP tree data structure.
Definition: gp.h:44
XCSF data structure.
Definition: xcsf.h:85
XCSF data structures.