
Brain.js - hliyan
https://github.com/BrainJS/brain.js
======
hombre_fatal
A 19-part interactive neural network course that uses brain.js was posted to
HN last week:
[https://scrimba.com/g/gneuralnetworks](https://scrimba.com/g/gneuralnetworks)

~~~
Etheryte
Even as someone who has only superficial knowledge of the topic, that course
was very underwhelming.

~~~
sickcodebruh
As someone with absolutely no knowledge of the topic, I found that course to
be very digestible and pleasant.

~~~
hombre_fatal
Same. It was so accessible (voiceover in an online code editor) that I just
did it instead of bookmarking it for a day that never arrives.

~~~
axel180
That is really cool to hear!

------
shados
The sample app (the color contrast stuff) hurt my feelings a bit. I used to
work on an app that needed to do something similar and I ended up fighting
with the YIQ formula (it really doesn't work for a lot of cases). Playing with
the sample just a bit and I ended up replicating what had taken me weeks to do
back in the days...

~~~
axel180
This was good, correct? I'd love to hear what your use case was, like which
colors didn't work, etc.

~~~
shados
Haha, sorry if it was unclear, my tone was in jest.

Yeah, basically what Im trying to say is that this is awesome. It was several
years ago so I don't have my old code anymore (different job), but it was in
the printing industry, where we wanted to warn customers that their choices of
color were...dubious.

However, it's extremely subjective. An example is certain shades of
red/orange. The formula might tell you that using white text is a bad idea,
but they're really the same to read, and white looks better.

One thing I'd have to play around more than my free time allows, but I had to
deal with back then, was backgrounds with multiple color. Where it got really
tricky is when the text overlaps multiple colors, you have to decide if you're
seeing enough of the text that one foreground color is ok, or if it's too much
and you have to say "no". It was incredibly tricky to do, especially with
things like antialiasing involved. Training a model with that data probably
would give much better results than my tweaked formulas of old.

------
danielmorozoff
Can someone comment on performance -- speed vs training vs other frameworks.
Most of our work is in TF/Pytorch and I have not used any JS implementations
would love to hear some peoples insights into how it compares.

~~~
vorticalbox
I just did the maths one.

1 to 10 addition, 2000 iterations took about 5 mins on repl.it

It got the maths wrong so will need more training

------
portmanteaufu
From the README:

    
    
        brain.js is a library of Neural Networks written in JavaScript.

------
berdon
Saw this and thought, "Huh, I wonder if harthur is back at it", but nope. Nice
to see someone picked it up though!

~~~
franciscop
I followed the progress back then and felt very bad for both, that such an
awesome library was going down and the bad situation she found herself into.
Hope she is doing well! And happy to see brain being reborn.

~~~
hliyan
What happened to the author? I'm not aware of the history...

~~~
axel180
What happened was essentially bullies. I think it is apparent now that the
library and, more importantly, the idea of a data first neural network
architecture in javascript isn't going away.

~~~
spiffytech
What do you mean by "data-first"? What other forms could a JS NN architecture
take?

~~~
axel180
A lot of neural networks start by first constructing the neural network
structure, and eventually getting around to running the data through it. Where
in brain.js, line 2 in most examples (just after instantiation) is train with
data.

------
revskill
JS nails it again even with Neuron Networks. What saddens me in latest years
is the direction of library development, where people put more focus on Python
instead of Javascript. Javascript is universal, you can reuse your code in
both browser, native apps and server. Python ? I don't think so. My dream of
"getting the job done" is a universal language, universal ecosystem/libraries.
We need universal developers, no need for full-stack developers anymore.

~~~
noobiemcfoob
I am a full stack developer using python for everything but what's in my HTML
pages. And I'd replace that javascript with python as soon as it would be
viable. Javascript is fine for what it is, but the idea of it as a universal
language is gross.

------
quu
Great. From this source code, I can find well that the speed is optimized even
simple for-loop levels in JavaScript.

------
boltzmannbrain
y tho? [https://js.tensorflow.org/](https://js.tensorflow.org/)

~~~
hliyan
I'm aware of tensorflow.js, but what really struck me with brain.js was this
snippet from the very beginning of the readme file:

how to approximate the XOR function using brain.js

    
    
      const net = new brain.NeuralNetwork(config);
    
      net.train([{input: [0, 0], output: [0]},
               {input: [0, 1], output: [1]},
               {input: [1, 0], output: [1]},
               {input: [1, 1], output: [0]}]);
    
      const output = net.run([1, 0]);  // [0.987]
    
    

This is how you win over newcomers -- quick, accessible demonstrations of the
product/library's capabilities. A sample is worth a thousand words. Tensorflow
may have a lot of great, detailed examples, but its documentation fails in
this regard.

~~~
hombre_fatal
Great point.

This is why I used p2.js for javascript game physics over franken-emscripten
Box2d ports.

The readme and source code are extremely accessible
([https://github.com/schteppe/p2.js#sample-
code](https://github.com/schteppe/p2.js#sample-code)).

When I was trying to optimize my collision detection, I stepped in to p2.js
source to read narrowphase vs broadphase implementations. Last I used Box2d, I
was reading c++ pdf documentation.

~~~
axel180
Really cool example!

