Last active
March 22, 2023 12:47
-
-
Save kenwebb/9862ffa75b5468b8f8bccff8446ebea7 to your computer and use it in GitHub Desktop.
TinyML course edX
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
<?xml version="1.0" encoding="UTF-8"?> | |
<!--Xholon Workbook http://www.primordion.com/Xholon/gwt/ MIT License, Copyright (C) Ken Webb, Wed Mar 22 2023 08:47:20 GMT-0400 (Eastern Daylight Saving Time)--> | |
<XholonWorkbook> | |
<Notes><![CDATA[ | |
Xholon | |
------ | |
Title: TinyML course edX | |
Description: | |
Url: http://www.primordion.com/Xholon/gwt/ | |
InternalName: 9862ffa75b5468b8f8bccff8446ebea7 | |
Keywords: | |
My Notes | |
-------- | |
21 March 2023 | |
I am working through the Harvard TinyML course provided through edX. | |
The course programming exercises use Google colab (Jupiter notebooks in the Google cloud). | |
The programmiing language is Python, with Tensor Flow. | |
My goal with this workbook is to think about how to do some this stuff with Xholon. | |
See my JavaScript functional programming examples in: | |
~/gwtspace/Xholon/Xholon/script/javascript | |
- for example, basics01.js | |
References | |
---------- | |
(1) https://edx.org/course/fundamentals-of-tinyml | |
Fundamentals of TinyML | |
Focusing on the basics of machine learning and embedded systems, such as smartphones, | |
this course will introduce you to the “language” of TinyML. | |
]]></Notes> | |
<markdown><![CDATA[ | |
### Fundamentals of TinyML | |
https://colab.research.google.com/github/tinyMLx/colabs/blob/master/2-1-4-ExploringLoss.ipynb#scrollTo=PwrR2q7tZKPi | |
``` python | |
import math | |
# Edit these parameters to try different loss | |
# measurements. Rerun this cell when done | |
# Your Y will be calculated as Y=wX+b, so | |
# if w=3, and b=-1, then Y=3x-1 | |
w = 2 | |
b = -1 | |
x = [-1, 0, 1, 2, 3, 4] | |
y = [-3, -1, 1, 3, 5, 7] | |
myY = [] | |
for thisX in x: | |
thisY = (w*thisX)+b | |
myY.append(thisY) | |
print("Real Y is " + str(y)) | |
print("My Y is " + str(myY)) | |
# let's calculate the loss | |
total_square_error = 0 | |
for i in range(0, len(y)): | |
square_error = (y[i] - myY[i]) ** 2 | |
total_square_error += square_error | |
print("My loss is: " + str(math.sqrt(total_square_error))) | |
``` | |
#### Here are the results: | |
``` | |
Real Y is [-3, -1, 1, 3, 5, 7] | |
My Y is [-3, -1, 1, 3, 5, 7] | |
My loss is: 0.0 | |
``` | |
]]></markdown> | |
<_-.XholonClass> | |
<PhysicalSystem/> | |
<!-- | |
<Block/> | |
<Brick/> | |
<Height superClass="Quantity"/>--> | |
</_-.XholonClass> | |
<xholonClassDetails> | |
<!--<Block> | |
<port name="height" connector="Height"/> | |
</Block>--> | |
</xholonClassDetails> | |
<PhysicalSystem> | |
<!--<Block> | |
<Height>0.1 m</Height> | |
</Block> | |
<Brick multiplicity="2"/>--> | |
<Script> | |
const w = 2; | |
const b = -1; | |
const x = [-1, 0, 1, 2, 3, 4]; | |
const y = [-3, -1, 1, 3, 5, 7]; | |
const myY = x.map(item => (item * w + b), []); | |
const sum = (a, b) => a + b; | |
// loss function - sum of absoulute values of the differences between 2 arrays c and d | |
const lossFuncAbs = (c, d) => c.reduce(sum); | |
// loss function - sum of squares of the differences between 2 arrays c and d | |
//const lossFuncSq = | |
const node = $wnd.xh.root(); | |
node.println(`w and b are ${w} ${b}`); | |
node.println(`Real x is ${x}`); | |
node.println(`Real y is ${y}`); | |
node.println(`My y is ${myY}`); | |
node.println(`My loss is ${lossFuncAbs(y, myY)}`); | |
</Script> | |
</PhysicalSystem> | |
<Blockbehavior implName="org.primordion.xholon.base.Behavior_gwtjs"><![CDATA[ | |
var a = 123; | |
var b = 456; | |
var c = a * b; | |
if (console) { | |
console.log(c); | |
} | |
//# sourceURL=Blockbehavior.js | |
]]></Blockbehavior> | |
<Heightbehavior implName="org.primordion.xholon.base.Behavior_gwtjs"><![CDATA[ | |
var myHeight, testing; | |
var beh = { | |
postConfigure: function() { | |
testing = Math.floor(Math.random() * 10); | |
myHeight = this.cnode.parent(); | |
}, | |
act: function() { | |
myHeight.println(this.toString()); | |
}, | |
toString: function() { | |
return "testing:" + testing; | |
} | |
} | |
//# sourceURL=Heightbehavior.js | |
]]></Heightbehavior> | |
<Brickbehavior implName="org.primordion.xholon.base.Behavior_gwtjs"><![CDATA[ | |
$wnd.xh.Brickbehavior = function Brickbehavior() {} | |
$wnd.xh.Brickbehavior.prototype.postConfigure = function() { | |
this.brick = this.cnode.parent(); | |
this.iam = " red brick"; | |
}; | |
$wnd.xh.Brickbehavior.prototype.act = function() { | |
this.brick.println("I am a" + this.iam); | |
}; | |
//# sourceURL=Brickbehavior.js | |
]]></Brickbehavior> | |
<Brickbehavior implName="org.primordion.xholon.base.Behavior_gwtjs"><![CDATA[ | |
console.log("I'm another brick behavior"); | |
]]></Brickbehavior> | |
<SvgClient><Attribute_String roleName="svgUri"><![CDATA[data:image/svg+xml, | |
<svg width="100" height="50" xmlns="http://www.w3.org/2000/svg"> | |
<g> | |
<title>TinyML</title> | |
<rect id="PhysicalSystem/Script" fill="#98FB98" height="50" width="50" x="25" y="0"/> | |
<g> | |
<title>Script</title> | |
<rect id="PhysicalSystem/Script" 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