Thursday, March 31, 2011

jStat is alive

In April 2010 I began working on a JavaScript statistical library called jStat. After hammering out a bunch of basic functionality I didn't pay much attention to it. Then a few weeks ago across the wire comes a new JavaScript statistical library called, well, jStat. It even had its own website. The author of that library, Matthew Williams, had done a lot more of the graphical work and created some sick demos on the webpage. So I dropped him a line and asked if we could merge projects. Lo and behold, he was rock awesome and so we started up a repo at GitHub.

It's been wicked busy the last week as we've been hammering out the details of the framework. Right now it's in the process of being completely revamped, and we invite everyone who wants to come check it out.

The API is sickly cool. Granted we took one from the jQuery book of chainability, but that doesn't make it any less sweet. For example, if you want to start working with a vector and calculate their sums, means, etc. you can chain all these together and pass callback functions to retrieve the results once they've been calculated. The passed callback function will be called as many times as objects have been passed to the jStat object. For example:

j$(vector).sum(function(val) {
    // do something with the sum
}).mean(function(val) {
    // and here's the mean
}).min(function(val) {
    // needed that min value
}).max(function(val) {
    // and why not grab the max value while we're at it
});

or if that's too complicated then you can just not pass a callback and it will return the results instead:

j$(vector).sum(); // returns the sum
j$(matrix).sum(); // returns an array of the sum of columns
j$(matrix).sum(true); // returns the sum of everything

and if that's still too complicated, or not performant enough, then you can tap into the underlying static methods:

j$.sum(array); // returns sum of array

The API is supposed to be as flexible as possible so it will be applicable in almost any scenario. The core file also doesn't have any dependencies so it will run server-side with something like Node.js. While we have set specific goals for ourselves, it's been left open enough to allow almost anyone to jump in with additional items.

It's been my life the last week, and hope someone else can have as much fun with it as I have.