140 printf(
"%s\n", json_str);
236 cJSON *json = cJSON_CreateObject();
237 cJSON_AddStringToObject(json,
"type",
"neural");
239 cJSON *network = cJSON_Parse(network_str);
241 cJSON_AddItemToObject(json,
"network", network);
242 char *
string = cJSON_Print(json);
256 const cJSON *item = cJSON_GetObjectItem(json,
"network");
258 printf(
"Import error: missing network\n");
284 xcsf->act->largs = la;
308 for (cJSON *iter = json; iter != NULL; iter = iter->next) {
316 if (
xcsf->act->largs == NULL) {
317 xcsf->act->largs = larg;
320 while (layer_iter->
next != NULL) {
321 layer_iter = layer_iter->
next;
323 layer_iter->
next = larg;
size_t act_neural_load(const struct XCSF *xcsf, struct Cl *c, FILE *fp)
Reads a neural network action from a file.
bool act_neural_general(const struct XCSF *xcsf, const struct Cl *c1, const struct Cl *c2)
Dummy function since neural actions do not generalise another.
void act_neural_json_import(const struct XCSF *xcsf, struct Cl *c, const cJSON *json)
Creates a neural action from a cJSON object.
void act_neural_free(const struct XCSF *xcsf, const struct Cl *c)
Frees the memory used by a neural network action.
void act_neural_print(const struct XCSF *xcsf, const struct Cl *c)
Prints a neural network action.
void act_neural_copy(const struct XCSF *xcsf, struct Cl *dest, const struct Cl *src)
Copies a neural network action from one classifier to another.
void act_neural_update(const struct XCSF *xcsf, const struct Cl *c, const double *x, const double *y)
Dummy function since neural network actions are not updated.
int act_neural_compute(const struct XCSF *xcsf, const struct Cl *c, const double *x)
Computes the current neural network action using the input.
void act_neural_cover(const struct XCSF *xcsf, const struct Cl *c, const double *x, const int action)
Generates a neural network that covers the specified input:action.
bool act_neural_crossover(const struct XCSF *xcsf, const struct Cl *c1, const struct Cl *c2)
Dummy function since crossover is not performed on neural actions.
void act_neural_init(const struct XCSF *xcsf, struct Cl *c)
Creates and initialises an action neural network.
void act_neural_param_defaults(struct XCSF *xcsf)
Initialises default neural action parameters.
char * act_neural_param_json_import(struct XCSF *xcsf, cJSON *json)
Sets the neural network parameters from a cJSON object.
bool act_neural_mutate(const struct XCSF *xcsf, const struct Cl *c)
Mutates a neural network action.
char * act_neural_json_export(const struct XCSF *xcsf, const struct Cl *c)
Returns a json formatted string representation of a neural action.
size_t act_neural_save(const struct XCSF *xcsf, const struct Cl *c, FILE *fp)
Writes a neural network action to a file.
Neural network action functions.
double * neural_outputs(const struct Net *net)
Returns the outputs from the output layer of a neural network.
bool neural_mutate(const struct Net *net)
Mutates a neural network.
void neural_create(struct Net *net, struct ArgsLayer *arg)
Initialises and creates a new neural network from a parameter list.
size_t neural_load(struct Net *net, FILE *fp)
Reads a neural network from a file.
void neural_json_import(struct Net *net, const struct ArgsLayer *arg, const cJSON *json)
Creates a neural network from a cJSON object.
void neural_free(struct Net *net)
Frees a neural network.
void neural_rand(const struct Net *net)
Randomises the layers within a neural network.
void neural_copy(struct Net *dest, const struct Net *src)
Copies a neural network.
void neural_propagate(struct Net *net, const double *input, const bool train)
Forward propagates a neural network.
char * neural_json_export(const struct Net *net, const bool return_weights)
Returns a json formatted string representation of a neural network.
size_t neural_save(const struct Net *net, FILE *fp)
Writes a neural network to a file.
Neural network activation functions.
#define LOGISTIC
Logistic [0,1].
#define LINEAR
Linear [-inf,inf].
#define SOFTMAX
Layer type softmax.
#define CONNECTED
Layer type connected.
void layer_args_init(struct ArgsLayer *args)
Sets layer parameters to default values.
char * layer_args_json_import(struct ArgsLayer *args, cJSON *json)
Sets the layer parameters from a cJSON object.
void layer_args_free(struct ArgsLayer **largs)
Frees memory used by a list of layer parameters and points to NULL.
void layer_args_validate(struct ArgsLayer *args)
Checks network layer arguments are valid.
struct ArgsLayer * layer_args_copy(const struct ArgsLayer *src)
Creates and returns a copy of specified layer parameters.
An implementation of an average pooling layer.
An implementation of a fully-connected layer of perceptrons.
An implementation of a 2D convolutional layer.
An implementation of a dropout layer.
An implementation of a long short-term memory layer.
An implementation of a 2D maxpooling layer.
An implementation of a Gaussian noise adding layer.
An implementation of a recurrent layer of perceptrons.
An implementation of a softmax layer.
An implementation of a 2D upsampling layer.
Neural network action data structure.
struct Net net
Neural network.
Parameters for initialising a neural network layer.
_Bool evolve_weights
Ability to evolve weights.
int n_init
Initial number of units / neurons / filters.
_Bool evolve_neurons
Ability to evolve number of units.
int function
Activation function.
int max_neuron_grow
Maximum number neurons to add per mutation event.
int n_max
Maximum number of units / neurons.
double scale
Usage depends on layer implementation.
int n_inputs
Number of inputs.
int type
Layer type: CONNECTED, DROPOUT, etc.
struct ArgsLayer * next
Next layer parameters.
_Bool evolve_connect
Ability to evolve weight connectivity.
Classifier data structure.
void * act
Action structure.
Utility functions for random number handling, etc.
static int argmax(const double *X, const int N)
Returns the index of the largest element in vector X.