-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
220 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
class NDCG | ||
|
||
def initialize(list) | ||
@list = list | ||
@at = 10 | ||
end | ||
|
||
def CG | ||
@list[0..@at].inject(0) { |sum,x| sum + x} | ||
end | ||
|
||
def DCG(list) | ||
list[0..@at].each.with_index.inject(0) { |sum,(x,i) | sum + ((2**x - 1) / (Math::log(i+2) / Math::log(2)))} | ||
end | ||
|
||
def IDCG | ||
self.DCG(@list.sort.reverse) | ||
end | ||
|
||
def at num | ||
@at = num - 1 | ||
dcg = DCG(@list).to_f | ||
idcg = IDCG() | ||
return (idcg == 0 ? 0 : (dcg / idcg)) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
require './lib/evaluation/ndcg' | ||
|
||
module EvaluateModule | ||
|
||
def self.included(base) | ||
base.send :include, InstanceMethods | ||
end | ||
|
||
module InstanceMethods | ||
def initialize(solution_file, prediction_file) | ||
@solution_file = solution_file | ||
@prediction_file = prediction_file | ||
end | ||
|
||
def by(method) | ||
case method | ||
when "NDCG@10" | ||
return NDCGev.calculate(@solution_file, @prediction_file, 10) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
require './lib/common/ndcg.rb' | ||
|
||
class NDCGev | ||
|
||
def self.calculate(real_solution, my_solution, at) | ||
real = File.readlines(real_solution) | ||
my = File.readlines(my_solution) | ||
|
||
if(my.size != real.size) | ||
abort("some predictions are missing") | ||
end | ||
|
||
index = 0 | ||
sum = 0 | ||
c = 0 | ||
while index < my.size | ||
line = my[index] | ||
real_list = [] | ||
temp_index = index | ||
while temp_index < my.size | ||
words = real[temp_index].split(',') | ||
break if words[0] != my[index].split(',')[0] | ||
real_list << [words[1],words[2].strip.to_i] | ||
temp_index += 1 | ||
end | ||
|
||
size = real_list.size | ||
|
||
my_rel = my[index..temp_index-1].map { |l| real_list.find { |w| w[0] == l.split(',')[1]} [1]} | ||
ndcg = NDCG.new(my_rel).at(at) | ||
if(ndcg != 0 or (ndcg == 0 and my_rel.uniq != [0])) | ||
sum += ndcg | ||
c += 1 | ||
end | ||
index = temp_index | ||
end | ||
|
||
return sum.to_f / c | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,31 @@ | ||
--- | ||
method: borda | ||
method: kemeny | ||
out: /home/pooya/Projects/UTR/samples/output.dat | ||
estimators: | ||
listnet: | ||
path: /home/pooya/Projects/UTR/samples/listnet.dat | ||
weight: 2 | ||
ranknet: | ||
path: /home/pooya/Projects/UTR/samples/ranknet.dat | ||
weight: 3 | ||
listmle: | ||
path: /home/pooya/Projects/UTR/samples/listmle.dat | ||
weight: 3 | ||
svm: | ||
path: /home/pooya/Projects/UTR/samples/svm.dat | ||
pooya: | ||
path: /home/pooya/Projects/UTR/samples/pooya.dat | ||
weight: 1 | ||
hamed: | ||
path: /home/pooya/Projects/UTR/samples/hamed.dat | ||
weight: 2 | ||
javid: | ||
path: /home/pooya/Projects/UTR/samples/javid.dat | ||
weight: 5 | ||
|
||
# method: kemeny | ||
# out: /home/pooya/Projects/UTR/samples/output.dat | ||
# estimators: | ||
# listnet: | ||
# path: /home/pooya/Projects/UTR/samples/listnet.dat | ||
# weight: 2 | ||
# ranknet: | ||
# path: /home/pooya/Projects/UTR/samples/ranknet.dat | ||
# weight: 3 | ||
# listmle: | ||
# path: /home/pooya/Projects/UTR/samples/listmle.dat | ||
# weight: 3 | ||
# svm: | ||
# path: /home/pooya/Projects/UTR/samples/svm.dat | ||
# weight: 1 | ||
# evaluation: | ||
# solution_file: /home/pooya/Projects/UTR/samples/solution.dat |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,9 @@ | ||
--- | ||
syntax: Your YML config file has syntax error | ||
syntax: Your YML config file has syntax error. | ||
conf_not_found: Config file not found. maybe you should use absolute path. | ||
no_out: You haven't specified output file in the config file. | ||
no_method: You haven't specified aggregation method in the config file. | ||
no_method: You haven't specified aggregation method in the config file. | ||
no_ev_method: no evaluation method found in the config file. | ||
no_ev_solution: no evaluation solution path found in the config file. | ||
group_ids_not_match: group ids in ranking files do not match with each other. | ||
instance_ids_not_match: instance ids in ranking files do not match with each other. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
require './lib/utr.rb' | ||
|
||
utr = UTR.new("/home/pooya/Projects/UTR/lib/inits/config.yml") | ||
utr.run | ||
utr.run | ||
#utr.evaluate("NDCG@10") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
1,8,9 | ||
1,5,8 | ||
1,4,7 | ||
1,2,6 | ||
1,7,5 | ||
1,3,4 | ||
1,9,3 | ||
1,1,2 | ||
1,6,1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
1,8,9 | ||
1,6,8 | ||
1,1,7 | ||
1,4,6 | ||
1,9,5 | ||
1,7,4 | ||
1,5,3 | ||
1,2,2 | ||
1,3,1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,9 @@ | ||
1,222,5 | ||
1,333,4 | ||
1,444,3 | ||
1,111,2 | ||
1,555,1 | ||
2,236,5 | ||
2,234,4 | ||
2,233,3 | ||
2,231,2 | ||
2,232,1 | ||
1,8,9 | ||
1,6,8 | ||
1,1,7 | ||
1,4,6 | ||
1,9,5 | ||
1,7,4 | ||
1,5,3 | ||
1,2,2 | ||
1,3,1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
1,5,9 | ||
1,9,8 | ||
1,8,7 | ||
1,4,6 | ||
1,2,5 | ||
1,6,4 | ||
1,3,3 | ||
1,1,2 | ||
1,7,1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
1,333,5 | ||
1,222,4 | ||
1,555,3 | ||
1,444,2 | ||
1,111,1 | ||
2,233,5 | ||
2,234,4 | ||
2,231,3 | ||
2,232,2 | ||
2,236,1 |
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
describe Kemeny do | ||
it "should rank correctly" do | ||
end | ||
end |