Skip to content

Instantly share code, notes, and snippets.

@kenwebb
Last active March 27, 2019 16:47
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 kenwebb/1dfa7272c9300a1b5213b5056e7bc4f8 to your computer and use it in GitHub Desktop.
Save kenwebb/1dfa7272c9300a1b5213b5056e7bc4f8 to your computer and use it in GitHub Desktop.
brain.js
<?xml version="1.0" encoding="UTF-8"?>
<!--Xholon Workbook http://www.primordion.com/Xholon/gwt/ MIT License, Copyright (C) Ken Webb, Wed Mar 27 2019 12:46:44 GMT-0400 (Eastern Daylight Time)-->
<XholonWorkbook>
<Notes><![CDATA[
Xholon
------
Title: brain.js
Description:
Url: http://www.primordion.com/Xholon/gwt/
InternalName: 1dfa7272c9300a1b5213b5056e7bc4f8
Keywords:
My Notes
--------
March 27, 2019
Keyfer Mathewson gave a presentation last night at the Machine Learning & Artificial Intelligence meetup. He demoed brain.js and TensorFlow.js.
In this workbook, I explore brain.js.
http://127.0.0.1:8888/Xholon.html?app=brain.js&src=lstr&gui=clsc&jslib=brain.js/browser
References
----------
(1) https://github.com/BrainJS/brain.js
Neural networks in JavaScript
(2) https://www.meetup.com/Machine-Learning-Artificial-Intelligence-Ottawa/
]]></Notes>
<_-.XholonClass>
<PhysicalSystem/>
<Brain/>
</_-.XholonClass>
<xholonClassDetails>
</xholonClassDetails>
<PhysicalSystem>
<Brain/>
</PhysicalSystem>
<Brainbehavior implName="org.primordion.xholon.base.Behavior_gwtjs"><![CDATA[
var me, beh = {
postConfigure: function() {
me = this.cnode.parent();
me.println("starting Brainbehavior ...");
// 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 $wnd.brain.NeuralNetwork(config);
net.train([
{input: [0, 0], output: [0]},
{input: [0, 1], output: [1]},
{input: [1, 0], output: [1]},
{input: [1, 1], output: [0]}
]);
const output = net.run([1, 0]); // [0.987] [0.9332800507545471]
//console.log(output);
me.println(output);
},
act: function() {
//me.println(this.toString());
}
}
//# sourceURL=Brainbehavior.js
]]></Brainbehavior>
<SvgClient><Attribute_String roleName="svgUri"><![CDATA[data:image/svg+xml,
<svg width="100" height="50" xmlns="http://www.w3.org/2000/svg">
<g>
<title>Brain</title>
<rect id="PhysicalSystem/Brain" fill="#98FB98" height="50" width="50" x="25" y="0"/>
<g>
<title>Brain</title>
<rect id="PhysicalSystem/Brain" fill="#6AB06A" height="50" width="10" x="80" y="0"/>
</g>
</g>
</svg>
]]></Attribute_String><Attribute_String roleName="setup">${MODELNAME_DEFAULT},${SVGURI_DEFAULT}</Attribute_String></SvgClient>
</XholonWorkbook>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment