111 for (
int i = 0; i <
xcsf->y_dim; ++i) {
125 printf(
"%s\n", json_str);
222 while (iter != NULL) {
247 while (iter != NULL) {
275 while (iter != NULL) {
296 const struct Net *net = &pred->
net;
309 struct Net *net = &pred->
net;
310 const struct Layer *
h = NULL;
332 new.eta = largs->
eta;
335 new.decay = largs->
decay;
353 struct Net *net = &pred->
net;
354 struct Layer *l = NULL;
356 for (
int i = 0;
i < n_del && net->
n_layers > 1; ++
i) {
366 new.n_init =
xcsf->y_dim;
367 new.n_max =
xcsf->y_dim;
372 new.eta = largs->
eta;
375 new.decay = largs->
decay;
379 new.n_inputs =
xcsf->y_dim;
396 cJSON *json = cJSON_CreateObject();
397 cJSON_AddStringToObject(json,
"type",
"neural");
399 cJSON *network = cJSON_Parse(network_str);
401 cJSON_AddItemToObject(json,
"network", network);
402 char *
string = cJSON_Print(json);
417 const cJSON *item = cJSON_GetObjectItem(json,
"network");
419 printf(
"Import error: missing network\n");
449 xcsf->pred->largs = la;
468 for (cJSON *iter = json; iter != NULL; iter = iter->next) {
476 if (
xcsf->pred->largs == NULL) {
477 xcsf->pred->largs = larg;
480 while (layer_iter->
next != NULL) {
481 layer_iter = layer_iter->
next;
483 layer_iter->
next = larg;
void neural_push(struct Net *net, struct Layer *l)
Inserts a layer at the head of a neural network.
bool neural_mutate(const struct Net *net)
Mutates a neural network.
double neural_size(const struct Net *net)
Returns the total number of non-zero weights in a neural network.
void neural_create(struct Net *net, struct ArgsLayer *arg)
Initialises and creates a new neural network from a parameter list.
double neural_output(const struct Net *net, const int IDX)
Returns the output of a specified neuron in the output layer of a neural network.
void neural_resize(const struct Net *net)
Resizes neural network layers as necessary.
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_learn(const struct Net *net, const double *truth, const double *input)
Performs a gradient descent update on a neural network.
void neural_free(struct Net *net)
Frees 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.
void neural_pop(struct Net *net)
Removes the layer at the head of a neural network.
size_t neural_save(const struct Net *net, FILE *fp)
Writes a neural network to a file.
void neural_insert(struct Net *net, struct Layer *l, const int pos)
Inserts a layer into a neural network.
Neural network activation functions.
#define LOGISTIC
Logistic [0,1].
#define LINEAR
Linear [-inf,inf].
static struct Layer * layer_init(const struct ArgsLayer *args)
Creates and initialises a new layer.
#define SOFTMAX
Layer type softmax.
#define CONVOLUTIONAL
Layer type convolutional.
#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.
int pred_neural_layers(const struct XCSF *xcsf, const struct Cl *c)
Returns the number of layers within a neural network prediction.
bool pred_neural_mutate(const struct XCSF *xcsf, const struct Cl *c)
Mutates a neural network prediction.
char * pred_neural_json_export(const struct XCSF *xcsf, const struct Cl *c)
Returns a json formatted string representation of a neural prediction.
size_t pred_neural_save(const struct XCSF *xcsf, const struct Cl *c, FILE *fp)
Writes a neural network prediction to a file.
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.
void pred_neural_compute(const struct XCSF *xcsf, const struct Cl *c, const double *x)
Forward propagates a neural network prediction with a provided input.
void pred_neural_print(const struct XCSF *xcsf, const struct Cl *c)
Prints a neural network prediction.
void pred_neural_free(const struct XCSF *xcsf, const struct Cl *c)
Frees the memory used by a neural network prediction.
void pred_neural_init(const struct XCSF *xcsf, struct Cl *c)
Creates and initialises a neural network prediction.
char * pred_neural_param_json_import(struct XCSF *xcsf, cJSON *json)
Sets the neural network parameters from a cJSON object.
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.
void pred_neural_ae_to_classifier(const struct XCSF *xcsf, const struct Cl *c, const int n_del)
Removes prediction (decoder) layers and inserts softmax output layer.
void pred_neural_json_import(const struct XCSF *xcsf, struct Cl *c, const cJSON *json)
Creates a neural prediction from a cJSON object.
void pred_neural_copy(const struct XCSF *xcsf, struct Cl *dest, const struct Cl *src)
Copies a neural network prediction from one classifier to another.
void pred_neural_expand(const struct XCSF *xcsf, const struct Cl *c)
Creates and inserts a hidden layer before the prediction output 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.
void pred_neural_update(const struct XCSF *xcsf, const struct Cl *c, const double *x, const double *y)
Backward propagates and updates a neural network prediction.
bool pred_neural_crossover(const struct XCSF *xcsf, const struct Cl *c1, const struct Cl *c2)
Dummy function since neural predictions do not perform crossover.
double pred_neural_size(const struct XCSF *xcsf, const struct Cl *c)
Returns the size of a neural network prediction.
void pred_neural_param_defaults(struct XCSF *xcsf)
Initialises default neural prediction parameters.
size_t pred_neural_load(const struct XCSF *xcsf, struct Cl *c, FILE *fp)
Reads a neural network prediction from a file.
Multi-layer perceptron neural network prediction functions.
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.
_Bool sgd_weights
Ability to update weights with gradient descent.
_Bool evolve_functions
Ability to evolve activation function.
double decay
Weight decay for gradient descent.
double momentum
Momentum for gradient descent.
int function
Activation function.
_Bool evolve_eta
Ability to evolve gradient descent rate.
int max_neuron_grow
Maximum number neurons to add per mutation event.
double eta
Gradient descent rate.
double eta_min
Current gradient descent rate.
int n_max
Maximum number of units / neurons.
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 * pred
Prediction structure.
double * prediction
Current classifier prediction.
Neural network layer data structure.
int n_inputs
Number of layer inputs.
int max_outputs
Maximum number of neurons in the layer.
int n_outputs
Number of layer outputs.
int n_active
Number of active weights / connections.
int type
Layer type: CONNECTED, DROPOUT, etc.
double eta
Gradient descent rate.
Forward declaration of layer structure.
struct Llist * prev
Pointer to the previous layer (forward)
struct Layer * layer
Pointer to the layer data structure.
struct Llist * next
Pointer to the next layer (backward)
Neural network data structure.
int n_layers
Number of layers (hidden + output)
struct Llist * tail
Pointer to the tail layer (first layer)
struct Llist * head
Pointer to the head layer (output layer)
int n_outputs
Number of network outputs.
Multi-layer perceptron neural network prediction data structure.
struct Net net
Neural network.
Utility functions for random number handling, etc.