-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHITS.java
More file actions
95 lines (92 loc) · 2.69 KB
/
HITS.java
File metadata and controls
95 lines (92 loc) · 2.69 KB
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
import java.util.ArrayList;
import java.util.Collections;
public class HITS {
//Algorithm Link: https://en.wikipedia.org/wiki/HITS_algorithm
ArrayList<HITS_TEAM> h_list = new ArrayList<>();
//Constants
int STEP_LIMIT = 1000;//1000 Seems good, 10000 doesn't seem to change much
public HITS(ArrayList<Data> game_List, ArrayList<Team> team_List) {
//Generating a new Team List
for(int i = 0;i < team_List.size();i++) {
h_list.add(new HITS_TEAM(team_List.get(i).name));
}
//Generating Opponent List
for(int i = 0;i < game_List.size();i++) {
String w = game_List.get(i).winner;
String l = game_List.get(i).loser;
for(int a = 0;a < h_list.size();a++) {
if(h_list.get(a).name.equals(w)) {
for(int z = 0;z < h_list.size();z++) {
if(h_list.get(z).name.equals(l)) {
h_list.get(a).opp_list.add(h_list.get(z));
break;
}
}
h_list.get(a).wl_list.add(1);
}
else if(h_list.get(a).name.equals(l)) {
for(int z = 0;z < h_list.size();z++) {
if(h_list.get(z).name.equals(w)) {
h_list.get(a).opp_list.add(h_list.get(z));
break;
}
}
h_list.get(a).wl_list.add(0);
}
}
}
//Actual Algorithm
for(int i = 0;i < STEP_LIMIT;i++) {
double norm = 0.0;
for(int a = 0;a < h_list.size();a++) {
h_list.get(a).auth = 0;
for(int z = 0;z < h_list.get(a).wl_list.size();z++) {
if(h_list.get(a).wl_list.get(z) == 1) {
h_list.get(a).auth += h_list.get(a).opp_list.get(z).hub;
}
}
norm += Math.pow(h_list.get(a).auth, 2);
}
norm = Math.sqrt(norm);
for(int a = 0;a < h_list.size();a++) {
h_list.get(a).auth = h_list.get(a).auth/norm;
}
norm = 0;
for(int a = 0;a < h_list.size();a++) {
h_list.get(a).hub = 0;
for(int z = 0;z < h_list.get(a).wl_list.size();z++) {
if(h_list.get(a).wl_list.get(z) == 0) {
h_list.get(a).hub += h_list.get(a).opp_list.get(z).auth;
}
}
norm += Math.pow(h_list.get(a).hub, 2);
}
norm = Math.sqrt(norm);
for(int a = 0;a < h_list.size();a++) {
h_list.get(a).hub = h_list.get(a).hub/norm;
}
}
//Printout
for(int i = 0;i < h_list.size();i++) {
for(int a = 0;a < h_list.size();a++) {
if(h_list.get(i).auth > h_list.get(a).auth) {
Collections.swap(h_list,i,a);
}
}
}
for(int i = 0;i < h_list.size();i++) {
System.out.println("TEAM NAME,TEAM AUTH,TEAM HUB");
System.out.println(h_list.get(i).name + " , " + h_list.get(i).auth*1000 + " , " + h_list.get(i).hub*1000);
}
}
}
class HITS_TEAM{
String name;
double auth = 1.0;
double hub = 1.0;
ArrayList<HITS_TEAM> opp_list = new ArrayList<>();
ArrayList<Integer> wl_list = new ArrayList<>();
public HITS_TEAM(String n) {
name = n;
}
}