Last active
August 29, 2015 13:56
-
-
Save adrianseeley/9299194 to your computer and use it in GitHub Desktop.
GATO.GENNA.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//<html><script> | |
function genna (input_nodes) { | |
// create identity genna | |
var identity = []; | |
// iterate through number of input nodes required | |
for (var a = 0; a < input_nodes; a++) | |
// create input node, pointing at the output node with the identity process | |
identity.push({inputs: [], outputs: [input_nodes], process: 0}); | |
// create the output node | |
identity.push({inputs: []}); | |
// create the return object | |
var ret = { | |
// attach the identity as the starting expression | |
dna: identity, | |
// attach null starting fitness | |
fitness: null, | |
// define a null starting class output pair list | |
class_output_pairs: null, | |
// define a null starting class list | |
classes: null, | |
// define the processes | |
proccesses: [ | |
function identity (dna, node) { | |
// if node has no inputs, provide a zero | |
if (node.inputs.length == 0) node.inputs.push(0); | |
// iterate all inputs | |
for (var a = 0; a < node.inputs.length; a++) | |
// iterate all outputs | |
for (var b = 0; b < node.outputs.length; b++) | |
// copy input to output | |
dna[node.outputs[b]].inputs.push(node.inputs[a]); | |
}, | |
function sum (dna, node) { | |
// define a sum register | |
var sum = 0; | |
// iterate all inputs | |
for (var a = 0; a < node.inputs.length; a++) | |
// add input to sum | |
sum += node.inputs[a]; | |
// iterate all outputs | |
for (var a = 0; a < node.outputs.length; a++) | |
// copy sum to output | |
dna[node.outputs[a]].inputs.push(sum); | |
}, | |
function average (dna, node) { | |
// if node has no inputs, provide a zero | |
if (node.inputs.length == 0) node.inputs.push(0); | |
// define an average register | |
var average = 0; | |
// iterate all inputs | |
for (var a = 0; a < node.inputs.length; a++) | |
// add input to average | |
average += node.inputs[a]; | |
// divide average by total inputs | |
average /= node.inputs.length; | |
// iterate all outputs | |
for (var a = 0; a < node.outputs.length; a++) | |
// copy average to output | |
dna[node.outputs[a]].inputs.push(average); | |
}, | |
function product (dna, node) { | |
// define a product register | |
var product = 1; | |
// iterate all inputs | |
for (var a = 0; a < node.inputs.length; a++) | |
// multiply input to product | |
product *= node.inputs[a]; | |
// iterate all outputs | |
for (var a = 0; a < node.outputs.length; a++) | |
// copy product to output | |
dna[node.outputs[a]].inputs.push(product); | |
}, | |
function or (dna, node) { | |
// define a register for the result | |
var result = 0; | |
// iterate all inputs | |
for (var a = 0; a < node.inputs.length; a++) | |
// if input was greater than or equal to 1 (activated boolean value) | |
if (node.inputs[a] >= 1) | |
// result is marked one for any value over 1 (or) | |
result = 1; | |
// iterate all outputs | |
for (var a = 0; a < node.outputs.length; a++) | |
// copy result to output | |
dna[node.outputs[a]].inputs.push(result); | |
}, | |
function and (dna, node) { | |
// define a register for the result | |
var result = 1; | |
// iterate all inputs | |
for (var a = 0; a < node.inputs.length; a++) | |
// if input was less than 1 (inactivated boolean value) | |
if (node.inputs[a] < 1) | |
// result is marked zero for any value under 1 (and) | |
result = 0; | |
// if there were no inputs | |
if (node.inputs.length == 0) | |
// mark result zero | |
result = 0; | |
// iterate all outputs | |
for (var a = 0; a < node.outputs.length; a++) | |
// copy result to output | |
dna[node.outputs[a]].inputs.push(result); | |
}, | |
function xor (dna, node) { | |
// define a register for the result | |
var result = 0; | |
// iterate all inputs | |
for (var a = 0; a < node.inputs.length; a++) | |
// if input was greater than or equal to 1 (activated boolean value) | |
if (node.inputs[a] >= 1) | |
// result is incremented | |
result++; | |
// if result is greater than 1 (meaning not exclusive activation) | |
if (result > 1) | |
// mark result zero | |
result = 0; | |
// iterate all outputs | |
for (var a = 0; a < node.outputs.length; a++) | |
// copy result to output | |
dna[node.outputs[a]].inputs.push(result); | |
}, | |
function times_negative_one (dna, node) { | |
// if node has no inputs, provide a zero | |
if (node.inputs.length == 0) node.inputs.push(0); | |
// iterate all inputs | |
for (var a = 0; a < node.inputs.length; a++) | |
// iterate all outputs | |
for (var b = 0; b < node.outputs.length; b++) | |
// copy input to output times negative one | |
dna[node.outputs[b]].inputs.push(node.inputs[a] * -1); | |
} | |
], | |
// define the expression runner | |
express: function (inputs, dna) { | |
// iterate dna nodes | |
for (var a = 0; a < dna.length; a++) | |
// reset dna node inputs | |
dna[a].inputs = []; | |
// iterate inputs | |
for (var a = 0; a < inputs.length; a++) | |
// stimulate input | |
dna[a].inputs.push(inputs[a]); | |
// iterate dna nodes (not output node, as it has no process) | |
for (var a = 0; a < dna.length - 1; a++) | |
// process node | |
ret.proccesses[dna[a].process](dna, dna[a]); | |
// define register for output sum | |
var output_sum = 0; | |
// iterate output node inputs | |
for (var a = 0; a < dna[dna.length - 1].inputs.length; a++) | |
// summate output node input | |
output_sum += dna[dna.length - 1].inputs[a]; | |
// return output sum as expression | |
return output_sum; | |
}, | |
// define the training function | |
train: function (training_list, iterations, error_rate_exit, complexity_exit, node_length_exit, nerf_rate, population_cap) { | |
// define a fitness function | |
function fitness (dna) { | |
// define a list to hold class output pairs | |
var class_output_pairs = []; | |
// iterate through training list | |
for (var a = 0; a < training_list.length; a++) | |
// express training case, store class and output | |
class_output_pairs.push({class: training_list[a].class, output: ret.express(training_list[a].inputs, dna)}); | |
// define registers to count each classes divergence and convergence | |
var divergence = 0; | |
var convergence = 0; | |
// iterate through class output pairs for the left side of the comparison | |
for (var a = 0; a < class_output_pairs.length; a++) | |
// iterate through class output pairs for the right side of the comparison | |
for (var b = 0; b < class_output_pairs.length; b++) | |
// skip self | |
if (a != b) | |
// if left side and right side share a class | |
if (class_output_pairs[a].class == class_output_pairs[b].class){ | |
// measure the convergence of the pair | |
convergence += val = Math.abs(class_output_pairs[b].output - class_output_pairs[a].output); | |
} | |
// otherwise the left side and right side have different classes | |
else | |
// measure the divergence of the pair | |
divergence += Math.abs(class_output_pairs[b].output - class_output_pairs[a].output); | |
// if convergence and divergence are both 0 return infinity (worst result) | |
if (convergence >= 0 && divergence == 0) return Infinity; | |
// if convergence is 0 and divergence is any positive number return epsilon over divergence | |
if (convergence == 0 && divergence > 0) return 0.00000001 / divergence; | |
// return the convergence divergence ratio as the fitness | |
return convergence / divergence; | |
}; | |
// define a complexity function | |
function complexity (dna) { | |
// define a register to hold number of outputs | |
var outputs = 0; | |
// iterate all nodes (not output node as it has no outputs) | |
for (var a = 0; a < dna.length - 1; a++) | |
// add number of outputs to total | |
outputs += dna[a].outputs.length; | |
// return total number of outputs as complexity | |
return outputs; | |
}; | |
// define a mutation function | |
function mutate (dna) { | |
// define a list of viable mutations | |
var viable_mutations = []; | |
// iterate dna nodes (not output node as it does not mutate) | |
for (var a = 0; a < dna.length - 1; a++) { | |
// iterate righter more dna nodes (output is included as it may be outputted to) | |
for (var b = a + 1; b < dna.length; b++) | |
// add new output as a viable mutation | |
viable_mutations.push({type: 'new output', source: a, destination: b}); | |
// if node has more than one output | |
if (dna[a].outputs.length > 1) | |
// iterate existing outputs | |
for (var b = 0; b < dna[a].outputs.length; b++) | |
// add remove output as a viable mutation | |
viable_mutations.push({type: 'remove output', source: a, output: b}); | |
// iterate through available processes | |
for (var b = 0; b < ret.proccesses.length; b++) | |
// skip current node process | |
if (dna[a].process != b) | |
// add change process as a viable mutation | |
viable_mutations.push({type: 'change process', source: a, process: b}); | |
// if this is not an input node | |
if (a >= input_nodes) | |
// add remove node as a viable mutation | |
viable_mutations.push({type: 'remove node', source: a}) | |
} | |
// iterate non input dna nodes | |
for (var a = input_nodes; a < dna.length; a++) | |
// iterate available processes | |
for (var b = 0; b < ret.proccesses.length; b++) | |
// add new node as a viable mutation | |
viable_mutations.push({type: 'new node', source: a, process: b}); | |
// choose a viable mutation randomly | |
var mutation = viable_mutations[Math.floor(Math.random() * viable_mutations.length)]; | |
// perform mutation | |
switch (mutation.type) { | |
case 'new output': | |
// add the new output | |
dna[mutation.source].outputs.push(mutation.destination); | |
break; | |
case 'remove output': | |
// remove the output | |
dna[mutation.source].outputs.splice(mutation.output, 1); | |
break; | |
case 'change process': | |
// change the process | |
dna[mutation.source].process = mutation.process; | |
break; | |
case 'remove node': | |
// 1. any nodes referencing the removal point as an output, inherit the outputs of the removed node in place of that output | |
// iterate up to the removal point | |
for (var a = 0; a < mutation.source; a++) | |
// iterate through nodes outputs | |
for (var b = 0; b < dna[a].outputs.length; b++) | |
// if this output points to the removal point | |
if (dna[a].outputs[b] == mutation.source) | |
// replace the link to the removal point, with the outputs of the removed node | |
dna[a].outputs = dna[a].outputs.slice(0, b).concat(dna[mutation.source].outputs).concat(dna[a].outputs.slice(b + 1)); | |
// 2. any nodes referencing any point after the removal point as an output, have those after-points shifted left one to preserve linkage after removal of node | |
// iterate all nodes (except output node as it has no outputs) | |
for (var a = 0; a < dna.length - 1; a++) | |
// iterate through nodes outputs | |
for (var b = 0; b < dna[a].outputs.length; b++) | |
// if output reference is past mutation point | |
if (dna[a].outputs[b] > mutation.source) | |
// shift output reference left one, to accomodate removal of node | |
dna[a].outputs[b]--; | |
// 3. remove the node | |
dna.splice(mutation.source, 1); | |
break; | |
case 'new node': | |
// 1. any node referencing the insertion point or after as an output, have those at-or-after-points shifted right one to preserve linkage after insertion of node | |
// iterate all nodes (except output node as it has no outputs) | |
for (var a = 0; a < dna.length - 1; a++) | |
// iterate through nodes outputs | |
for (var b = 0; b < dna[a].outputs.length; b++) | |
// if output reference is at or past insertion point | |
if (dna[a].outputs[b] >= mutation.source) | |
// shift output reference right one, to accomodate insertion of node | |
dna[a].outputs[b]++; | |
// 2. insert the new node, by default a nodes only output is the output node | |
dna.splice(mutation.source, 0, {inputs: [], outputs: [dna.length], process: mutation.process}); | |
break; | |
default: throw 'unknown mutation type: ' + JSON.stringify(mutation); | |
} | |
// return the mutated dna | |
return dna; | |
}; | |
// create a dna population from the current expression | |
var population = [JSON.parse(JSON.stringify(ret.dna))]; | |
// provide starting fitness | |
population[0].fitness = fitness(population[0]); | |
// provide starting nerf | |
population[0].nerf = 1.0; | |
// provide starting age | |
population[0].age = 0; | |
// provide starting complexity | |
population[0].complexity = complexity(population[0]); | |
// provide start JSON | |
population[0].JSON = JSON.stringify(population[0]); | |
// iterate till iterations or exit condidions met | |
for (var a = 0; a < iterations && (population[0].fitness > error_rate_exit || population[0].complexity > complexity_exit || population[0].length > node_length_exit); a++) { | |
// trace | |
console.log( | |
'iter: ' + a, | |
'fit: ' + population[0].fitness + '->(' + error_rate_exit + ')', | |
'compl: ' + population[0].complexity + '->(' + complexity_exit + ')', | |
'nleng: ' + population[0].length + '->(' + node_length_exit + ')', | |
'age: ' + population[0].age | |
); | |
// iterate through population to cap | |
for (var b = 0; b < population.length && b < population_cap; b++) { | |
// clone populus dna | |
population.push(JSON.parse(JSON.stringify(population[b]))); | |
// mutate until unique | |
var unique = true; | |
do { | |
// reset unique flag | |
unique = true; | |
// mutate cloned dna | |
population[population.length - 1] = mutate(population[population.length - 1]); | |
// define json of mutant | |
population[population.length - 1].JSON = JSON.stringify(population[population.length - 1]); | |
// iterate through population to ensure uniqueness (skip self at end) | |
for (var c = 0; c < population.length - 1; c++) | |
// if this populus matches the new mutant | |
if (population[c].JSON == population[population.length - 1].JSON) { | |
// mark not unique | |
unique = false; | |
// break unique check | |
break; | |
} | |
// loop until unique | |
} while (!unique) | |
// provide mutant dna fitness | |
population[population.length - 1].fitness = fitness(population[population.length - 1]); | |
// provide mutant dna nerf | |
population[population.length - 1].nerf = 1.0; | |
// provide mutant dna age | |
population[population.length - 1].age = 0; | |
// provide mutant dna complexity | |
population[population.length - 1].complexity = complexity(population[population.length - 1]); | |
// if populus host dna failed to produce a more fit mutant dna | |
if (population[b].fitness < population[population.length - 1].fitness) | |
// nerf queen dna | |
population[b].nerf *= nerf_rate; | |
} | |
// sort dna population | |
population.sort(function (left, right) { | |
return ((left.fitness * left.nerf) - (right.fitness * right.nerf)) || left.complexity - right.complexity || left.length - right.length ; | |
}); | |
// cap dna population | |
while (population.length > population_cap) | |
// remove dna population overflow | |
population.pop(); | |
// iterate dna population | |
for (var b = 0; b < population.length; b++) | |
// age populus | |
population[b].age++; | |
} | |
// final sort dna population without nerf | |
population.sort(function (left, right) { | |
// fitness, with ties resolved by least complex being better, then ties resolved by least nodes being better | |
return (left.fitness - right.fitness) || left.complexity - right.complexity || left.length - right.length; | |
}); | |
// set queen as genna dna | |
ret.dna = population[0]; | |
// set fitness | |
ret.fitness = population[0].fitness; | |
// define class output pairs for dna | |
ret.class_output_pairs = []; | |
// define classes for dna | |
ret.classes = {}; | |
// iterate through training list | |
for (var a = 0; a < training_list.length; a++) { | |
// express training case, store class and output | |
ret.class_output_pairs.push({class: training_list[a].class, output: ret.express(training_list[a].inputs, ret.dna)}); | |
// if dna does not already have class | |
if (!ret.classes.hasOwnProperty(training_list[a].class)) | |
// add class | |
ret.classes[training_list[a].class] = 0; | |
// count class occurence | |
ret.classes[training_list[a].class]++; | |
} | |
}, | |
// define the test function | |
test: function (inputs) { | |
// express the inputs using the queen dna | |
var output = ret.express(inputs, ret.dna); | |
// clone the class occurences hash to use as distance to class registers | |
var distance_to_classes = JSON.parse(JSON.stringify(ret.classes)); | |
// iterate classes | |
for (var a in distance_to_classes) | |
// reset value | |
distance_to_classes[a] = 0; | |
// iterate class output pairs | |
for (var a = 0; a < ret.class_output_pairs.length; a++) | |
// calculate distance to class | |
distance_to_classes[ret.class_output_pairs[a].class] += Math.abs(output - ret.class_output_pairs[a].output); | |
// define register for lowest average distance | |
var lowest_average_distance = null; | |
var class_of_lowest_average_distance = null; | |
// iterate distances | |
for (var a in distance_to_classes) { | |
// average distance by number of class occurences | |
distance_to_classes[a] /= ret.classes[a]; | |
// if average distance to class is lower than lowest, or if lowest is not marked yet | |
if (lowest_average_distance == null || distance_to_classes[a] < lowest_average_distance) { | |
// store lowest average distance | |
lowest_average_distance = distance_to_classes[a]; | |
// store class of lowest average distance | |
class_of_lowest_average_distance = a; | |
} | |
} | |
// return the class of the lowest average distance | |
return class_of_lowest_average_distance; | |
} | |
}; | |
return ret; | |
}; | |
var g = genna(4); | |
var training_list = | |
// xor | |
/*[{inputs: [0, 0], class: 0}, | |
{inputs: [0, 1], class: 1}, | |
{inputs: [1, 0], class: 1}, | |
{inputs: [1, 1], class: 0}];*/ | |
// and | |
/* [{inputs: [0, 0], class: 0}, | |
{inputs: [0, 1], class: 0}, | |
{inputs: [1, 0], class: 0}, | |
{inputs: [1, 1], class: 1}]; */ | |
// iris | |
[{inputs: [5.1,3.5,1.4,0.2], class: 'Iris-setosa'}, | |
{inputs: [4.9,3.0,1.4,0.2], class: 'Iris-setosa'}, | |
{inputs: [4.7,3.2,1.3,0.2], class: 'Iris-setosa'}, | |
{inputs: [4.6,3.1,1.5,0.2], class: 'Iris-setosa'}, | |
{inputs: [5.0,3.6,1.4,0.2], class: 'Iris-setosa'}, | |
{inputs: [5.4,3.9,1.7,0.4], class: 'Iris-setosa'}, | |
{inputs: [4.6,3.4,1.4,0.3], class: 'Iris-setosa'}, | |
{inputs: [5.0,3.4,1.5,0.2], class: 'Iris-setosa'}, | |
{inputs: [4.4,2.9,1.4,0.2], class: 'Iris-setosa'}, | |
{inputs: [4.9,3.1,1.5,0.1], class: 'Iris-setosa'}, | |
{inputs: [5.4,3.7,1.5,0.2], class: 'Iris-setosa'}, | |
{inputs: [4.8,3.4,1.6,0.2], class: 'Iris-setosa'}, | |
{inputs: [4.8,3.0,1.4,0.1], class: 'Iris-setosa'}, | |
{inputs: [4.3,3.0,1.1,0.1], class: 'Iris-setosa'}, | |
{inputs: [5.8,4.0,1.2,0.2], class: 'Iris-setosa'}, | |
{inputs: [5.7,4.4,1.5,0.4], class: 'Iris-setosa'}, | |
{inputs: [5.4,3.9,1.3,0.4], class: 'Iris-setosa'}, | |
{inputs: [5.1,3.5,1.4,0.3], class: 'Iris-setosa'}, | |
{inputs: [5.7,3.8,1.7,0.3], class: 'Iris-setosa'}, | |
{inputs: [5.1,3.8,1.5,0.3], class: 'Iris-setosa'}, | |
{inputs: [5.4,3.4,1.7,0.2], class: 'Iris-setosa'}, | |
{inputs: [5.1,3.7,1.5,0.4], class: 'Iris-setosa'}, | |
{inputs: [4.6,3.6,1.0,0.2], class: 'Iris-setosa'}, | |
{inputs: [5.1,3.3,1.7,0.5], class: 'Iris-setosa'}, | |
{inputs: [4.8,3.4,1.9,0.2], class: 'Iris-setosa'}, | |
{inputs: [5.0,3.0,1.6,0.2], class: 'Iris-setosa'}, | |
{inputs: [5.0,3.4,1.6,0.4], class: 'Iris-setosa'}, | |
{inputs: [5.2,3.5,1.5,0.2], class: 'Iris-setosa'}, | |
{inputs: [5.2,3.4,1.4,0.2], class: 'Iris-setosa'}, | |
{inputs: [4.7,3.2,1.6,0.2], class: 'Iris-setosa'}, | |
{inputs: [4.8,3.1,1.6,0.2], class: 'Iris-setosa'}, | |
{inputs: [5.4,3.4,1.5,0.4], class: 'Iris-setosa'}, | |
{inputs: [5.2,4.1,1.5,0.1], class: 'Iris-setosa'}, | |
{inputs: [5.5,4.2,1.4,0.2], class: 'Iris-setosa'}, | |
{inputs: [4.9,3.1,1.5,0.1], class: 'Iris-setosa'}, | |
{inputs: [5.0,3.2,1.2,0.2], class: 'Iris-setosa'}, | |
{inputs: [5.5,3.5,1.3,0.2], class: 'Iris-setosa'}, | |
{inputs: [4.9,3.1,1.5,0.1], class: 'Iris-setosa'}, | |
{inputs: [4.4,3.0,1.3,0.2], class: 'Iris-setosa'}, | |
{inputs: [5.1,3.4,1.5,0.2], class: 'Iris-setosa'}, | |
{inputs: [5.0,3.5,1.3,0.3], class: 'Iris-setosa'}, | |
{inputs: [4.5,2.3,1.3,0.3], class: 'Iris-setosa'}, | |
{inputs: [4.4,3.2,1.3,0.2], class: 'Iris-setosa'}, | |
{inputs: [5.0,3.5,1.6,0.6], class: 'Iris-setosa'}, | |
{inputs: [5.1,3.8,1.9,0.4], class: 'Iris-setosa'}, | |
{inputs: [4.8,3.0,1.4,0.3], class: 'Iris-setosa'}, | |
{inputs: [5.1,3.8,1.6,0.2], class: 'Iris-setosa'}, | |
{inputs: [4.6,3.2,1.4,0.2], class: 'Iris-setosa'}, | |
{inputs: [5.3,3.7,1.5,0.2], class: 'Iris-setosa'}, | |
{inputs: [5.0,3.3,1.4,0.2], class: 'Iris-setosa'}, | |
{inputs: [7.0,3.2,4.7,1.4], class: 'Iris-versicolor'}, | |
{inputs: [6.4,3.2,4.5,1.5], class: 'Iris-versicolor'}, | |
{inputs: [6.9,3.1,4.9,1.5], class: 'Iris-versicolor'}, | |
{inputs: [5.5,2.3,4.0,1.3], class: 'Iris-versicolor'}, | |
{inputs: [6.5,2.8,4.6,1.5], class: 'Iris-versicolor'}, | |
{inputs: [5.7,2.8,4.5,1.3], class: 'Iris-versicolor'}, | |
{inputs: [6.3,3.3,4.7,1.6], class: 'Iris-versicolor'}, | |
{inputs: [4.9,2.4,3.3,1.0], class: 'Iris-versicolor'}, | |
{inputs: [6.6,2.9,4.6,1.3], class: 'Iris-versicolor'}, | |
{inputs: [5.2,2.7,3.9,1.4], class: 'Iris-versicolor'}, | |
{inputs: [5.0,2.0,3.5,1.0], class: 'Iris-versicolor'}, | |
{inputs: [5.9,3.0,4.2,1.5], class: 'Iris-versicolor'}, | |
{inputs: [6.0,2.2,4.0,1.0], class: 'Iris-versicolor'}, | |
{inputs: [6.1,2.9,4.7,1.4], class: 'Iris-versicolor'}, | |
{inputs: [5.6,2.9,3.6,1.3], class: 'Iris-versicolor'}, | |
{inputs: [6.7,3.1,4.4,1.4], class: 'Iris-versicolor'}, | |
{inputs: [5.6,3.0,4.5,1.5], class: 'Iris-versicolor'}, | |
{inputs: [5.8,2.7,4.1,1.0], class: 'Iris-versicolor'}, | |
{inputs: [6.2,2.2,4.5,1.5], class: 'Iris-versicolor'}, | |
{inputs: [5.6,2.5,3.9,1.1], class: 'Iris-versicolor'}, | |
{inputs: [5.9,3.2,4.8,1.8], class: 'Iris-versicolor'}, | |
{inputs: [6.1,2.8,4.0,1.3], class: 'Iris-versicolor'}, | |
{inputs: [6.3,2.5,4.9,1.5], class: 'Iris-versicolor'}, | |
{inputs: [6.1,2.8,4.7,1.2], class: 'Iris-versicolor'}, | |
{inputs: [6.4,2.9,4.3,1.3], class: 'Iris-versicolor'}, | |
{inputs: [6.6,3.0,4.4,1.4], class: 'Iris-versicolor'}, | |
{inputs: [6.8,2.8,4.8,1.4], class: 'Iris-versicolor'}, | |
{inputs: [6.7,3.0,5.0,1.7], class: 'Iris-versicolor'}, | |
{inputs: [6.0,2.9,4.5,1.5], class: 'Iris-versicolor'}, | |
{inputs: [5.7,2.6,3.5,1.0], class: 'Iris-versicolor'}, | |
{inputs: [5.5,2.4,3.8,1.1], class: 'Iris-versicolor'}, | |
{inputs: [5.5,2.4,3.7,1.0], class: 'Iris-versicolor'}, | |
{inputs: [5.8,2.7,3.9,1.2], class: 'Iris-versicolor'}, | |
{inputs: [6.0,2.7,5.1,1.6], class: 'Iris-versicolor'}, | |
{inputs: [5.4,3.0,4.5,1.5], class: 'Iris-versicolor'}, | |
{inputs: [6.0,3.4,4.5,1.6], class: 'Iris-versicolor'}, | |
{inputs: [6.7,3.1,4.7,1.5], class: 'Iris-versicolor'}, | |
{inputs: [6.3,2.3,4.4,1.3], class: 'Iris-versicolor'}, | |
{inputs: [5.6,3.0,4.1,1.3], class: 'Iris-versicolor'}, | |
{inputs: [5.5,2.5,4.0,1.3], class: 'Iris-versicolor'}, | |
{inputs: [5.5,2.6,4.4,1.2], class: 'Iris-versicolor'}, | |
{inputs: [6.1,3.0,4.6,1.4], class: 'Iris-versicolor'}, | |
{inputs: [5.8,2.6,4.0,1.2], class: 'Iris-versicolor'}, | |
{inputs: [5.0,2.3,3.3,1.0], class: 'Iris-versicolor'}, | |
{inputs: [5.6,2.7,4.2,1.3], class: 'Iris-versicolor'}, | |
{inputs: [5.7,3.0,4.2,1.2], class: 'Iris-versicolor'}, | |
{inputs: [5.7,2.9,4.2,1.3], class: 'Iris-versicolor'}, | |
{inputs: [6.2,2.9,4.3,1.3], class: 'Iris-versicolor'}, | |
{inputs: [5.1,2.5,3.0,1.1], class: 'Iris-versicolor'}, | |
{inputs: [5.7,2.8,4.1,1.3], class: 'Iris-versicolor'}, | |
{inputs: [6.3,3.3,6.0,2.5], class: 'Iris-virginica'}, | |
{inputs: [5.8,2.7,5.1,1.9], class: 'Iris-virginica'}, | |
{inputs: [7.1,3.0,5.9,2.1], class: 'Iris-virginica'}, | |
{inputs: [6.3,2.9,5.6,1.8], class: 'Iris-virginica'}, | |
{inputs: [6.5,3.0,5.8,2.2], class: 'Iris-virginica'}, | |
{inputs: [7.6,3.0,6.6,2.1], class: 'Iris-virginica'}, | |
{inputs: [4.9,2.5,4.5,1.7], class: 'Iris-virginica'}, | |
{inputs: [7.3,2.9,6.3,1.8], class: 'Iris-virginica'}, | |
{inputs: [6.7,2.5,5.8,1.8], class: 'Iris-virginica'}, | |
{inputs: [7.2,3.6,6.1,2.5], class: 'Iris-virginica'}, | |
{inputs: [6.5,3.2,5.1,2.0], class: 'Iris-virginica'}, | |
{inputs: [6.4,2.7,5.3,1.9], class: 'Iris-virginica'}, | |
{inputs: [6.8,3.0,5.5,2.1], class: 'Iris-virginica'}, | |
{inputs: [5.7,2.5,5.0,2.0], class: 'Iris-virginica'}, | |
{inputs: [5.8,2.8,5.1,2.4], class: 'Iris-virginica'}, | |
{inputs: [6.4,3.2,5.3,2.3], class: 'Iris-virginica'}, | |
{inputs: [6.5,3.0,5.5,1.8], class: 'Iris-virginica'}, | |
{inputs: [7.7,3.8,6.7,2.2], class: 'Iris-virginica'}, | |
{inputs: [7.7,2.6,6.9,2.3], class: 'Iris-virginica'}, | |
{inputs: [6.0,2.2,5.0,1.5], class: 'Iris-virginica'}, | |
{inputs: [6.9,3.2,5.7,2.3], class: 'Iris-virginica'}, | |
{inputs: [5.6,2.8,4.9,2.0], class: 'Iris-virginica'}, | |
{inputs: [7.7,2.8,6.7,2.0], class: 'Iris-virginica'}, | |
{inputs: [6.3,2.7,4.9,1.8], class: 'Iris-virginica'}, | |
{inputs: [6.7,3.3,5.7,2.1], class: 'Iris-virginica'}, | |
{inputs: [7.2,3.2,6.0,1.8], class: 'Iris-virginica'}, | |
{inputs: [6.2,2.8,4.8,1.8], class: 'Iris-virginica'}, | |
{inputs: [6.1,3.0,4.9,1.8], class: 'Iris-virginica'}, | |
{inputs: [6.4,2.8,5.6,2.1], class: 'Iris-virginica'}, | |
{inputs: [7.2,3.0,5.8,1.6], class: 'Iris-virginica'}, | |
{inputs: [7.4,2.8,6.1,1.9], class: 'Iris-virginica'}, | |
{inputs: [7.9,3.8,6.4,2.0], class: 'Iris-virginica'}, | |
{inputs: [6.4,2.8,5.6,2.2], class: 'Iris-virginica'}, | |
{inputs: [6.3,2.8,5.1,1.5], class: 'Iris-virginica'}, | |
{inputs: [6.1,2.6,5.6,1.4], class: 'Iris-virginica'}, | |
{inputs: [7.7,3.0,6.1,2.3], class: 'Iris-virginica'}, | |
{inputs: [6.3,3.4,5.6,2.4], class: 'Iris-virginica'}, | |
{inputs: [6.4,3.1,5.5,1.8], class: 'Iris-virginica'}, | |
{inputs: [6.0,3.0,4.8,1.8], class: 'Iris-virginica'}, | |
{inputs: [6.9,3.1,5.4,2.1], class: 'Iris-virginica'}, | |
{inputs: [6.7,3.1,5.6,2.4], class: 'Iris-virginica'}, | |
{inputs: [6.9,3.1,5.1,2.3], class: 'Iris-virginica'}, | |
{inputs: [5.8,2.7,5.1,1.9], class: 'Iris-virginica'}, | |
{inputs: [6.8,3.2,5.9,2.3], class: 'Iris-virginica'}, | |
{inputs: [6.7,3.3,5.7,2.5], class: 'Iris-virginica'}, | |
{inputs: [6.7,3.0,5.2,2.3], class: 'Iris-virginica'}, | |
{inputs: [6.3,2.5,5.0,1.9], class: 'Iris-virginica'}, | |
{inputs: [6.5,3.0,5.2,2.0], class: 'Iris-virginica'}, | |
{inputs: [6.2,3.4,5.4,2.3], class: 'Iris-virginica'}, | |
{inputs: [5.9,3.0,5.1,1.8], class: 'Iris-virginica'}]; | |
console.log(training_list[0].inputs); | |
g.train( | |
// training_list | |
training_list.slice(0, training_list.length - 10), | |
// iterations | |
100000, | |
// error_rate_exit | |
0, | |
// complexity exit | |
Infinity, | |
// node length exit | |
Infinity, | |
// nerf_rate | |
1.01, | |
// population_cap | |
100 | |
); | |
for (var a = 0; a < training_list.length; a++) | |
console.log(JSON.stringify(training_list[a]) + ' -> ' + g.test(training_list[a].inputs)); | |
//console.log(JSON.stringify(g, null, ' ')); | |
//</script></html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment