Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How would you create custom models using typescript #679

Open
thinkong opened this issue Sep 20, 2024 · 6 comments
Open

How would you create custom models using typescript #679

thinkong opened this issue Sep 20, 2024 · 6 comments
Labels
question Further information is requested

Comments

@thinkong
Copy link

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.

@vivekjoshy vivekjoshy added the question Further information is requested label Sep 20, 2024
@EklipZgit
Copy link

EklipZgit commented Oct 7, 2024

@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
Copy link
Owner

philihp commented Oct 11, 2024

@thinkong your issue should be resolved with #690

@EklipZgit i think your issue is different, but it should be solved by #687, thank you @eddyfidel!

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

@philihp
Copy link
Owner

philihp commented Oct 11, 2024

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

@philihp philihp closed this as completed Oct 11, 2024
@EklipZgit
Copy link

EklipZgit commented Oct 12, 2024

@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
Copy link
Contributor

@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
Copy link
Owner

philihp commented Oct 25, 2024

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.

@philihp philihp reopened this Oct 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

5 participants