Skip to main content

Posts

Visualizing popular machine learning algorithms

I put together an experiment to compare different classification machine learning algorithms in real time to gain insight into which ones handle certain situations better than others: http://jsfiddle.net/wybiral/3bdkp5c0/embedded/result/ Currently the algorithms covered are: Linear regression (with cubic expansion on feature space) Logistic regression (with cubic expansion on feature space) Neural network (sigmoidal feed forward back propagation) K nearest neighbor (where k=5) Naive bayes Support vector machine (gauss kernel) Discriminate analysis The bottom dropdown has a few simple datasets but you can also click on the classification space to add new blue/orange points. As the algorithm trains you'll see the background color morph to display the classification boundary. Change the algorithm (via the dropdown on the top) and see how it impacts the classification boundary.

Halloween Strategy Game

As a fun little side project to kick off the season I decided to write a Halloween themed strategy game (in the style of the tower defense genre). Appropriate for children (there is no gore or violence) although it may be a bit challenging for young ones. Click Here  to play! As the narrator explains... Monsters appear every Halloween night and take all of your candy. It's up to you to build spooky decorations to scare them off as they get progressively more difficult to frighten. It was written from scratch in Javascript leveraging HTML Canvas , jQuery , and UnderscroreJS . I took most of the images from google image search. If you own any of them and would either like credit or want them removed, contact me immediately! Happy Halloween!

Web Guitar

I finally got around to porting some of my old code to use HTML5's  Web Audio API . It's a guitar tab editor that uses web audio to playback your tabs. The sound is synthesized using the code in the textarea below the editor. By default, the code is a basic string pluck synthesis , but you can change it to produce whatever waveforms you'd like. It's primitive. It hasn't been tested on anything other than chrome. The UI has no documentation. It's got some growing up to do, but it's still fun to play around with. Here it is:  Web Guitar Demo Load the example "Moonlight sonata" and press play. Hint: clicking above the strings in the editor will toggle between 4, 8, 16, 1, 2 which is the reciprocal of the duration of the note. Also, after clicking on a string, you can navigate the editor using the arrow keys.

Quantum Algorithms

I've added a few examples to my quantum circuit editor / simulator . The most interesting of which being Grover's Algorithm  for unsorted search. Go ahead and  try it out . Hit "Enter" to evaluate the circuit and get a table of probable outcomes. The gate F7 makes the fifth qubit in the "|1>" state if the first four qubits are in the state "|0111>" (seven). The circuit is able to determine that "|0111>" is the magic number with over 96% accuracy and only three calls to F7. I also included an F5 gate. Go ahead and right click those F7 gates away, select the F5 gate, and then drag it into the three places the F7 was. Now it will find "|0101>". You can save the entire circuit by pressing Ctrl+S. Double click on the GROV, F7, and F5 gates to see what their circuits look like (or to edit them to create your own versions). Some of the other examples include: Toffoli gate (you can make one simply by dragging...

Quantum Circuit Simulator

All I wanted for Christmas was a quantum circuit simulator. So I wrote one in Javascript using NumericJS . Check it out: http://www.davyw.com/quantum For a good "Hello world" circuit, here's the diagram for a Bell State ... Try evaluating it yourself and see that |00> or |11> are the only possible outcomes. You can even compile your own circuits into gates to use in other circuits. Construct a circuit that transforms a single qubit into |0> with 75% probability and |1> with 25% probability, such as: Then compile that into gate "F" and use it to create a superposition of |00> with 75% prob and |11> with 25% prob, like this: Let me know if you find any use out of this. And definitely let me know if you find any bugs.

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 ; }