XCSF  1.4.7
XCSF learning classifier system
cond_rectangle.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 "xcsf.h"
28 
32 struct CondRectangle {
33  double *b1;
34  double *b2;
35  double *mu;
36 };
37 
38 bool
39 cond_rectangle_crossover(const struct XCSF *xcsf, const struct Cl *c1,
40  const struct Cl *c2);
41 
42 bool
43 cond_rectangle_general(const struct XCSF *xcsf, const struct Cl *c1,
44  const struct Cl *c2);
45 
46 bool
47 cond_rectangle_match(const struct XCSF *xcsf, const struct Cl *c,
48  const double *x);
49 
50 bool
51 cond_rectangle_mutate(const struct XCSF *xcsf, const struct Cl *c);
52 
53 void
54 cond_rectangle_copy(const struct XCSF *xcsf, struct Cl *dest,
55  const struct Cl *src);
56 
57 void
58 cond_rectangle_cover(const struct XCSF *xcsf, const struct Cl *c,
59  const double *x);
60 
61 void
62 cond_rectangle_free(const struct XCSF *xcsf, const struct Cl *c);
63 
64 void
65 cond_rectangle_init(const struct XCSF *xcsf, struct Cl *c);
66 
67 void
68 cond_rectangle_print(const struct XCSF *xcsf, const struct Cl *c);
69 
70 void
71 cond_rectangle_update(const struct XCSF *xcsf, const struct Cl *c,
72  const double *x, const double *y);
73 
74 double
75 cond_rectangle_size(const struct XCSF *xcsf, const struct Cl *c);
76 
77 size_t
78 cond_rectangle_save(const struct XCSF *xcsf, const struct Cl *c, FILE *fp);
79 
80 size_t
81 cond_rectangle_load(const struct XCSF *xcsf, struct Cl *c, FILE *fp);
82 
83 char *
84 cond_rectangle_json_export(const struct XCSF *xcsf, const struct Cl *c);
85 
86 void
87 cond_rectangle_json_import(const struct XCSF *xcsf, struct Cl *c,
88  const cJSON *json);
89 
93 static struct CondVtbl const cond_rectangle_vtbl = {
102 };
void cond_rectangle_copy(const struct XCSF *xcsf, struct Cl *dest, const struct Cl *src)
Copies a hyperrectangle condition from one classifier to another.
void cond_rectangle_free(const struct XCSF *xcsf, const struct Cl *c)
Frees the memory used by a hyperrectangle condition.
static struct CondVtbl const cond_rectangle_vtbl
Hyperrectangle condition implemented functions.
bool cond_rectangle_general(const struct XCSF *xcsf, const struct Cl *c1, const struct Cl *c2)
Returns whether classifier c1 has a condition more general than c2.
void cond_rectangle_json_import(const struct XCSF *xcsf, struct Cl *c, const cJSON *json)
Creates a hyperrectangle from a cJSON object.
char * cond_rectangle_json_export(const struct XCSF *xcsf, const struct Cl *c)
Returns a json formatted string representation of a hyperrectangle.
void cond_rectangle_print(const struct XCSF *xcsf, const struct Cl *c)
Prints a hyperrectangle condition.
void cond_rectangle_update(const struct XCSF *xcsf, const struct Cl *c, const double *x, const double *y)
Updates a hyperrectangle, sliding the centers towards the mean input.
void cond_rectangle_init(const struct XCSF *xcsf, struct Cl *c)
Creates and initialises a hyperrectangle condition.
size_t cond_rectangle_save(const struct XCSF *xcsf, const struct Cl *c, FILE *fp)
Writes a hyperrectangle condition to a file.
bool cond_rectangle_mutate(const struct XCSF *xcsf, const struct Cl *c)
Mutates a hyperrectangle condition with the self-adaptive rate.
bool cond_rectangle_crossover(const struct XCSF *xcsf, const struct Cl *c1, const struct Cl *c2)
Performs uniform crossover with two hyperrectangle conditions.
double cond_rectangle_size(const struct XCSF *xcsf, const struct Cl *c)
Returns the size of a hyperrectangle condition.
size_t cond_rectangle_load(const struct XCSF *xcsf, struct Cl *c, FILE *fp)
Reads a hyperrectangle condition from a file.
void cond_rectangle_cover(const struct XCSF *xcsf, const struct Cl *c, const double *x)
Generates a hyperrectangle that matches the current input.
bool cond_rectangle_match(const struct XCSF *xcsf, const struct Cl *c, const double *x)
Calculates whether a hyperrectangle condition matches an input.
Interface for classifier conditions.
Definition: __init__.py:1
Classifier data structure.
Definition: xcsf.h:45
Hyperrectangle condition data structure.
double * b2
Spreads for CSR, second bound for UBR.
double * mu
Mutation rates.
double * b1
Centers for CSR, first bound for UBR.
Condition interface data structure.
Definition: condition.h:104
XCSF data structure.
Definition: xcsf.h:85
XCSF data structures.