AIfES 2  2.0.0
aiopti_sgd.h
Go to the documentation of this file.
1 
49 #ifndef AIOPTI_SGD
50 #define AIOPTI_SGD
51 
52 #include "core/aifes_core.h"
53 
54 typedef struct aiopti_sgd aiopti_sgd_t;
59 struct aiopti_sgd {
68  void *momentum;
70 
75 
83  void (*tensor_sub)(const aitensor_t *a, const aitensor_t *b, aitensor_t *result);
84 
92  void (*tensor_add)(const aitensor_t *a, const aitensor_t *b, aitensor_t *result);
93 
101  void (*scalar_mul)(const void *scalar, const aitensor_t *a, aitensor_t *result);
102 
110  void (*zero_tensor)(aitensor_t *tensor);
111 
113 };
114 
120 extern const aicore_optitype_t *aiopti_sgd_type;
121 
122 
133 
147 
159 
177 void aiopti_sgd_init_optimem_with_momentum(aiopti_t *self, const aitensor_t *params, const aitensor_t *gradients, void *optimem);
178 
190 void aiopti_sgd_init_optimem_without_momentum(aiopti_t *self, const aitensor_t *params, const aitensor_t *gradients, void *optimem);
191 
207 
236 void aiopti_sgd_update_params_with_momentum(aiopti_t *self, aitensor_t *params, const aitensor_t *gradients, void *optimem);
237 
260 void aiopti_sgd_update_params_without_momentum(aiopti_t *self, aitensor_t *params, const aitensor_t *gradients, void *optimem);
261 
262 #ifdef AIDEBUG_PRINT_MODULE_SPECS
268 void aiopti_sgd_print_specs(const aiopti_t *self, int (*print)(const char *format, ...));
269 #endif // AIDEBUG_PRINT_MODULE_SPECS
270 
271 #endif // AIOPTI_SGD
272 
AIfES 2 core interface.
void aiopti_sgd_print_specs(const aiopti_t *self, int(*print)(const char *format,...))
Print the optimizer specification.
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_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:159
General Stochastic Gradient Descent (SGD) optimizer struct.
Definition: aiopti_sgd.h:59
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:101
void * momentum
aiscalar: Momentum(set to null to save optimization memory)
Definition: aiopti_sgd.h:68
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:83
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:92
aiopti_t base
Inherited field members from general optimizer struct.
Definition: aiopti_sgd.h:60
void(* zero_tensor)(aitensor_t *tensor)
Required math function: Sets the elements of a tensor to zero.
Definition: aiopti_sgd.h:110
AIfES optimizer interface.
Definition: aifes_core.h:413
A tensor in AIfES.
Definition: aifes_math.h:98