XCSF  1.4.7
XCSF learning classifier system
cond_ternary.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 CondTernary {
33  char *string;
34  int length;
35  double *mu;
36  char *tmp_input;
37 };
38 
39 void
41 
42 char *
44 
45 char *
46 cond_ternary_param_json_import(struct XCSF *xcsf, cJSON *json);
47 
48 bool
49 cond_ternary_crossover(const struct XCSF *xcsf, const struct Cl *c1,
50  const struct Cl *c2);
51 
52 bool
53 cond_ternary_general(const struct XCSF *xcsf, const struct Cl *c1,
54  const struct Cl *c2);
55 
56 bool
57 cond_ternary_match(const struct XCSF *xcsf, const struct Cl *c,
58  const double *x);
59 
60 bool
61 cond_ternary_mutate(const struct XCSF *xcsf, const struct Cl *c);
62 
63 void
64 cond_ternary_copy(const struct XCSF *xcsf, struct Cl *dest,
65  const struct Cl *src);
66 
67 void
68 cond_ternary_cover(const struct XCSF *xcsf, const struct Cl *c,
69  const double *x);
70 
71 void
72 cond_ternary_free(const struct XCSF *xcsf, const struct Cl *c);
73 
74 void
75 cond_ternary_init(const struct XCSF *xcsf, struct Cl *c);
76 
77 void
78 cond_ternary_print(const struct XCSF *xcsf, const struct Cl *c);
79 
80 void
81 cond_ternary_update(const struct XCSF *xcsf, const struct Cl *c,
82  const double *x, const double *y);
83 
84 double
85 cond_ternary_size(const struct XCSF *xcsf, const struct Cl *c);
86 
87 size_t
88 cond_ternary_save(const struct XCSF *xcsf, const struct Cl *c, FILE *fp);
89 
90 size_t
91 cond_ternary_load(const struct XCSF *xcsf, struct Cl *c, FILE *fp);
92 
93 char *
94 cond_ternary_json_export(const struct XCSF *xcsf, const struct Cl *c);
95 
96 void
97 cond_ternary_json_import(const struct XCSF *xcsf, struct Cl *c,
98  const cJSON *json);
99 
103 static struct CondVtbl const cond_ternary_vtbl = {
112 };
double cond_ternary_size(const struct XCSF *xcsf, const struct Cl *c)
Returns the size of a ternary condition.
Definition: cond_ternary.c:277
static struct CondVtbl const cond_ternary_vtbl
Ternary condition implemented functions.
Definition: cond_ternary.h:103
void cond_ternary_init(const struct XCSF *xcsf, struct Cl *c)
Creates and initialises a ternary bitstring condition.
Definition: cond_ternary.c:64
bool cond_ternary_match(const struct XCSF *xcsf, const struct Cl *c, const double *x)
Calculates whether a ternary condition matches an input.
Definition: cond_ternary.c:161
char * cond_ternary_param_json_export(const struct XCSF *xcsf)
Returns a json formatted string of the ternary parameters.
Definition: cond_ternary.c:387
void cond_ternary_update(const struct XCSF *xcsf, const struct Cl *c, const double *x, const double *y)
Dummy update function.
Definition: cond_ternary.c:144
bool cond_ternary_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: cond_ternary.c:238
void cond_ternary_copy(const struct XCSF *xcsf, struct Cl *dest, const struct Cl *src)
Copies a ternary condition from one classifier to another.
Definition: cond_ternary.c:99
char * cond_ternary_param_json_import(struct XCSF *xcsf, cJSON *json)
Sets the ternary parameters from a cJSON object.
Definition: cond_ternary.c:405
void cond_ternary_cover(const struct XCSF *xcsf, const struct Cl *c, const double *x)
Generates a ternary condition that matches the current input.
Definition: cond_ternary.c:120
bool cond_ternary_mutate(const struct XCSF *xcsf, const struct Cl *c)
Mutates a ternary condition.
Definition: cond_ternary.c:211
void cond_ternary_print(const struct XCSF *xcsf, const struct Cl *c)
Prints a ternary condition.
Definition: cond_ternary.c:263
void cond_ternary_json_import(const struct XCSF *xcsf, struct Cl *c, const cJSON *json)
Creates a ternary condition from a cJSON object.
Definition: cond_ternary.c:362
void cond_ternary_free(const struct XCSF *xcsf, const struct Cl *c)
Frees the memory used by a ternary condition.
Definition: cond_ternary.c:82
bool cond_ternary_crossover(const struct XCSF *xcsf, const struct Cl *c1, const struct Cl *c2)
Performs uniform crossover with two ternary conditions.
Definition: cond_ternary.c:185
size_t cond_ternary_save(const struct XCSF *xcsf, const struct Cl *c, FILE *fp)
Writes a ternary condition to a file.
Definition: cond_ternary.c:292
char * cond_ternary_json_export(const struct XCSF *xcsf, const struct Cl *c)
Returns a json formatted string representation of a ternary condition.
Definition: cond_ternary.c:338
void cond_ternary_param_defaults(struct XCSF *xcsf)
Initialises default ternary condition parameters.
Definition: cond_ternary.c:426
size_t cond_ternary_load(const struct XCSF *xcsf, struct Cl *c, FILE *fp)
Reads a ternary condition from a file.
Definition: cond_ternary.c:311
Interface for classifier conditions.
Definition: __init__.py:1
Classifier data structure.
Definition: xcsf.h:45
Ternary condition data structure.
Definition: cond_ternary.h:32
int length
Length of the bitstring.
Definition: cond_ternary.h:34
char * string
Ternary bitstring.
Definition: cond_ternary.h:33
double * mu
Mutation rates.
Definition: cond_ternary.h:35
char * tmp_input
Temporary storage for float conversion.
Definition: cond_ternary.h:36
Condition interface data structure.
Definition: condition.h:104
XCSF data structure.
Definition: xcsf.h:85
XCSF data structures.