-
Notifications
You must be signed in to change notification settings - Fork 36
/
Mixer.cpp
33 lines (29 loc) · 842 Bytes
/
Mixer.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#include "Mixer.hpp"
Mixer::Mixer(const Shared* const sh, const int n, const int m, const int s) : shared(sh),
n(n), m(m), s(s),
lowerLimitOfLearningRate(s == 1 ? MIN_LEARNING_RATE_S1 : MIN_LEARNING_RATE_SN),
isAdaptiveLearningRate(sh->GetOptionAdaptiveLearningRate()),
scaleFactor(0), tx(n), wx(n * m), cxt(s), info(s), rates(s), pr(s) {
for( uint64_t i = 0; i < s; ++i ) {
pr[i] = 2048; //initial p=0.5
rates[i] = MAX_LEARNING_RATE;
}
reset();
}
void Mixer::add(const int x) {
assert(nx < n);
assert(x == short(x));
tx[nx++] = static_cast<short>(x);
}
void Mixer::set(const uint32_t cx, const uint32_t range) {
assert(numContexts < s);
assert(cx < range);
assert(base + range <= m);
cxt[numContexts++] = base + cx;
base += range;
}
void Mixer::reset() {
nx = 0;
base = 0;
numContexts = 0;
}