43 switch (
xcsf->cond->type) {
75 printf(
"Invalid condition type specified: %d\n",
xcsf->cond->type);
112 printf(
"condition_type_as_string(): invalid type: %d\n", type);
188 cJSON *json = cJSON_CreateObject();
189 cJSON_AddNumberToObject(json,
"eta", cond->
eta);
190 cJSON_AddNumberToObject(json,
"min", cond->
min);
191 cJSON_AddNumberToObject(json,
"max", cond->
max);
192 cJSON_AddNumberToObject(json,
"spread_min", cond->
spread_min);
193 char *
string = cJSON_Print(json);
207 for (cJSON *iter = json; iter != NULL; iter = iter->next) {
208 if (strncmp(iter->string,
"eta\0", 4) == 0 && cJSON_IsNumber(iter)) {
210 }
else if (strncmp(iter->string,
"min\0", 4) == 0 &&
211 cJSON_IsNumber(iter)) {
213 }
else if (strncmp(iter->string,
"max\0", 4) == 0 &&
214 cJSON_IsNumber(iter)) {
216 }
else if (strncmp(iter->string,
"spread_min\0", 11) == 0 &&
217 cJSON_IsNumber(iter)) {
235 cJSON *json = cJSON_CreateObject();
237 char *json_str = NULL;
238 switch (cond->
type) {
262 if (json_str != NULL) {
263 cJSON *params = cJSON_Parse(json_str);
264 if (params != NULL) {
265 cJSON_AddItemToObject(json,
"args", params);
269 char *
string = cJSON_Print(json);
284 switch (
xcsf->cond->type) {
306 printf(
"cond_param_json_import(): unknown type.\n");
323 s += fwrite(&cond->
type,
sizeof(
int), 1, fp);
324 s += fwrite(&cond->
eta,
sizeof(
double), 1, fp);
325 s += fwrite(&cond->
min,
sizeof(
double), 1, fp);
326 s += fwrite(&cond->
max,
sizeof(
double), 1, fp);
327 s += fwrite(&cond->
spread_min,
sizeof(
double), 1, fp);
328 s += fwrite(&cond->
p_dontcare,
sizeof(
double), 1, fp);
329 s += fwrite(&cond->
bits,
sizeof(
int), 1, fp);
347 s += fread(&cond->
type,
sizeof(
int), 1, fp);
348 s += fread(&cond->
eta,
sizeof(
double), 1, fp);
349 s += fread(&cond->
min,
sizeof(
double), 1, fp);
350 s += fread(&cond->
max,
sizeof(
double), 1, fp);
351 s += fread(&cond->
spread_min,
sizeof(
double), 1, fp);
352 s += fread(&cond->
p_dontcare,
sizeof(
double), 1, fp);
353 s += fread(&cond->
bits,
sizeof(
int), 1, fp);
368 free(
xcsf->cond->targs);
369 free(
xcsf->cond->dargs);
370 xcsf->cond->targs = NULL;
371 xcsf->cond->dargs = NULL;
381 printf(
"Warning: tried to set COND ETA too small\n");
384 printf(
"Warning: tried to set COND ETA too large\n");
407 printf(
"Warning: tried to set COND P_DONTCARE too small\n");
408 xcsf->cond->p_dontcare = 0;
410 printf(
"Warning: tried to set COND P_DONTCARE too large\n");
411 xcsf->cond->p_dontcare = 1;
413 xcsf->cond->p_dontcare = a;
421 printf(
"Warning: tried to set COND SPREAD_MIN too small\n");
422 xcsf->cond->spread_min = 0;
424 xcsf->cond->spread_min = a;
432 printf(
"Warning: tried to set COND BITS too small\n");
433 xcsf->cond->bits = 1;
435 xcsf->cond->bits = a;
453 printf(
"Warning: tried to set COND TYPE too small\n");
454 xcsf->cond->type = 0;
456 xcsf->cond->type = a;
char * cond_dgp_param_json_export(const struct XCSF *xcsf)
Returns a json formatted string of the DGP parameters.
void cond_dgp_param_defaults(struct XCSF *xcsf)
Initialises default DGP condition parameters.
char * cond_dgp_param_json_import(struct XCSF *xcsf, cJSON *json)
Sets the DGP parameters from a cJSON object.
Dynamical GP graph condition functions.
static struct CondVtbl const cond_dgp_vtbl
Dynamical GP graph condition implemented functions.
Always-matching dummy condition functions.
static struct CondVtbl const cond_dummy_vtbl
Dummy condition implemented functions.
Hyperellipsoid condition functions.
static struct CondVtbl const cond_ellipsoid_vtbl
Hyperellipsoid condition implemented functions.
void cond_gp_param_defaults(struct XCSF *xcsf)
Initialises default tree GP condition parameters.
char * cond_gp_param_json_import(struct XCSF *xcsf, cJSON *json)
Sets the tree GP parameters from a cJSON object.
char * cond_gp_param_json_export(const struct XCSF *xcsf)
Returns a json formatted string of the tree GP parameters.
Tree GP condition functions.
static struct CondVtbl const cond_gp_vtbl
Tree GP condition implemented functions.
char * cond_neural_param_json_import(struct XCSF *xcsf, cJSON *json)
Sets the neural network parameters from a cJSON object.
void cond_neural_param_defaults(struct XCSF *xcsf)
Initialises default neural condition parameters.
Multi-layer perceptron neural network condition functions.
static struct CondVtbl const cond_neural_vtbl
Multi-layer perceptron neural network condition implemented functions.
Hyperrectangle condition functions.
static struct CondVtbl const cond_rectangle_vtbl
Hyperrectangle condition implemented functions.
char * cond_ternary_param_json_export(const struct XCSF *xcsf)
Returns a json formatted string of the ternary parameters.
char * cond_ternary_param_json_import(struct XCSF *xcsf, cJSON *json)
Sets the ternary parameters from a cJSON object.
void cond_ternary_param_defaults(struct XCSF *xcsf)
Initialises default ternary condition parameters.
Ternary condition functions.
static struct CondVtbl const cond_ternary_vtbl
Ternary condition implemented functions.
char * cond_param_json_import(struct XCSF *xcsf, cJSON *json)
Sets the condition parameters from a cJSON object.
void condition_set(const struct XCSF *xcsf, struct Cl *c)
Sets a classifier's condition functions to the implementations.
void cond_param_set_type(struct XCSF *xcsf, const int a)
static char * cond_param_json_export_csr(const struct XCSF *xcsf)
Returns a json formatted string of the center-spread parameters.
void cond_param_set_spread_min(struct XCSF *xcsf, const double a)
size_t cond_param_load(struct XCSF *xcsf, FILE *fp)
Loads condition parameters.
int condition_type_as_int(const char *type)
Returns the integer representation of a condition type given a name.
void cond_param_set_bits(struct XCSF *xcsf, const int a)
static char * cond_param_json_import_csr(struct XCSF *xcsf, cJSON *json)
Sets the center-spread parameters from a cJSON object.
void cond_param_set_min(struct XCSF *xcsf, const double a)
size_t cond_param_save(const struct XCSF *xcsf, FILE *fp)
Saves condition parameters.
void cond_param_set_p_dontcare(struct XCSF *xcsf, const double a)
void cond_param_set_max(struct XCSF *xcsf, const double a)
int cond_param_set_type_string(struct XCSF *xcsf, const char *a)
char * cond_param_json_export(const struct XCSF *xcsf)
Returns a json formatted string of the condition parameters.
void cond_param_defaults(struct XCSF *xcsf)
Initialises default condition parameters.
void cond_param_free(struct XCSF *xcsf)
Frees condition parameters.
const char * condition_type_as_string(const int type)
Returns a string representation of a condition type from an integer.
void cond_param_set_eta(struct XCSF *xcsf, const double a)
#define COND_STRING_NEURAL
Neural.
#define COND_STRING_RULE_NETWORK
Rule network.
#define COND_STRING_HYPERRECTANGLE_CSR
CSR.
#define COND_TYPE_TERNARY
Condition type ternary.
#define COND_TYPE_DGP
Condition type DGP.
#define COND_TYPE_INVALID
Error code for invalid condition.
#define COND_STRING_RULE_NEURAL
Rule neural.
#define COND_TYPE_HYPERRECTANGLE_UBR
Condition type UBR hyperrectangle.
#define COND_TYPE_HYPERELLIPSOID
Condition type hyperellipsoid.
#define COND_TYPE_DUMMY
Condition type dummy.
#define RULE_TYPE_NEURAL
Condition type and action type neural.
#define RULE_TYPE_DGP
Condition type and action type DGP.
#define COND_STRING_TERNARY
Ternary.
#define COND_STRING_GP
Tree GP.
#define COND_STRING_RULE_DGP
Rule DGP.
#define RULE_TYPE_NETWORK
Condition type and prediction type neural.
#define COND_TYPE_HYPERRECTANGLE_CSR
Condition type CSR hyperrectangle.
#define COND_STRING_DUMMY
Dummy.
#define COND_STRING_HYPERELLIPSOID
Hyperellipsoid.
#define COND_STRING_DGP
DGP.
#define COND_TYPE_GP
Condition type tree GP.
#define COND_STRING_HYPERRECTANGLE_UBR
UBR.
#define COND_TYPE_NEURAL
Condition type neural network.
size_t graph_args_save(const struct ArgsDGP *args, FILE *fp)
Saves DGP parameters.
size_t graph_args_load(struct ArgsDGP *args, FILE *fp)
Loads DGP parameters.
void tree_args_free(struct ArgsGPTree *args)
Frees memory used by GP tree parameters.
size_t tree_args_load(struct ArgsGPTree *args, FILE *fp)
Loads Tree GP parameters.
size_t tree_args_save(const struct ArgsGPTree *args, FILE *fp)
Saves Tree GP parameters.
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.
Dynamical GP graph rule (condition + action) functions.
static struct ActVtbl const rule_dgp_act_vtbl
Dynamical GP rule action implemented functions.
static struct CondVtbl const rule_dgp_cond_vtbl
Dynamical GP rule condition implemented functions.
Neural network rule (condition + action) functions.
static struct ActVtbl const rule_neural_act_vtbl
Neural network rule action implemented functions.
static struct CondVtbl const rule_neural_cond_vtbl
Neural network rule condition implemented functions.
Parameters for initialising and operating conditions.
double min
Minimum value expected from inputs.
double eta
Gradient descent rate.
double p_dontcare
Don't care probability.
struct ArgsDGP * dargs
DGP parameters.
struct ArgsGPTree * targs
Tree GP parameters.
int type
Classifier condition type: hyperrectangles, etc.
int bits
Bits per float to binarise inputs.
double spread_min
Minimum initial spread.
struct ArgsLayer * largs
Linked-list of layer parameters.
double max
Maximum value expected from inputs.
Classifier data structure.
struct ActVtbl const * act_vptr
Functions acting on actions.
struct CondVtbl const * cond_vptr
Functions acting on conditions.
Utility functions for random number handling, etc.