81 printf(
"neural_layer_noise_copy(): incorrect source layer type\n");
84 struct Layer *l = malloc(
sizeof(
struct Layer));
155 const double *input,
double *
delta)
226 printf(
"%s\n", json_str);
240 (void) return_weights;
241 cJSON *json = cJSON_CreateObject();
242 cJSON_AddStringToObject(json,
"type",
"noise");
243 cJSON_AddNumberToObject(json,
"n_inputs", l->
n_inputs);
244 cJSON_AddNumberToObject(json,
"n_outputs", l->
n_outputs);
245 cJSON_AddNumberToObject(json,
"probability", l->
probability);
246 cJSON_AddNumberToObject(json,
"stdev", l->
scale);
247 char *
string = cJSON_Print(json);
262 s += fwrite(&l->
n_inputs,
sizeof(
int), 1, fp);
263 s += fwrite(&l->
n_outputs,
sizeof(
int), 1, fp);
265 s += fwrite(&l->
probability,
sizeof(
double), 1, fp);
266 s += fwrite(&l->
scale,
sizeof(
double), 1, fp);
267 s += fwrite(&l->
out_w,
sizeof(
int), 1, fp);
268 s += fwrite(&l->
out_h,
sizeof(
int), 1, fp);
269 s += fwrite(&l->
out_c,
sizeof(
int), 1, fp);
283 s += fread(&l->
n_inputs,
sizeof(
int), 1, fp);
284 s += fread(&l->
n_outputs,
sizeof(
int), 1, fp);
286 s += fread(&l->
probability,
sizeof(
double), 1, fp);
287 s += fread(&l->
scale,
sizeof(
double), 1, fp);
288 s += fread(&l->
out_w,
sizeof(
int), 1, fp);
289 s += fread(&l->
out_h,
sizeof(
int), 1, fp);
290 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 NOISE
Layer type noise.
void neural_layer_noise_free(const struct Layer *l)
Free memory used by a noise layer.
void neural_layer_noise_rand(struct Layer *l)
Dummy function since noise layers have no weights.
void neural_layer_noise_print(const struct Layer *l, const bool print_weights)
Prints a noise layer.
void neural_layer_noise_resize(struct Layer *l, const struct Layer *prev)
Resizes a noise layer if the previous layer has changed size.
void neural_layer_noise_update(const struct Layer *l)
Dummy function since a noise layer has no weights.
void neural_layer_noise_init(struct Layer *l, const struct ArgsLayer *args)
Initialises a noise layer.
size_t neural_layer_noise_save(const struct Layer *l, FILE *fp)
Writes a noise layer to a file.
static void free_layer_arrays(const struct Layer *l)
Free memory used by a noise layer.
static void malloc_layer_arrays(struct Layer *l)
Allocate memory used by a noise layer.
size_t neural_layer_noise_load(struct Layer *l, FILE *fp)
Reads a noise layer from a file.
char * neural_layer_noise_json_export(const struct Layer *l, const bool return_weights)
Returns a json formatted string representation of a noise layer.
void neural_layer_noise_backward(const struct Layer *l, const struct Net *net, const double *input, double *delta)
Backward propagates a noise layer.
struct Layer * neural_layer_noise_copy(const struct Layer *src)
Initialises and creates a copy of one noise layer from another.
bool neural_layer_noise_mutate(struct Layer *l)
Dummy function since a noise layer cannot be mutated.
void neural_layer_noise_forward(const struct Layer *l, const struct Net *net, const double *input)
Forward propagates a noise layer.
double * neural_layer_noise_output(const struct Layer *l)
Returns the output from a noise layer.
An implementation of a Gaussian noise adding layer.
Parameters for initialising a neural network layer.
double probability
Usage depends on layer implementation.
int channels
Pool, Conv, and Upsample.
double scale
Usage depends on layer implementation.
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_normal(const double mu, const double sigma)
Returns a random Gaussian with specified mean and standard deviation.
double rand_uniform(const double min, const double max)
Returns a uniform random float [min,max].
Utility functions for random number handling, etc.