Skip to content

Instantly share code, notes, and snippets.

@nemanjan00
Created June 20, 2018 21:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nemanjan00/e32189b1a950debfc623ab5dc923d736 to your computer and use it in GitHub Desktop.
Save nemanjan00/e32189b1a950debfc623ab5dc923d736 to your computer and use it in GitHub Desktop.
const synaptic = require("synaptic");
// input:
// hot: 0 - 10
// crazy: 0 - 10
//
// output:
// no-go: 0/1
// danger-zone: 0/1
// fun-zone: 0/1
// date-her: 0/1
// marriage-material: 0/1
// unicorns: 0/1
// tranny: 0/1
let generator = (crazy, hot) => {
if(crazy === undefined || hot === undefined){
crazy = Math.random() * 10;
hot = Math.random() * 10;
}
let noGo = 0;
let dangerZone = 0;
let funZone = 0;
let dateHer = 0;
let marriageMaterial = 0;
let unicorns = 0;
let tranny = 0;
if(hot < 5) {
noGo = 1;
} else if(hot >= 5 && hot < 8){
if(crazy > hot){
dangerZone = 1;
} else {
funZone = 1;
}
} else {
if(crazy < 4){
tranny = 1;
} else if(crazy <= 4.5) {
unicorns = 1;
} else if (crazy < 5) {
marriageMaterial = 1;
} else if (hot < crazy) {
dateHer = 1;
} else {
dangerZone = 1;
}
}
if(crazy > hot) noGo = 1;
return {
input: [
hot / 10,
crazy / 10,
],
output: [
noGo,
dangerZone,
funZone,
dateHer,
marriageMaterial,
unicorns,
tranny
]
}
}
let nn = {
results: undefined,
perceptron: undefined,
train: () => {
nn.perceptron = new synaptic.Architect.Perceptron(2, 7, 7);
const trainer = new synaptic.Trainer(nn.perceptron);
let trainingSet = new Array(10000)
trainingSet = trainingSet.fill(undefined).map(generator);
return trainer.train(trainingSet, {
iterations: 100000,
error: .001
});
},
validate: () => {
const outputs = [];
let data = generator();
outputs.push({
result: nn.perceptron.activate(data.input).map(result => result.toFixed(3)),
input: data
});
return outputs;
}
}
console.log(nn.train());
console.log(JSON.stringify(nn.validate(), null, 4));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment