ONE - On-device Neural Engine
Loading...
Searching...
No Matches
SGD.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2023 Samsung Electronics Co., Ltd. All Rights Reserved
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#ifndef __ONERT_BACKEND_TRAIN_OPTIMIZER_SGD_H__
18#define __ONERT_BACKEND_TRAIN_OPTIMIZER_SGD_H__
19
21
22namespace onert
23{
24namespace backend
25{
26namespace train
27{
28namespace optimizer
29{
30
36{
37public:
39
40public:
41 struct Property
42 {
43 double momentum{0.0};
44 bool nesterov{false};
45 };
46
47public:
48 explicit SGD() : _props{}, _learning_rate{0.01} {}
49 explicit SGD(const Property &props) : _props{props}, _learning_rate{0.01} {}
50 explicit SGD(double lr) : _props{}, _learning_rate{lr} {}
51 explicit SGD(const Property &props, double lr) : _props{props}, _learning_rate{lr} {}
52
53public:
59 std::string name() const override { return std::string{"SGD"}; }
60
67 double getLearningRate(uint32_t iteration = 0) const override;
68
74 virtual uint32_t getVarCount() const override { return 0; };
75
81 void applyGradient(const UpdateFactors &factors) const override;
82
83private:
84 Property _props;
85 double _learning_rate;
86};
87
88} // namespace optimizer
89} // namespace train
90} // namespace backend
91} // namespace onert
92
93#endif // __ONERT_BACKEND_TRAIN_OPTIMIZER_SGD_H__
SGD(const Property &props, double lr)
Definition SGD.h:51
exec::train::optimizer::UpdateFactors UpdateFactors
Definition SGD.h:38
double getLearningRate(uint32_t iteration=0) const override
Get the Learning Rate.
Definition SGD.cc:32
std::string name() const override
Get the name of optimizer.
Definition SGD.h:59
SGD(const Property &props)
Definition SGD.h:49
void applyGradient(const UpdateFactors &factors) const override
Apply gradient to a trainable tensor.
Definition SGD.cc:38
virtual uint32_t getVarCount() const override
Get the number of optimizer variables s.
Definition SGD.h:74
Base class for all optimizers.
Definition Optimizer.h:43
std::tuple< const backend::IPortableTensor &, backend::train::ITrainableTensor &, size_t > UpdateFactors
Definition Optimizer.h:36