philihp / openskill.js

A faster, open-license alternative to Microsoft TrueSkill
https://www.npmjs.com/package/openskill
MIT License
203 stars 19 forks source link

How would you create custom models using typescript #679

Open thinkong opened 1 month ago

thinkong commented 1 month ago

Hi,

I am trying to implement some kind of custom model that would work with my game.

I am currently using typescript and was trying to import 'Model' but it seems that 'types' is not actually exported.

Is there a recommended way to create a custom model?

Also.. I can't find how I can use the other models via typescript. It seems the models folder is not actually exported to to use.

EklipZgit commented 1 month ago

@philihp I'm running into the same thing. I'd like to test out the other models, image

but they're not exported.

The readme incorrectly shows importing a private path inside the module, which we obviously can't do: image

I'm pretty new to node.js so correct me if I'm missing something, but this seems like a miss, and all of those models SHOULD be exported in the main index.js?

Thanks

@vivekjoshy I don't think this is a question, this is a bug.

EDIT

OK, seems like

const {bradleyTerryFull} = require('openskill');
{model: bradleyTerryFull}

does work, despite this not working


const os = require('openskill');

{model: os.bradleyTerryFull}

not working, which is odd when os.rate and os.rating work.

The docs need to be updated to give a proper example rather than importing a private folder, and the names of all the other model classes should be listed in the documentation as nothing autocompletes for this so we're just left guessing or have to go digging through the github source still.

philihp commented 1 month ago

@thinkong your issue should be resolved with https://github.com/philihp/openskill.js/pull/690

@EklipZgit i think your issue is different, but it should be solved by https://github.com/philihp/openskill.js/pull/687, thank you @eddyfidel!

i'll push out a new version in a moment.

philihp commented 1 month ago

Should be fixed in 4.1.0, please let me know if anything is wonky!

EklipZgit commented 1 month ago

@philihp so the actual models you can pick from aren't exported still (plackettLuce for example). I still have to do

const {bradleyTerryFull, rate} = require('openskill');
rate(..., {model: bradleyTerryFull});

and that type is still unknown, even though this works.

It would also be great to have examples of how to pass custom parameters to the models (for example the python impl https://openskill.me/en/stable/api/openskill/models/weng_lin/plackett_luce/index.html#openskill.models.weng_lin.plackett_luce.PlackettLuceRating has all these parameters mu=25.0, sigma=25.0 / 3.0, beta=25.0 / 6.0, kappa=0.0001, gamma=_gamma, tau=25.0 / 300.0, limit_sigma=False, balance=False as does your JS version, but even the python docs don't document what these do). I can find their documentation in the white paper, I assume, but I have NO IDEA how to customize any of these parameters when calling openskill.rate() with this JS package.

How would I run with plackettLuce with limit_sigma, or tweaked beta, etc?


EDIT, actually,

const {bradleyTerryFull, rate} = require('openskill');
rate(..., {model: bradleyTerryFull});

worked before but no longer works after the update (bradleyTerryFull is now undefined). I can't even select one of the other models now, as without them exported and the change you made to the way you were pulling in types, I guess this now prevents those from being pulled out of the module at all. So, I think you need to explicitly export those, too.

eddyfidel commented 4 weeks ago

@EklipZgit it seems you're facing an issue with importing models and passing custom parameters in the latest version of the openskill package. Here's how you can resolve these issues:

  1. Importing Models: In the newer version, models are not exported by default. You can import them like this:

    import {
     bradleyTerryFull,
     bradleyTerryPart,
     plackettLuce,
     thurstoneMostellerFull,
     thurstoneMostellerPart,
    } from "openskill/models";
  2. Passing Custom Parameters: You can pass custom parameters like limitSigma or a tweaked beta when calling the rate function like this:

    const [newTeam1Ratings, newTeam2Ratings] = rate(
     [team1Ratings, team2Ratings],
     {
       model: plackettLuce,  // or any other model like bradleyTerryFull
       beta: 25.0 / 6.0,     // Tweaked beta
       limitSigma: true      // Example for limitSigma
     }
    );

This should allow you to customize the parameters you're interested in, such as limitSigma or beta.

philihp commented 2 weeks ago

Noted! I'll reopen this and see if I can do better on the next iteration, but if you'd like to submit a PR to add this doc I'd love to include it.