npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

wenglin

v1.0.2

Published

Weng-Lin skill algorithm implementation

Downloads

3

Readme

Javascript implementation of Weng-Lin Rating, using Bradley Terry model as described at https://jmlr.csail.mit.edu/papers/volume12/weng11a/weng11a.pdf

Installation

Add wenglin to your list of dependencies in package.json:

npm install --save wenglin  

Importing wenglin module

Use CommonJS's require

const {    
  Rater,    
  Team,    
  Player 
} = require('wenglin');  

Quick example

const rater = Rater();
const WINNER = 1; 
const LOSER = 0; 

const team_1 = new Team({players: [new Player()], score: WINNER});
const team_2 = new Team({players: [new Player()], score: LOSER});

const result = rater(team_1, team_2)

Modules

Player skill is represented by two parameters: mu and sigma
Mu is the actual skill of the player and sigma is its standard deviation.
Default values for mu and sigma are 25. and 25 / 3.

Rater is the main rating processor. It is initialized with BETA (sigma / 2) parameter by default so it can me omitted.

const rater = new Rater();
const rater = new Rater(BETA);

Once rater is initialized, it can be invoked with all teams as separated arguments:

rater(team_1, team_2, team_3, ...);

Team: Team represents a set of players, each with its skill data and a score. Score scale does not matter. It is compared between teams pairs and considered win, draw or loss.

const team_1 = new Team({players: [player_1, player_2, ...], score: 0});
const team_1 = new Team({players: [player_x, player_y, ...], score: 1});

Player: This class stores a player's skill, mu and sigma. Player class is initialized with default mu and sigma but can also be overwritten.

> const player = new Player();
> const player = new Player({mu: 25, sigma: 25 / 3,});

Player skill can be obtained calling its skill method

> const player = new Player({mu: 25, sigma: 25 / 3, ref: my_db_player});
> player.skill()
{ mu: 25, sigma_sq: 69.44444444444446, sigma: 8.333333333333334 }

Player can also store a reference to an object of your choice to keep track of players in your implementation and ease its usage after Rater results are returned.

> const my_db_player = {id: 'Player id'};
> const player = new Player({mu: 25, sigma: 25 / 3, ref: my_db_player});
> player.ref();
{ id: 'Player id' } 

Full usage example

Following example represents a match between tree teams of two players each. Team 1 loses the match and teams 2 and 3 win with a draw.

> const {    
  Rater,    
  Team,    
  Player
} = require('wenglin');  
> const team_1 = new Team({players: [new Player(), new Player()], score: 60});  
> const team_2 = new Team({players: [new Player(), new Player()], score: 80});  
> const team_3 = new Team({players: [new Player(), new Player()], score: 80});  
> const BETA = 4.16;
> Rater(BETA)(team_1, team_2, team_3);  

[  
  Player {  _mu: 21.071628993408070, _sigma: 8.018753738744802, _sigma_sq: 64.30041152263375, _ref: undefined},  
  Player {  _mu: 21.071628993408070, _sigma: 8.018753738744802, _sigma_sq: 64.30041152263375, _ref: undefined},  
  Player {  _mu: 26.964185503295965, _sigma: 8.018753738744802, _sigma_sq: 64.30041152263375, _ref: undefined},  
  Player {  _mu: 26.964185503295965, _sigma: 8.018753738744802, _sigma_sq: 64.30041152263375, _ref: undefined},  
  Player {  _mu: 26.964185503295965, _sigma: 8.018753738744802, _sigma_sq: 64.30041152263375, _ref: undefined},  
  Player {  _mu: 26.964185503295965, _sigma: 8.018753738744802, _sigma_sq: 64.30041152263375, _ref: undefined}  
]

Results

Rater output is an array of Player objects with the new rating and in the same input order. Original players are kept intact. After results are returned by rater, you can iterate over result items to obtain each reference and data at your side.

> const BETA = 4;
> const result = Rater(BETA)(team_1, team_2, ...);  
> player_1_skill = result.map(it => it.skill())  
[  
 {mu: 23.035814496704035, sigma: 8.17755635771097, sigma_sq: 66.8724279835391},  
 {mu: 23.035814496704035, sigma: 8.17755635771097, sigma_sq: 66.8724279835391},  
 {mu: 26.964185503295965, sigma: 8.17755635771097, sigma_sq: 66.8724279835391},  
 {mu: 26.964185503295965, sigma: 8.17755635771097, sigma_sq: 66.8724279835391}  
]