Sequential Quantum Gate Decomposer  v1.9.3
Powerful decomposition of general unitarias into one- and two-qubit gates gates
Adam.h
Go to the documentation of this file.
1 /*
2 Created on Fri Jun 26 14:13:26 2020
3 Copyright 2020 Peter Rakyta, Ph.D.
4 
5 Licensed under the Apache License, Version 2.0 (the "License");
6 you may not use this file except in compliance with the License.
7 You may obtain a copy of the License at
8 
9  http://www.apache.org/licenses/LICENSE-2.0
10 
11 Unless required by applicable law or agreed to in writing, software
12 distributed under the License is distributed on an "AS IS" BASIS,
13 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 See the License for the specific language governing permissions and
15 limitations under the License.
16 
17 @author: Peter Rakyta, Ph.D.
18 */
23 #ifndef ADAM_H
24 #define ADAM_H
25 
26 #include "matrix_real.h"
27 #include <map>
28 #include <cstdlib>
29 #include <time.h>
30 #include <ctime>
31 
32 
36 class Adam {
37 
38 
39 public:
40 
41  // learning rate of the Adam algorithm
42  double eta;
43 
44 
45 protected:
46 
50  double beta1;
52  double beta2;
53  // epsilon regularization parameter of the Adam algorithm
54  double epsilon;
55 
61  int64_t iter_t;
62 
64  double beta1_t;
66  double beta2_t;
67 
71  double f0_mean;
73  int f0_idx;
74 
78  int decreasing_idx = 0;
82  double f0_prev;
83 
84 
85 public:
86 
90 Adam();
91 
99 Adam( double beta1_in, double beta2_in, double epsilon_in, double eta_in);
100 
104 virtual ~Adam();
105 
106 
110 void reset();
111 
112 
117 
122 int update( Matrix_real& parameters, Matrix_real& grad, const double& f0 );
123 
124 
128 double get_decreasing_test();
129 
130 };
131 
132 
133 #endif //Adam
int update(Matrix_real &parameters, Matrix_real &grad, const double &f0)
Call to set the number of gate blocks to be optimized in one shot.
int64_t iter_t
iteration index
Definition: Adam.h:61
double f0_prev
previous value of the cost function
Definition: Adam.h:82
parameter_num
[set adaptive gate structure]
int decreasing_idx
current index in the decreasing_vec array
Definition: Adam.h:78
Matrix_real f0_vec
vector stroing the lates values of cost function values to test local minimum
Definition: Adam.h:69
matrix_base< int > decreasing_vec
vector containing 1 if cost function decreased from previous value, and -1 if it increased ...
Definition: Adam.h:76
virtual ~Adam()
Destructor of the class.
Definition: common/Adam.cpp:82
double beta2_t
beta2^t
Definition: Adam.h:66
double f0_mean
Mean of the latest cost function values to test local minimum.
Definition: Adam.h:71
double epsilon
Definition: Adam.h:54
void initialize_moment_and_variance(int parameter_num)
?????????????
double beta1_t
beta1^t
Definition: Adam.h:64
double get_decreasing_test()
?????????????
Matrix_real var
variance parameter of the Adam algorithm
Definition: Adam.h:59
void reset()
?????????????
Definition: common/Adam.cpp:90
double beta2
parameter beta2 of the Adam algorithm
Definition: Adam.h:52
double eta
Definition: Adam.h:42
Adam()
Nullary constructor of the class.
Definition: common/Adam.cpp:31
Matrix_real mom
momentum parameter of the Adam algorithm
Definition: Adam.h:57
double beta1
parameter beta1 of the Adam algorithm
Definition: Adam.h:50
double decreasing_test
decreasing_test
Definition: Adam.h:80
int f0_idx
current index in the f0_vec array
Definition: Adam.h:73
A class for Adam optimization according to https://towardsdatascience.com/how-to-implement-an-adam-op...
Definition: Adam.h:36
Class to store data of complex arrays and its properties.
Definition: matrix_real.h:39
int num_threads
Store the number of OpenMP threads. (During the calculations OpenMP multithreading is turned off...
Definition: Adam.h:48