| AIfES 2 2.0.0

aiopti_adam.h
Go to the documentation of this file.
1
45 #ifndef AIOPTI_ADAM
46 #define AIOPTI_ADAM
47
48 #include "core/aifes_core.h"
49
50 typedef struct aiopti_adam aiopti_adam_t;
51 typedef struct aiopti_adam_momentums aiopti_adam_momentums_t;
56 struct aiopti_adam {
57 aiopti_t base;
65 void *beta1;
66 void *beta2;
67 void *eps;
69
75 void *beta1t;
76 void *beta2t;
77 void *one_minus_beta1;
78 void *one_minus_beta2;
79 void *lrt;
81
86
94 void (*multiply)(const aitensor_t *a, const aitensor_t *b, aitensor_t *result);
95
103 void (*divide)(const aitensor_t *a, const aitensor_t *b, aitensor_t *result);
104
112 void (*tensor_add)(const aitensor_t *a, const aitensor_t *b, aitensor_t *result);
113
121 void (*tensor_sub)(const aitensor_t *a, const aitensor_t *b, aitensor_t *result);
122
130 void (*scalar_mul)(const void *scalar, const aitensor_t *a, aitensor_t *result);
131
139 void (*scalar_add)(const void *scalar, const aitensor_t *a, aitensor_t *result);
140
148 void (*sqrt)(const aitensor_t *x, aitensor_t *result);
149
157 void (*zero_tensor)(aitensor_t *tensor);
158
160 };
161
167 extern const aicore_optitype_t *aiopti_adam_type;
168
174 struct aiopti_adam_momentums {
175 aitensor_t m;
176 aitensor_t v;
177 };
178
188 aiopti_t *aiopti_adam(aiopti_adam_t *opti);
189
202 uint32_t aiopti_adam_sizeof_optimem(aiopti_t *self, const aitensor_t *params);
203
224 void aiopti_adam_init_optimem(aiopti_t *self, const aitensor_t *params, const aitensor_t *gradients, void *optimem);
225
240 void aiopti_adam_zero_gradients(aiopti_t *self, aitensor_t *gradients);
241
280 void aiopti_adam_update_params(aiopti_t *self, aitensor_t *params, const aitensor_t *gradients, void *optimem);
281
282 #ifdef AIDEBUG_PRINT_MODULE_SPECS
287 void aiopti_adam_print_specs(const aiopti_t *self);
288 #endif // AIDEBUG_PRINT_MODULE_SPECS
289
290 #endif // AIOPTI_ADAM
291
aifes_core.h
AIfES 2 core interface.
aiopti_adam_update_params
void aiopti_adam_update_params(aiopti_t *self, aitensor_t *params, const aitensor_t *gradients, void *optimem)
Update the given parameter tensor with respect to the gradients.
aiopti_adam_init_optimem
void aiopti_adam_init_optimem(aiopti_t *self, const aitensor_t *params, const aitensor_t *gradients, void *optimem)
Initialization of the optimization memory buffer.
aiopti_adam_zero_gradients
void aiopti_adam_zero_gradients(aiopti_t *self, aitensor_t *gradients)
Set the gradients to zero.
aiopti_adam_sizeof_optimem
uint32_t aiopti_adam_sizeof_optimem(aiopti_t *self, const aitensor_t *params)
Calculates the required memory for the optimization step.
aiopti_adam_print_specs
void aiopti_adam_print_specs(const aiopti_t *self)
Print the optimizer specification.
aiopti_adam_type
const aicore_optitype_t * aiopti_adam_type
Adam optimizer type.
aiopti_adam
aiopti_t * aiopti_adam(aiopti_adam_t *opti)
Initialize the given Adam optimizer.
aicore_optitype
Type indicator of the optimizer to check for the optimizer type.
Definition: aifes_core.h:160
aiopti_adam_momentums
Struct for the momentum tensors of an Adam optimizer.
Definition: aiopti_adam.h:174
aiopti_adam_momentums::v
aitensor_t v
Second momentum vector.
Definition: aiopti_adam.h:176
aiopti_adam_momentums::m
aitensor_t m
First momentum vector.
Definition: aiopti_adam.h:175
aiopti_adam
General Adam optimizer struct.
Definition: aiopti_adam.h:56
aiopti_adam::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_adam.h:130
aiopti_adam::one_minus_beta1
void * one_minus_beta1
aiscalar: Auxiliary variable to calculate
Definition: aiopti_adam.h:77
aiopti_adam::multiply
void(* multiply)(const aitensor_t *a, const aitensor_t *b, aitensor_t *result)
Required math function: Element wise tensor multiplication.
Definition: aiopti_adam.h:94
aiopti_adam::scalar_add
void(* scalar_add)(const void *scalar, const aitensor_t *a, aitensor_t *result)
Required math function: Element wise addition of a scalar to a tensor.
Definition: aiopti_adam.h:139
aiopti_adam::divide
void(* divide)(const aitensor_t *a, const aitensor_t *b, aitensor_t *result)
Required math function: Element wise tensor dividation.
Definition: aiopti_adam.h:103
aiopti_adam::sqrt
void(* sqrt)(const aitensor_t *x, aitensor_t *result)
Required math function: Square root.
Definition: aiopti_adam.h:148
aiopti_adam::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_adam.h:121
aiopti_adam::eps
void * eps
aiscalar: Small positive number for numerical stability (avoid dividing by 0)
Definition: aiopti_adam.h:67
aiopti_adam::one_minus_beta2
void * one_minus_beta2
aiscalar: Auxiliary variable to calculate
Definition: aiopti_adam.h:78
aiopti_adam::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_adam.h:112
aiopti_adam::base
aiopti_t base
Inherited field members from general optimizer struct.
Definition: aiopti_adam.h:57
aiopti_adam::beta1t
void * beta1t
aiscalar: Auxiliary variable to calculate
Definition: aiopti_adam.h:75
aiopti_adam::beta2t
void * beta2t
aiscalar: Auxiliary variable to calculate
Definition: aiopti_adam.h:76
aiopti_adam::lrt
void * lrt
aiscalar: Auxiliary variable to calculate
Definition: aiopti_adam.h:79
aiopti_adam::beta2
void * beta2
aiscalar: Exponential decay rate for the second moment estimates
Definition: aiopti_adam.h:66
aiopti_adam::zero_tensor
void(* zero_tensor)(aitensor_t *tensor)
Required math function: Sets the elements of a tensor to zero.
Definition: aiopti_adam.h:157
aiopti_adam::beta1
void * beta1
aiscalar: Exponential decay rate for the first moment estimates
Definition: aiopti_adam.h:65
aiopti
AIfES optimizer interface.
Definition: aifes_core.h:438
aitensor
A tensor in AIfES.
Definition: aifes_math.h:89