Live data from Hacker News

Show HN: Advanced Mathematics Library for Node.js and JavaScript

github.com

31–40 of 49 posts

Re: Show HN: Advanced Mathematics Library for Node.js and JavaScript

#32

Earlier quoted context omitted.

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.

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

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

Re: Show HN: Advanced Mathematics Library for Node.js and JavaScript

#33
post #16
post #14

Earlier quoted context omitted.

I should point out this is normal for floating-point numbers. Erlang and Ruby do the exact same thing: $ erl 1> 0.2 + 0.1. 0.30000000000000004 2> 0.94 - 0.01. 0.9299999999999999 3> 0.3 + 0.544. 0.8440000000000001 $ irb 1.9.2-p290 :001 > 0.2 + 0.1 => 0.30000000000000004 1.9.2-p290 :002 > 0.94 - 0.01 => 0.9299999999999999 1.9.2-p290 :003 > 0.3 + 0.544 => 0.8440000000000001 1.9.2-p290 :004 >

That's why you don't compare floating point numbers with the = operator. You use something like: fabs( a-b ) where epsilon is usually defined by the language as a very small quantity (example values in C are 1E-8 for a float, 1E-15 for double), or you can just use a hard coded value appropriate to the values you are comparing.

yes, we're currently doing that. look here: https://github.com/sjkaliski/numbers.js/blob/master/lib/numb...

Re: Show HN: Advanced Mathematics Library for Node.js and JavaScript

#34
post #25
post #18

Earlier quoted context omitted.

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

For statistics I'd be interested in seeing quantiles, regressions, and coefficient of determination. I intend to contribute what I can in those areas.

That'd be great

Re: Show HN: Advanced Mathematics Library for Node.js and JavaScript

#36
post #31

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.

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.

Re: Show HN: Advanced Mathematics Library for Node.js and JavaScript

#37
post #31

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.

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.

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

Re: Show HN: Advanced Mathematics Library for Node.js and JavaScript

#38
post #16
post #14

Earlier quoted context omitted.

I should point out this is normal for floating-point numbers. Erlang and Ruby do the exact same thing: $ erl 1> 0.2 + 0.1. 0.30000000000000004 2> 0.94 - 0.01. 0.9299999999999999 3> 0.3 + 0.544. 0.8440000000000001 $ irb 1.9.2-p290 :001 > 0.2 + 0.1 => 0.30000000000000004 1.9.2-p290 :002 > 0.94 - 0.01 => 0.9299999999999999 1.9.2-p290 :003 > 0.3 + 0.544 => 0.8440000000000001 1.9.2-p290 :004 >

That's why you don't compare floating point numbers with the = operator. You use something like: fabs( a-b ) where epsilon is usually defined by the language as a very small quantity (example values in C are 1E-8 for a float, 1E-15 for double), or you can just use a hard coded value appropriate to the values you are comparing.

That "where epsilon is usually defined by the language as a very small quantity" is BAD advice. double.epsilon and float.epsilon (std::numeric_limits::epsilon in C++) are "machine epsilons": numbers equal to the difference between 1 and the next representable value. In other words: 1 and 1+epsilon can be represented exactly, but there are no representable numbers between the two. The distance between representable numbers never goes down when you move away from zero. That means, that, for x,y >= 1 there is no difference between

       x == y

and

     |x - y| As I said, things get worse if your comparison is between larger numbers. For example, the smallest double larger than 1024 is 1024+1024 epsilon (IIRC; I am too lazy to double-check that now)

The epsilon used in numerical algorithms is an entirely different beast than the machine epsilon.

That epsilon you should pick as follows: make a numerical analysis of your problem, choose a good algorithm, and determine the desired accuracy of your answer. From those, derive a (relative, absolute, whatever) error you can live with.

Alternatively, pick a reasonable value from thin air and hope for the best/test your code to get confidence that it will return good values (do not do this when programming flight control software, pacemakers, etc). Oftentimes, it is not really hard to produce a reasonable value. For example, an iterative procedure that produces pixel coordinate likely can stop once the absolute error is less than .01 pixel, and possibly a lot earlier.

Finally, in the ideal world, you will use a good way to test for your accuracy, for example one from boost test: http://www.boost.org/doc/libs/1_52_0/libs/test/doc/html/utf/... (contains useful links to more in-depth discussions)

And, by the way, 1E-8 is lower than the machine epsilon for floats, and 1E-15 larger than that for doubles. http://en.wikipedia.org/wiki/Machine_epsilon gives them as 1.2E-7, respectively 2.2E-16.

Re: Show HN: Advanced Mathematics Library for Node.js and JavaScript

#39

Earlier quoted context omitted.

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

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

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

Re: Show HN: Advanced Mathematics Library for Node.js and JavaScript

#40
post #5

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!

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

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.

Post reply on HN