Permalink
Browse files

some structural updates

  • Loading branch information...
1 parent ddd750c commit 9c83c622da4139fe9b98875207c7c543a7514546 @larskuhnt larskuhnt committed Apr 9, 2010
View
@@ -11,6 +11,7 @@ begin
gem.homepage = "http://github.com/larskuhnt/trueskill"
gem.authors = ["Lars Kuhnt"]
gem.add_development_dependency "rspec", ">= 1.2.9"
+ gem.add_dependency('narray', '>= 0.5.9.7')
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
end
Jeweler::GemcutterTasks.new
View
@@ -1,20 +1,42 @@
+# Author: Lars Kuhnt
+# Copyright Saulabs
+
module TrueSkill
+ #
+ #
class Calculation
- @@k = 10
- cattr_accessor :k
+ # uncertainty of the skill’s standard deviation
+ # TODO: valid values: ]0,???]
+ # TODO: this should depend on the time the player did not play
+ @@tau = 1.0
- def initialize(configuration)
- @configuration = configuration
- end
+ # small beta value indicates a high-skill game (e.g. Go) since smaller
+ # differences in points lead to the 80%:20% ratio. Likewise, a game based
+ # on chance (e.g. Uno) is a low-skill game that would have a higher beta
+ # and smaller skill chain.
+ # TODO: valid values: ]0,???]
+ @@beta = 10
- def evaluate(game)
-
+ def initialize(game)
+ @game = game
end
+
private
+ # team must be an array of players with a minimum of one player
+ def performance(team)
+ rating = 0
+ deviation = 0
+ team.each do |player|
+ rating += player.activity * player.rating
+ deviation += player.activity * player.activity * player.deviation * player.deviation
+ end
+ return [rating, deviation]
+ end
+
end
end
View
@@ -1,21 +0,0 @@
-puts "loaded #{__FILE__}"
-
-module TrueSkill
-
- class Game
-
- # array of players
- attr_accessor :teams
-
- # result of the game coded as array
- # example: [0,1] team at index 1 won
- attr_accessor :result
-
- def initialize(teams = [], result = [])
- @teams = teams
- @result = result
- end
-
- end
-
-end
View
@@ -1,17 +0,0 @@
-module TrueSkill
-
- class Player
-
- # mean value of the players rating
- attr_accessor :rating
-
- # standard deviation of the players rating
- attr_accessor :deviation
-
- def initialize(rating = 25.0, deviation = 8.333333)
- @rating = rating
- @deviation = deviation
- end
- end
-
-end
View
@@ -0,0 +1,50 @@
+module TrueSkill
+
+ class Rating
+
+ # gaussian normal distribution values
+ attr_accessor :mean, :deviation, :variance, :precision, :precision_mean
+
+ # how active was the player in the game
+ # valid values: [0.0, 1.0]
+ attr_accessor :activity
+
+ def self.with_deviation(mean, deviation)
+ rating = Rating.new
+ rating.mean = mean
+ rating.deviation = deviation
+ rating.variance = deviation * deviation
+ rating.precision = 1 / rating.variance.to_f
+ rating.precision_mean = rating.precision * mean
+ return rating
+ end
+
+ def self.with_precision(mean, precision)
+ rating = Rating.new
+ rating.precision = precision
+ rating.precision_mean = mean
+ rating.variance = 1 / precision
+ rating.deviation = Math.sqrt(rating.variance)
+ rating.mean = mean / precision
+ return rating
+ end
+
+ def *(other)
+
+ end
+
+ def +(other)
+
+ end
+
+ def ==(other)
+ self.mean == other.mean && self.variance == other.variance
+ end
+
+ def equals(other)
+ self == other
+ end
+
+ end
+
+end
View
@@ -1,3 +1,6 @@
+require 'rubygems'
+require 'narray'
+
Dir["#{File.dirname(__FILE__)}/**/*.rb"].each do |filename|
require filename
end
View
@@ -1,13 +0,0 @@
-require File.dirname(__FILE__) + '/../spec_helper'
-
-describe "Game" do
-
- before :each do
- @game = TrueSkill::Game.new
- end
-
- it "should respond to result" do
- @game.result.should be_nil
- end
-
-end
View
@@ -1,17 +0,0 @@
-require File.dirname(__FILE__) + '/../spec_helper'
-
-describe "Player" do
-
- before :each do
- @player = TrueSkill::Player.new
- end
-
- it "should have a default rating of 25.0" do
- @player.rating.should == 25.0
- end
-
- it "should have a default deviation of 8.333333" do
- @player.deviation.should == 8.333333
- end
-
-end
View
@@ -0,0 +1,60 @@
+require File.dirname(__FILE__) + '/../spec_helper'
+
+describe "Rating" do
+
+ describe 'initialize with deviation' do
+
+ before :each do
+ @rating = TrueSkill::Rating.with_deviation(25.0, 8.333333)
+ end
+
+ it "should have a default mean value of 25.0" do
+ @rating.mean.should == 25.0
+ end
+
+ it "should have a default deviation of 8.333333" do
+ @rating.deviation.should be_close(8.333333, 0.000001)
+ end
+
+ it "should set the variance to 69.444438" do
+ @rating.variance.should be_close(69.4444, 0.0001)
+ end
+
+ it "should set the precision to 0.0016" do
+ @rating.precision.should be_close(0.0144, 0.0001)
+ end
+
+ it "should set the precision_mean to 0.04" do
+ @rating.precision_mean.should be_close(0.36, 0.0001)
+ end
+
+ end
+
+ describe 'initialize with precision' do
+
+ before :each do
+ @rating = TrueSkill::Rating.with_precision(0.36, 0.0144)
+ end
+
+ it "should have a default mean value of 25.0" do
+ @rating.mean.should == 25.0
+ end
+
+ it "should have a default deviation of 8.333333" do
+ @rating.deviation.should be_close(8.333333, 0.000001)
+ end
+
+ it "should set the variance to 69.444438" do
+ @rating.variance.should be_close(69.4444, 0.0001)
+ end
+
+ it "should set the precision to 0.0016" do
+ @rating.precision.should be_close(0.0144, 0.0001)
+ end
+
+ it "should set the precision_mean to 0.04" do
+ @rating.precision_mean.should be_close(0.36, 0.0001)
+ end
+
+ end
+end
View
@@ -1,20 +1,5 @@
-require File.dirname(__FILE__) + '/../spec_helper'
+require File.dirname(__FILE__) + '/spec_helper'
describe "TrueSkill" do
- describe 'update for a single game' end
-
- before :each do
- @player1 = TrueSkill::Player.new
- @player2 = TrueSkill::Player.new
- @game = TrueSkill::Game.new([[@player1], [@player2]], [1,0])
- end
-
- it "should" do
- TrueSkill.update(@game)
-
- end
-
- end
-
end
View
@@ -24,7 +24,10 @@ Gem::Specification.new do |s|
"README.rdoc",
"Rakefile",
"VERSION",
+ "lib/models/calculation.rb",
+ "lib/models/rating.rb",
"lib/trueskill.rb",
+ "spec/models/rating_spec.rb",
"spec/spec.opts",
"spec/spec_helper.rb",
"spec/trueskill_spec.rb",
@@ -36,7 +39,8 @@ Gem::Specification.new do |s|
s.rubygems_version = %q{1.3.6}
s.summary = %q{A library for the trueskill rating system}
s.test_files = [
- "spec/spec_helper.rb",
+ "spec/models/rating_spec.rb",
+ "spec/spec_helper.rb",
"spec/trueskill_spec.rb"
]
@@ -46,11 +50,14 @@ Gem::Specification.new do |s|
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
s.add_development_dependency(%q<rspec>, [">= 1.2.9"])
+ s.add_runtime_dependency(%q<narray>, [">= 0.5.9.7"])
else
s.add_dependency(%q<rspec>, [">= 1.2.9"])
+ s.add_dependency(%q<narray>, [">= 0.5.9.7"])
end
else
s.add_dependency(%q<rspec>, [">= 1.2.9"])
+ s.add_dependency(%q<narray>, [">= 0.5.9.7"])
end
end

0 comments on commit 9c83c62

Please sign in to comment.