Skip to content

Commit

Permalink
renamed...
Browse files Browse the repository at this point in the history
  • Loading branch information
py4 committed Oct 7, 2014
1 parent f7ab145 commit fcdae8a
Show file tree
Hide file tree
Showing 4 changed files with 122 additions and 19 deletions.
18 changes: 9 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,31 +25,31 @@ Now you should edit the sample config file according to your needs.

```yaml
method: kemeny
out: /home/pooya/Projects/UTR/samples/output.dat
out: /home/pooya/Projects/PAL/samples/output.dat
estimators:
listnet:
path: /home/pooya/Projects/UTR/samples/listnet.dat
path: /home/pooya/Projects/PAL/samples/listnet.dat
weight: 2
ranknet:
path: /home/pooya/Projects/UTR/samples/ranknet.dat
path: /home/pooya/Projects/PAL/samples/ranknet.dat
weight: 3
listmle:
path: /home/pooya/Projects/UTR/samples/listmle.dat
path: /home/pooya/Projects/PAL/samples/listmle.dat
weight: 3
svm:
path: /home/pooya/Projects/UTR/samples/svm.dat
path: /home/pooya/Projects/PAL/samples/svm.dat
weight: 1
evaluation:
solution_file: /home/pooya/Projects/UTR/samples/solution.dat
solution_file: /home/pooya/Projects/PAL/samples/solution.dat
```
Then in the `rank.rb` file you should address the config file and set if you want to evaluate the aggregation or not.
```ruby
require './lib/pal.rb'
utr = UTR.new("/home/pooya/Projects/PAL/lib/inits/config.yml")
utr.run
#utr.evaluate("NDCG@10")
pal = PAL.new("/home/pooya/Projects/PAL/lib/inits/config.yml")
pal.run
#pal.evaluate("NDCG@10")
```

And finally:
Expand Down
12 changes: 6 additions & 6 deletions lib/inits/config.yml
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
method: borda
out: /home/pooya/Projects/UTR/samples/output.dat
out: /home/pooya/Projects/PAL/samples/output.dat
estimators:
listnet:
path: /home/pooya/Projects/UTR/samples/listnet.dat
path: /home/pooya/Projects/PAL/samples/listnet.dat
weight: 2
ranknet:
path: /home/pooya/Projects/UTR/samples/ranknet.dat
path: /home/pooya/Projects/PAL/samples/ranknet.dat
weight: 3
listmle:
path: /home/pooya/Projects/UTR/samples/listmle.dat
path: /home/pooya/Projects/PAL/samples/listmle.dat
weight: 3
svm:
path: /home/pooya/Projects/UTR/samples/svm.dat
path: /home/pooya/Projects/PAL/samples/svm.dat
weight: 1
evaluation:
solution_file: /home/pooya/Projects/UTR/samples/solution.dat
solution_file: /home/pooya/Projects/PAL/samples/solution.dat
103 changes: 103 additions & 0 deletions lib/pal.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
require './lib/inits/config.rb'
require './lib/methods/kemeny'
require './lib/methods/borda'
require './lib/methods/copeland'
require './lib/methods/schulze'
require './lib/evaluation/evaluate'

class PAL

def initialize(config_file)
Conf.init(config_file)
end

module Methods
class Kemeny
include KemenyModule
end

class Borda
include BordaModule
end

class Copeland
include CopelandModule
end

class Schulze
include SchulzeModule
end
end

class Evaluatation
include EvaluateModule
end

def load_data
puts $MESSAGES[:loading_data]

data = Hash.new { |h,k| h[k] = Hash.new { |hh,kk| hh[kk] = {} }}
Conf.estimators.each_with_index do |estimator,i|
File.readlines(Conf.get_path(estimator)).each do |line|
splitted = line.split(',')
group_id, instance_id, score = splitted[0].to_i, splitted[1].to_i, splitted[2].to_f
data[estimator][group_id][instance_id] = score
end
end

validate data

return data
end

def dump_result result
puts $MESSAGES[:dumping]

file = File.open(Conf.get_output,'w')
result.each do |group_id, array|
array.each_with_index do |instance_id, i|
file.puts("#{group_id},#{instance_id},#{array.size - i}")
end
end
file.close
end

def run
data = load_data

case Conf.method
when "kemeny"
dump_result Methods::Kemeny.run data
when "borda"
dump_result Methods::Borda.run data
when "copeland"
dump_result Methods::Copeland.run data
when "schulze"
dump_result Methods::Schulze.run data
end

puts $MESSAGES[:done]
end

def evaluate(method)
puts $MESSAGES[:evaluating]

Conf.estimators.each do |estimator|
result = Evaluatation.new(Conf.get_ev_solution, Conf.get_path(estimator)).by(method)
puts "#{estimator} #{method} -> #{result}"
end
result = Evaluatation.new(Conf.get_ev_solution, Conf.get_output).by(method)
puts "#{Conf.method} aggregation method #{method} -> #{result} "
end

private
def validate data
data.keys[0..-2].each_with_index do |estimator, i|
abort(ERROR[:group_ids_not_match]) if data[estimator].keys.sort != data[data.keys[i+1]].keys.sort
data[estimator].each do |group_id, hash|
abort($ERRORS[:instance_ids_not_match]) if hash.keys.sort != data[data.keys[i+1]][group_id].keys.sort
end
end
end

end
8 changes: 4 additions & 4 deletions rank.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
require './lib/utr.rb'
require './lib/pal.rb'

utr = UTR.new("/home/pooya/Projects/UTR/lib/inits/config.yml")
utr.run
#utr.evaluate("NDCG@10")
pal = PAL.new("/home/pooya/Projects/PAL/lib/inits/config.yml")
pal.run
#pal.evaluate("NDCG@10")

0 comments on commit fcdae8a

Please sign in to comment.