Skip to content

Commit

Permalink
properties that enforce that probabilism is working, as is lack of
Browse files Browse the repository at this point in the history
  • Loading branch information
StoneCypher committed Aug 19, 2017
1 parent 18c4a31 commit 5c1d171
Show file tree
Hide file tree
Showing 5 changed files with 91 additions and 5 deletions.
2 changes: 1 addition & 1 deletion dist/jssm.es5.cjs.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/jssm.es5.cjs.min.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/lib/index.html
Expand Up @@ -2,7 +2,7 @@
<html>
<head>
<meta charset='utf-8' />
<title>jssm 4.5.1 | Documentation</title>
<title>jssm 4.5.2 | Documentation</title>
<meta name='viewport' content='width=device-width,initial-scale=1'>
<link href='assets/bass.css' type='text/css' rel='stylesheet' />
<link href='assets/style.css' type='text/css' rel='stylesheet' />
Expand All @@ -14,7 +14,7 @@
<div class='fixed xs-hide fix-3 overflow-auto max-height-100'>
<div class='py1 px2'>
<h3 class='mb0 no-anchor'>jssm</h3>
<div class='mb1'><code>4.5.1</code></div>
<div class='mb1'><code>4.5.2</code></div>
<input
placeholder='Filter'
id='filter-input'
Expand Down
2 changes: 1 addition & 1 deletion package.json
@@ -1,6 +1,6 @@
{
"name": "jssm",
"version": "4.5.1",
"version": "4.5.2",
"engines": {
"node": ">=6.0.0"
},
Expand Down
86 changes: 86 additions & 0 deletions src/js/tests/sample_select.js
Expand Up @@ -15,11 +15,97 @@ describe('weighted_sample_select/1', async it => {
jssm.weighted_sample_select(0, [{item:'a',probability:2},{item:'a',probability:3}]) )
);



describe('has reasonable unweighted distribution', async uit => {

const unweighted = new jssm.Machine({

initial_state: 'a',

transitions: [

{ from: 'a', to: 'b' },
{ from: 'a', to: 'c' },

{ from: 'b', to: 'a' },
{ from: 'b', to: 'c' },

{ from: 'c', to: 'a' },
{ from: 'c', to: 'b' }

]

});

const res = unweighted.probabilistic_histo_walk(1500);

// statistically each should be around 500. raise alarms if they aren't 300.
uit('a expects 500 requires 300', t => t.is(true, res.get('a') >= 300));
uit('b expects 500 requires 300', t => t.is(true, res.get('b') >= 300));
uit('c expects 500 requires 300', t => t.is(true, res.get('c') >= 300));

});



describe('has reasonable weighted distribution', async uit => {

const weighted = new jssm.Machine({

initial_state: 'a',

transitions: [

{ from: 'a', to: 'b', probability: 0.5 },
{ from: 'a', to: 'c', probability: 4 },
{ from: 'a', to: 'd', probability: 0.5 },
{ from: 'a', to: 'e', probability: 0.5 },

{ from: 'b', to: 'a', probability: 0.5 },
{ from: 'b', to: 'c', probability: 4 },
{ from: 'b', to: 'd', probability: 0.5 },
{ from: 'b', to: 'e', probability: 0.5 },

{ from: 'c', to: 'a', probability: 0.5 },
{ from: 'c', to: 'b', probability: 0.5 },
{ from: 'c', to: 'd', probability: 0.5 },
{ from: 'c', to: 'e', probability: 0.5 },

{ from: 'd', to: 'a', probability: 0.5 },
{ from: 'd', to: 'b', probability: 0.5 },
{ from: 'd', to: 'c', probability: 4 },
{ from: 'd', to: 'e', probability: 0.5 },

{ from: 'e', to: 'a', probability: 0.5 },
{ from: 'e', to: 'b', probability: 0.5 },
{ from: 'e', to: 'c', probability: 4 },
{ from: 'e', to: 'd', probability: 0.5 }

]

});

const res = weighted.probabilistic_histo_walk(2500);

// statistically each should be around 375, or 1050 for c. raise alarms if they aren't 250, or 800 for c.
uit('a expects 375 requires 250', t => t.is(true, res.get('a') >= 250));
uit('b expects 375 requires 250', t => t.is(true, res.get('b') >= 250));
uit('c expects 1050 requires 800', t => t.is(true, res.get('c') >= 800));
uit('d expects 375 requires 250', t => t.is(true, res.get('c') >= 250));
uit('e expects 375 requires 250', t => t.is(true, res.get('c') >= 250));

});

// stochastics would help, eg "every returned item is a member" and "in a
// sufficient list any positive sample size is reasonable" and "always
// returns the right sample size" - whargarbl todo


});





// stochable

0 comments on commit 5c1d171

Please sign in to comment.