XCSF  1.4.7
XCSF learning classifier system
pred_neural.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 "neural.h"
27 #include "neural_activations.h"
28 #include "neural_layer.h"
29 #include "prediction.h"
30 #include "xcsf.h"
31 
35 struct PredNeural {
36  struct Net net;
37 };
38 
39 void
41 
42 char *
43 pred_neural_param_json_import(struct XCSF *xcsf, cJSON *json);
44 
45 bool
46 pred_neural_crossover(const struct XCSF *xcsf, const struct Cl *c1,
47  const struct Cl *c2);
48 
49 bool
50 pred_neural_mutate(const struct XCSF *xcsf, const struct Cl *c);
51 
52 double
53 pred_neural_eta(const struct XCSF *xcsf, const struct Cl *c, const int layer);
54 
55 int
56 pred_neural_connections(const struct XCSF *xcsf, const struct Cl *c,
57  const int layer);
58 
59 int
60 pred_neural_layers(const struct XCSF *xcsf, const struct Cl *c);
61 
62 int
63 pred_neural_neurons(const struct XCSF *xcsf, const struct Cl *c,
64  const int layer);
65 
66 double
67 pred_neural_size(const struct XCSF *xcsf, const struct Cl *c);
68 
69 size_t
70 pred_neural_load(const struct XCSF *xcsf, struct Cl *c, FILE *fp);
71 
72 size_t
73 pred_neural_save(const struct XCSF *xcsf, const struct Cl *c, FILE *fp);
74 
75 void
76 pred_neural_compute(const struct XCSF *xcsf, const struct Cl *c,
77  const double *x);
78 
79 void
80 pred_neural_copy(const struct XCSF *xcsf, struct Cl *dest,
81  const struct Cl *src);
82 
83 void
84 pred_neural_free(const struct XCSF *xcsf, const struct Cl *c);
85 
86 void
87 pred_neural_init(const struct XCSF *xcsf, struct Cl *c);
88 
89 void
90 pred_neural_print(const struct XCSF *xcsf, const struct Cl *c);
91 
92 void
93 pred_neural_update(const struct XCSF *xcsf, const struct Cl *c, const double *x,
94  const double *y);
95 
96 void
97 pred_neural_expand(const struct XCSF *xcsf, const struct Cl *c);
98 
99 void
100 pred_neural_ae_to_classifier(const struct XCSF *xcsf, const struct Cl *c,
101  const int n_del);
102 
103 char *
104 pred_neural_json_export(const struct XCSF *xcsf, const struct Cl *c);
105 
106 void
107 pred_neural_json_import(const struct XCSF *xcsf, struct Cl *c,
108  const cJSON *json);
109 
114 static struct PredVtbl const pred_neural_vtbl = {
120 };
Definition: __init__.py:1
An implementation of a multi-layer perceptron neural network.
Neural network activation functions.
Interface for neural network layers.
int pred_neural_layers(const struct XCSF *xcsf, const struct Cl *c)
Returns the number of layers within a neural network prediction.
Definition: pred_neural.c:292
bool pred_neural_mutate(const struct XCSF *xcsf, const struct Cl *c)
Mutates a neural network prediction.
Definition: pred_neural.c:153
char * pred_neural_json_export(const struct XCSF *xcsf, const struct Cl *c)
Returns a json formatted string representation of a neural prediction.
Definition: pred_neural.c:392
size_t pred_neural_save(const struct XCSF *xcsf, const struct Cl *c, FILE *fp)
Writes a neural network prediction to a file.
Definition: pred_neural.c:183
int pred_neural_connections(const struct XCSF *xcsf, const struct Cl *c, const int layer)
Returns the number of active connections in a neural prediction layer.
Definition: pred_neural.c:268
void pred_neural_compute(const struct XCSF *xcsf, const struct Cl *c, const double *x)
Forward propagates a neural network prediction with a provided input.
Definition: pred_neural.c:106
void pred_neural_print(const struct XCSF *xcsf, const struct Cl *c)
Prints a neural network prediction.
Definition: pred_neural.c:122
void pred_neural_free(const struct XCSF *xcsf, const struct Cl *c)
Frees the memory used by a neural network prediction.
Definition: pred_neural.c:58
void pred_neural_init(const struct XCSF *xcsf, struct Cl *c)
Creates and initialises a neural network prediction.
Definition: pred_neural.c:45
char * pred_neural_param_json_import(struct XCSF *xcsf, cJSON *json)
Sets the neural network parameters from a cJSON object.
Definition: pred_neural.c:465
int pred_neural_neurons(const struct XCSF *xcsf, const struct Cl *c, const int layer)
Returns the number of neurons in a neural prediction layer.
Definition: pred_neural.c:240
void pred_neural_ae_to_classifier(const struct XCSF *xcsf, const struct Cl *c, const int n_del)
Removes prediction (decoder) layers and inserts softmax output layer.
Definition: pred_neural.c:349
void pred_neural_json_import(const struct XCSF *xcsf, struct Cl *c, const cJSON *json)
Creates a neural prediction from a cJSON object.
Definition: pred_neural.c:414
void pred_neural_copy(const struct XCSF *xcsf, struct Cl *dest, const struct Cl *src)
Copies a neural network prediction from one classifier to another.
Definition: pred_neural.c:73
static struct PredVtbl const pred_neural_vtbl
Multi-layer perceptron neural network prediction implemented functions.
Definition: pred_neural.h:114
void pred_neural_expand(const struct XCSF *xcsf, const struct Cl *c)
Creates and inserts a hidden layer before the prediction output layer.
Definition: pred_neural.c:306
double pred_neural_eta(const struct XCSF *xcsf, const struct Cl *c, const int layer)
Returns the gradient descent rate of a neural prediction layer.
Definition: pred_neural.c:216
void pred_neural_update(const struct XCSF *xcsf, const struct Cl *c, const double *x, const double *y)
Backward propagates and updates a neural network prediction.
Definition: pred_neural.c:91
bool pred_neural_crossover(const struct XCSF *xcsf, const struct Cl *c1, const struct Cl *c2)
Dummy function since neural predictions do not perform crossover.
Definition: pred_neural.c:137
double pred_neural_size(const struct XCSF *xcsf, const struct Cl *c)
Returns the size of a neural network prediction.
Definition: pred_neural.c:168
void pred_neural_param_defaults(struct XCSF *xcsf)
Initialises default neural prediction parameters.
Definition: pred_neural.c:431
size_t pred_neural_load(const struct XCSF *xcsf, struct Cl *c, FILE *fp)
Reads a neural network prediction from a file.
Definition: pred_neural.c:199
Interface for classifier predictions.
Classifier data structure.
Definition: xcsf.h:45
Neural network data structure.
Definition: neural.h:48
Multi-layer perceptron neural network prediction data structure.
Definition: pred_neural.h:35
struct Net net
Neural network.
Definition: pred_neural.h:36
Prediction interface data structure.
Definition: prediction.h:96
XCSF data structure.
Definition: xcsf.h:85
XCSF data structures.