| 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 {
57 aiopti_t base;
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
129 aiopti_t *aiopti_sgd(aiopti_sgd_t *opti);
130
143 uint32_t aiopti_sgd_sizeof_optimem_with_momentum(aiopti_t *self, const aitensor_t *params);
144
155 uint32_t aiopti_sgd_sizeof_optimem_without_momentum(aiopti_t *self, const aitensor_t *params);
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
203 void aiopti_sgd_zero_gradients(aiopti_t *self, aitensor_t *gradients);
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
264 void aiopti_sgd_print_specs(const aiopti_t *self);
265 #endif // AIDEBUG_PRINT_MODULE_SPECS
266
267 #endif // AIOPTI_SGD
268
aifes_core.h
AIfES 2 core interface.
aiopti_sgd
aiopti_t * aiopti_sgd(aiopti_sgd_t *opti)
Initialize the given SGD optimizer.
aiopti_sgd_init_optimem_with_momentum
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.
aiopti_sgd_sizeof_optimem_without_momentum
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.
aiopti_sgd_sizeof_optimem_with_momentum
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.
aiopti_sgd_print_specs
void aiopti_sgd_print_specs(const aiopti_t *self)
Print the optimizer specification.
aiopti_sgd_zero_gradients
void aiopti_sgd_zero_gradients(aiopti_t *self, aitensor_t *gradients)
Set the gradients to zero.
aiopti_sgd_type
const aicore_optitype_t * aiopti_sgd_type
SGD optimizer type.
aiopti_sgd_update_params_with_momentum
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.
aiopti_sgd_init_optimem_without_momentum
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.
aiopti_sgd_update_params_without_momentum
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.
aicore_optitype
Type indicator of the optimizer to check for the optimizer type.
Definition: aifes_core.h:160
aiopti_sgd
General Stochastic Gradient Descent (SGD) optimizer struct.
Definition: aiopti_sgd.h:56
aiopti_sgd::scalar_mul
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
aiopti_sgd::momentum
void * momentum
aiscalar: Momentum(set to null to save optimization memory)
Definition: aiopti_sgd.h:65
aiopti_sgd::tensor_sub
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
aiopti_sgd::tensor_add
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_sgd::base
aiopti_t base
Inherited field members from general optimizer struct.
Definition: aiopti_sgd.h:57
aiopti_sgd::zero_tensor
void(* zero_tensor)(aitensor_t *tensor)
Required math function: Sets the elements of a tensor to zero.
Definition: aiopti_sgd.h:107
aiopti
AIfES optimizer interface.
Definition: aifes_core.h:438
aitensor
A tensor in AIfES.
Definition: aifes_math.h:89