84 const int old = act->
action;
122 new->action = src_act->
action;
123 new->mu = malloc(
sizeof(
double) *
N_MU);
124 memcpy(new->mu, src_act->
mu,
sizeof(
double) *
N_MU);
137 printf(
"%s\n", json_str);
181 new->mu = malloc(
sizeof(
double) *
N_MU);
217 s += fwrite(&act->
action,
sizeof(
int), 1, fp);
218 s += fwrite(act->
mu,
sizeof(
double),
N_MU, fp);
235 s += fread(&new->action,
sizeof(
int), 1, fp);
236 new->mu = malloc(
sizeof(
double) *
N_MU);
237 s += fread(new->mu,
sizeof(
double),
N_MU, fp);
253 cJSON *json = cJSON_CreateObject();
254 cJSON_AddStringToObject(json,
"type",
"integer");
255 cJSON_AddNumberToObject(json,
"action", act->
action);
256 cJSON *mutation = cJSON_CreateDoubleArray(act->
mu,
N_MU);
257 cJSON_AddItemToObject(json,
"mutation", mutation);
258 char *
string = cJSON_Print(json);
275 const cJSON *item = cJSON_GetObjectItem(json,
"action");
276 if (item != NULL && cJSON_IsNumber(item)) {
277 act->
action = item->valueint;
void act_integer_copy(const struct XCSF *xcsf, struct Cl *dest, const struct Cl *src)
Copies an integer action from one classifier to another.
void act_integer_free(const struct XCSF *xcsf, const struct Cl *c)
Frees the memory used by an integer action.
bool act_integer_crossover(const struct XCSF *xcsf, const struct Cl *c1, const struct Cl *c2)
Dummy function since integer actions do not perform crossover.
static const int MU_TYPE[(1)]
Self-adaptation method for mutating integer actions.
int act_integer_compute(const struct XCSF *xcsf, const struct Cl *c, const double *x)
Returns a classifier's integer action.
size_t act_integer_save(const struct XCSF *xcsf, const struct Cl *c, FILE *fp)
Writes an integer action to a file.
void act_integer_update(const struct XCSF *xcsf, const struct Cl *c, const double *x, const double *y)
Dummy function since integer actions are not updated.
void act_integer_json_import(const struct XCSF *xcsf, struct Cl *c, const cJSON *json)
Creates an integer action from a cJSON object.
#define N_MU
Number of integer action mutation rates.
void act_integer_init(const struct XCSF *xcsf, struct Cl *c)
Initialises an integer action.
bool act_integer_mutate(const struct XCSF *xcsf, const struct Cl *c)
Mutates an integer action.
bool act_integer_general(const struct XCSF *xcsf, const struct Cl *c1, const struct Cl *c2)
Returns whether the action of classifier c1 is more general than c2.
size_t act_integer_load(const struct XCSF *xcsf, struct Cl *c, FILE *fp)
Reads an integer action from a file.
char * act_integer_json_export(const struct XCSF *xcsf, const struct Cl *c)
Returns a json formatted string representation of an integer action.
void act_integer_cover(const struct XCSF *xcsf, const struct Cl *c, const double *x, const int action)
Sets an integer action to a specified value.
void act_integer_print(const struct XCSF *xcsf, const struct Cl *c)
Prints an integer action.
integer action functions.
void sam_json_import(double *mu, const int N, const cJSON *json)
Initialises a mutation vector from a cJSON object.
void sam_init(double *mu, const int N, const int *type)
Initialises self-adaptive mutation rates.
void sam_adapt(double *mu, const int N, const int *type)
Self-adapts mutation rates.
Self-adaptive mutation functions.
#define SAM_LOG_NORMAL
Log normal self-adaptation.
Integer action data structure.
int action
Integer action.
double * mu
Mutation rates.
Classifier data structure.
void * act
Action structure.
int rand_uniform_int(const int min, const int max)
Returns a uniform random integer [min,max] not inclusive of max.
double rand_uniform(const double min, const double max)
Returns a uniform random float [min,max].
Utility functions for random number handling, etc.