Coder Social home page Coder Social logo

q-learning.js's Introduction

q-learning.js

Q-Learning Algorithm in JavaScript

It's based on this tutorial: A Painless Q-Learning Tutorial.

This belongs to a set of AI algorithms in JS to be used by assemblino.js.

This algorithm is suitable to search, path finding, control, as it retains in memory an heuristics to achieve the goal, from any reachable discrete state.

Demo

Example 1: basic

Example 2: game agent

Usage Example

Learning

The argument to the constructor is the gamma parameter. Default 0.5

var learner = new QLearner(0.8);

Add transitions like this:

 learner.add(fromState, toState, reward, actionName);

In this last expression, if fromState or toState do not exist they are added automatically. If no reward is know pass undefined, if actionName is not important leave it undefined.

If no reward is known and actionName is not important:

learner.add(fromState, toState);

Reward is known and actionName is not important:

learner.add(fromState, toState, reward);

Reward is not known and actionName is important

learner.add(fromState, toState, undefined, actionName);

States and actions set, then make it learn. The argument is the number of iterations.

learner.learn(1000);

Running

To use what the learner knows. Set an initial state

learner.setState('s0');

then call to choose the best action and automatically apply it.

learner.runOnce();

and get the next state with

var cur = learner.getState();

or get the best action:

var ba = learner.bestAction();

or run it until it stays in the same state, or solution.

var current = null;
while (current!==learner.getState()){
    current = learner.getState();
    learner.runOnce();
}

q-learning.js's People

Contributors

nrox avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.