Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Don't need to store local copy of ratings -- get speedup by passing.

  • Loading branch information...
commit 4d2a8a055321c2981a453fc4d82fb781da2ea5c7 1 parent 54c9a25
@WebDrake authored
Showing with 16 additions and 18 deletions.
  1. +16 −18 dregs/codetermine.d
View
34 dregs/codetermine.d
@@ -11,7 +11,6 @@ struct CoDetermination(alias This, alias ObjectReputation, alias UserDivergence,
UserID = size_t, ObjectID = size_t, Reputation = double)
{
private immutable Reputation convergence_;
- private Rating!(UserID, ObjectID, Reputation)[] ratings_;
private Reputation[] reputationUser_;
private Reputation[] divergenceUser_;
private size_t[] linksUser_;
@@ -36,20 +35,19 @@ struct CoDetermination(alias This, alias ObjectReputation, alias UserDivergence,
divergenceUser_.length = users;
reputationObject_.length = objects;
reputationObjectOld_.length = objects;
- ratings_ = ratings;
- userReputationInit;
- objectReputationInit;
+ userReputationInit(ratings);
+ objectReputationInit(ratings);
Reputation diff;
size_t iterations = 0;
do {
- userDivergence;
- userReputation;
+ userDivergence(ratings);
+ userReputation(ratings);
reputationObjectOld_[] = reputationObject_[];
- objectReputation;
+ objectReputation(ratings);
diff = 0;
foreach(size_t o, Reputation rep; reputationObject_) {
auto aux = rep - reputationObjectOld_[o];
@@ -132,10 +130,10 @@ mixin template ThisDKVDlinear(UserID = size_t, ObjectID = size_t, Reputation = d
mixin template ObjectReputationInitBasic(UserID = size_t, ObjectID = size_t, Reputation = double)
{
- private final pure nothrow void objectReputationInit()
+ private final pure nothrow void objectReputationInit(Rating!(UserID, ObjectID, Reputation)[] ratings)
{
weightSum_.length = reputationObject_.length;
- objectReputation;
+ objectReputation(ratings);
}
}
@@ -146,7 +144,7 @@ mixin template ObjectReputationWeightedAverage(UserID = size_t, ObjectID = size_
mixin ObjectReputationInitBasic!(UserID, ObjectID, Reputation);
- private final pure nothrow void objectReputation()
+ private final pure nothrow void objectReputation(Rating!(UserID, ObjectID, Reputation)[] ratings)
in
{
assert(weightSum_.length == reputationObject_.length);
@@ -156,7 +154,7 @@ mixin template ObjectReputationWeightedAverage(UserID = size_t, ObjectID = size_
weightSum_[] = 0;
reputationObject_[] = 0;
- foreach(r; ratings_) {
+ foreach(r; ratings) {
reputationObject_[r.object] += reputationUser_[r.user] * r.weight;
weightSum_[r.object] += reputationUser_[r.user];
}
@@ -169,11 +167,11 @@ mixin template ObjectReputationWeightedAverage(UserID = size_t, ObjectID = size_
mixin template UserDivergenceSquare(UserID = size_t, ObjectID = size_t, Reputation = double)
{
- private final pure nothrow userDivergence()
+ private final pure nothrow userDivergence(Rating!(UserID, ObjectID, Reputation)[] ratings)
{
divergenceUser_[] = 0;
- foreach(r; ratings_) {
+ foreach(r; ratings) {
Reputation aux = r.weight - reputationObject_[r.object];
divergenceUser_[r.user] += aux*aux;
}
@@ -183,12 +181,12 @@ mixin template UserDivergenceSquare(UserID = size_t, ObjectID = size_t, Reputati
mixin template UserReputationInitBasic(UserID = size_t, ObjectID = size_t, Reputation = double)
{
- private final pure nothrow void userReputationInit()
+ private final pure nothrow void userReputationInit(Rating!(UserID, ObjectID, Reputation)[] ratings)
{
linksUser_.length = reputationUser_.length;
linksUser_[] = 0;
- foreach(r; ratings_)
+ foreach(r; ratings)
linksUser_[r.user]++;
reputationUser_[] = 1.0;
@@ -202,7 +200,7 @@ mixin template UserReputationInversePower(UserID = size_t, ObjectID = size_t, Re
mixin UserReputationInitBasic!(UserID, ObjectID, Reputation);
- private final pure nothrow void userReputation()
+ private final pure nothrow void userReputation(Rating!(UserID, ObjectID, Reputation)[] ratings)
in
{
assert(exponent_ >= 0);
@@ -227,7 +225,7 @@ mixin template UserReputationExponential(UserID = size_t, ObjectID = size_t, Rep
mixin UserReputationInitBasic!(UserID, ObjectID, Reputation);
- private final pure nothrow void userReputation()
+ private final pure nothrow void userReputation(Rating!(UserID, ObjectID, Reputation)[] ratings)
in
{
assert(exponent_ >= 0);
@@ -250,7 +248,7 @@ mixin template UserReputationLinear(UserID = size_t, ObjectID = size_t, Reputati
mixin UserReputationInitBasic!(UserID, ObjectID, Reputation);
- private final pure nothrow void userReputation()
+ private final pure nothrow void userReputation(Rating!(UserID, ObjectID, Reputation)[] ratings)
in
{
assert(minDivergence_ > 0);
Please sign in to comment.
Something went wrong with that request. Please try again.