-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathNaturalnessDynamicModel.js
47 lines (37 loc) · 1.33 KB
/
NaturalnessDynamicModel.js
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
const EventTree = require('./EventTree.js');
const DEPTH = 8;
const INTERPOLATION = 2;
const DENOMINATOR_BIAS = 1;
class NaturalnessDynamicModel {
constructor(depth = DEPTH, interpolation = INTERPOLATION, denominatorBias = DENOMINATOR_BIAS) {
this.depth = depth;
this.interpolation = interpolation;
this.denominatorBias = denominatorBias;
this.model = new EventTree(this.depth, this.interpolation, this.denominatorBias);
}
learn(eventSequence) {
this.model.learn(eventSequence);
}
learnWithSlidingWindow(eventSequence) {
this.model.learnWithSlidingWindow(eventSequence);
}
learnAllSuffix(eventSequence) {
this.model.learnAllSuffix(eventSequence);
}
getProbability(context) {
let result = [];
let candidateMap = this.model.getCandidate();
let probabilityMap = this.model.getInterpolatedProbabilityMap(context);
for (let candidate of candidateMap.keys()) {
result.push({
event: candidateMap.get(candidate),
probability : probabilityMap.get(candidate)
});
}
return result;
}
crossEntropy(eventSequence) {
return this.model.crossEntropy(eventSequence);
}
}
module.exports = NaturalnessDynamicModel;