Skip to main content

Posts

Showing posts with the label machine learning

Teach a computer to play air hockey

I'm always looking for an excuse to build something fun... So it was only a matter of time before I got the idea to create a virtual air hockey game, and then train a neural network to play it. Check it out: https://github.com/wybiral/air-hockey The idea is pretty simple. First setup some basic physics for controlling the puck and paddles. Instead of writing a new physics engine I decided to go with matter.js (it's easy to use and supports everything I needed here). The neural network is a basic multilayer perceptron handled using synaptic.js (another great library that works well here). It's trained to recreate the actions of a human player given the position of the objects as inputs. I've also been using this mini-project to track my development process using releases so if you're curious how this was put together you can look at each step along the way here: https://github.com/wybiral/air-hockey/releases The next step will probably be to add export/impo...

NumericJS Logistic Regression Classifier

The other day I post ed about numericjs and provided a simple PCA implementation using it. Today I rewrote my logistic regression classifer using numericjs. Below is the commented sourcecode and demo in jsFiddle. For the demo, you click on the large square (in the "Result" panel) to add a point. The dropdown box labeled "group" allows you to select the color of point to add. You can change the learning rate (alpha) and the regularization parameter (lambda) to see how it changes the classification. In case you're using a feed reader and can't see the box below, click here . ​

Numeric Javascript

I just recently found this javascript library. So far it's looking pretty good. I've always wanted some sort of Javascript equivalent to NumPy and while this isn't anywhere near that extreme, it does offer some pretty handy features . Here's a jsFiddle I put together to show it performing a simple implementation of PCA (Principle Component Analysis) on a fictional dataset. The first component should have a slope of approximately 0.357 Here's a quick snippet, the actual PCA function using numericjs... function  pca ( X )  {      /*          Return matrix of all principle components as column vectors      */              var  m  =  X . length ;      var  sigma  =  numeric . div ( numeric . dot ( numeric . transpose ( X ) ,  X ) ,  m ) ;      return  numeric . svd ( sigma ) . U ; }