Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

added readme, some doc and cleaned up gem- and rakefile

  • Loading branch information...
commit 7febe24f155c8b9772e4c43b10eb5866bbc09a29 1 parent 010b933
Lars Kuhnt authored April 27, 2010
22  .gitignore
... ...
@@ -1,21 +1,5 @@
1  
-## MAC OS
2 1
 .DS_Store
3  
-
4  
-## TEXTMATE
5  
-*.tmproj
6  
-tmtags
7  
-
8  
-## EMACS
9  
-*~
10  
-\#*
11  
-.\#*
12  
-
13  
-## VIM
14  
-*.swp
15  
-
16  
-## PROJECT::GENERAL
17 2
 coverage
18  
-rdoc
19  
-pkg
20  
-
21  
-## PROJECT::SPECIFIC
  3
+doc
  4
+.yardoc
  5
+*.gem
0  CHANGELOG
No changes.
8  Gemfile
... ...
@@ -0,0 +1,8 @@
  1
+source :gemcutter
  2
+
  3
+gem 'rake',       '>= 0.8.7'
  4
+gem 'rspec',      '>= 1.3.0'
  5
+gem 'rcov',       '>= 0.9.8'
  6
+gem 'yard',       '>= 0.5.4'
  7
+gem 'yard-rspec', '>= 0.1.0'
  8
+gem 'bluecloth',  '>= 2.0.5'
4  HISTORY.md
Source Rendered
... ...
@@ -0,0 +1,4 @@
  1
+v0.1.0
  2
+------
  3
+
  4
+* Initial release of the trueskill gem
2  LICENSE
... ...
@@ -1,4 +1,4 @@
1  
-Copyright (c) 2009 Lars Kuhnt
  1
+Copyright (c) 2010 Lars Kuhnt
2 2
 
3 3
 Permission is hereby granted, free of charge, to any person obtaining
