Giter Site home page Giter Site logo

tentone / cart-pendulum Goto Github PK

View Code? Open in Web Editor NEW
0.0 2.0 0.0 7.46 MB

Small cart w/ inverted pendulum game for basic machine learning concept experiments.

Home Page: https://tentone.github.io/cart-pendulum/

License: MIT License

JavaScript 2.26% CoffeeScript 97.74%
cart-pendulum machine-learning artificial-intelligence linear-regression linear-models

cart-pendulum's Introduction

Cart Pendulum

  • Small game to demonstrate basic machine learning concepts using a simple linear regression model.

  • The objective of the game is to balance the stick in the cart while keeping the cart inside of the lines as long as possible.

  • The game ends if the stick falls off the cart or if the cart hits the side walls. To control the cart the player can press left or right to accelerate the cart.

  • Might seem a fairly simple task but takes a while even for a human player to master it. Try it out here for yourself. Or just watch me trying to play it bellow.

  • While the game is running a score is calculated based on the amount of time that the player was able to hold the pendulum without hitting the wall.

Linear Model

  • A live demo of the linear model is available with two training approaches for the linear model. Training parameters can be changed in the GUI.
  • The model has three inputs: the position and velocity of the cart and the angle of pendulum.
  • The model has two outputs: left button pressed and right button pressed.
  • For each input parameter a linear weight (m) and offset (b) are be applied.
  • The final decision is the sum of all weights that is then compared with a threshold to decide the action.

Training Linear Model

  • The challenge with training is to determine the ideal m andb for each input variable and the e value.
  • In other words training will consist in experimenting different values until we reach a value that is successful.
  • A simple approach to train the model is simply to randomly test for values until a good set of parameters appears that yields a good score.
  • As we can see for this case after 490K combinations we obtained one that yields perfect results!
  • Took a while but means that simple linear model can handle the task.

  • This training approach of course would not be usable for any real complex environment.
  • To ensure convergence of the training process a iterative/genetic approach should be used.

  • We start with a random base model, test variations of the model and select the one that improved results, repeat until we get good results.

  • With iterative training we can get near perfect results few epochs (~5 in average) wich is a lot faster than random testing.

  • During this process we should also look out for local maximum. This happens when we get stuck with values that cannot be improved further.

Neural-Network

  • Now that we got the basics right lets try and train the system using a more complex neural model with brain.js.
  • Try the NN version here, you will need data for training that can be generated by playing the game manually or obtained from the git repo.
  • Our inputs will be the same position, velocity and angle and the outputs will be right and left.
  • Contrary to the linear model where we test combinations of parameters to find the best configuration.
  • For the neural-network we need to provide datasets of game variables and decisions for training.
  • These datasets can be recorded from sessions from human players or even for example from the linear model.
[
	{"input": [0.4562460470209,-0.0022812302351045,0.456246047020],
	 "output": [0.0,1.0]}, ...
]
  • After training a visualization of the network can be generated where we can observe the inputs their weights and the outputs produced.

License

  • This project is distributed under MIT license and can be used for commercial applications.
  • License is available on the Github page of the project.

cart-pendulum's People

Contributors

tentone avatar

Watchers

 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.