diff --git a/rb/glicko2.rb b/rb/glicko2.rb index 009ba86..3d5c0ab 100755 --- a/rb/glicko2.rb +++ b/rb/glicko2.rb @@ -1,4 +1,4 @@ -#!/usr/bin/env ruby +#!/usr/bin/env ruby -w # # @@ -136,22 +136,23 @@ class Glicko2 add_result(opponent,Glicko2::DRAW) end + # util func + def Glicko2.g(deviation) + 1.0 / (Math.sqrt(1.0 + 3.0 * deviation ** 2.0 / (Math::PI ** 2.0))) + end + + # util func + def Glicko2.E(rating, rating_opponent, deviation_opponent) + 1.0 / (1.0 + Math.exp(-Glicko2.g(deviation_opponent)*(rating - rating_opponent))); + end + # Update rating based on current results list, and clear results. def update - # util func - def Glicko2.g(deviation) - 1.0 / (Math.sqrt(1.0 + 3.0 * deviation ** 2.0 / (Math::PI ** 2.0))) - end - - # util func - def Glicko2.E(rating, rating_opponent, deviation_opponent) - 1.0 / (1.0 + Math.exp(-Glicko2.g(deviation_opponent)*(rating - rating_opponent))); - end - # bail if no opponents set if @results.empty? - return nil + @g2deviation = Math.sqrt(@g2deviation**2.0 + @g2volatility**2.0) + return end # compute variance diff --git a/rb/test_glicko2.rb b/rb/test_glicko2.rb index a2da9ca..ccf6d1a 100644 --- a/rb/test_glicko2.rb +++ b/rb/test_glicko2.rb @@ -1,6 +1,6 @@ -#!/usr/bin/env ruby +#!/usr/bin/env ruby -w -require 'glicko2' +require_relative 'glicko2' require 'test/unit' class TestGlicko2 < Test::Unit::TestCase @@ -26,7 +26,7 @@ class TestGlicko2 < Test::Unit::TestCase a.update() assert_in_delta(1464.05,a.rating,0.01) - assert_in_delta(151.516,a.deviation,0.01) + assert_in_delta(151.875,a.deviation,0.01) end