58 Adam::Adam(
double beta1_in,
double beta2_in,
double epsilon_in,
double eta_in ) {
141 if ( parameter_num != grad.
size() ) {
142 std::string error(
"Adam::update: number of parameters shoulod be equal to the number of elements in gradient vector");
150 if ( parameter_num !=
mom.
size() ) {
151 std::string error(
"Adam::update: number of parameters shoulod be equal to the number of elements in momentum vector");
200 double grad_var = 0.0;
202 grad_var +=
var[idx];
205 int barren_plateau = 0;
206 if ( grad_var < epsilon && decreasing_test > 0.7 ) {
214 double* grad_data = grad.
get_data();
215 double* param_data = parameters.
get_data();
217 tbb::task_arena ta(4);
219 tbb::parallel_for( 0, parameter_num, 1, [&](
int idx) {
221 mom_data[idx] =
beta1 * mom_data[idx] + (1-
beta1) * grad_data[idx];
222 var_data[idx] =
beta2 * var_data[idx] + (1-
beta2) * grad_data[idx] * grad_data[idx];
226 double mom_bias_corr = mom_data[idx]/(1-
beta1_t);
229 double var_bias_corr = var_data[idx]/(1-
beta2_t);
232 if ( barren_plateau ) {
233 param_data[idx] = param_data[idx] -
eta * mom_bias_corr/(sqrt(var_bias_corr) +
epsilon/100);
236 param_data[idx] = param_data[idx] -
eta * mom_bias_corr/(sqrt(var_bias_corr) +
epsilon);
int update(Matrix_real ¶meters, Matrix_real &grad, const double &f0)
Call to set the number of gate blocks to be optimized in one shot.
Header file for a class containing basic methods for the decomposition process.
int64_t iter_t
iteration index
double f0_prev
previous value of the cost function
parameter_num
[set adaptive gate structure]
int decreasing_idx
current index in the decreasing_vec array
Matrix_real f0_vec
vector stroing the lates values of cost function values to test local minimum
matrix_base< int > decreasing_vec
vector containing 1 if cost function decreased from previous value, and -1 if it increased ...
virtual ~Adam()
Destructor of the class.
double f0_mean
Mean of the latest cost function values to test local minimum.
scalar * get_data() const
Call to get the pointer to the stored data.
void initialize_moment_and_variance(int parameter_num)
?????????????
double get_decreasing_test()
?????????????
Matrix_real var
variance parameter of the Adam algorithm
void reset()
?????????????
double beta2
parameter beta2 of the Adam algorithm
Adam()
Nullary constructor of the class.
Matrix_real mom
momentum parameter of the Adam algorithm
double beta1
parameter beta1 of the Adam algorithm
double decreasing_test
decreasing_test
int f0_idx
current index in the f0_vec array
int size() const
Call to get the number of the allocated elements.
Class to store data of complex arrays and its properties.
int num_threads
Store the number of OpenMP threads. (During the calculations OpenMP multithreading is turned off...