78 printf(
"neural_layer_softmax_copy(): incorrect source layer type\n");
81 struct Layer *l = malloc(
sizeof(
struct Layer));
117 double largest = input[0];
119 if (input[
i] > largest) {
125 const double e = exp((input[
i] / l->
scale) - (largest / l->
scale));
143 const double *input,
double *
delta)
173 printf(
"%s\n", json_str);
186 const bool return_weights)
188 (void) return_weights;
189 cJSON *json = cJSON_CreateObject();
190 cJSON_AddStringToObject(json,
"type",
"softmax");
191 cJSON_AddNumberToObject(json,
"n_inputs", l->
n_inputs);
192 cJSON_AddNumberToObject(json,
"n_outputs", l->
n_outputs);
193 cJSON_AddNumberToObject(json,
"temperature", l->
scale);
194 char *
string = cJSON_Print(json);
260 s += fwrite(&l->
n_inputs,
sizeof(
int), 1, fp);
261 s += fwrite(&l->
n_outputs,
sizeof(
int), 1, fp);
263 s += fwrite(&l->
scale,
sizeof(
double), 1, fp);
277 s += fread(&l->
n_inputs,
sizeof(
int), 1, fp);
278 s += fread(&l->
n_outputs,
sizeof(
int), 1, fp);
280 s += fread(&l->
scale,
sizeof(
double), 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 SOFTMAX
Layer type softmax.
double * neural_layer_softmax_output(const struct Layer *l)
Returns the output from a softmax layer.
void neural_layer_softmax_backward(const struct Layer *l, const struct Net *net, const double *input, double *delta)
Backward propagates a softmax layer.
void neural_layer_softmax_free(const struct Layer *l)
Free memory used by a softmax layer.
static void free_layer_arrays(const struct Layer *l)
Free memory used by a softmax layer.
static void malloc_layer_arrays(struct Layer *l)
Allocate memory used by a softmax layer.
char * neural_layer_softmax_json_export(const struct Layer *l, const bool return_weights)
Returns a json formatted string representation of a softmax layer.
struct Layer * neural_layer_softmax_copy(const struct Layer *src)
Initialises and creates a copy of one softmax layer from another.
size_t neural_layer_softmax_load(struct Layer *l, FILE *fp)
Reads a softmax layer from a file.
void neural_layer_softmax_print(const struct Layer *l, const bool print_weights)
Prints a softmax layer.
void neural_layer_softmax_init(struct Layer *l, const struct ArgsLayer *args)
Creates and initialises a softmax layer.
size_t neural_layer_softmax_save(const struct Layer *l, FILE *fp)
Writes a softmax layer to a file.
void neural_layer_softmax_forward(const struct Layer *l, const struct Net *net, const double *input)
Forward propagates a softmax layer.
void neural_layer_softmax_update(const struct Layer *l)
Dummy function since a softmax layer has no weights.
void neural_layer_softmax_rand(struct Layer *l)
Dummy function since softmax layers have no weights.
void neural_layer_softmax_resize(struct Layer *l, const struct Layer *prev)
Resizes a softmax layer if the previous layer has changed size.
bool neural_layer_softmax_mutate(struct Layer *l)
Dummy function since a softmax layer cannot be mutated.
An implementation of a softmax layer.
Parameters for initialising a neural network layer.
double scale
Usage depends on layer implementation.
int n_inputs
Number of inputs.
Neural network layer data structure.
double * output
Current neuron outputs (after 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.
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.
Utility functions for random number handling, etc.