38 switch (
xcsf->pred->type) {
54 printf(
"prediction_set(): invalid type: %d\n",
xcsf->pred->type);
81 printf(
"prediction_type_as_string(): invalid type: %d\n", type);
141 cJSON *json = cJSON_CreateObject();
142 cJSON_AddStringToObject(json,
"type",
144 char *json_str = NULL;
145 switch (pred->
type) {
160 if (json_str != NULL) {
161 cJSON *params = cJSON_Parse(json_str);
162 if (params != NULL) {
163 cJSON_AddItemToObject(json,
"args", params);
167 char *
string = cJSON_Print(json);
182 switch (
xcsf->pred->type) {
197 printf(
"pred_param_json_import(): unknown type.\n");
214 s += fwrite(&pred->
type,
sizeof(
int), 1, fp);
215 s += fwrite(&pred->
eta,
sizeof(
double), 1, fp);
216 s += fwrite(&pred->
eta_min,
sizeof(
double), 1, fp);
217 s += fwrite(&pred->
lambda,
sizeof(
double), 1, fp);
218 s += fwrite(&pred->
scale_factor,
sizeof(
double), 1, fp);
219 s += fwrite(&pred->
x0,
sizeof(
double), 1, fp);
220 s += fwrite(&pred->
evolve_eta,
sizeof(
bool), 1, fp);
236 s += fread(&pred->
type,
sizeof(
int), 1, fp);
237 s += fread(&pred->
eta,
sizeof(
double), 1, fp);
238 s += fread(&pred->
eta_min,
sizeof(
double), 1, fp);
239 s += fread(&pred->
lambda,
sizeof(
double), 1, fp);
241 s += fread(&pred->
x0,
sizeof(
double), 1, fp);
242 s += fread(&pred->
evolve_eta,
sizeof(
bool), 1, fp);
272 for (
int i = 0; i <
xcsf->x_dim; ++i) {
273 tmp_input[idx] = x[i];
279 for (
int i = 0; i <
xcsf->x_dim; ++i) {
280 for (
int j = i; j <
xcsf->x_dim; ++j) {
281 tmp_input[idx] = x[i] * x[j];
294 printf(
"Warning: tried to set PRED ETA too small\n");
297 printf(
"Warning: tried to set PRED ETA too large\n");
308 printf(
"Warning: tried to set PRED ETA_MIN too small\n");
309 xcsf->pred->eta_min = 0;
311 printf(
"Warning: tried to set PRED ETA_MIN too large\n");
312 xcsf->pred->eta_min = 1;
314 xcsf->pred->eta_min = a;
321 xcsf->pred->lambda = a;
327 xcsf->pred->scale_factor = a;
339 xcsf->pred->evolve_eta = a;
346 printf(
"Warning: tried to set PRED TYPE too small\n");
347 xcsf->pred->type = 0;
349 xcsf->pred->type = a;
char * layer_args_json_export(struct ArgsLayer *args)
Returns a json formatted string of the neural layer parameters.
size_t layer_args_load(struct ArgsLayer **largs, FILE *fp)
Loads neural network layer parameters.
void layer_args_free(struct ArgsLayer **largs)
Frees memory used by a list of layer parameters and points to NULL.
size_t layer_args_save(const struct ArgsLayer *args, FILE *fp)
Saves neural network layer parameters.
Piece-wise constant prediction functions.
static struct PredVtbl const pred_constant_vtbl
Constant prediction implemented functions.
char * pred_neural_param_json_import(struct XCSF *xcsf, cJSON *json)
Sets the neural network parameters from a cJSON object.
void pred_neural_param_defaults(struct XCSF *xcsf)
Initialises default neural prediction parameters.
Multi-layer perceptron neural network prediction functions.
static struct PredVtbl const pred_neural_vtbl
Multi-layer perceptron neural network prediction implemented functions.
char * pred_nlms_param_json_export(const struct XCSF *xcsf)
Returns a json formatted string of the NLMS parameters.
char * pred_nlms_param_json_import(struct XCSF *xcsf, cJSON *json)
Sets the NLMS parameters from a cJSON object.
Normalised least mean squares prediction functions.
static struct PredVtbl const pred_nlms_vtbl
Normalised least mean squares prediction implemented functions.
char * pred_rls_param_json_export(const struct XCSF *xcsf)
Returns a json formatted string of the RLS parameters.
char * pred_rls_param_json_import(struct XCSF *xcsf, cJSON *json)
Sets the RLS parameters from a cJSON object.
Recursive least mean squares prediction functions.
static struct PredVtbl const pred_rls_vtbl
Recursive least mean squares prediction implemented functions.
size_t pred_param_load(struct XCSF *xcsf, FILE *fp)
Loads prediction parameters.
void pred_param_free(struct XCSF *xcsf)
Frees prediction parameters.
const char * prediction_type_as_string(const int type)
Returns a string representation of a prediction type from the integer.
size_t pred_param_save(const struct XCSF *xcsf, FILE *fp)
Saves prediction parameters.
int prediction_type_as_int(const char *type)
Returns the integer representation of a prediction type given a name.
void pred_param_set_x0(struct XCSF *xcsf, const double a)
int pred_param_set_type_string(struct XCSF *xcsf, const char *a)
void pred_param_set_lambda(struct XCSF *xcsf, const double a)
char * pred_param_json_import(struct XCSF *xcsf, cJSON *json)
Sets the prediction parameters from a cJSON object.
void prediction_set(const struct XCSF *xcsf, struct Cl *c)
Sets a classifier's prediction functions to the implementations.
void pred_param_set_type(struct XCSF *xcsf, const int a)
void pred_param_set_eta_min(struct XCSF *xcsf, const double a)
void pred_param_set_evolve_eta(struct XCSF *xcsf, const bool a)
void pred_param_set_eta(struct XCSF *xcsf, const double a)
void pred_param_set_scale_factor(struct XCSF *xcsf, const double a)
void pred_transform_input(const struct XCSF *xcsf, const double *x, const double X0, double *tmp_input)
Prepares the input state for least squares computation.
void pred_param_defaults(struct XCSF *xcsf)
Initialises default prediction parameters.
char * pred_param_json_export(const struct XCSF *xcsf)
Returns a json formatted string of the prediction parameters.
#define PRED_TYPE_NLMS_LINEAR
Prediction type linear nlms.
#define PRED_STRING_NLMS_LINEAR
Linear nlms.
#define PRED_STRING_RLS_QUADRATIC
Quadratic rls.
#define PRED_TYPE_NEURAL
Prediction type neural.
#define PRED_TYPE_RLS_QUADRATIC
Prediction type quadratic rls.
#define PRED_STRING_CONSTANT
Constant.
#define PRED_STRING_NEURAL
Neural.
#define PRED_TYPE_NLMS_QUADRATIC
Prediction type quadratic nlms.
#define PRED_STRING_NLMS_QUADRATIC
Quadratic nlms.
#define PRED_TYPE_CONSTANT
Prediction type constant.
#define PRED_TYPE_INVALID
Error code for invalid prediction.
#define PRED_TYPE_RLS_LINEAR
Prediction type linear rls.
#define PRED_STRING_RLS_LINEAR
Linear rls.
Parameters for initialising and operating predictions.
double eta_min
Minimum gradient descent rate.
bool evolve_eta
Whether to evolve the gradient descent rate.
double scale_factor
Initial values for the RLS gain-matrix.
double x0
Prediction weight vector offset value.
struct ArgsLayer * largs
Linked-list of layer parameters.
int type
Classifier prediction type: least squares, etc.
double lambda
RLS forget rate.
double eta
Gradient descent rate.
Classifier data structure.
struct PredVtbl const * pred_vptr
Functions acting on predictions.
Utility functions for random number handling, etc.