
Show HN: Advanced Mathematics Library for Node.js and JavaScript - sjkaliski
https://github.com/sjkaliski/numbers.js
======
angersock
First of all, good work!

A couple of observations:

1\. You should probably go ahead and implement at least LU decomposition, QR
factorization, and maybe some eigenvalue/eigenvector stuff if you want to
claim "advanced".

2\. You should use the recursive definition of the determinant in the >3x3
matrix case.

3\. You should consider adding some vector methods of the form: ax+by (for
scalar a & b, and vector x & y). This can be useful for doing linear
interpolation and whatnot.

4\. You should add cross products/outer products for vectors.

5\. You should have a mechanism for generating a Gaussian or normal
distribution, or at least supply some standard mappings from your (presumably
uniform) random function to something more useful (Gaussian, Possoin, Weibull,
whatever).

6\. An FFT would be nice. :)

7\. Quaternions would also be handy for graphics folks, or motion folks.

8\. Complex number support would be cool.

9\. Support for optimization, like integer programming, linear programming, or
even least-squares or whatever would be nice.

~

Again, great work--I look forward to seeing how this project evolves!

~~~
sjkaliski
This is a fantastic list. There are a few people who've expressed interest in
working on eigenvalue work. I'll definitely be adding a couple of these in, in
the next few days. I'll keep you posted.

~~~
micro_cam
Sparse and dense matrix math and eigensolvers would be really nice. Especially
solvers that let you efficiently get the eigenvectors associated with the
smallest eigenvalues as this comes up in graph and image partitioning.

------
Xcelerate
This is pretty cool. I've been using CoffeeScript to post-process MD
simulation results because it's such an easy language to get things done in.
Tools like this will make it even easier.

Although, could someone clarify for me the floating point issues mentioned by
Steve? I wasn't aware there were issues...

~~~
dbaupp
[https://en.wikipedia.org/wiki/Floating_point#Accuracy_proble...](https://en.wikipedia.org/wiki/Floating_point#Accuracy_problems)

It is the same as trying to store 1/3 = 0.333... as a finite decimal.
Basically, a floating point number only has a finite space to put the
component after the decimal point, so it gets truncated and made inaccurate,
just like truncating 1/3 to 0.3333 will mean that calculations become wrong:
3*0.3333 = 0.9999 ≠ 1.

~~~
Xcelerate
Ah, ok. Thank you. This isn't a problem for me then. It appears to be just
typical floating-point math. I was thinking perhaps JavaScript did something
else weird that I didn't know about.

------
Zikes
Any interest in adding various statistical regression functions? I had to
write some for JavaScript recently, one of which can be found at
[http://stackoverflow.com/questions/13590922/how-can-i-
use-d3...](http://stackoverflow.com/questions/13590922/how-can-i-use-d3-js-to-
create-a-trend-exponential-regression-line)

Seems to work for me, but I haven't had it reviewed by a real mathematician
yet.

~~~
sjkaliski
Most certainly. Would love to push the statistics further. Working on
integrating some econometrics tools in the next version.

------
BasDirks
What audience do you have in mind calling this advanced? (Not criticising your
library, it looks useful).

~~~
dbyrd
Just out of curiosity, what features would you want to add to make it more
advanced? I'll make tickets for them.

~~~
Zikes
For statistics I'd be interested in seeing quantiles, regressions, and
coefficient of determination.

I intend to contribute what I can in those areas.

~~~
sjkaliski
That'd be great

------
tqs
I've used <http://www.numericjs.com/> to handle basic vector/matrix arithmetic
and for numerically solving minimization problems to create constraint-based
UIs.

Can you give an overview of how your library is different? Is it just a
different set of math tools or is the architecture somehow different? Thanks!

~~~
fourstar
Constraint-based UIs are not something I'm familiar with, but sound
interesting. Can you expand on that for me please?

~~~
tqs
<http://recursivedrawing.com/>

When you drag and drop the shapes, the drawing changes in non-trivial ways.
For example, try dragging a shape deep down in the recursion hierarchy.

In a normal drag-and-drop application, it's fairly easy to compute how to,
say, adjust the left/top of a div in response to the mouse movement events.
However, with Recursive Drawing, I knew that there were certain properties I'd
have to adjust during a drag operation, but because of all the nested
transformations, it was tricky to figure out the math of how exactly to adjust
them.

So instead, I set up a constraint problem. I know that the exact spot I've
mousedown'ed on needs to stay under my mouse no matter what. That's the
fundamental constraint of the drag-and-drop gesture. Then I set the properties
that I knew I could change (e.g. positions or scaling/rotation of a specific
shape) and set them as free variables in an energy minimization function. I
solved the problem numerically using numeric.js's uncmin (unconstrained
minimization, an algorithm originally written in FORTRAN, I believe).

