Last active
February 27, 2019 22:50
-
-
Save kenwebb/9afb3d0795256930f524485b2b09f2fd to your computer and use it in GitHub Desktop.
Stochastic Tree Wanderers
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 Feb 27 2019 17:49:38 GMT-0500 (Eastern Standard Time)--> | |
<XholonWorkbook> | |
<Notes><![CDATA[ | |
Xholon | |
------ | |
Title: Stochastic Tree Wanderers | |
Description: | |
Url: http://www.primordion.com/Xholon/gwt/ | |
InternalName: 9afb3d0795256930f524485b2b09f2fd | |
Keywords: | |
My Notes | |
-------- | |
February 17, 2019 | |
- based partly on workbook: "Web Cryptography API" 036d7c299b7c96e4838059e06b6d8334 | |
http://127.0.0.1:8888/wb/editwb.html?app=036d7c299b7c96e4838059e06b6d8334&src=gist | |
- see also my print notebook for Feb 17 | |
- see also TreeWanderer.java | |
- see also various app-specific behaviors in Bestiary, Island, etc. | |
- I would also like to use TensorFlow and TensorFlow/probability | |
February 18, 2019 | |
- I've added "idle" to Avatar | |
to display the database content | |
------------------------------- | |
xh.IndexedDBService.display("AvatarStateDB", "avastate", ["state", "action", "count"]); | |
Saskatoon (Car Toy Book Avatario), idle, 29 | |
Saskatoon (Car Toy Book Avatario), next, 3 | |
Saskatoon (Car Toy Book Avatario), prev, 1 | |
... | |
xh.IndexedDBService.display("AvatarStateDB", "avastate", ["hash", "state", "action", "count"]); | |
09710d1dfb67f188cceb5ff6d0ae1b9b166c1e6b9c4a76c0c07bb6379dde28aa, Saskatoon (Car Toy Book Avatario), first, 1 | |
09710d1dfb67f188cceb5ff6d0ae1b9b166c1e6b9c4a76c0c07bb6379dde28aa, Saskatoon (Car Toy Book Avatario), idle, 22 | |
09710d1dfb67f188cceb5ff6d0ae1b9b166c1e6b9c4a76c0c07bb6379dde28aa, Saskatoon (Car Toy Book Avatario), next, 4 | |
09710d1dfb67f188cceb5ff6d0ae1b9b166c1e6b9c4a76c0c07bb6379dde28aa, Saskatoon (Car Toy Book Avatario), prev, 8 | |
09c5ada38019c45c6617e2f4461f5bf46622f1f451c37cfad99c5b7d44884f34, Victoria (Car Toy Book Avatario), first, 6 | |
09c5ada38019c45c6617e2f4461f5bf46622f1f451c37cfad99c5b7d44884f34, Victoria (Car Toy Book Avatario), idle, 38 | |
... | |
generated probabilities: | |
{"09710d1dfb67f188cceb5ff6d0ae1b9b166c1e6b9c4a76c0c07bb6379dde28aa":[ | |
{"action":"first","count":"1","probability":0.02857142857142857}, | |
{"action":"next","count":"4","probability":0.14285714285714285}, | |
{"action":"prev","count":"8","probability":0.37142857142857144}, | |
{"action":"idle","count":"22","probability":1}], | |
"09c5ada38019c45c6617e2f4461f5bf46622f1f451c37cfad99c5b7d44884f34":[ | |
{"action":"next","count":"5","probability":0.08620689655172414}, | |
{"action":"first","count":"6","probability":0.1896551724137931}, | |
{"action":"prev","count":"9","probability":0.3448275862068966}, | |
{"action":"idle","count":"38","probability":1}], | |
February 20, 2019 | |
To include the StochasticBehavior.js library | |
-------------------------------------------- | |
http://127.0.0.1:8888/Xholon.html?app=Stochastic+Tree+Wanderers&src=lstr&gui=none&jslib=StochasticBehavior | |
http://127.0.0.1:8888/Xholon.html?app=Stochastic+Tree+Wanderers&src=lstr&gui=none&jslib=StochasticBehavior&hide=xhtabs,xhfooter | |
February 22, 2019 | |
----------------- | |
I added a second Avatar to the model. It sort-of works. | |
February 23, 2019 | |
----------------- | |
Ideas | |
----- | |
(1) as an option, the order of child nodes should not be important | |
ex: "One (Two Three)" should be treated the same as "One (Three Two)" | |
both of these should generate the same hash | |
use my array-like stuff: | |
http://127.0.0.1:8888/wb/editwb.html?app=JavaScript+array-like&src=lstr | |
https://gist.github.com/kenwebb/224a6815a2557a35210b3c0f089d88d1 | |
and my dplyr-like stuff: | |
http://127.0.0.1:8888/wb/editwb.html?app=tidyverse+dplyr&src=lstr | |
https://gist.github.com/kenwebb/5c0ca96bc2cf1aca750616925706f108 | |
could also use filtering and other dplyr-like verbs | |
(2) nameTemplate | |
Xholon getName(nameTemplate) | |
for now, I could offer 3 levels of specificity: | |
1. structure only, very general "(...." ex: (()()) | |
2. "R" roleName or className | |
3. "i" id | |
+. there are all sorts of other nameTemplate possibilities | |
possibly I could have a new nameTemplate that specifies sort and filter options | |
calling name("F....") could return 0 or 1, or name or null depending on whether it meets the filter specification | |
calling name("S....") could return the index of the node as a sort index | |
(3) I could put the results of multiple nameTemplates in the same IndexedDB | |
different Avatars could search DB using different templates | |
(4) | |
How can I think about this in terms of Categaory Theory (CT)? | |
The simplest coding is a null coding, where every Xholon subtree is the same as every other subtree. | |
CT 0 -> ... -> 1 ??? | |
Set, pointed set, ordered set, etc. | |
Think how this stuff relates to ideas in Statistics | |
Think about how to determine amount of differrence and similarity between quantities/structures | |
never match vs sometimes match vs always match | |
probability 0.0 range[0.0..1.0] 1.0 | |
References | |
---------- | |
(1) search: JavaScript probability dictionary | |
(2) https://www.tensorflow.org/probability/overview | |
I haven't used any of this stuff yet | |
]]></Notes> | |
<_-.XholonClass> | |
<PhysicalSystem/> | |
<!--<IndexedDB/>--> | |
<TestWorld/> | |
<!-- places --> | |
<City/> | |
<!-- things --> | |
<Thing/> | |
<Things/> | |
<!-- buttons --> | |
<DisplayDbButton superClass="script"/> | |
<QueryDbButton superClass="script"/> | |
<!-- DB query results --> | |
<QueryResults superClass="Attribute_String"/> | |
<QueryResultsProcessor superClass="script"/> | |
<!-- StochasticBehavior.js setup --> | |
<SetupStochasticBehavior superClass="script"/> | |
</_-.XholonClass> | |
<xholonClassDetails> | |
<!-- see colors from: https://www.w3schools.com/colors/colors_schemes.asp --> | |
<!-- | |
https://www.w3schools.com/colors/colors_triadic.asp | |
#F0F7D4 #B2D732 #4424D6 #FC600A #110934 | |
--> | |
<!--<Avatar><Color>rgba(252, 96, 10, 0.8)</Color></Avatar> | |
<Thing><Color>rgba(68, 36, 214, 0.8)</Color></Thing> | |
<City><Color>rgba(178, 215, 50, 0.5)</Color></City> | |
<TestWorld><Color>rgba(240, 247, 212, 1.0)</Color></TestWorld>--> | |
<Avatar><Color>hex+a #FC600A 0.8</Color></Avatar> | |
<Thing><Color>hex+a #4424D6 0.8</Color></Thing> | |
<City><Color>hex+a #B2D732 0.5</Color></City> | |
<TestWorld><Color>hex+a #F0F7D4 1.0</Color></TestWorld> | |
<PhysicalSystem><Color>white</Color></PhysicalSystem> | |
</xholonClassDetails> | |
<PhysicalSystem> | |
<!--<IndexedDB/>--> | |
<TestWorld> | |
<City roleName="Halifax"/> | |
<City roleName="Montreal"/> | |
<City roleName="Ottawa"/> | |
<City roleName="Toronto"/> | |
<City roleName="Winnipeg"/> | |
<City roleName="Saskatoon"/> | |
<City roleName="Calgary"/> | |
<City roleName="Vancouver"/> | |
<City roleName="Victoria"/> | |
<City roleName="Iqaluit"> | |
<Avatar roleName="Avatario" multiplicity="5"/> <!-- "Second" won't work; it needs roleName "Avatario" because that's what the training data has --> | |
</City> | |
</TestWorld> | |
<Things> | |
<Thing roleName="House" multiplicity="5"/> | |
<Thing roleName="Car" multiplicity="5"/> | |
<Thing roleName="Bicycle" multiplicity="5"/> | |
<Thing roleName="Toy" multiplicity="5"/> | |
<Thing roleName="Dog" multiplicity="5"/> | |
<Thing roleName="Book" multiplicity="5"/> | |
</Things> | |
<DisplayDbButton> | |
var beh = new $wnd.xh.StochasticBehavior.DisplayDbButton(); | |
//# sourceURL=DisplayDbButton.js | |
</DisplayDbButton> | |
<QueryDbButton> | |
var beh = new $wnd.xh.StochasticBehavior.QueryDbButton(); | |
//# sourceURL=QueryDbButton.js | |
</QueryDbButton> | |
<QueryResults> | |
<QueryResultsProcessor> | |
//$wnd.xh.root().println("starting QueryResultsProcessor 1"); | |
var ava = $wnd.xh.avatar(); | |
var beh = new $wnd.xh.StochasticBehavior.QueryResultsProcessor(ava); | |
//# sourceURL=QueryResultsProcessor.js | |
</QueryResultsProcessor> | |
<QueryResultsProcessor multiplicity="5"> | |
//$wnd.xh.root().println("starting QueryResultsProcessor 2"); | |
var ava = this.xpath("../../TestWorld/City[@roleName='Iqaluit']/Avatar").action("next"); | |
var beh = new $wnd.xh.StochasticBehavior.QueryResultsProcessor(ava); | |
ava.action("script;\nparam transcript false;\nwait 5;\nprev;prev;prev;"); | |
//# sourceURL=QueryResultsProcessor2.js | |
</QueryResultsProcessor> | |
<!-- SetupStochasticBehavior is positioned last, so it will be invoked first --> | |
<SetupStochasticBehavior> | |
//$wnd.xh.root().println("starting SetupStochastic"); | |
const constants01 = { | |
DEFAULT_MAX_LEVELS: 99, | |
DEFAULT_NAME_TEMPLATE: "R^^^^^", // "^^C^^^" | |
DEFAULT_DB_NAME: "AvatarStateDB", | |
DEFAULT_DB_STORE_NAME: "avastate", | |
DEFAULT_DB_STORE_KEY: ["hash", "action"], | |
DEFAULT_COLLECT_DATA: false, // whether or not to collect new data | |
BRACKETS: [" ("," ",")"] | |
} | |
const constants02 = { | |
DEFAULT_MAX_LEVELS: 1, | |
DEFAULT_NAME_TEMPLATE: "R^^^^^", | |
DEFAULT_DB_NAME: "SecondDB", | |
DEFAULT_DB_STORE_NAME: "secstate", | |
DEFAULT_DB_STORE_KEY: ["hash", "action"], | |
DEFAULT_COLLECT_DATA: false, | |
BRACKETS: [" ("," ",")"] | |
} | |
const constants03 = { | |
DEFAULT_MAX_LEVELS: 99, | |
DEFAULT_NAME_TEMPLATE: "R^^^^^", | |
DEFAULT_DB_NAME: "ThirdDB", | |
DEFAULT_DB_STORE_NAME: "thrdstate", | |
DEFAULT_DB_STORE_KEY: ["hash", "action"], | |
DEFAULT_COLLECT_DATA: false, | |
BRACKETS: [" ("," ",")"] | |
} | |
const constants04 = { | |
DEFAULT_MAX_LEVELS: 99, | |
DEFAULT_NAME_TEMPLATE: "^^^^i^", | |
DEFAULT_DB_NAME: "FourthDB", | |
DEFAULT_DB_STORE_NAME: "frthstate", | |
DEFAULT_DB_STORE_KEY: ["hash", "action"], | |
DEFAULT_COLLECT_DATA: false, | |
BRACKETS: [" ("," ",")"] | |
} | |
const constants05 = { | |
DEFAULT_MAX_LEVELS: 99, | |
DEFAULT_NAME_TEMPLATE: "^^^^i^", | |
DEFAULT_DB_NAME: "FifthDB", | |
DEFAULT_DB_STORE_NAME: "fithstate", | |
DEFAULT_DB_STORE_KEY: ["hash", "action"], | |
DEFAULT_COLLECT_DATA: false, | |
BRACKETS: ["(","",")"], | |
IGNORE_LIST: ["42", "57"] | |
} | |
const constants06 = { | |
DEFAULT_MAX_LEVELS: 99, | |
DEFAULT_NAME_TEMPLATE: "R^^^^^", | |
DEFAULT_DB_NAME: "SixthDB", | |
DEFAULT_DB_STORE_NAME: "sxthstate", | |
DEFAULT_DB_STORE_KEY: ["hash", "action"], | |
DEFAULT_COLLECT_DATA: false, | |
BRACKETS: ["[","","]"], | |
IGNORE_LIST: ["Avatario"], | |
CONTROL_DETERMINISTICALLY: true, | |
DETERMINIST_ACTIONS: "iflt xpath(.) random 0.02 next elseif ifgt xpath(.) random 0.98 prev else idle;" | |
} | |
const constants07 = { | |
DEFAULT_MAX_LEVELS: 1, | |
DEFAULT_NAME_TEMPLATE: "R^^^^^", | |
DEFAULT_DB_NAME: "SeventhDB", | |
DEFAULT_DB_STORE_NAME: "svnthstate", | |
DEFAULT_DB_STORE_KEY: ["hash", "action"], | |
DEFAULT_COLLECT_DATA: false, | |
BRACKETS: ["[","","]"], | |
IGNORE_LIST: ["Avatario"], | |
CONTROL_DETERMINISTICALLY: false, | |
DETERMINIST_ACTIONS: "iflt xpath(.) random 0.02 next elseif ifgt xpath(.) random 0.98 prev else idle;" | |
} | |
// Test Time | |
const constants08 = { | |
DEFAULT_MAX_LEVELS: 1, | |
DEFAULT_NAME_TEMPLATE: "R^^^^^", | |
DEFAULT_DB_NAME: "EighthDB", | |
DEFAULT_DB_STORE_NAME: "eithstate", | |
DEFAULT_DB_STORE_KEY: ["hash", "action"], | |
DEFAULT_COLLECT_DATA: false, | |
BRACKETS: ["[","","]"], | |
IGNORE_LIST: ["Avatario"], | |
CONTROL_DETERMINISTICALLY: false, | |
TIMESTEP_MODULO: 7 // test 0 1 2 OK | |
} | |
$wnd.xh.StochasticBehavior.setup(constants07); | |
//# sourceURL=SetupStochasticBehavior.js | |
</SetupStochasticBehavior> | |
</QueryResults> | |
<!-- xpath="./PhysicalSystem/TestWorld" --> | |
<Animate selection="#xhanim" xpath="./PhysicalSystem/TestWorld" duration="0.25" cssStyle=".d3cpnode circle {stroke-width: 0px;}" efParams="{"selection":"#xhanim","sort":"disable","width":600,"height":600,"mode":"tween","labelContainers":false,"includeId":true,"shape":"circle","useIcons":false}"/> | |
</PhysicalSystem> | |
<PhysicalSystembehavior implName="org.primordion.xholon.base.Behavior_gwtjs"><![CDATA[ | |
$wnd.xh.css.style("body {background-color: #110934; color: white}"); | |
$wnd.xh.css.style("textarea {background-color: rgba(240, 247, 212, 1.0);}"); | |
//# sourceURL=PhysicalSystembehavior.js | |
]]></PhysicalSystembehavior> | |
<TestWorldbehavior implName="org.primordion.xholon.base.Behavior_gwtjs"><![CDATA[ | |
//$wnd.xh.root().println("starting TestWorldbehavior"); | |
const AVA_TEST = false; //false; // whether or not to repeatedly run the Avatar test suite | |
const AVA_TRAIN = false; | |
this.me = this.parent(); | |
if ($wnd.xh.html["selectTab"]) { | |
$wnd.xh.html.selectTab(0); // display contents of the "out" tab | |
} | |
this.me.parent().append(this.remove()); | |
var city = this.me.first(); | |
var things = this.me.next(); | |
var thing = things.first(); | |
while (thing) { | |
var nextThing = thing.next(); | |
city.append(thing.remove()); | |
thing = nextThing; | |
city = city.next(); | |
if (city == null) { | |
city = this.me.first(); | |
} | |
} | |
this.ava = $wnd.xh.avatar(); | |
var beh = new $wnd.xh.StochasticBehavior.CollectData(null, null, null, this.ava); | |
this.ava.action("param currentActions true;"); | |
var initActions = "param transcript false;param setCtxtOnselect false;param repeat true;appear;become this role " + "Avatario" + ";" + "enter;enter testWorld;enter;pause;"; | |
this.ava.action(initActions); | |
if (AVA_TEST) { // test suite | |
var testActions = "script;\nnext;\nnext;\nprev;\nprev;\nenter;\nwait 5;\nexit;\nbreakpoint;"; | |
this.ava.action(testActions); | |
} | |
if (AVA_TRAIN) { // minimal training | |
var script = ` | |
script; | |
enter;\nnext;\nnext;\nnext;\nprev;\nprev;\nprev;\nexit; | |
next; | |
enter;\nnext;\nnext;\nnext;\nprev;\nprev;\nprev;\nexit; | |
next; | |
enter;\nnext;\nnext;\nnext;\nprev;\nprev;\nprev;\nexit; | |
next; | |
enter;\nnext;\nnext;\nnext;\nprev;\nprev;\nprev;\nexit; | |
next; | |
enter;\nnext;\nnext;\nnext;\nprev;\nprev;\nprev;\nexit; | |
next; | |
enter;\nnext;\nnext;\nnext;\nprev;\nprev;\nprev;\nexit; | |
next; | |
enter;\nnext;\nnext;\nnext;\nprev;\nprev;\nprev;\nexit; | |
next; | |
enter;\nnext;\nnext;\nnext;\nprev;\nprev;\nprev;\nexit; | |
next; | |
enter;\nnext;\nnext;\nnext;\nprev;\nprev;\nprev;\nexit; | |
next; | |
enter;\nnext;\nnext;\nnext;\nprev;\nprev;\nprev;\nexit; | |
next; | |
prev; | |
prev; | |
prev; | |
prev; | |
prev; | |
prev; | |
prev; | |
prev; | |
prev; | |
prev; | |
exit; | |
enter; | |
breakpoint; | |
` | |
this.ava.text(script); | |
} | |
this.ava.action("pause;"); | |
//# sourceURL=TestWorldbehavior.js | |
]]></TestWorldbehavior> | |
<SvgClient><Attribute_String roleName="svgUri"><![CDATA[data:image/svg+xml, | |
<svg width="100" height="50" xmlns="http://www.w3.org/2000/svg"> | |
<g> | |
<title>DisplayDbButton</title> | |
<rect id="PhysicalSystem/DisplayDbButton" fill="rgba(240, 247, 212, 1.0)" height="50" width="50" x="25" y="0"/> | |
<g> | |
<title>QueryDbButton</title> | |
<rect id="PhysicalSystem/QueryDbButton" fill="rgba(178, 215, 50, 0.5)" 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