-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.d
75 lines (56 loc) · 1.67 KB
/
test.d
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import std.math, std.random, std.stdio,
dregs.core, dregs.codetermine;
struct RatingIsh
{
size_t user;
size_t object;
double weight;
this(size_t u, size_t o, double w)
{
user = u;
object = o;
weight = w;
}
}
void main()
{
Rating!(size_t, size_t, double)[] ratings;
double[] objectQuality;
double[] userError;
Mt19937 rng;
auto yzlm = YZLM(1e-24, 0.8, 1e-36);
auto dkvdLin = DKVDlinear(1e-24, 1e-36);
auto dkvdExp = DKVDexp(1e-24, 0.8);
rng.seed(1001);
objectQuality.length = 1000;
userError.length = 1000;
size_t iterTotal = 0;
ratings.length = userError.length * objectQuality.length;
alias yzlm algorithm;
foreach(size_t i; 0..100) {
foreach(ref double Q; objectQuality)
Q = uniform(0.0, 10.0, rng);
foreach(ref double sigma2; userError)
sigma2 = uniform(0.0, 1.0, rng);
assumeSafeAppend(ratings);
size_t pos = 0;
foreach(size_t object, double Q; objectQuality) {
foreach(size_t user, double sigma2; userError) {
ratings[pos] = Rating!(size_t, size_t, double)(user, object, uniform(Q-sigma2, Q+sigma2, rng));
pos++;
}
}
ratings.length = pos;
writeln("[", i, "] Generated ", ratings.length, " ratings.");
auto result = algorithm.reputation(userError.length, objectQuality.length, ratings);
writeln("Exited in ", result.iterations, " iterations with diff = ", result.diff);
iterTotal += result.iterations;
double deltaQ = 0;
foreach(size_t object, double rep; result.reputationObject)
deltaQ += (rep - objectQuality[object]) ^^ 2.0;
deltaQ = sqrt(deltaQ/objectQuality.length);
writeln("Error in quality estimate: ", deltaQ);
writeln("--------");
}
writeln("Total iterations: ", iterTotal);
}