4 4
 a copy of this software and associated documentation files (the
66  README.md
Source Rendered
... ...
@@ -0,0 +1,66 @@
  1
+trueskill
  2
+=========
  3
+
  4
+trueskill is a rating-system for games with an arbitrary number of teams and players developed by Microsoft Research. It is based on the Glicko rating system and solves some major flaws of the ELO system.
  5
+
  6
+Usage
  7
+-----
  8
+
  9
+Example:
  10
+    
  11
+    require 'rubygems'
  12
+    require 'saulabs/trueskill'
  13
+    
  14
+    include Saulabs::TrueSkill
  15
+    
  16
+    # team 1 has just one player with a mean skill of 27.1, a skill-deviation of 2.13
  17
+    # and an play activity of 100 %
  18
+    team1 = [Rating.new(27.1, 2.13, 1.0)]
  19
+    
  20
+    # team 2 has two players
  21
+    team2 = [Rating.new(22.0, 0.98, 0.8), Rating.new(31.1, 5.33, 0.9)]
  22
+    
  23
+    # team 1 finished first and team 2 second
  24
+    graph = FactorGraph.new([team1, team2], [1,2])
  25
+    
  26
+    # update the Ratings
  27
+    graph.update_skills
  28
+
  29
+Installation
  30
+------------
  31
+
  32
+To install the TrueSkill gem, simply run
  33
+
  34
+    [sudo] gem install trueskill
  35
+
  36
+Add the following to your script:
  37
+   
  38
+    require 'saulabs/trueskill'
  39
+
  40
+Known issues
  41
+------------
  42
+
  43
+* The calculation of the ranking probability is not yet implemented
  44
+
  45
+Plans
  46
+-----
  47
+
  48
+* 
  49
+
  50
+Note on Patches/Pull Requests
  51
+-----------------------------
  52
+ 
  53
+* Fork the project.
  54
+* Make your feature addition or bug fix.
  55
+* Add tests for it. This is important so I don't break it in a
  56
+  future version unintentionally.
  57
+* Commit, do not mess with rakefile, version, or history.
  58
+  (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
  59
+* Send me a pull request. Bonus points for topic branches.
  60
+
  61
+Copyright
  62
+---------
  63
+
  64
+© 2010 Lars Kuhnt (<http://saulabs.net>). 
  65
+
  66
+See LICENSE for details.
17  README.rdoc
Source Rendered
... ...
@@ -1,17 +0,0 @@
1  
-= trueskill
2  
-
3  
-Description goes here.
4  
-
5  
-== Note on Patches/Pull Requests
6  
- 
7  
-* Fork the project.
8  
-* Make your feature addition or bug fix.
9  
-* Add tests for it. This is important so I don't break it in a
10  
-  future version unintentionally.
11  
-* Commit, do not mess with rakefile, version, or history.
12  
-  (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
13  
-* Send me a pull request. Bonus points for topic branches.
14  
-
15  
-== Copyright
16  
-
17  
-Copyright (c) 2010 Lars Kuhnt. See LICENSE for details.
50  Rakefile
... ...
@@ -1,46 +1,24 @@
1 1
 require 'rubygems'
2 2
 require 'rake'
  3
+require 'bundler'
3 4
 
4  
-begin
5  
-  require 'jeweler'
6  
-  Jeweler::Tasks.new do |gem|
7  
-    gem.name = "trueskill"
8  
-    gem.summary = %Q{A ruby library for the trueskill rating system}
9  
-    gem.description = %Q{A ruby library for the trueskill rating system}
10  
-    gem.email = "lars.kuhnt@gmail.com"
11  
-    gem.homepage = "http://github.com/saulabs/trueskill"
12  
-    gem.authors = ["Lars Kuhnt"]
13  
-    gem.add_development_dependency "rspec", ">= 1.2.9"
14  
-    gem.add_dependency('narray', '>= 0.5.9.7')
15  
-    # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
16  
-  end
17  
-  Jeweler::GemcutterTasks.new
18  
-rescue LoadError
19  
-  puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
20  
-end
  5
+Bundler.setup
  6
+Bundler.require
21 7
 
22 8
 require 'spec/rake/spectask'
23  
-Spec::Rake::SpecTask.new(:spec) do |spec|
24  
-  spec.libs << 'lib' << 'spec'
25  
-  spec.spec_files = FileList['spec/**/*_spec.rb']
26  
-end
27  
-
28  
-Spec::Rake::SpecTask.new(:rcov) do |spec|
29  
-  spec.libs << 'lib' << 'spec'
30  
-  spec.pattern = 'spec/**/*_spec.rb'
31  
-  spec.rcov = true
32  
-end
33  
-
34  
-task :spec => :check_dependencies
35 9
 
  10
+desc 'Default: run specs.'
36 11
 task :default => :spec
37 12
 
38  
-require 'rake/rdoctask'
39  
-Rake::RDocTask.new do |rdoc|
40  
-  version = File.exist?('VERSION') ? File.read('VERSION') : ""
  13
+desc 'Run the specs'
  14
+Spec::Rake::SpecTask.new(:spec) do |t|
  15
+  t.rcov_opts  << '--exclude "gems/*,spec/*"'
  16
+  t.rcov       = true
  17
+  t.rcov_dir   = 'doc/coverage'
  18
+  t.spec_files = FileList['spec/**/*_spec.rb']
  19
+end
41 20
 
42  
-  rdoc.rdoc_dir = 'rdoc'
43  
-  rdoc.title = "trueskill #{version}"
44  
-  rdoc.rdoc_files.include('README*')
45  
-  rdoc.rdoc_files.include('lib/**/*.rb')
  21
+YARD::Rake::YardocTask.new(:doc) do |t|
  22
+  t.files   = ['lib/**/*.rb', 'HISTORY.md']
  23
+  t.options = ['--no-private', '--title', 'trueskill Documentation', '--readme', 'README.md']
46 24
 end
1  VERSION
... ...
@@ -1 +0,0 @@
1  
-0.1.0
24  lib/saulabs/gauss/distribution.rb
... ...
@@ -1,10 +1,13 @@
1 1
 module Saulabs
2 2
   module Gauss
  3
+    
  4
+    # Implementation of a gaussian distribution
  5
+    # 
3 6
     class Distribution
4 7
       
5  
-      SQRT2 = Math.sqrt(2).freeze
6  
-      INV_SQRT_2PI = (1 / Math.sqrt(2 * Math::PI)).freeze
7  
-      LOG_SQRT_2PI = Math.log(Math.sqrt(2 * Math::PI)).freeze
  8
+      @@sqrt2 = Math.sqrt(2).freeze
  9
+      @@inv_sqrt_2pi = (1 / Math.sqrt(2 * Math::PI)).freeze
  10
+      @@log_sqrt_2pi = Math.log(Math.sqrt(2 * Math::PI)).freeze
8 11
     
9 12
       # gaussian normal distribution values
10 13
       attr_accessor :mean, :deviation, :variance, :precision, :precision_mean
@@ -22,8 +25,7 @@ def initialize(mean = 0.0, deviation = 0.0)
22 25
       class << self
23 26
         
24 27
         def standard
25  
-          @@standard ||= Distribution.new(0.0, 1.0)
26  
-          @@standard
  28
+          Distribution.new(0.0, 1.0)
27 29
         end
28 30
       
29 31
         def with_deviation(mean, deviation)
@@ -46,7 +48,7 @@ def log_product_normalization(x, y)
46 48
           return 0.0 if x.precision == 0.0 || y.precision == 0.0
47 49
           variance_sum = x.variance + y.variance
48 50
           mean_diff = x.mean - y.mean
49  
-          -LOG_SQRT_2PI - (Math.log(variance_sum) / 2.0) - (mean_diff**2 / (2.0 * variance_sum))
  51
+          -@@log_sqrt_2pi - (Math.log(variance_sum) / 2.0) - (mean_diff**2 / (2.0 * variance_sum))
50 52
         end
51 53
       
52 54
         def log_ratio_normalization(x, y)
@@ -54,24 +56,24 @@ def log_ratio_normalization(x, y)
54 56
           variance_diff = y.variance - x.variance
55 57
           return 0.0 if variance_diff == 0.0
56 58
           mean_diff = x.mean - y.mean
57  
-          Math.log(y.variance) + LOG_SQRT_2PI - (Math.log(variance_diff) / 2.0) + (mean_diff**2 / (2.0 * variance_diff))
  59
+          Math.log(y.variance) + @@log_sqrt_2pi - (Math.log(variance_diff) / 2.0) + (mean_diff**2 / (2.0 * variance_diff))
58 60
         end
59 61
         
60 62
         # Computes the cummulative Gaussian distribution at a specified point of interest
61 63
         def cumulative_distribution_function(x)
62  
-          0.5 * (1 + Math.erf(x / SQRT2))
  64
+          0.5 * (1 + Math.erf(x / @@sqrt2))
63 65
         end
64 66
         alias_method :cdf, :cumulative_distribution_function
65 67
         
66 68
         # Computes the Gaussian density at a specified point of interest
67 69
         def probability_density_function(x)
68  
-          INV_SQRT_2PI * Math.exp(-0.5 * (x**2))
  70
+          @@inv_sqrt_2pi * Math.exp(-0.5 * (x**2))
69 71
         end
70 72
         alias_method :pdf, :probability_density_function
71 73
         
72 74
         # The inverse of the cummulative Gaussian distribution function
73 75
         def quantile_function(x)
74  
-          -SQRT2 * Math.erfc(2.0 * x)
  76
+          -@@sqrt2 * Math.erfc(2.0 * x)
75 77
         end
76 78
         alias_method :inv_cdf, :quantile_function
77 79
         
@@ -79,7 +81,7 @@ def quantile_function(x)
79 81
       
80 82
       def value_at(x)
81 83
         exp = -(x - @mean)**2.0 / (2.0 * @variance)
82  
-        (1.0/@deviation) * INV_SQRT_2PI * Math.exp(exp)
  84
+        (1.0/@deviation) * @@inv_sqrt_2pi * Math.exp(exp)
83 85
       end
84 86
       
85 87
       # copy values from other distribution
2  lib/saulabs/trueskill/factor_graph.rb
@@ -5,7 +5,7 @@ class FactorGraph
5 5
       
6 6
       attr_reader :teams, :beta, :beta_squared, :draw_probability, :epsilon, :layers
7 7
       
8  
-      # teams: 2 dimensional array of ratings
  8
+      # @param teams (Array) 2 dimensional array of ratings
9 9
       def initialize(teams, ranks, options = {})
10 10
         @teams = teams
11 11
         @ranks = ranks
7  spec/saulabs/trueskill_spec.rb
... ...
@@ -0,0 +1,7 @@
  1
+require File.dirname(__FILE__) + '/../../spec_helper'
  2
+
  3
+describe Saulabs::TrueSkill do
  4
+  
  5
+  
  6
+  
  7
+end
3  spec/spec.opts
... ...
@@ -1 +1,4 @@
1 1
 --color
  2
+--format specdoc
  3
+--loadby mtime
  4
+--reverse
112  trueskill.gemspec
... ...
@@ -1,99 +1,25 @@
1  
-# Generated by jeweler
2  
-# DO NOT EDIT THIS FILE DIRECTLY
3  
-# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4 1
 # -*- encoding: utf-8 -*-
5 2
 
6  
-Gem::Specification.new do |s|
7  
-  s.name = %q{trueskill}
8  
-  s.version = "0.1.0"
9  
-
10  
-  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11  
-  s.authors = ["Lars Kuhnt"]
12  
-  s.date = %q{2010-04-21}
13  
-  s.description = %q{A ruby library for the trueskill rating system}
14  
-  s.email = %q{lars.kuhnt@gmail.com}
15  
-  s.extra_rdoc_files = [
16  
-    "LICENSE",
17  
-     "README.rdoc"
18  
-  ]
19  
-  s.files = [
20  
-    ".document",
21  
-     ".gitignore",
22  
-     "CHANGELOG",
23  
-     "LICENSE",
24  
-     "README.rdoc",
25  
-     "Rakefile",
26  
-     "VERSION",
27  
-     "lib/saulabs/gauss.rb",
28  
-     "lib/saulabs/gauss/distribution.rb",
29  
-     "lib/saulabs/gauss/truncated_correction.rb",
30  
-     "lib/saulabs/trueskill.rb",
31  
-     "lib/saulabs/trueskill/factor_graph.rb",
32  
-     "lib/saulabs/trueskill/factors/base.rb",
33  
-     "lib/saulabs/trueskill/factors/greater_than.rb",
34  
-     "lib/saulabs/trueskill/factors/likelihood.rb",
35  
-     "lib/saulabs/trueskill/factors/prior.rb",
36  
-     "lib/saulabs/trueskill/factors/weighted_sum.rb",
37  
-     "lib/saulabs/trueskill/factors/within.rb",
38  
-     "lib/saulabs/trueskill/layers/base.rb",
39  
-     "lib/saulabs/trueskill/layers/iterated_team_performances.rb",
40  
-     "lib/saulabs/trueskill/layers/performances_to_team_performances.rb",
41  
-     "lib/saulabs/trueskill/layers/prior_to_skills.rb",
42  
-     "lib/saulabs/trueskill/layers/skills_to_performances.rb",
43  
-     "lib/saulabs/trueskill/layers/team_difference_comparision.rb",
44  
-     "lib/saulabs/trueskill/layers/team_performance_differences.rb",
45  
-     "lib/saulabs/trueskill/rating.rb",
46  
-     "lib/saulabs/trueskill/schedules/base.rb",
47  
-     "lib/saulabs/trueskill/schedules/loop.rb",
48  
-     "lib/saulabs/trueskill/schedules/sequence.rb",
49  
-     "lib/saulabs/trueskill/schedules/step.rb",
50  
-     "spec/saulabs/gauss/distribution_spec.rb",
51  
-     "spec/saulabs/gauss/truncated_correction_spec.rb",
52  
-     "spec/saulabs/trueskill/factor_graph_spec.rb",
53  
-     "spec/saulabs/trueskill/factors/greater_than_spec.rb",
54  
-     "spec/saulabs/trueskill/factors/likelihood_spec.rb",
55  
-     "spec/saulabs/trueskill/factors/prior_spec.rb",
56  
-     "spec/saulabs/trueskill/factors/weighted_sum_spec.rb",
57  
-     "spec/saulabs/trueskill/factors/within_spec.rb",
58  
-     "spec/saulabs/trueskill/layers/prior_to_skills_spec.rb",
59  
-     "spec/saulabs/trueskill/schedules_spec.rb",
60  
-     "spec/spec.opts",
61  
-     "spec/spec_helper.rb",
62  
-     "trueskill.gemspec"
63  
-  ]
64  
-  s.homepage = %q{http://github.com/saulabs/trueskill}
65  
-  s.rdoc_options = ["--charset=UTF-8"]
66  
-  s.require_paths = ["lib"]
67  
-  s.rubygems_version = %q{1.3.6}
68  
-  s.summary = %q{A ruby library for the trueskill rating system}
69  
-  s.test_files = [
70  
-    "spec/saulabs/gauss/distribution_spec.rb",
71  
-     "spec/saulabs/gauss/truncated_correction_spec.rb",
72  
-     "spec/saulabs/trueskill/factor_graph_spec.rb",
73  
-     "spec/saulabs/trueskill/factors/greater_than_spec.rb",
74  
-     "spec/saulabs/trueskill/factors/likelihood_spec.rb",
75  
-     "spec/saulabs/trueskill/factors/prior_spec.rb",
76  
-     "spec/saulabs/trueskill/factors/weighted_sum_spec.rb",
77  
-     "spec/saulabs/trueskill/factors/within_spec.rb",
78  
-     "spec/saulabs/trueskill/layers/prior_to_skills_spec.rb",
79  
-     "spec/saulabs/trueskill/schedules_spec.rb",
80  
-     "spec/spec_helper.rb"
81  
-  ]
82 3
 
83  
-  if s.respond_to? :specification_version then
84  
-    current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
85  
-    s.specification_version = 3
  4
+pkg_files = ['README.md','HISTORY.md','Rakefile','LICENSE' ]
  5
+pkg_files += Dir['lib/**/*.rb']
  6
+pkg_files += Dir['spec/**/*.rb']
86 7
 
87  
-    if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
88  
-      s.add_development_dependency(%q<rspec>, [">= 1.2.9"])
89  
-      s.add_runtime_dependency(%q<narray>, [">= 0.5.9.7"])
90  
-    else
91  
-      s.add_dependency(%q<rspec>, [">= 1.2.9"])
92  
-      s.add_dependency(%q<narray>, [">= 0.5.9.7"])
93  
-    end
94  
-  else
95  
-    s.add_dependency(%q<rspec>, [">= 1.2.9"])
96  
-    s.add_dependency(%q<narray>, [">= 0.5.9.7"])
97  
-  end
  8
+Gem::Specification.new do |s|
  9
+  s.name                      = "trueskill"
  10
+  s.version                   = "0.1.0"
  11
+  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to?(:required_rubygems_version=)
  12
+  s.authors                   = ["Lars Kuhnt"]
  13
+  s.date                      = "2010-04-21"
  14
+  s.description               = "A ruby library for the trueskill rating system"
  15
+  s.email                     = "lars@sauspiel.de"
  16
+  s.files                     = pkg_files
  17
+  s.homepage                  = "http://github.com/saulabs/trueskill"
  18
+  s.has_rdoc                  = false
  19
+  s.require_paths             = ["lib"]
  20
+  s.rubygems_version          = "1.3.6"
  21
+  s.summary                   = "A ruby library for the trueskill rating system"
  22
+  s.description               = ""
  23
+  s.test_files                = Dir['spec/**/*.{rb,yml,opts}']
98 24
 end
99 25
 

0 notes on commit 7febe24

Please sign in to comment.
Something went wrong with that request. Please try again.