XCSF 1.4.8
XCSF learning classifier system
Loading...
Searching...
No Matches
clset_neural.c
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#include "clset_neural.h"
25#include "cl.h"
26#include "cond_neural.h"
27#include "condition.h"
28#include "pred_neural.h"
29#include "prediction.h"
30#include "utils.h"
31
38double
39clset_mean_cond_layers(const struct XCSF *xcsf, const struct Set *set)
40{
41 int sum = 0;
42 int cnt = 0;
43 if (xcsf->cond->type == COND_TYPE_NEURAL ||
44 xcsf->cond->type == RULE_TYPE_NEURAL) {
45 const struct Clist *iter = set->list;
46 while (iter != NULL) {
47 sum += cond_neural_layers(xcsf, iter->cl);
48 ++cnt;
49 iter = iter->next;
50 }
51 }
52 if (cnt != 0) {
53 return (double) sum / cnt;
54 }
55 return 0;
56}
64double
65clset_mean_cond_neurons(const struct XCSF *xcsf, const struct Set *set,
66 const int layer)
67{
68 int sum = 0;
69 int cnt = 0;
70 if (xcsf->cond->type == COND_TYPE_NEURAL ||
71 xcsf->cond->type == RULE_TYPE_NEURAL) {
72 const struct Clist *iter = set->list;
73 while (iter != NULL) {
74 sum += cond_neural_neurons(xcsf, iter->cl, layer);
75 ++cnt;
76 iter = iter->next;
77 }
78 }
79 if (cnt != 0) {
80 return (double) sum / cnt;
81 }
82 return 0;
83}
84
92double
93clset_mean_cond_connections(const struct XCSF *xcsf, const struct Set *set,
94 const int layer)
95{
96 int sum = 0;
97 int cnt = 0;
98 if (xcsf->cond->type == COND_TYPE_NEURAL ||
99 xcsf->cond->type == RULE_TYPE_NEURAL) {
100 const struct Clist *iter = set->list;
101 while (iter != NULL) {
102 sum += cond_neural_connections(xcsf, iter->cl, layer);
103 ++cnt;
104 iter = iter->next;
105 }
106 }
107 if (cnt != 0) {
108 return (double) sum / cnt;
109 }
110 return 0;
111}
112
120double
121clset_mean_pred_neurons(const struct XCSF *xcsf, const struct Set *set,
122 const int layer)
123{
124 int sum = 0;
125 int cnt = 0;
126 if (xcsf->pred->type == PRED_TYPE_NEURAL) {
127 const struct Clist *iter = set->list;
128 while (iter != NULL) {
129 sum += pred_neural_neurons(xcsf, iter->cl, layer);
130 ++cnt;
131 iter = iter->next;
132 }
133 }
134 if (cnt != 0) {
135 return (double) sum / cnt;
136 }
137 return 0;
138}
139
146double
147clset_mean_pred_layers(const struct XCSF *xcsf, const struct Set *set)
148{
149 int sum = 0;
150 int cnt = 0;
151 if (xcsf->pred->type == PRED_TYPE_NEURAL) {
152 const struct Clist *iter = set->list;
153 while (iter != NULL) {
154 sum += pred_neural_layers(xcsf, iter->cl);
155 ++cnt;
156 iter = iter->next;
157 }
158 }
159 if (cnt != 0) {
160 return (double) sum / cnt;
161 }
162 return 0;
163}
164
172double
173clset_mean_pred_eta(const struct XCSF *xcsf, const struct Set *set,
174 const int layer)
175{
176 double sum = 0;
177 int cnt = 0;
178 if (xcsf->pred->type == PRED_TYPE_NEURAL) {
179 const struct Clist *iter = set->list;
180 while (iter != NULL) {
181 sum += pred_neural_eta(xcsf, iter->cl, layer);
182 ++cnt;
183 iter = iter->next;
184 }
185 }
186 if (cnt != 0) {
187 return sum / cnt;
188 }
189 return 0;
190}
191
199double
200clset_mean_pred_connections(const struct XCSF *xcsf, const struct Set *set,
201 const int layer)
202{
203 int sum = 0;
204 int cnt = 0;
205 if (xcsf->pred->type == PRED_TYPE_NEURAL) {
206 const struct Clist *iter = set->list;
207 while (iter != NULL) {
208 sum += pred_neural_connections(xcsf, iter->cl, layer);
209 ++cnt;
210 iter = iter->next;
211 }
212 }
213 if (cnt != 0) {
214 return (double) sum / cnt;
215 }
216 return 0;
217}
Functions operating on classifiers.
double clset_mean_cond_neurons(const struct XCSF *xcsf, const struct Set *set, const int layer)
Calculates the mean number of condition neurons for a given layer.
double clset_mean_pred_eta(const struct XCSF *xcsf, const struct Set *set, const int layer)
Calculates the mean prediction layer ETA of classifiers in the set.
double clset_mean_cond_layers(const struct XCSF *xcsf, const struct Set *set)
Calculates the mean number of condition layers in the set.
double clset_mean_pred_connections(const struct XCSF *xcsf, const struct Set *set, const int layer)
Calculates the mean number of prediction connections in the set.
double clset_mean_pred_layers(const struct XCSF *xcsf, const struct Set *set)
Calculates the mean number of prediction layers in the set.
double clset_mean_cond_connections(const struct XCSF *xcsf, const struct Set *set, const int layer)
Calculates the mean number of condition connections in the set.
double clset_mean_pred_neurons(const struct XCSF *xcsf, const struct Set *set, const int layer)
Calculates the mean number of prediction neurons for a given layer.
Functions operating on sets of neural classifiers.
int cond_neural_neurons(const struct XCSF *xcsf, const struct Cl *c, int layer)
Returns the number of neurons in a neural condition layer.
int cond_neural_layers(const struct XCSF *xcsf, const struct Cl *c)
Returns the number of layers within a neural network condition.
int cond_neural_connections(const struct XCSF *xcsf, const struct Cl *c, int layer)
Returns the number of active connections in a neural condition layer.
Multi-layer perceptron neural network condition functions.
Interface for classifier conditions.
#define RULE_TYPE_NEURAL
Condition type and action type neural.
Definition condition.h:38
#define COND_TYPE_NEURAL
Condition type neural network.
Definition condition.h:33
int pred_neural_layers(const struct XCSF *xcsf, const struct Cl *c)
Returns the number of layers within a neural network prediction.
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.
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.
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.
Multi-layer perceptron neural network prediction functions.
Interface for classifier predictions.
#define PRED_TYPE_NEURAL
Prediction type neural.
Definition prediction.h:34
Classifier linked list.
Definition xcsf.h:68
struct Clist * next
Pointer to the next list element.
Definition xcsf.h:70
struct Cl * cl
Pointer to classifier data structure.
Definition xcsf.h:69
Classifier set.
Definition xcsf.h:76
struct Clist * list
Linked list of classifiers.
Definition xcsf.h:77
XCSF data structure.
Definition xcsf.h:85
Utility functions for random number handling, etc.