Generate or learn various random processes.
Both discrete- and continious-time models are supported in either forward or reverse mode.
to genenerate a process (if configured in the forward/generate mode), or learn process parameters (if
configured in the reverse/learning mode).
Open/Close
RANDPR
Generates various random processes.
Requires: module:man, module:stream
Example
R2.1 - config methods:
var ran = new RAN({
p: [.4],
});
Example
R2.3 - config methods:
var ran = new RAN({
emP: {
dims: [3,3],
weights: [1,1]
},
markov: { states: 9, 0: {1: 0.8, 2: 0.1}, 1: {0: 0.1}, "0,1": { "1,0": .4} }
});
Example
R2.4 - config methods:
var ran = new RAN({
emP: {
dims: [2,2,2],
weights: [1,1,1]
},
markov: "random"
});
Example
R3 sync pipe with various textbook examples, custom filtering with supervised learning validation:
var ran = new RAN({
markov: [[0.1, 0.9], [0.1, 0.9]],
batch: 50,
filter: function (str, ev) {
switch (ev.at) {
case "config":
str.push(ev);
break;
case "batch":
Trace(ev);
break;
case "end":
Trace(ev);
var
A = ev.stats.mle_tr_probs,
B = ev.stats.mle_em_probs,
H = ev.stats.mle_holding_times;
Trace("MLEs", {
holdTimes: JSON.stringify(H),
emProbs: JSON.stringify(B),
trProbs: JSON.stringify(A)
});
str.push(ev);
break;
}
},
N: 500,
steps: 500
});
ran.pipe( function (store) {
Trace(store);
});
Example
R3.1 - gen process for R3.2 with async pipe to stdout:
var ran = new RAN({
markov: [[0.1, 0.9], [0.1, 0.9]],
batch: 800,
N: 1000,
filter: function (str,ev) {
switch (ev.at) {
case "batch":
case "config":
case "end":
Trace(JSON.stringify(ev));
}
},
steps: 800
});
ran.pipe(process.stdout);
Example
R3.2 - gen process for R3.3 using async pipe to stdout:
var ran = new RAN({
markov: [[0.1, 0.9], [0.1, 0.9]],
N: 10,
filter: function (str,ev) {
switch (ev.at) {
case "jump":
Trace(ev);
break;
default:
}
},
steps: 20
});
ran.pipe(process.stdout);
Example
R3.3 - supervised learning with R3.2 evs using sync pipe to store:
var
evs = [
{ at: 'jump', t: 1, s: 1, index: 3, state: 0, hold: 0, obs: null },
{ at: 'jump', t: 1, s: 1, index: 5, state: 1, hold: 0, obs: null },
{ at: 'jump', t: 1, s: 1, index: 6, state: 1, hold: 0, obs: null },
{ at: 'jump', t: 1, s: 1, index: 7, state: 1, hold: 0, obs: null },
{ at: 'jump', t: 1, s: 1, index: 8, state: 1, hold: 0, obs: null },
{ at: 'jump', t: 1, s: 1, index: 9, state: 1, hold: 0, obs: null },
{ at: 'jump', t: 2, s: 2, index: 2, state: 0, hold: 0, obs: null },
{ at: 'jump', t: 2, s: 2, index: 3, state: 1, hold: 0, obs: null },
{ at: 'jump', t: 3, s: 3, index: 2, state: 1, hold: 0, obs: null },
{ at: 'jump', t: 3, s: 3, index: 6, state: 0, hold: 0, obs: null },
{ at: 'jump', t: 4, s: 4, index: 6, state: 1, hold: 0, obs: null },
{ at: 'jump', t: 5, s: 5, index: 1, state: 0, hold: 0, obs: null },
{ at: 'jump', t: 6, s: 6, index: 1, state: 1, hold: 0, obs: null },
{ at: 'jump', t: 8, s: 8, index: 9, state: 0, hold: 0, obs: null },
{ at: 'jump', t: 9, s: 9, index: 3, state: 0, hold: 0, obs: null },
{ at: 'jump', t: 9, s: 9, index: 8, state: 0, hold: 0, obs: null },
{ at: 'jump', t: 9, s: 9, index: 9, state: 1, hold: 0, obs: null },
{ at: 'jump', t: 10, s: 10, index: 3, state: 1, hold: 0, obs: null },
{ at: 'jump', t: 10, s: 10, index: 8, state: 1, hold: 0, obs: null },
{ at: 'jump', t: 11, s: 11, index: 4, state: 0, hold: 0, obs: null },
{ at: 'jump', t: 13, s: 13, index: 4, state: 1, hold: 0, obs: null },
{ at: 'jump', t: 13, s: 13, index: 8, state: 0, hold: 0, obs: null },
{ at: 'jump', t: 14, s: 14, index: 8, state: 1, hold: 0, obs: null },
{ at: 'jump', t: 15, s: 15, index: 0, state: 0, hold: 0, obs: null },
{ at: 'jump', t: 16, s: 16, index: 0, state: 1, hold: 0, obs: null },
{ at: 'jump', t: 16, s: 16, index: 1, state: 0, hold: 0, obs: null },
{ at: 'jump', t: 16, s: 16, index: 3, state: 0, hold: 0, obs: null },
{ at: 'jump', t: 17, s: 17, index: 3, state: 1, hold: 0, obs: null },
{ at: 'jump', t: 18, s: 18, index: 1, state: 1, hold: 0, obs: null },
{ at: 'jump', t: 18, s: 18, index: 3, state: 0, hold: 0, obs: null },
{ at: 'jump', t: 18, s: 18, index: 6, state: 0, hold: 0, obs: null },
{ at: 'jump', t: 18, s: 18, index: 9, state: 0, hold: 0, obs: null },
{ at: 'jump', t: 19, s: 19, index: 3, state: 1, hold: 0, obs: null },
{ at: 'jump', t: 19, s: 19, index: 6, state: 1, hold: 0, obs: null },
{ at: 'jump', t: 19, s: 19, index: 9, state: 1, hold: 0, obs: null }
],
ran = new RAN({
learn: function (supercb) {
evs.$( true, (evs) => {
Trace( evs ? ` supervising ${evs.length} events` : " supervised" );
if (evs)
supercb(evs);
else
supercb(null);
});
},
batch: 50,
filter: function (str, ev) {
switch (ev.at) {
case "config":
Trace(ev);
str.push(ev);
break;
case "batch":
Trace(ev);
break;
case "end":
str.push(ev);
break;
}
},
markov: {},
K: 2,
N: 50
});
ran.pipe( function (store) {
Trace(store);
});
RANDPR~filter()
Output event filter
filter: function (str, ev, ran) { // event ev for stream/store str
switch ( ev.at ) { // streaming plugins provide an "at" to filter events on
case "...":
case "...":
str.push(ev); // return the event
}
}
Kind: inner method of RANDPR