91 printf(
"neural_layer_dropout_copy(): incorrect source layer type\n");
94 struct Layer *l = malloc(
sizeof(
struct Layer));
153 const double *input,
double *
delta)
228 printf(
"%s\n", json_str);
241 const bool return_weights)
243 (void) return_weights;
244 cJSON *json = cJSON_CreateObject();
245 cJSON_AddStringToObject(json,
"type",
"dropout");
246 cJSON_AddNumberToObject(json,
"n_inputs", l->
n_inputs);
247 cJSON_AddNumberToObject(json,
"n_outputs", l->
n_outputs);
248 cJSON_AddNumberToObject(json,
"probability", l->
probability);
249 char *
string = cJSON_Print(json);
264 s += fwrite(&l->
n_inputs,
sizeof(
int), 1, fp);
265 s += fwrite(&l->
n_outputs,
sizeof(
int), 1, fp);
267 s += fwrite(&l->
probability,
sizeof(
double), 1, fp);
268 s += fwrite(&l->
scale,
sizeof(
double), 1, fp);
269 s += fwrite(&l->
out_w,
sizeof(
int), 1, fp);
270 s += fwrite(&l->
out_h,
sizeof(
int), 1, fp);
271 s += fwrite(&l->
out_c,
sizeof(
int), 1, fp);
285 s += fread(&l->
n_inputs,
sizeof(
int), 1, fp);
286 s += fread(&l->
n_outputs,
sizeof(
int), 1, fp);
288 s += fread(&l->
probability,
sizeof(
double), 1, fp);
289 s += fread(&l->
scale,
sizeof(
double), 1, fp);
290 s += fread(&l->
out_w,
sizeof(
int), 1, fp);
291 s += fread(&l->
out_h,
sizeof(
int), 1, fp);
292 s += fread(&l->
out_c,
sizeof(
int), 1, fp);
Neural network activation functions.
void layer_defaults(struct Layer *l)
Initialises a layer to default values.
void layer_guard_outputs(const struct Layer *l)
Check number of outputs is within bounds.
#define DROPOUT
Layer type dropout.
void neural_layer_dropout_resize(struct Layer *l, const struct Layer *prev)
Resizes a dropout layer if the previous layer has changed size.
struct Layer * neural_layer_dropout_copy(const struct Layer *src)
Initialises and creates a copy of one dropout layer from another.
void neural_layer_dropout_forward(const struct Layer *l, const struct Net *net, const double *input)
Forward propagates a dropout layer.
void neural_layer_dropout_rand(struct Layer *l)
Dummy function since dropout layers have no weights.
static void free_layer_arrays(const struct Layer *l)
Free memory used by a dropout layer.
static void malloc_layer_arrays(struct Layer *l)
Allocate memory used by a dropout layer.
char * neural_layer_dropout_json_export(const struct Layer *l, const bool return_weights)
Returns a json formatted string representation of a dropout layer.
void neural_layer_dropout_update(const struct Layer *l)
Dummy function since a dropout layer has no weights.
size_t neural_layer_dropout_save(const struct Layer *l, FILE *fp)
Writes a dropout layer to a file.
double * neural_layer_dropout_output(const struct Layer *l)
Returns the output from a dropout layer.
void neural_layer_dropout_print(const struct Layer *l, const bool print_weights)
Prints a dropout layer.
void neural_layer_dropout_init(struct Layer *l, const struct ArgsLayer *args)
Initialises a dropout layer.
void neural_layer_dropout_free(const struct Layer *l)
Free memory used by a dropout layer.
void neural_layer_dropout_backward(const struct Layer *l, const struct Net *net, const double *input, double *delta)
Backward propagates a dropout layer.
size_t neural_layer_dropout_load(struct Layer *l, FILE *fp)
Reads a dropout layer from a file.
bool neural_layer_dropout_mutate(struct Layer *l)
Dummy function since a dropout layer cannot be mutated.
An implementation of a dropout layer.
Parameters for initialising a neural network layer.
double probability
Usage depends on layer implementation.
int channels
Pool, Conv, and Upsample.
int width
Pool, Conv, and Upsample.
int height
Pool, Conv, and Upsample.
int n_inputs
Number of inputs.
Neural network layer data structure.
double * output
Current neuron outputs (after activation function)
double * state
Current neuron states (before activation function)
int n_inputs
Number of layer inputs.
double scale
Usage depends on layer implementation.
struct LayerVtbl const * layer_vptr
Functions acting on layers.
int max_outputs
Maximum number of neurons in the layer.
double probability
Usage depends on layer implementation.
int n_outputs
Number of layer outputs.
int out_w
Pool, Conv, and Upsample.
int type
Layer type: CONNECTED, DROPOUT, etc.
int out_c
Pool, Conv, and Upsample.
double * delta
Delta for updating weights.
int out_h
Pool, Conv, and Upsample.
Neural network data structure.
bool train
Whether the network is in training mode.
double rand_uniform(const double min, const double max)
Returns a uniform random float [min,max].
Utility functions for random number handling, etc.