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

gmcts

v0.1.2

Published

a General purpose Monte Carlo Tree Search (gMCTS)

Downloads

12

Readme

Downloads Auto Test Status license Gitter chat

gMCTS : Generic Monte Carlo Tree Search

This implementation of MCTS makes minimal assumptions about your simulation (or game), allowing you to focus on making your simulation and have gMCTS do the search.

Section Links : Construction , Execution , Examples , FAQ , Related , and References

Construction

gMCTS constructor

var gMCTS = require('gmcts')
var search = gMCTS.new()

Or as a one-liner

var search = require('gmcts').new()

Execution

search.simulate( simulation , C=2 )

Do one full simulation. This does everything needed under the covers needed for MCTS including the following steps : tree traversal, node expansion, rollout, and backprop. simulation is an object that is or wraps your simulation, and C is the exploration constant (default of 2). This returns the final output of the simulation.

var result = search.simulate( simulation )

search.best_action()

Retrive the action with the best score.

var best = search.best_action()

If there are two actions, 'left' and 'right' with scores 7 and 2 respectively, then...

console.log(action_n_score)
'left'

search.action_scores()

Retrieve the actions and scores.

var action_n_score = gMCTS.actions_and_scores()

If there are two actions, 'left' and 'right' with scores 7 and 2 respectively, then...

console.log(action_n_score)
[ {action:'left',score:7} , {action:'right',score:2} ]

Simulation

This is the specification of the simulation object that you pass to gMCTS

var simulation = {
    'get_actions' : // return a list of possible actions given the current state of the simulation
        function get_actions(),
    'do_action' : // preform the given action 
        function do_action(action),
    'is_terminal' : // return True if the simulation has 'ended'
        function is_terminal(),
    'value' : // the 'value' of the simulation at its current state.  Only called if the simulation is terminal
        function value()
}

get_actions

Must return a list of objects that can be an associative array key, like strings or integers.

do_action

Is called with an action collected from get_actions. This needs to update the internal state of the simulation.

is_terminal

Return true if the simulation has 'ended', false otherwise. The end condition is of your own choice, but ensure there is an end condition. If your simulation doesn't end after a fixed number of actions, consider adding a counter and returning true for is_terminal after 1,000 or so actions, to avoid an infinite loop.

value

The extimated value of the simulation

Example

If you have installed this as a npm dependency first change directory to node_modules/gmcts/.

Template

The template is a boiler plate of how to get started. It has a dummy simulation stubbed out. Execute it like so:

node examples/template.js 

Demo

A simulation that mimics John Levine's example in this video

node examples/demo.js 

There are 7 states, S0, S1, ... S6, with actions (A1, A2 ... A6) that go to exactly their corresponding state. The simulation starts in S0, which has actions A1 and A2 that go to S1 and S2 accordingly. The whole graph looks like this

S0 ---> action A1 ---> S1 ---> action A3 ---> S3
    |                      |
    |                      --> action A4 ---> S4 
    |
    |
    --> action A2 ---> S2 ---> action A5 ---> S5
                           |
                           --> action A6 ---> S6

The rollout values for the different states are as follows

S1 = 20
S2 = 10
S3 = 0
S5 = 14

After 4 simulations search.action_scores() will correctly return that action A1 has a value of 10 and A2 has a value of 12.

Related AI Projects

This is part of a set of related projects.

References