Published
Edited
Apr 6, 2022
Insert cell
# Brain.js Issue #712
Insert cell
{
// provide optional config object (or undefined). Defaults shown.
const config = {
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 brain.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) {
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: true });

return [
net.run(normiliseData(red)),
net.run(normiliseData(blue)),
net.run(normiliseData(green)),
net.run(normiliseData(yellow)),
];
}
Insert cell
brain = require('brain.js')
Insert cell

One platform to build and deploy the best data apps

Experiment and prototype by building visualizations in live JavaScript notebooks. Collaborate with your team and decide which concepts to build out.
Use Observable Framework to build data apps locally. Use data loaders to build in any language or library, including Python, SQL, and R.
Seamlessly deploy to Observable. Test before you ship, use automatic deploy-on-commit, and ensure your projects are always up-to-date.
Learn more