Skip to content

Commit 282f3dc

Browse files
committed
Reversed momentum list. m and delta tensors no longer mismatch
1 parent 8d3db66 commit 282f3dc

File tree

3 files changed

+7
-7
lines changed

3 files changed

+7
-7
lines changed

src/autodiff.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,9 @@ void var::evaluateLeaves()const{
106106
auto &w1_shape = node.weights[0].shape;
107107
auto &w2_shape = node.weights[1].shape;
108108
if(node.type == matmul){
109-
tape.grads[node.parents[0]] += gradient * node.weights[0].t();
109+
tape.grads[node.parents[0]] += gradient * node.weights[0].t();
110110
tape.grads[node.parents[1]] += node.weights[1].t() * gradient;
111+
111112
}
112113
else if(node.type == scalar){
113114
if(w1_shape == g_shape){

src/optim.cc

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,10 @@ void GD::step(){
1414
}
1515
}
1616

17-
/*
1817
Moment::Moment(ParStack& p_list, double l_rate_, double moment_)
1918
: Opt(p_list), l_rate(l_rate_), moment(moment_){
2019
for(auto &it : param_list){
21-
m_list.emplace_front(nn::Tensor(it->data.shape, 0));
20+
m_list.push_back(nn::Tensor(it->data.shape, 0));
2221
}
2322
}
2423

@@ -30,5 +29,4 @@ void Moment::step(){
3029
++p_it;
3130
}
3231
}
33-
*/
3432
} // namespace opt

src/optim.hpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#define OPTIM_H
33

44
#include "net.hpp"
5+
#include <list>
56

67
namespace opt{
78
typedef std::forward_list<nn::Net::Parameter*> ParStack;
@@ -22,16 +23,16 @@ class GD: public Opt{
2223
private:
2324
double l_rate;
2425
};
25-
/*
26+
2627
class Moment : public Opt{
2728
public:
2829
Moment(ParStack&, double = 0.1, double = 0.9);
2930
void step();
3031
~Moment(){};
3132
private:
3233
double l_rate, moment;
33-
std::forward_list<nn::Tensor> m_list;
34+
std::list<nn::Tensor> m_list;
3435
};
35-
*/
36+
3637
} // namespace opt
3738
#endif // OPTIM_H

0 commit comments

Comments
 (0)