Skip to content

Commit

Permalink
avoid zero
Browse files Browse the repository at this point in the history
  • Loading branch information
imbajin committed Feb 22, 2022
1 parent 2fc2cc9 commit 3fea9a5
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@

/**
* AdamicAdar is one of the prediction algorithms in graph, you can get more
* info and definition in wikipedia
* info and definition in:
* https://en.wikipedia.org/wiki/Adamic/Adar_index
*/
@Path("graphs/{graph}/traversers/adamicadar")
@Singleton
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@

/**
* ResourceAllocation is one of the prediction algorithms in graph, you can get
* more info and definition in wikipedia
* more info and definition in:
* https://arxiv.org/pdf/0901.0553.pdf
*/
@Path("graphs/{graph}/traversers/resourceallocation")
@Singleton
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,10 @@ public double adamicAdar(Id source, Id target, Directions dir,

double sum = 0.0;
for (Id vid : neighbors) {
sum += 1.0 / Math.log(this.edgesCount(vid, step));
long currentDegree = this.edgesCount(vid, step);
if (currentDegree > 0) {
sum += 1.0 / Math.log(currentDegree);
}
}
return sum;
}
Expand All @@ -57,7 +60,10 @@ public double resourceAllocation(Id source, Id target, Directions dir,

double sum = 0.0;
for (Id vid : neighbors) {
sum += 1.0 / this.edgesCount(vid, step);
long currentDegree = this.edgesCount(vid, step);
if (currentDegree > 0) {
sum += 1.0 / currentDegree;
}
}
return sum;
}
Expand Down

0 comments on commit 3fea9a5

Please sign in to comment.