MCPcopy Create free account
hub / github.com/OriginQ/QPanda-2 / run

Method run

Core/Variational/Optimizer.cpp:89–112  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

87}
88
89bool VanillaGradientDescentOptimizer::run(
90 std::vector<var> &leaves,
91 size_t t)
92{
93 (void)(t);
94
95 std::unordered_map<var, MatrixXd> gradient;
96 for (auto iter : leaves)
97 {
98 gradient[iter] = zeros_like(iter);
99 }
100
101 auto leaf_set = m_cost_function.findNonConsts(leaves);
102 auto var = m_cost_function.getRoot();
103
104 eval(var, true);
105 back(m_cost_function, gradient, leaf_set);
106 for (auto iter : leaves)
107 {
108 iter.setValue(iter.getValue() - m_learning_rate * gradient[iter]);
109 }
110
111 return true;
112}
113
114MomentumOptimizer::MomentumOptimizer(
115 var lost,

Callers

nothing calls this directly

Calls 14

zeros_likeFunction · 0.85
moveFunction · 0.85
findNonConstsMethod · 0.80
getRootMethod · 0.80
evalFunction · 0.70
backFunction · 0.70
powFunction · 0.50
setValueMethod · 0.45
getValueMethod · 0.45
findMethod · 0.45
endMethod · 0.45
arrayMethod · 0.45

Tested by

no test coverage detected