Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

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

  • Loading branch information...
commit 7febe24f155c8b9772e4c43b10eb5866bbc09a29 1 parent 010b933
@larskuhnt larskuhnt authored
View
22 .gitignore
@@ -1,21 +1,5 @@
-## MAC OS
.DS_Store
-
-## TEXTMATE
-*.tmproj
-tmtags
-
-## EMACS
-*~
-\#*
-.\#*
-
-## VIM
-*.swp
-
-## PROJECT::GENERAL
coverage
-rdoc
-pkg
-
-## PROJECT::SPECIFIC
+doc
+.yardoc
+*.gem
View
0  CHANGELOG
No changes.
View
8 Gemfile
@@ -0,0 +1,8 @@
+source :gemcutter
+
+gem 'rake', '>= 0.8.7'
+gem 'rspec', '>= 1.3.0'
+gem 'rcov', '>= 0.9.8'
+gem 'yard', '>= 0.5.4'
+gem 'yard-rspec', '>= 0.1.0'
+gem 'bluecloth', '>= 2.0.5'
View
4 HISTORY.md
@@ -0,0 +1,4 @@
+v0.1.0
+------
+
+* Initial release of the trueskill gem
View
2  LICENSE
@@ -1,4 +1,4 @@
-Copyright (c) 2009 Lars Kuhnt
+Copyright (c) 2010 Lars Kuhnt
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
View
66 README.md
@@ -0,0 +1,66 @@
+trueskill
+=========
+
+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.
+
+Usage
+-----
+
+Example:
+
+ require 'rubygems'
+ require 'saulabs/trueskill'
+
+ include Saulabs::TrueSkill
+
+ # team 1 has just one player with a mean skill of 27.1, a skill-deviation of 2.13
+ # and an play activity of 100 %
+ team1 = [Rating.new(27.1, 2.13, 1.0)]
+
+ # team 2 has two players
+ team2 = [Rating.new(22.0, 0.98, 0.8), Rating.new(31.1, 5.33, 0.9)]
+
+ # team 1 finished first and team 2 second
+ graph = FactorGraph.new([team1, team2], [1,2])
+
+ # update the Ratings
+ graph.update_skills
+
+Installation
+------------
+
+To install the TrueSkill gem, simply run
+
+ [sudo] gem install trueskill
+
+Add the following to your script:
+
+ require 'saulabs/trueskill'
+
+Known issues
+------------
+
+* The calculation of the ranking probability is not yet implemented
+
+Plans
+-----
+
+*
+
+Note on Patches/Pull Requests
+-----------------------------
+
+* Fork the project.
+* Make your feature addition or bug fix.
+* Add tests for it. This is important so I don't break it in a
+ future version unintentionally.
+* Commit, do not mess with rakefile, version, or history.
+ (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)
+* Send me a pull request. Bonus points for topic branches.
+
+Copyright
+---------
+
+© 2010 Lars Kuhnt (<http://saulabs.net>).
+
+See LICENSE for details.
View
17 README.rdoc
@@ -1,17 +0,0 @@
-= trueskill
-
-Description goes here.
-
-== Note on Patches/Pull Requests
-
-* Fork the project.
-* Make your feature addition or bug fix.
-* Add tests for it. This is important so I don't break it in a
- future version unintentionally.
-* Commit, do not mess with rakefile, version, or history.
- (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)
-* Send me a pull request. Bonus points for topic branches.
-
-== Copyright
-
-Copyright (c) 2010 Lars Kuhnt. See LICENSE for details.
View
50 Rakefile
@@ -1,46 +1,24 @@
require 'rubygems'
require 'rake'
+require 'bundler'
-begin
- require 'jeweler'
- Jeweler::Tasks.new do |gem|
- gem.name = "trueskill"
- gem.summary = %Q{A ruby library for the trueskill rating system}
- gem.description = %Q{A ruby library for the trueskill rating system}
- gem.email = "lars.kuhnt@gmail.com"
- gem.homepage = "http://github.com/saulabs/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
-rescue LoadError
- puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
-end
+Bundler.setup
+Bundler.require
require 'spec/rake/spectask'
-Spec::Rake::SpecTask.new(:spec) do |spec|
- spec.libs << 'lib' << 'spec'
- spec.spec_files = FileList['spec/**/*_spec.rb']
-end
-
-Spec::Rake::SpecTask.new(:rcov) do |spec|
- spec.libs << 'lib' << 'spec'
- spec.pattern = 'spec/**/*_spec.rb'
- spec.rcov = true
-end
-
-task :spec => :check_dependencies
+desc 'Default: run specs.'
task :default => :spec
-require 'rake/rdoctask'
-Rake::RDocTask.new do |rdoc|
- version = File.exist?('VERSION') ? File.read('VERSION') : ""
+desc 'Run the specs'
+Spec::Rake::SpecTask.new(:spec) do |t|
+ t.rcov_opts << '--exclude "gems/*,spec/*"'
+ t.rcov = true
+ t.rcov_dir = 'doc/coverage'
+ t.spec_files = FileList['spec/**/*_spec.rb']
+end
- rdoc.rdoc_dir = 'rdoc'
- rdoc.title = "trueskill #{version}"
- rdoc.rdoc_files.include('README*')
- rdoc.rdoc_files.include('lib/**/*.rb')
+YARD::Rake::YardocTask.new(:doc) do |t|
+ t.files = ['lib/**/*.rb', 'HISTORY.md']
+ t.options = ['--no-private', '--title', 'trueskill Documentation', '--readme', 'README.md']
end
View
1  VERSION
@@ -1 +0,0 @@
-0.1.0
View
24 lib/saulabs/gauss/distribution.rb
@@ -1,10 +1,13 @@
module Saulabs
module Gauss
+
+ # Implementation of a gaussian distribution
+ #
class Distribution
- SQRT2 = Math.sqrt(2).freeze
- INV_SQRT_2PI = (1 / Math.sqrt(2 * Math::PI)).freeze
- LOG_SQRT_2PI = Math.log(Math.sqrt(2 * Math::PI)).freeze
+ @@sqrt2 = Math.sqrt(2).freeze
+ @@inv_sqrt_2pi = (1 / Math.sqrt(2 * Math::PI)).freeze
+ @@log_sqrt_2pi = Math.log(Math.sqrt(2 * Math::PI)).freeze
# gaussian normal distribution values
attr_accessor :mean, :deviation, :variance, :precision, :precision_mean
@@ -22,8 +25,7 @@ def initialize(mean = 0.0, deviation = 0.0)
class << self
def standard
- @@standard ||= Distribution.new(0.0, 1.0)
- @@standard
+ Distribution.new(0.0, 1.0)
end
def with_deviation(mean, deviation)
@@ -46,7 +48,7 @@ def log_product_normalization(x, y)
return 0.0 if x.precision == 0.0 || y.precision == 0.0
variance_sum = x.variance + y.variance
mean_diff = x.mean - y.mean
- -LOG_SQRT_2PI - (Math.log(variance_sum) / 2.0) - (mean_diff**2 / (2.0 * variance_sum))
+ -@@log_sqrt_2pi - (Math.log(variance_sum) / 2.0) - (mean_diff**2 / (2.0 * variance_sum))
end
def log_ratio_normalization(x, y)
@@ -54,24 +56,24 @@ def log_ratio_normalization(x, y)
variance_diff = y.variance - x.variance
return 0.0 if variance_diff == 0.0
mean_diff = x.mean - y.mean
- Math.log(y.variance) + LOG_SQRT_2PI - (Math.log(variance_diff) / 2.0) + (mean_diff**2 / (2.0 * variance_diff))
+ Math.log(y.variance) + @@log_sqrt_2pi - (Math.log(variance_diff) / 2.0) + (mean_diff**2 / (2.0 * variance_diff))
end
# Computes the cummulative Gaussian distribution at a specified point of interest
def cumulative_distribution_function(x)
- 0.5 * (1 + Math.erf(x / SQRT2))
+ 0.5 * (1 + Math.erf(x / @@sqrt2))
end
alias_method :cdf, :cumulative_distribution_function
# Computes the Gaussian density at a specified point of interest
def probability_density_function(x)
- INV_SQRT_2PI * Math.exp(-0.5 * (x**2))
+ @@inv_sqrt_2pi * Math.exp(-0.5 * (x**2))
end
alias_method :pdf, :probability_density_function
# The inverse of the cummulative Gaussian distribution function
def quantile_function(x)
- -SQRT2 * Math.erfc(2.0 * x)
+ -@@sqrt2 * Math.erfc(2.0 * x)
end
alias_method :inv_cdf, :quantile_function
@@ -79,7 +81,7 @@ def quantile_function(x)
def value_at(x)
exp = -(x - @mean)**2.0 / (2.0 * @variance)
- (1.0/@deviation) * INV_SQRT_2PI * Math.exp(exp)
+ (1.0/@deviation) * @@inv_sqrt_2pi * Math.exp(exp)
end
# copy values from other distribution
View
2  lib/saulabs/trueskill/factor_graph.rb
@@ -5,7 +5,7 @@ class FactorGraph
attr_reader :teams, :beta, :beta_squared, :draw_probability, :epsilon, :layers
- # teams: 2 dimensional array of ratings
+ # @param teams (Array) 2 dimensional array of ratings
def initialize(teams, ranks, options = {})
@teams = teams
@ranks = ranks
View
7 spec/saulabs/trueskill_spec.rb
@@ -0,0 +1,7 @@
+require File.dirname(__FILE__) + '/../../spec_helper'
+
+describe Saulabs::TrueSkill do
+
+
+
+end
View
3  spec/spec.opts
@@ -1 +1,4 @@
--color
+--format specdoc
+--loadby mtime
+--reverse
View
112 trueskill.gemspec
@@ -1,99 +1,25 @@
-# Generated by jeweler
-# DO NOT EDIT THIS FILE DIRECTLY
-# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
# -*- encoding: utf-8 -*-
-Gem::Specification.new do |s|
- s.name = %q{trueskill}
- s.version = "0.1.0"
-
- s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
- s.authors = ["Lars Kuhnt"]
- s.date = %q{2010-04-21}
- s.description = %q{A ruby library for the trueskill rating system}
- s.email = %q{lars.kuhnt@gmail.com}
- s.extra_rdoc_files = [
- "LICENSE",
- "README.rdoc"
- ]
- s.files = [
- ".document",
- ".gitignore",
- "CHANGELOG",
- "LICENSE",
- "README.rdoc",
- "Rakefile",
- "VERSION",
- "lib/saulabs/gauss.rb",
- "lib/saulabs/gauss/distribution.rb",
- "lib/saulabs/gauss/truncated_correction.rb",
- "lib/saulabs/trueskill.rb",
- "lib/saulabs/trueskill/factor_graph.rb",
- "lib/saulabs/trueskill/factors/base.rb",
- "lib/saulabs/trueskill/factors/greater_than.rb",
- "lib/saulabs/trueskill/factors/likelihood.rb",
- "lib/saulabs/trueskill/factors/prior.rb",
- "lib/saulabs/trueskill/factors/weighted_sum.rb",
- "lib/saulabs/trueskill/factors/within.rb",
- "lib/saulabs/trueskill/layers/base.rb",
- "lib/saulabs/trueskill/layers/iterated_team_performances.rb",
- "lib/saulabs/trueskill/layers/performances_to_team_performances.rb",
- "lib/saulabs/trueskill/layers/prior_to_skills.rb",
- "lib/saulabs/trueskill/layers/skills_to_performances.rb",
- "lib/saulabs/trueskill/layers/team_difference_comparision.rb",
- "lib/saulabs/trueskill/layers/team_performance_differences.rb",
- "lib/saulabs/trueskill/rating.rb",
- "lib/saulabs/trueskill/schedules/base.rb",
- "lib/saulabs/trueskill/schedules/loop.rb",
- "lib/saulabs/trueskill/schedules/sequence.rb",
- "lib/saulabs/trueskill/schedules/step.rb",
- "spec/saulabs/gauss/distribution_spec.rb",
- "spec/saulabs/gauss/truncated_correction_spec.rb",
- "spec/saulabs/trueskill/factor_graph_spec.rb",
- "spec/saulabs/trueskill/factors/greater_than_spec.rb",
- "spec/saulabs/trueskill/factors/likelihood_spec.rb",
- "spec/saulabs/trueskill/factors/prior_spec.rb",
- "spec/saulabs/trueskill/factors/weighted_sum_spec.rb",
- "spec/saulabs/trueskill/factors/within_spec.rb",
- "spec/saulabs/trueskill/layers/prior_to_skills_spec.rb",
- "spec/saulabs/trueskill/schedules_spec.rb",
- "spec/spec.opts",
- "spec/spec_helper.rb",
- "trueskill.gemspec"
- ]
- s.homepage = %q{http://github.com/saulabs/trueskill}
- s.rdoc_options = ["--charset=UTF-8"]
- s.require_paths = ["lib"]
- s.rubygems_version = %q{1.3.6}
- s.summary = %q{A ruby library for the trueskill rating system}
- s.test_files = [
- "spec/saulabs/gauss/distribution_spec.rb",
- "spec/saulabs/gauss/truncated_correction_spec.rb",
- "spec/saulabs/trueskill/factor_graph_spec.rb",
- "spec/saulabs/trueskill/factors/greater_than_spec.rb",
- "spec/saulabs/trueskill/factors/likelihood_spec.rb",
- "spec/saulabs/trueskill/factors/prior_spec.rb",
- "spec/saulabs/trueskill/factors/weighted_sum_spec.rb",
- "spec/saulabs/trueskill/factors/within_spec.rb",
- "spec/saulabs/trueskill/layers/prior_to_skills_spec.rb",
- "spec/saulabs/trueskill/schedules_spec.rb",
- "spec/spec_helper.rb"
- ]
- if s.respond_to? :specification_version then
- current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
- s.specification_version = 3
+pkg_files = ['README.md','HISTORY.md','Rakefile','LICENSE' ]
+pkg_files += Dir['lib/**/*.rb']
+pkg_files += Dir['spec/**/*.rb']
- 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
+Gem::Specification.new do |s|
+ s.name = "trueskill"
+ s.version = "0.1.0"
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to?(:required_rubygems_version=)
+ s.authors = ["Lars Kuhnt"]
+ s.date = "2010-04-21"
+ s.description = "A ruby library for the trueskill rating system"
+ s.email = "lars@sauspiel.de"
+ s.files = pkg_files
+ s.homepage = "http://github.com/saulabs/trueskill"
+ s.has_rdoc = false
+ s.require_paths = ["lib"]
+ s.rubygems_version = "1.3.6"
+ s.summary = "A ruby library for the trueskill rating system"
+ s.description = ""
+ s.test_files = Dir['spec/**/*.{rb,yml,opts}']
end
Please sign in to comment.
Something went wrong with that request. Please try again.