jssm 5.152.0 → 5.154.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +7 -7
- package/custom-elements.json +293 -7
- package/dist/cdn/instance.js +352 -11
- package/dist/cdn/viz.js +374 -16
- package/dist/cli/fsl-export-system-prompt.cjs +1 -1
- package/dist/cli/fsl-render.cjs +1 -1
- package/dist/cli/fsl.cjs +1 -1
- package/dist/cli/lib.cjs +1 -1
- package/dist/cli/lib.mjs +1 -1
- package/dist/deno/README.md +7 -7
- package/dist/deno/jssm.d.ts +70 -5
- package/dist/deno/jssm.js +1 -1
- package/dist/deno/jssm_types.d.ts +31 -1
- package/dist/jssm.es5.cjs +1 -1
- package/dist/jssm.es5.iife.js +1 -1
- package/dist/jssm.es6.mjs +1 -1
- package/dist/jssm_viz.cjs +1 -1
- package/dist/jssm_viz.iife.cjs +1 -1
- package/dist/jssm_viz.mjs +1 -1
- package/dist/wc/instance.js +2 -0
- package/dist/wc/widgets.define.js +3 -2
- package/dist/wc/widgets.js +331 -34
- package/jssm.es5.d.cts +100 -5
- package/jssm.es6.d.ts +100 -5
- package/jssm_viz.es5.d.cts +95 -4
- package/jssm_viz.es6.d.ts +95 -4
- package/package.json +1 -1
package/dist/cdn/instance.js
CHANGED
|
@@ -888,7 +888,19 @@ function peg$parse(input, options) {
|
|
|
888
888
|
node.loc = location();
|
|
889
889
|
}
|
|
890
890
|
return node;
|
|
891
|
-
}, peg$c1573 = peg$otherExpectation("
|
|
891
|
+
}, peg$c1573 = peg$otherExpectation("oarrange declaration"), peg$c1574 = "oarrange", peg$c1575 = peg$literalExpectation("oarrange", false), peg$c1576 = function (value) {
|
|
892
|
+
const node = { key: 'oarrange_declaration', value };
|
|
893
|
+
if (options.locations) {
|
|
894
|
+
node.loc = location();
|
|
895
|
+
}
|
|
896
|
+
return node;
|
|
897
|
+
}, peg$c1577 = peg$otherExpectation("farrange declaration"), peg$c1578 = "farrange", peg$c1579 = peg$literalExpectation("farrange", false), peg$c1580 = function (value) {
|
|
898
|
+
const node = { key: 'farrange_declaration', value };
|
|
899
|
+
if (options.locations) {
|
|
900
|
+
node.loc = location();
|
|
901
|
+
}
|
|
902
|
+
return node;
|
|
903
|
+
}, peg$c1581 = peg$otherExpectation("arrange declaration"), peg$currPos = 0, peg$savedPos = 0, peg$posDetailsCache = [{ line: 1, column: 1 }], peg$maxFailPos = 0, peg$maxFailExpected = [], peg$silentFails = 0, peg$result;
|
|
892
904
|
if ("startRule" in options) {
|
|
893
905
|
if (!(options.startRule in peg$startRuleFunctions)) {
|
|
894
906
|
throw new Error("Can't start parsing from rule \"" + options.startRule + "\".");
|
|
@@ -20456,6 +20468,176 @@ function peg$parse(input, options) {
|
|
|
20456
20468
|
}
|
|
20457
20469
|
return s0;
|
|
20458
20470
|
}
|
|
20471
|
+
function peg$parseOArrangeDeclaration() {
|
|
20472
|
+
var s0, s1, s2, s3, s4, s5, s6;
|
|
20473
|
+
peg$silentFails++;
|
|
20474
|
+
s0 = peg$currPos;
|
|
20475
|
+
if (input.substr(peg$currPos, 8) === peg$c1574) {
|
|
20476
|
+
s1 = peg$c1574;
|
|
20477
|
+
peg$currPos += 8;
|
|
20478
|
+
}
|
|
20479
|
+
else {
|
|
20480
|
+
s1 = peg$FAILED;
|
|
20481
|
+
if (peg$silentFails === 0 && peg$currPos >= peg$maxFailPos) {
|
|
20482
|
+
peg$fail(peg$c1575);
|
|
20483
|
+
}
|
|
20484
|
+
}
|
|
20485
|
+
if (s1 !== peg$FAILED) {
|
|
20486
|
+
s2 = peg$parseWS();
|
|
20487
|
+
if (s2 === peg$FAILED) {
|
|
20488
|
+
s2 = null;
|
|
20489
|
+
}
|
|
20490
|
+
if (s2 !== peg$FAILED) {
|
|
20491
|
+
s3 = peg$parseLabelOrLabelList();
|
|
20492
|
+
if (s3 !== peg$FAILED) {
|
|
20493
|
+
s4 = peg$parseWS();
|
|
20494
|
+
if (s4 === peg$FAILED) {
|
|
20495
|
+
s4 = null;
|
|
20496
|
+
}
|
|
20497
|
+
if (s4 !== peg$FAILED) {
|
|
20498
|
+
if (input.charCodeAt(peg$currPos) === 59) {
|
|
20499
|
+
s5 = peg$c1213;
|
|
20500
|
+
peg$currPos++;
|
|
20501
|
+
}
|
|
20502
|
+
else {
|
|
20503
|
+
s5 = peg$FAILED;
|
|
20504
|
+
if (peg$silentFails === 0 && peg$currPos >= peg$maxFailPos) {
|
|
20505
|
+
peg$fail(peg$c1214);
|
|
20506
|
+
}
|
|
20507
|
+
}
|
|
20508
|
+
if (s5 !== peg$FAILED) {
|
|
20509
|
+
s6 = peg$parseWS();
|
|
20510
|
+
if (s6 === peg$FAILED) {
|
|
20511
|
+
s6 = null;
|
|
20512
|
+
}
|
|
20513
|
+
if (s6 !== peg$FAILED) {
|
|
20514
|
+
peg$savedPos = s0;
|
|
20515
|
+
s1 = peg$c1576(s3);
|
|
20516
|
+
s0 = s1;
|
|
20517
|
+
}
|
|
20518
|
+
else {
|
|
20519
|
+
peg$currPos = s0;
|
|
20520
|
+
s0 = peg$FAILED;
|
|
20521
|
+
}
|
|
20522
|
+
}
|
|
20523
|
+
else {
|
|
20524
|
+
peg$currPos = s0;
|
|
20525
|
+
s0 = peg$FAILED;
|
|
20526
|
+
}
|
|
20527
|
+
}
|
|
20528
|
+
else {
|
|
20529
|
+
peg$currPos = s0;
|
|
20530
|
+
s0 = peg$FAILED;
|
|
20531
|
+
}
|
|
20532
|
+
}
|
|
20533
|
+
else {
|
|
20534
|
+
peg$currPos = s0;
|
|
20535
|
+
s0 = peg$FAILED;
|
|
20536
|
+
}
|
|
20537
|
+
}
|
|
20538
|
+
else {
|
|
20539
|
+
peg$currPos = s0;
|
|
20540
|
+
s0 = peg$FAILED;
|
|
20541
|
+
}
|
|
20542
|
+
}
|
|
20543
|
+
else {
|
|
20544
|
+
peg$currPos = s0;
|
|
20545
|
+
s0 = peg$FAILED;
|
|
20546
|
+
}
|
|
20547
|
+
peg$silentFails--;
|
|
20548
|
+
if (s0 === peg$FAILED) {
|
|
20549
|
+
s1 = peg$FAILED;
|
|
20550
|
+
if (peg$silentFails === 0 && peg$currPos >= peg$maxFailPos) {
|
|
20551
|
+
peg$fail(peg$c1573);
|
|
20552
|
+
}
|
|
20553
|
+
}
|
|
20554
|
+
return s0;
|
|
20555
|
+
}
|
|
20556
|
+
function peg$parseFArrangeDeclaration() {
|
|
20557
|
+
var s0, s1, s2, s3, s4, s5, s6;
|
|
20558
|
+
peg$silentFails++;
|
|
20559
|
+
s0 = peg$currPos;
|
|
20560
|
+
if (input.substr(peg$currPos, 8) === peg$c1578) {
|
|
20561
|
+
s1 = peg$c1578;
|
|
20562
|
+
peg$currPos += 8;
|
|
20563
|
+
}
|
|
20564
|
+
else {
|
|
20565
|
+
s1 = peg$FAILED;
|
|
20566
|
+
if (peg$silentFails === 0 && peg$currPos >= peg$maxFailPos) {
|
|
20567
|
+
peg$fail(peg$c1579);
|
|
20568
|
+
}
|
|
20569
|
+
}
|
|
20570
|
+
if (s1 !== peg$FAILED) {
|
|
20571
|
+
s2 = peg$parseWS();
|
|
20572
|
+
if (s2 === peg$FAILED) {
|
|
20573
|
+
s2 = null;
|
|
20574
|
+
}
|
|
20575
|
+
if (s2 !== peg$FAILED) {
|
|
20576
|
+
s3 = peg$parseLabelOrLabelList();
|
|
20577
|
+
if (s3 !== peg$FAILED) {
|
|
20578
|
+
s4 = peg$parseWS();
|
|
20579
|
+
if (s4 === peg$FAILED) {
|
|
20580
|
+
s4 = null;
|
|
20581
|
+
}
|
|
20582
|
+
if (s4 !== peg$FAILED) {
|
|
20583
|
+
if (input.charCodeAt(peg$currPos) === 59) {
|
|
20584
|
+
s5 = peg$c1213;
|
|
20585
|
+
peg$currPos++;
|
|
20586
|
+
}
|
|
20587
|
+
else {
|
|
20588
|
+
s5 = peg$FAILED;
|
|
20589
|
+
if (peg$silentFails === 0 && peg$currPos >= peg$maxFailPos) {
|
|
20590
|
+
peg$fail(peg$c1214);
|
|
20591
|
+
}
|
|
20592
|
+
}
|
|
20593
|
+
if (s5 !== peg$FAILED) {
|
|
20594
|
+
s6 = peg$parseWS();
|
|
20595
|
+
if (s6 === peg$FAILED) {
|
|
20596
|
+
s6 = null;
|
|
20597
|
+
}
|
|
20598
|
+
if (s6 !== peg$FAILED) {
|
|
20599
|
+
peg$savedPos = s0;
|
|
20600
|
+
s1 = peg$c1580(s3);
|
|
20601
|
+
s0 = s1;
|
|
20602
|
+
}
|
|
20603
|
+
else {
|
|
20604
|
+
peg$currPos = s0;
|
|
20605
|
+
s0 = peg$FAILED;
|
|
20606
|
+
}
|
|
20607
|
+
}
|
|
20608
|
+
else {
|
|
20609
|
+
peg$currPos = s0;
|
|
20610
|
+
s0 = peg$FAILED;
|
|
20611
|
+
}
|
|
20612
|
+
}
|
|
20613
|
+
else {
|
|
20614
|
+
peg$currPos = s0;
|
|
20615
|
+
s0 = peg$FAILED;
|
|
20616
|
+
}
|
|
20617
|
+
}
|
|
20618
|
+
else {
|
|
20619
|
+
peg$currPos = s0;
|
|
20620
|
+
s0 = peg$FAILED;
|
|
20621
|
+
}
|
|
20622
|
+
}
|
|
20623
|
+
else {
|
|
20624
|
+
peg$currPos = s0;
|
|
20625
|
+
s0 = peg$FAILED;
|
|
20626
|
+
}
|
|
20627
|
+
}
|
|
20628
|
+
else {
|
|
20629
|
+
peg$currPos = s0;
|
|
20630
|
+
s0 = peg$FAILED;
|
|
20631
|
+
}
|
|
20632
|
+
peg$silentFails--;
|
|
20633
|
+
if (s0 === peg$FAILED) {
|
|
20634
|
+
s1 = peg$FAILED;
|
|
20635
|
+
if (peg$silentFails === 0 && peg$currPos >= peg$maxFailPos) {
|
|
20636
|
+
peg$fail(peg$c1577);
|
|
20637
|
+
}
|
|
20638
|
+
}
|
|
20639
|
+
return s0;
|
|
20640
|
+
}
|
|
20459
20641
|
function peg$parseArrangeDeclaration() {
|
|
20460
20642
|
var s0;
|
|
20461
20643
|
peg$silentFails++;
|
|
@@ -20463,13 +20645,19 @@ function peg$parse(input, options) {
|
|
|
20463
20645
|
if (s0 === peg$FAILED) {
|
|
20464
20646
|
s0 = peg$parseArrangeEndDeclaration();
|
|
20465
20647
|
if (s0 === peg$FAILED) {
|
|
20466
|
-
s0 = peg$
|
|
20648
|
+
s0 = peg$parseOArrangeDeclaration();
|
|
20649
|
+
if (s0 === peg$FAILED) {
|
|
20650
|
+
s0 = peg$parseFArrangeDeclaration();
|
|
20651
|
+
if (s0 === peg$FAILED) {
|
|
20652
|
+
s0 = peg$parseRegularArrangeDeclaration();
|
|
20653
|
+
}
|
|
20654
|
+
}
|
|
20467
20655
|
}
|
|
20468
20656
|
}
|
|
20469
20657
|
peg$silentFails--;
|
|
20470
20658
|
if (s0 === peg$FAILED) {
|
|
20471
20659
|
if (peg$silentFails === 0 && peg$currPos >= peg$maxFailPos) {
|
|
20472
|
-
peg$fail(peg$
|
|
20660
|
+
peg$fail(peg$c1581);
|
|
20473
20661
|
}
|
|
20474
20662
|
}
|
|
20475
20663
|
return s0;
|
|
@@ -22370,7 +22558,8 @@ function compile_rule_handler(rule) {
|
|
|
22370
22558
|
return { agg_as: 'state_declaration', val: { state: rule.name, declarations: rule.value } };
|
|
22371
22559
|
}
|
|
22372
22560
|
if (['arrange_declaration', 'arrange_start_declaration',
|
|
22373
|
-
'arrange_end_declaration'
|
|
22561
|
+
'arrange_end_declaration', 'oarrange_declaration',
|
|
22562
|
+
'farrange_declaration'].includes(rule.key)) {
|
|
22374
22563
|
return { agg_as: rule.key, val: [rule.value] };
|
|
22375
22564
|
}
|
|
22376
22565
|
// things that can only exist once and are just a value under their own name
|
|
@@ -22576,6 +22765,8 @@ function compile(tree) {
|
|
|
22576
22765
|
arrange_declaration: [],
|
|
22577
22766
|
arrange_start_declaration: [],
|
|
22578
22767
|
arrange_end_declaration: [],
|
|
22768
|
+
oarrange_declaration: [],
|
|
22769
|
+
farrange_declaration: [],
|
|
22579
22770
|
machine_version: [],
|
|
22580
22771
|
default_state_config: [],
|
|
22581
22772
|
default_active_state_config: [],
|
|
@@ -22701,6 +22892,7 @@ function compile(tree) {
|
|
|
22701
22892
|
}
|
|
22702
22893
|
});
|
|
22703
22894
|
['arrange_declaration', 'arrange_start_declaration', 'arrange_end_declaration',
|
|
22895
|
+
'oarrange_declaration', 'farrange_declaration',
|
|
22704
22896
|
'machine_author', 'machine_contributor', 'machine_reference', 'theme',
|
|
22705
22897
|
'state_declaration', 'property_definition', 'default_state_config',
|
|
22706
22898
|
'default_start_state_config', 'default_end_state_config',
|
|
@@ -23371,7 +23563,7 @@ var constants = /*#__PURE__*/Object.freeze({
|
|
|
23371
23563
|
* Useful for runtime diagnostics and for embedding in serialized machine
|
|
23372
23564
|
* snapshots so that deserializers can detect version-skew.
|
|
23373
23565
|
*/
|
|
23374
|
-
const version = "5.
|
|
23566
|
+
const version = "5.154.0";
|
|
23375
23567
|
|
|
23376
23568
|
// whargarbl lots of these return arrays could/should be sets
|
|
23377
23569
|
const { state_name_chars, state_name_first_chars, action_label_chars } = constants;
|
|
@@ -23686,9 +23878,13 @@ function find_connected_components(states, edges) {
|
|
|
23686
23878
|
}
|
|
23687
23879
|
return result;
|
|
23688
23880
|
}
|
|
23881
|
+
/** Default number of independent Monte-Carlo runs when none is declared. */
|
|
23882
|
+
const STOCHASTIC_DEFAULT_RUNS = 1000;
|
|
23883
|
+
/** Default per-run step cap (montecarlo) / walk length (steady_state). */
|
|
23884
|
+
const STOCHASTIC_DEFAULT_MAX_STEPS = 1000;
|
|
23689
23885
|
class Machine {
|
|
23690
23886
|
// whargarbl this badly needs to be broken up, monolith master
|
|
23691
|
-
constructor({ start_states, end_states = [], failed_outputs = [], initial_state, start_states_no_enforce, complete = [], transitions, machine_author, machine_comment, machine_contributor, machine_definition, machine_language, machine_license, machine_name, machine_version, npm_name, default_size, state_declaration, property_definition, state_property, fsl_version, dot_preamble = undefined, arrange_declaration = [], arrange_start_declaration = [], arrange_end_declaration = [], theme = ['default'], flow = 'down', graph_layout = 'dot', instance_name, history, boundary_depth_limit, data, default_state_config, default_active_state_config, default_hooked_state_config, default_terminal_state_config, default_start_state_config, default_end_state_config, default_transition_config, default_graph_config, group_registry, group_metadata, group_hooks, state_hooks, allows_override, config_allows_override, allow_islands, editor_config, rng_seed, time_source, timeout_source, clear_timeout_source }) {
|
|
23887
|
+
constructor({ start_states, end_states = [], failed_outputs = [], initial_state, start_states_no_enforce, complete = [], transitions, machine_author, machine_comment, machine_contributor, machine_definition, machine_language, machine_license, machine_name, machine_version, npm_name, default_size, state_declaration, property_definition, state_property, fsl_version, dot_preamble = undefined, arrange_declaration = [], arrange_start_declaration = [], arrange_end_declaration = [], oarrange_declaration = [], farrange_declaration = [], theme = ['default'], flow = 'down', graph_layout = 'dot', instance_name, history, boundary_depth_limit, data, default_state_config, default_active_state_config, default_hooked_state_config, default_terminal_state_config, default_start_state_config, default_end_state_config, default_transition_config, default_graph_config, group_registry, group_metadata, group_hooks, state_hooks, allows_override, config_allows_override, allow_islands, editor_config, rng_seed, time_source, timeout_source, clear_timeout_source }) {
|
|
23692
23888
|
this._time_source = time_source !== null && time_source !== void 0 ? time_source : (() => new Date().getTime());
|
|
23693
23889
|
this._create_started = this._time_source();
|
|
23694
23890
|
this._instance_name = instance_name;
|
|
@@ -23725,6 +23921,8 @@ class Machine {
|
|
|
23725
23921
|
this._arrange_declaration = arrange_declaration;
|
|
23726
23922
|
this._arrange_start_declaration = arrange_start_declaration;
|
|
23727
23923
|
this._arrange_end_declaration = arrange_end_declaration;
|
|
23924
|
+
this._oarrange_declaration = oarrange_declaration;
|
|
23925
|
+
this._farrange_declaration = farrange_declaration;
|
|
23728
23926
|
this._dot_preamble = dot_preamble;
|
|
23729
23927
|
this._themes = theme;
|
|
23730
23928
|
this._flow = flow;
|
|
@@ -24137,11 +24335,11 @@ class Machine {
|
|
|
24137
24335
|
}
|
|
24138
24336
|
this._created = this._time_source();
|
|
24139
24337
|
this.auto_set_state_timeout();
|
|
24140
|
-
this._arrange_declaration.forEach((arrange_pair) => arrange_pair.forEach((possibleState) => {
|
|
24338
|
+
[this._arrange_declaration, this._oarrange_declaration, this._farrange_declaration].forEach((declaration) => declaration.forEach((arrange_pair) => arrange_pair.forEach((possibleState) => {
|
|
24141
24339
|
if (!(this._states.has(possibleState))) {
|
|
24142
24340
|
throw new JssmError(this, `Cannot arrange state that does not exist "${possibleState}"`);
|
|
24143
24341
|
}
|
|
24144
|
-
}));
|
|
24342
|
+
})));
|
|
24145
24343
|
}
|
|
24146
24344
|
/********
|
|
24147
24345
|
*
|
|
@@ -24346,13 +24544,13 @@ class Machine {
|
|
|
24346
24544
|
* `;
|
|
24347
24545
|
*
|
|
24348
24546
|
* traffic_light.state(); // Off
|
|
24349
|
-
* traffic_light.props(); // { can_go: true, hesitate: true, stop_first: true
|
|
24547
|
+
* traffic_light.props(); // { can_go: true, hesitate: true, stop_first: true }
|
|
24350
24548
|
*
|
|
24351
24549
|
* traffic_light.go('Red');
|
|
24352
|
-
* traffic_light.props(); // { can_go: false, hesitate: true, stop_first: true
|
|
24550
|
+
* traffic_light.props(); // { can_go: false, hesitate: true, stop_first: true }
|
|
24353
24551
|
*
|
|
24354
24552
|
* traffic_light.go('Green');
|
|
24355
|
-
* traffic_light.props(); // { can_go: true, hesitate: false, stop_first: false
|
|
24553
|
+
* traffic_light.props(); // { can_go: true, hesitate: false, stop_first: false }
|
|
24356
24554
|
* ```
|
|
24357
24555
|
*
|
|
24358
24556
|
* @returns An object mapping every known property name to its current value
|
|
@@ -25200,6 +25398,147 @@ class Machine {
|
|
|
25200
25398
|
probabilistic_histo_walk(n) {
|
|
25201
25399
|
return histograph(this.probabilistic_walk(n));
|
|
25202
25400
|
}
|
|
25401
|
+
/** One non-destructive weighted-random walk over the graph from `start`.
|
|
25402
|
+
*
|
|
25403
|
+
* Reads the graph and advances the PRNG only — it never calls
|
|
25404
|
+
* {@link Machine.transition}, so it fires no hooks, mutates no machine
|
|
25405
|
+
* state, and touches no `data`. A state with no probabilistic exits
|
|
25406
|
+
* (a terminal, or a forced-only `~>` state) ends the walk.
|
|
25407
|
+
*
|
|
25408
|
+
* @param start - State to begin the walk from.
|
|
25409
|
+
* @param max_steps - Maximum transitions before the walk is step-capped.
|
|
25410
|
+
* @returns The {@link JssmStochasticRun} for this walk.
|
|
25411
|
+
*/
|
|
25412
|
+
_stochastic_one_walk(start, max_steps) {
|
|
25413
|
+
const states = [start];
|
|
25414
|
+
const edges = [];
|
|
25415
|
+
let cur = start;
|
|
25416
|
+
let terminated = false;
|
|
25417
|
+
for (let step = 0; step < max_steps; step++) {
|
|
25418
|
+
const exits = this.probable_exits_for(cur);
|
|
25419
|
+
if (exits.length === 0) {
|
|
25420
|
+
terminated = true;
|
|
25421
|
+
break;
|
|
25422
|
+
}
|
|
25423
|
+
const selected = weighted_rand_select(exits, undefined, this._rng);
|
|
25424
|
+
edges.push(`${cur}→${selected.to}`);
|
|
25425
|
+
cur = selected.to;
|
|
25426
|
+
states.push(cur);
|
|
25427
|
+
}
|
|
25428
|
+
return { states, edges, length: states.length - 1, terminated };
|
|
25429
|
+
}
|
|
25430
|
+
/** Lazily yield one {@link JssmStochasticRun} at a time.
|
|
25431
|
+
*
|
|
25432
|
+
* In `montecarlo` mode (default) yields `runs` independent walks from the
|
|
25433
|
+
* current state, each ending at a terminal or after `max_steps`. In
|
|
25434
|
+
* `steady_state` mode yields exactly one walk of `max_steps` steps. This
|
|
25435
|
+
* is the lazy engine behind {@link Machine.stochastic_summary}; the
|
|
25436
|
+
* fsl-stochastic panel drives it across animation frames.
|
|
25437
|
+
*
|
|
25438
|
+
* Passing `seed` reseeds the machine for reproducible runs. Unlike
|
|
25439
|
+
* {@link Machine.stochastic_summary}, the generator does NOT restore the
|
|
25440
|
+
* prior seed afterward — a direct caller's machine is left reseeded.
|
|
25441
|
+
*
|
|
25442
|
+
* @param opts - {@link JssmStochasticOptions}.
|
|
25443
|
+
* @returns A generator of per-run results.
|
|
25444
|
+
*
|
|
25445
|
+
* @example
|
|
25446
|
+
* const m = sm`a 'go' -> b 'go' -> c;`;
|
|
25447
|
+
* [...m.stochastic_runs({ runs: 2, seed: 1 })].length; // => 2
|
|
25448
|
+
*/
|
|
25449
|
+
*stochastic_runs(opts = {}) {
|
|
25450
|
+
var _a, _b, _c, _d, _e;
|
|
25451
|
+
if (opts.seed !== undefined) {
|
|
25452
|
+
this.rng_seed = opts.seed;
|
|
25453
|
+
}
|
|
25454
|
+
const mode = (_a = opts.mode) !== null && _a !== void 0 ? _a : 'montecarlo';
|
|
25455
|
+
const max_steps = (_b = opts.max_steps) !== null && _b !== void 0 ? _b : STOCHASTIC_DEFAULT_MAX_STEPS;
|
|
25456
|
+
const runs = (mode === 'steady_state')
|
|
25457
|
+
? 1
|
|
25458
|
+
: ((_e = (_c = opts.runs) !== null && _c !== void 0 ? _c : (_d = this.editor_config()) === null || _d === void 0 ? void 0 : _d.stochastic_run_count) !== null && _e !== void 0 ? _e : STOCHASTIC_DEFAULT_RUNS);
|
|
25459
|
+
const start = this.state();
|
|
25460
|
+
for (let i = 0; i < runs; i++) {
|
|
25461
|
+
yield this._stochastic_one_walk(start, max_steps);
|
|
25462
|
+
}
|
|
25463
|
+
}
|
|
25464
|
+
/** Run many weighted-random walks and return aggregate statistics.
|
|
25465
|
+
*
|
|
25466
|
+
* Honors `%` transition probabilities (via the existing probabilistic
|
|
25467
|
+
* machinery). Non-destructive: the machine's current state and
|
|
25468
|
+
* {@link Machine.rng_seed} are restored before returning, so calling this
|
|
25469
|
+
* never perturbs the live machine. `montecarlo` mode (default) reports
|
|
25470
|
+
* per-run `path_lengths`, `terminal_reached`, and `capped`; `steady_state`
|
|
25471
|
+
* mode runs one long walk and omits those fields.
|
|
25472
|
+
*
|
|
25473
|
+
* Timing (`after`) decorations and data-guard conditions are not modeled
|
|
25474
|
+
* by this sampler; it walks the probabilistic graph topology.
|
|
25475
|
+
*
|
|
25476
|
+
* @param opts - {@link JssmStochasticOptions}. `runs` defaults to the
|
|
25477
|
+
* machine's declared `editor: { stochastic_run_count }` (fsl#1334) when
|
|
25478
|
+
* present, otherwise {@link STOCHASTIC_DEFAULT_RUNS}.
|
|
25479
|
+
* @returns A {@link JssmStochasticSummary}.
|
|
25480
|
+
*
|
|
25481
|
+
* @see Machine.stochastic_runs
|
|
25482
|
+
* @see Machine.probabilistic_walk
|
|
25483
|
+
* @see Machine.editor_config
|
|
25484
|
+
*
|
|
25485
|
+
* @example
|
|
25486
|
+
* const m = sm`a 'go' -> b 'go' -> c;`;
|
|
25487
|
+
* const s = m.stochastic_summary({ runs: 100, seed: 1 });
|
|
25488
|
+
* s.terminal_reached; // => 100
|
|
25489
|
+
*/
|
|
25490
|
+
stochastic_summary(opts = {}) {
|
|
25491
|
+
var _a, _b, _c;
|
|
25492
|
+
const mode = (_a = opts.mode) !== null && _a !== void 0 ? _a : 'montecarlo';
|
|
25493
|
+
const saved_seed = this._rng_seed;
|
|
25494
|
+
if (opts.seed !== undefined) {
|
|
25495
|
+
this.rng_seed = opts.seed;
|
|
25496
|
+
}
|
|
25497
|
+
const effective_seed = this._rng_seed;
|
|
25498
|
+
const state_visits = new Map();
|
|
25499
|
+
const edge_traversals = new Map();
|
|
25500
|
+
const path_lengths = [];
|
|
25501
|
+
let terminal_reached = 0, capped = 0, runs = 0;
|
|
25502
|
+
try {
|
|
25503
|
+
for (const run of this.stochastic_runs(Object.assign(Object.assign({}, opts), { mode }))) {
|
|
25504
|
+
runs += 1;
|
|
25505
|
+
for (const s of run.states) {
|
|
25506
|
+
state_visits.set(s, ((_b = state_visits.get(s)) !== null && _b !== void 0 ? _b : 0) + 1);
|
|
25507
|
+
}
|
|
25508
|
+
for (const e of run.edges) {
|
|
25509
|
+
edge_traversals.set(e, ((_c = edge_traversals.get(e)) !== null && _c !== void 0 ? _c : 0) + 1);
|
|
25510
|
+
}
|
|
25511
|
+
if (mode === 'montecarlo') {
|
|
25512
|
+
if (run.terminated) {
|
|
25513
|
+
terminal_reached += 1;
|
|
25514
|
+
path_lengths.push(run.length);
|
|
25515
|
+
}
|
|
25516
|
+
else {
|
|
25517
|
+
capped += 1;
|
|
25518
|
+
}
|
|
25519
|
+
}
|
|
25520
|
+
}
|
|
25521
|
+
}
|
|
25522
|
+
finally {
|
|
25523
|
+
// restore the PRNG so the call is non-destructive even when the loop throws
|
|
25524
|
+
this.rng_seed = saved_seed;
|
|
25525
|
+
}
|
|
25526
|
+
const total_visits = [...state_visits.values()].reduce((a, b) => a + b, 0);
|
|
25527
|
+
const state_visit_fraction = new Map();
|
|
25528
|
+
for (const [s, c] of state_visits) {
|
|
25529
|
+
state_visit_fraction.set(s, c / total_visits);
|
|
25530
|
+
}
|
|
25531
|
+
const summary = {
|
|
25532
|
+
mode, runs, seed: effective_seed,
|
|
25533
|
+
state_visits, state_visit_fraction, edge_traversals,
|
|
25534
|
+
};
|
|
25535
|
+
if (mode === 'montecarlo') {
|
|
25536
|
+
summary.path_lengths = path_lengths;
|
|
25537
|
+
summary.terminal_reached = terminal_reached;
|
|
25538
|
+
summary.capped = capped;
|
|
25539
|
+
}
|
|
25540
|
+
return summary;
|
|
25541
|
+
}
|
|
25203
25542
|
/********
|
|
25204
25543
|
*
|
|
25205
25544
|
* List all actions available from this state. Please note that the order of
|
|
@@ -29666,6 +30005,7 @@ function split_ratio(coord, start, size) {
|
|
|
29666
30005
|
* @slot hook-log - Slot for the hook-firing log (`<fsl-hook-log>`, #664).
|
|
29667
30006
|
* @slot effective-properties - Slot for the resolved-properties panel (`<fsl-effective-properties>`, #665).
|
|
29668
30007
|
* @slot simulation - Slot for the random-walk simulation (`<fsl-simulation>`, #668).
|
|
30008
|
+
* @slot stochastic - Slot for the stochastic analysis panel (`<fsl-stochastic>`, fsl#1384).
|
|
29669
30009
|
* @slot export - Slot for the export menu (`<fsl-export>`, #667).
|
|
29670
30010
|
* @slot footer - Footer slot.
|
|
29671
30011
|
*/
|
|
@@ -30543,6 +30883,7 @@ class FslInstance extends i {
|
|
|
30543
30883
|
${docked ? '' : b `<section class="hook-log" ?hidden=${h('hook-log')}><slot name="hook-log"></slot></section>`}
|
|
30544
30884
|
<section class="effective-properties" ?hidden=${h('effective-properties')}><slot name="effective-properties"></slot></section>
|
|
30545
30885
|
<section class="simulation" ?hidden=${h('simulation')}><slot name="simulation"></slot></section>
|
|
30886
|
+
<section class="stochastic" ?hidden=${h('stochastic')}><slot name="stochastic"></slot></section>
|
|
30546
30887
|
<section class="export" ?hidden=${h('export')}><slot name="export"></slot></section>
|
|
30547
30888
|
`;
|
|
30548
30889
|
}
|