-
Notifications
You must be signed in to change notification settings - Fork 0
/
layer.h
38 lines (30 loc) · 1.36 KB
/
layer.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#ifndef _LAYER_H
#define _LAYER_H
#include "activation.h"
typedef struct LinearLayer
{
Matrix* weights; // [out_size, in_size]
Matrix* biases; // [out_size, 1]
Matrix* input; // [in_size, 1]
Matrix* activated_output; //[out_size , 1]
Matrix* unactivated_output;//[out_size , 1]
Activation activation;
Matrix* input_gradients; // [ input_size, 1] // gradients of the input of the layer
Matrix* output_gradients;// [output_size, 1] gradients of the output of the layer
Matrix* weight_gradients; // gradient of weights to be used in an optimizer
Matrix* bias_gradients;
int need_input_grad;
int is_trainable;
void (*forward) (struct LinearLayer* self);
void (*backward) (struct LinearLayer* self);
}LinearLayer;
void forwardLayer(LinearLayer* layer);
LinearLayer createLinearLayer(int input_size, int output_size, int need_input_grad, int is_sparse,Activation act);
void freeLinearLayer(LinearLayer* layer);
void calculateWeightGradients(Matrix* weights_gradients, Matrix* input, Matrix* output_gradients);
void calculateWeightGradientsSparse(Matrix* weights_gradients, Matrix* input, Matrix* output_gradients);
void forwardLinearLayer(LinearLayer* layer);
void backwardLinearLayer(LinearLayer* layer);
void forward_Sparse(LinearLayer* layer);
void backwardSparse(LinearLayer* layer);
#endif