Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NeuralNetwork returns the same results regardless of input #712

Closed
KCGD opened this issue May 14, 2021 · 4 comments
Closed

NeuralNetwork returns the same results regardless of input #712

KCGD opened this issue May 14, 2021 · 4 comments
Labels

Comments

@KCGD
Copy link

KCGD commented May 14, 2021

A GIF or MEME to give some spice of the internet

What is wrong?

the neural network returns the same thing no matter what input i give it

Where does it happen?

It happens both in NeuralNetwork() and NeuralNetworkGPU() on my pc (nodejs 12.18.0)
Interestingly NeuralNetwork and NeuralNetworkGPU return different results from eachother, but still have the same problem

How do we replicate the issue?

I guess just train a neuralnetwork, im not sure what is causing this to happen

  • Step 1
  • Step 2
  • Step 3

Expected behavior (i.e. solution)

the network should return different results if i give it different input, but it doesnt :\

Version information

Nodejs: 12.18.0, 64 bit

Browser: chrome stable (not using it)

Brain.js: 2.0.0-beta.2

How important is this (1-5)?

5, the neural network doesn't work with this problem

Other Comments

just a screenshot of the code im running

@KCGD KCGD added the bug label May 14, 2021
@vorticalbox
Copy link

NN do far better with numbers so you should on convert your data into an RGB value

[255, 0,0] // red
[0,255,0] //green
[0,0,255] // blue

then you should normalise your data, so dived your colours by 255 to get a value between 0 and 1

[255, 0,0] -> [1,0,0]
// orange
[255, 128, 0] -> [ 1, 0.5019607843137255, 0 ]

so putting it all together

import { NeuralNetwork, INeuralNetworkOptions } from 'brain.js';

// provide optional config object (or undefined). Defaults shown.
const config: INeuralNetworkOptions = {
  binaryThresh: 0.5,
  hiddenLayers: [3], // array of ints for the sizes of the hidden layers in the network
  activation: 'sigmoid', // supported activation types: ['sigmoid', 'relu', 'leaky-relu', 'tanh'],
  leakyReluAlpha: 0.01, // supported for activation type 'leaky-relu'
};

// create a simple feed forward neural network with backpropagation
const net = new NeuralNetwork(config);

const red = [255, 0, 0];
const green = [0, 255, 0];
const blue = [0, 0, 255];
const yellow = [255, 255, 0];
const orange = [255, 128, 0];

function normiliseData(colour: number[]) {
  return colour.map((c) => c / 255);
}
console.log(normiliseData(orange));

net.train([
  { input: normiliseData(red), output: normiliseData(blue) },
  { input: normiliseData(blue), output: normiliseData(red) },
  { input: normiliseData(green), output: normiliseData(yellow) },
  { input: normiliseData(yellow), output: normiliseData(orange) },
], { log: console.log, logPeriod: 1000 });
net.run(normiliseData(red)); 
// mostly blue
 [
  0.10830573737621307,
  0.033850573003292084,
  0.8939158916473389
]
net.run(normiliseData(yellow)); 
// mostly red, about 50% green
[
  0.9495605230331421,
  0.5147977471351624,
  0.050056517124176025
]

@Nelias
Copy link
Contributor

Nelias commented Dec 5, 2021

I have to confirm that this issue still exists. Even for normalized data between 0 and 1 in large arrays (length over 1000) it still returns exactly the same values after the training process.

@robertleeplummerjr
Copy link
Contributor

When I run this here, I get no issue. Can you try again and see if this is resolved?

@robertleeplummerjr
Copy link
Contributor

Closing because of inactivity.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants