Git Product home page Git Product logo

Comments (11)

robertleeplummerjr avatar robertleeplummerjr commented on May 4, 2024

How would you like it normalized?

from brain.js.

lodenrogue avatar lodenrogue commented on May 4, 2024

To fit the brain input/output. If my variables are greater than 1 I want it to normalize the data to be within a range of 0 to 1.

from brain.js.

robertleeplummerjr avatar robertleeplummerjr commented on May 4, 2024

I've been thinking about this for a bit, currently there is something like this built into brain.js. Consider the current README.md:

var net = new brain.NeuralNetwork();

net.train([{input: { r: 0.03, g: 0.7, b: 0.5 }, output: { black: 1 }},
           {input: { r: 0.16, g: 0.09, b: 0.2 }, output: { white: 1 }},
           {input: { r: 0.5, g: 0.5, b: 1.0 }, output: { white: 1 }}]);

var output = net.run({ r: 1, g: 0.4, b: 0 });  // { white: 0.99, black: 0.002 }

Here r, g, and b are normalized to the layers associated with them. This may not be exactly what you want, especially if you have thousands or more types. Another way you could do it, say if you had an object with the properties that you'd like to normalize:

var keys = mySuperObject.keys();
var normalizedValues = keys.map(function(key, i) {
  return i / keys.length;
});

from brain.js.

lodenrogue avatar lodenrogue commented on May 4, 2024

Lets say I have 10 mapped keys. If the value of one of those keys is 30 and I'm dividing that by 10 then the returned value is 3. That's not between 0 and 1.

A way I've found is iterating through your csv and finding the highest value. Then going back through the list again and dividing all values by this max value. This becomes slow when you have many values.

Maybe we can use some variation of the sigmoid function and tailor it to our needs?

from brain.js.

robertleeplummerjr avatar robertleeplummerjr commented on May 4, 2024

There is probably a better way, but try something like this:

var values = [];
for (var i = 0, max = 10000; i < max; i++) {
  values.push(i);
}

var normalizedInputValues = [];
values.forEach(function(value, index) {
  normalizedInputValues.push(index / values.length);
});

for (i = 0, max = normalizedInputValues.length; i < max; i++) {
  if (normalizedInputValues[i] > 1) throw new Error('This should never happen, but there is a value above 1 here at index of ' + i);
}

//have fun

from brain.js.

robertleeplummerjr avatar robertleeplummerjr commented on May 4, 2024

In the above mentioned:

var net = new brain.NeuralNetwork();

net.train([{input: { r: 0.03, g: 0.7, b: 0.5 }, output: { black: 1 }},
           {input: { r: 0.16, g: 0.09, b: 0.2 }, output: { white: 1 }},
           {input: { r: 0.5, g: 0.5, b: 1.0 }, output: { white: 1 }}]);

var output = net.run({ r: 1, g: 0.4, b: 0 });  // { white: 0.99, black: 0.002 }

The data is sort of normalized, but by layer, would this work for you?

var net = new brain.NeuralNetwork();

net.train([
  {input: { one: 0.03, two: 0.7, ... thirty: 0.5 }, output: { isValid: 1 }},
  {input: { one: 1, two: 0.02, ... thirty: 0.33 }, output: { isValid: 1 }},
  {input: { one: 0.3, two: 0.2, ... thirty: 0.2 }, output: { isValid: 0 }}
]);
var output = net.run({ one: 0.03, two: 0.8, ... thirty: 0.6 });  // { isValid: .89 }

Does this help?

from brain.js.

robertleeplummerjr avatar robertleeplummerjr commented on May 4, 2024

The other option at this point could be to use a recurrent neural net, such as an LSTM, but this is more for data translation and less about math.

from brain.js.

lodenrogue avatar lodenrogue commented on May 4, 2024

I've found another solution. Thank you for your attention.

from brain.js.

robertleeplummerjr avatar robertleeplummerjr commented on May 4, 2024

Care to share? We always want to improve for usefulness.

from brain.js.

lodenrogue avatar lodenrogue commented on May 4, 2024

I went with a different library: scikit-learn

from brain.js.

robertleeplummerjr avatar robertleeplummerjr commented on May 4, 2024

ty for the pointer!

from brain.js.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.