I probably could have figured out how to do this without numerical methods,
but this approach was a god-send when rapid prototyping the interactions.

Another good use of constraint systems for UIs is Ivan Sutherland's Sketchpad.
His paper on it is long but really worth at least skimming through if you're
interested in developing next-generation UIs!
<http://www.cl.cam.ac.uk/techreports/UCAM-CL-TR-574.pdf>

I also really like Rebecca Fiebrink's Wekinator, which is a framework for
making musical instruments from arbitrary inputs. The approach is similar in
that she uses numerical methods to solve for the constraints (the training
data). <http://wekinator.cs.princeton.edu/>

I think there's a lot of potential in constraint-based UIs and for me it's the
most compelling reason to have good numerical libraries in javascript.

------
napoleond
This is _awesome_! I started thinking about doing something similar a few
months ago, but the project I needed it for kind of fell through and I moved
on. Anyway, a few thoughts I had at the time:

    
    
      -should support FFT/convolution
      -could tie into http://sylvester.jcoglan.com/ for
       vector/matrix stuff (excellent library!)
        -I emailed jcoglan about the possibility of adding
         complex number support to Sylvester, he encouraged me
         to try but thought it might introduce too much function
         call overhead (caching function results might help a
         bit?)
      -I didn't get to look at it too closely, but
       https://github.com/jtobey/javascript-bignum looks
       interesting, as does https://github.com/pr1001/MathPlus
      -polynomial fit (least squares regression) and
       interpolation stuff is in high demand
      -it should be super easy to integrate output with d3.js
       (like the equivalent of MATLAB plot function)
    

Honestly, I doubt I would have been able to pull it off, but I intend to
contribute to this project as much as I can.

EDIT: Formatting

~~~
sjkaliski
Great, it'd be sweet to have you involved! FFT, polynomial fit, and d3.js
would be huge steps. For me, the most important thing is ensuring that all
changes are application driven. Building a library that's designed to be used
is top priority.

------
philip1209
Great. I'm studying for my operations research exam, and I've wanted to
"study" by implementing some of the algorithms we did by hand through code.

Is there interest in some more advanced matrix algebra functions -
specifically Gaussian reduction, simplex, sensitivity analysis, and maybe some
transport/network problems and integer programming?

~~~
sjkaliski
My primary focus from here on out is statistics and matrix algebra focused on
powering analytics. So yes, some of those functions would be of interest to
me.

~~~
philip1209
Ok. I'll start on some of it tonight.

~~~
sjkaliski
great! ping me at sjkaliski@gmail.com if need be

~~~
philip1209
Will do. I forked on Github from philipithomas. I'm mail@philipithomas.com.

------
saym
Along the same line, (heh line) my friend made a linear algebra library last
year.

I present to you "Clique: A Javascript Linear Algebra Library with
Applications to Spectral Analysis"

<https://github.com/Forns/clique>

------
JDDunn9
What's the use-case-scenario for this? Seems like if you had complex
calculations you needed to perform, you would do it on a server side language
like Python.

~~~
mistercow
1\. JavaScript is a server side language too.

2\. Canvas and WebGL pave the way for lots of cool graphical JS applications.
Linear algebra and calculus are particularly useful for graphics.

~~~
sjkaliski
Yeah, I really tried to keep elements of the browser in mind. Games and
graphics definitely can benefit from algebra and calculus.

------
whockey
Wow - looks awesome! Congrats Steve et all.

~~~
zachperret
w00t! Go Steve

------
misiti3780
Nice!

