XCSF  1.4.7
XCSF learning classifier system
pred_nlms.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 PredNLMS {
33  int n;
34  int n_weights;
35  double *weights;
36  double *mu;
37  double eta;
38  double *tmp_input;
39 };
40 
41 char *
42 pred_nlms_param_json_import(struct XCSF *xcsf, cJSON *json);
43 
44 char *
46 
47 bool
48 pred_nlms_crossover(const struct XCSF *xcsf, const struct Cl *c1,
49  const struct Cl *c2);
50 
51 bool
52 pred_nlms_mutate(const struct XCSF *xcsf, const struct Cl *c);
53 
54 double
55 pred_nlms_size(const struct XCSF *xcsf, const struct Cl *c);
56 
57 size_t
58 pred_nlms_load(const struct XCSF *xcsf, struct Cl *c, FILE *fp);
59 
60 size_t
61 pred_nlms_save(const struct XCSF *xcsf, const struct Cl *c, FILE *fp);
62 
63 void
64 pred_nlms_compute(const struct XCSF *xcsf, const struct Cl *c, const double *x);
65 
66 void
67 pred_nlms_copy(const struct XCSF *xcsf, struct Cl *dest, const struct Cl *src);
68 
69 void
70 pred_nlms_free(const struct XCSF *xcsf, const struct Cl *c);
71 
72 void
73 pred_nlms_init(const struct XCSF *xcsf, struct Cl *c);
74 
75 void
76 pred_nlms_print(const struct XCSF *xcsf, const struct Cl *c);
77 
78 void
79 pred_nlms_update(const struct XCSF *xcsf, const struct Cl *c, const double *x,
80  const double *y);
81 
82 char *
83 pred_nlms_json_export(const struct XCSF *xcsf, const struct Cl *c);
84 
85 void
86 pred_nlms_json_import(const struct XCSF *xcsf, struct Cl *c, const cJSON *json);
87 
91 static struct PredVtbl const pred_nlms_vtbl = {
97 };
Definition: __init__.py:1
void pred_nlms_json_import(const struct XCSF *xcsf, struct Cl *c, const cJSON *json)
Creates an NLMS prediction from a cJSON object.
Definition: pred_nlms.c:290
char * pred_nlms_param_json_export(const struct XCSF *xcsf)
Returns a json formatted string of the NLMS parameters.
Definition: pred_nlms.c:319
void pred_nlms_compute(const struct XCSF *xcsf, const struct Cl *c, const double *x)
Computes the current NLMS prediction for a provided input.
Definition: pred_nlms.c:138
char * pred_nlms_json_export(const struct XCSF *xcsf, const struct Cl *c)
Returns a json formatted string representation of an NLMS prediction.
Definition: pred_nlms.c:264
size_t pred_nlms_save(const struct XCSF *xcsf, const struct Cl *c, FILE *fp)
Writes an NLMS prediction to a file.
Definition: pred_nlms.c:223
bool pred_nlms_crossover(const struct XCSF *xcsf, const struct Cl *c1, const struct Cl *c2)
Dummy function since NLMS predictions do not perform crossover.
Definition: pred_nlms.c:170
void pred_nlms_print(const struct XCSF *xcsf, const struct Cl *c)
Prints an NLMS prediction.
Definition: pred_nlms.c:155
void pred_nlms_init(const struct XCSF *xcsf, struct Cl *c)
Initialises an NLMS prediction.
Definition: pred_nlms.c:44
static struct PredVtbl const pred_nlms_vtbl
Normalised least mean squares prediction implemented functions.
Definition: pred_nlms.h:91
void pred_nlms_free(const struct XCSF *xcsf, const struct Cl *c)
Frees the memory used by an NLMS prediction.
Definition: pred_nlms.c:96
bool pred_nlms_mutate(const struct XCSF *xcsf, const struct Cl *c)
Mutates the gradient descent rate used to update an NLMS prediction.
Definition: pred_nlms.c:186
double pred_nlms_size(const struct XCSF *xcsf, const struct Cl *c)
Returns the size of an NLMS prediction.
Definition: pred_nlms.c:208
void pred_nlms_update(const struct XCSF *xcsf, const struct Cl *c, const double *x, const double *y)
Updates an NLMS prediction for a given input and truth sample.
Definition: pred_nlms.c:115
char * pred_nlms_param_json_import(struct XCSF *xcsf, cJSON *json)
Sets the NLMS parameters from a cJSON object.
Definition: pred_nlms.c:341
void pred_nlms_copy(const struct XCSF *xcsf, struct Cl *dest, const struct Cl *src)
Copies an NLMS prediction from one classifier to another.
Definition: pred_nlms.c:79
size_t pred_nlms_load(const struct XCSF *xcsf, struct Cl *c, FILE *fp)
Reads an NLMS prediction from a file.
Definition: pred_nlms.c:244
Interface for classifier predictions.
Classifier data structure.
Definition: xcsf.h:45
Normalised least mean squares prediction data structure.
Definition: pred_nlms.h:32
double * mu
Mutation rates.
Definition: pred_nlms.h:36
int n_weights
Total number of weights.
Definition: pred_nlms.h:34
double * tmp_input
Temporary storage for updating weights.
Definition: pred_nlms.h:38
int n
Number of weights for each predicted variable.
Definition: pred_nlms.h:33
double eta
Gradient descent rate.
Definition: pred_nlms.h:37
double * weights
Weights used to compute prediction.
Definition: pred_nlms.h:35
Prediction interface data structure.
Definition: prediction.h:96
XCSF data structure.
Definition: xcsf.h:85
XCSF data structures.