AIfES 2  2.0.0
aiopti_sgd.h
Go to the documentation of this file.
1 
46 #ifndef AIOPTI_SGD
47 #define AIOPTI_SGD
48 
49 #include "core/aifes_core.h"
50 
51 typedef struct aiopti_sgd aiopti_sgd_t;
56 struct aiopti_sgd {
65  void *momentum;
67 
72 
80  void (*tensor_sub)(const aitensor_t *a, const aitensor_t *b, aitensor_t *result);
81 
89  void (*tensor_add)(const aitensor_t *a, const aitensor_t *b, aitensor_t *result);
90 
98  void (*scalar_mul)(const void *scalar, const aitensor_t *a, aitensor_t *result);
99 
107  void (*zero_tensor)(aitensor_t *tensor);
108 
110 };
111 
117 extern const aicore_optitype_t *aiopti_sgd_type;
118 
119 
130 
144 
156 
174 void aiopti_sgd_init_optimem_with_momentum(aiopti_t *self, const aitensor_t *params, const aitensor_t *gradients, void *optimem);
175 
187 void aiopti_sgd_init_optimem_without_momentum(aiopti_t *self, const aitensor_t *params, const aitensor_t *gradients, void *optimem);
188 
204 
233 void aiopti_sgd_update_params_with_momentum(aiopti_t *self, aitensor_t *params, const aitensor_t *gradients, void *optimem);
234 
257 void aiopti_sgd_update_params_without_momentum(aiopti_t *self, aitensor_t *params, const aitensor_t *gradients, void *optimem);
258 
259 #ifdef AIDEBUG_PRINT_MODULE_SPECS
265 #endif // AIDEBUG_PRINT_MODULE_SPECS
266 
267 #endif // AIOPTI_SGD
268 
AIfES 2 core interface.
aiopti_t * aiopti_sgd(aiopti_sgd_t *opti)
Initialize the given SGD optimizer.
void aiopti_sgd_init_optimem_with_momentum(aiopti_t *self, const aitensor_t *params, const aitensor_t *gradients, void *optimem)
Initialization of the optimization memory buffer when the momentum is not zero.
uint32_t aiopti_sgd_sizeof_optimem_without_momentum(aiopti_t *self, const aitensor_t *params)
Calculates the required memory for the optimization step when the momentum is zero.
uint32_t aiopti_sgd_sizeof_optimem_with_momentum(aiopti_t *self, const aitensor_t *params)
Calculates the required memory for the optimization step when the momentum is not zero.
void aiopti_sgd_print_specs(const aiopti_t *self)
Print the optimizer specification.
void aiopti_sgd_zero_gradients(aiopti_t *self, aitensor_t *gradients)
Set the gradients to zero.
const aicore_optitype_t * aiopti_sgd_type
SGD optimizer type.
void aiopti_sgd_update_params_with_momentum(aiopti_t *self, aitensor_t *params, const aitensor_t *gradients, void *optimem)
Update the given parameter tensor with respect to the gradients when the momentum is not zero.
void aiopti_sgd_init_optimem_without_momentum(aiopti_t *self, const aitensor_t *params, const aitensor_t *gradients, void *optimem)
Initialization of the optimization memory buffer when the momentum is zero.
void aiopti_sgd_update_params_without_momentum(aiopti_t *self, aitensor_t *params, const aitensor_t *gradients, void *optimem)
Update the given parameter tensor with respect to the gradients when the momentum is zero.
Type indicator of the optimizer to check for the optimizer type.
Definition: aifes_core.h:160
General Stochastic Gradient Descent (SGD) optimizer struct.
Definition: aiopti_sgd.h:56
void(* scalar_mul)(const void *scalar, const aitensor_t *a, aitensor_t *result)
Required math function: Multiplication of a scalar with a tensor.
Definition: aiopti_sgd.h:98
void * momentum
aiscalar: Momentum(set to null to save optimization memory)
Definition: aiopti_sgd.h:65
void(* tensor_sub)(const aitensor_t *a, const aitensor_t *b, aitensor_t *result)
Required math function: Element wise tensor subtraction.
Definition: aiopti_sgd.h:80
void(* tensor_add)(const aitensor_t *a, const aitensor_t *b, aitensor_t *result)
Required math function: Element wise tensor addition.
Definition: aiopti_sgd.h:89
aiopti_t base
Inherited field members from general optimizer struct.
Definition: aiopti_sgd.h:57
void(* zero_tensor)(aitensor_t *tensor)
Required math function: Sets the elements of a tensor to zero.
Definition: aiopti_sgd.h:107
AIfES optimizer interface.
Definition: aifes_core.h:438
A tensor in AIfES.
Definition: aifes_math.h:89