XCSF  1.4.7
XCSF learning classifier system
pred_rls.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 "prediction.h"
27 #include "xcsf.h"
28 
32 struct PredRLS {
33  int n;
34  int n_weights;
35  double *weights;
36  double *matrix;
37  double *tmp_input;
38  double *tmp_vec;
39  double *tmp_matrix1;
40  double *tmp_matrix2;
41 };
42 
43 char *
44 pred_rls_param_json_export(const struct XCSF *xcsf);
45 
46 char *
47 pred_rls_param_json_import(struct XCSF *xcsf, cJSON *json);
48 
49 bool
50 pred_rls_crossover(const struct XCSF *xcsf, const struct Cl *c1,
51  const struct Cl *c2);
52 
53 bool
54 pred_rls_mutate(const struct XCSF *xcsf, const struct Cl *c);
55 
56 double
57 pred_rls_size(const struct XCSF *xcsf, const struct Cl *c);
58 
59 size_t
60 pred_rls_load(const struct XCSF *xcsf, struct Cl *c, FILE *fp);
61 
62 size_t
63 pred_rls_save(const struct XCSF *xcsf, const struct Cl *c, FILE *fp);
64 
65 void
66 pred_rls_compute(const struct XCSF *xcsf, const struct Cl *c, const double *x);
67 
68 void
69 pred_rls_copy(const struct XCSF *xcsf, struct Cl *dest, const struct Cl *src);
70 
71 void
72 pred_rls_free(const struct XCSF *xcsf, const struct Cl *c);
73 
74 void
75 pred_rls_init(const struct XCSF *xcsf, struct Cl *c);
76 
77 void
78 pred_rls_print(const struct XCSF *xcsf, const struct Cl *c);
79 
80 void
81 pred_rls_update(const struct XCSF *xcsf, const struct Cl *c, const double *x,
82  const double *y);
83 
84 char *
85 pred_rls_json_export(const struct XCSF *xcsf, const struct Cl *c);
86 
87 void
88 pred_rls_json_import(const struct XCSF *xcsf, struct Cl *c, const cJSON *json);
89 
93 static struct PredVtbl const pred_rls_vtbl = {
99 };
Definition: __init__.py:1
void pred_rls_free(const struct XCSF *xcsf, const struct Cl *c)
Frees the memory used by an RLS prediction.
Definition: pred_rls.c:84
void pred_rls_copy(const struct XCSF *xcsf, struct Cl *dest, const struct Cl *src)
Copies an RLS prediction from one classifier to another.
Definition: pred_rls.c:69
void pred_rls_update(const struct XCSF *xcsf, const struct Cl *c, const double *x, const double *y)
Updates an RLS prediction for a given input and truth sample.
Definition: pred_rls.c:106
double pred_rls_size(const struct XCSF *xcsf, const struct Cl *c)
Returns the size of an RLS prediction.
Definition: pred_rls.c:220
static struct PredVtbl const pred_rls_vtbl
Recursive least mean squares prediction implemented functions.
Definition: pred_rls.h:93
void pred_rls_init(const struct XCSF *xcsf, struct Cl *c)
Initialises an RLS prediction.
Definition: pred_rls.c:34
char * pred_rls_json_export(const struct XCSF *xcsf, const struct Cl *c)
Returns a json formatted string representation of an RLS prediction.
Definition: pred_rls.c:276
size_t pred_rls_load(const struct XCSF *xcsf, struct Cl *c, FILE *fp)
Reads an RLS prediction from a file.
Definition: pred_rls.c:256
void pred_rls_print(const struct XCSF *xcsf, const struct Cl *c)
Prints an RLS prediction.
Definition: pred_rls.c:175
char * pred_rls_param_json_export(const struct XCSF *xcsf)
Returns a json formatted string of the RLS parameters.
Definition: pred_rls.c:323
void pred_rls_json_import(const struct XCSF *xcsf, struct Cl *c, const cJSON *json)
Creates an RLS prediction from a cJSON object.
Definition: pred_rls.c:299
bool pred_rls_crossover(const struct XCSF *xcsf, const struct Cl *c1, const struct Cl *c2)
Dummy function since RLS predictions do not perform crossover.
Definition: pred_rls.c:190
char * pred_rls_param_json_import(struct XCSF *xcsf, cJSON *json)
Sets the RLS parameters from a cJSON object.
Definition: pred_rls.c:342
void pred_rls_compute(const struct XCSF *xcsf, const struct Cl *c, const double *x)
Computes the current RLS prediction for a provided input.
Definition: pred_rls.c:158
bool pred_rls_mutate(const struct XCSF *xcsf, const struct Cl *c)
Dummy function since RLS predictions do not perform mutation.
Definition: pred_rls.c:206
size_t pred_rls_save(const struct XCSF *xcsf, const struct Cl *c, FILE *fp)
Writes an RLS prediction to a file.
Definition: pred_rls.c:235
Interface for classifier predictions.
Classifier data structure.
Definition: xcsf.h:45
Recursive least mean squares prediction data structure.
Definition: pred_rls.h:32
double * tmp_vec
Temporary storage for updating weights.
Definition: pred_rls.h:38
double * tmp_input
Temporary storage for updating weights.
Definition: pred_rls.h:37
double * matrix
Gain matrix used to update weights.
Definition: pred_rls.h:36
int n
Number of weights for each predicted variable.
Definition: pred_rls.h:33
double * weights
Weights used to compute prediction.
Definition: pred_rls.h:35
int n_weights
Total number of weights.
Definition: pred_rls.h:34
double * tmp_matrix2
Temporary storage for updating gain matrix.
Definition: pred_rls.h:40
double * tmp_matrix1
Temporary storage for updating gain matrix.
Definition: pred_rls.h:39
Prediction interface data structure.
Definition: prediction.h:96
XCSF data structure.
Definition: xcsf.h:85
XCSF data structures.