Skip to content

Commit 1ba6093

Browse files
author
Jason Walsh
committed
Support runkit documentation
1 parent 3ce7097 commit 1ba6093

25 files changed

+131
-227
lines changed

README.md

Lines changed: 62 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -16,26 +16,26 @@ Real-world examples will be provided from some of the following texts or courses
1616

1717
## Usage
1818

19-
### ES2015
19+
### CommonJS
2020

2121
```javascript
22-
import * as stoch from '@jwalsh/stochastic';
23-
const exp = stoch.exp(20);
22+
var stochastic = require('@jwalsh/stochastic');
23+
var norm = stochastic.norm(1, 1, 100);
2424
```
2525

26-
### CommonJS
26+
### ES2015
2727

2828
```javascript
29-
var stoch = require('@jwalsh/stochastic');
30-
var norm = stoch.norm(1, 1, 100);
29+
import * as stochastic from '@jwalsh/stochastic';
30+
const exp = stochastic.exp(20);
3131
```
3232

3333
### CDN
3434

3535
```html
3636
<script src="https://cdn.rawgit.com/jwalsh/stochastic/master/dist/bundle.min.js"></script>
3737
<script>
38-
console.log(stoch.exp(20));
38+
console.log(stochastic.exp(20));
3939
</script>
4040
```
4141

@@ -64,11 +64,11 @@ over the course of a standard 261 work-day year
6464
**Examples**
6565

6666
```javascript
67-
const poissP = stoch.poissP(1, 100, true);
67+
const poissP = stochastic.poissP(1, 100, true);
6868
```
6969

7070
```javascript
71-
const emails = stoch.hist(Array(261).fill().map(e => stoch.poissP(10, 8, true).length));
71+
const emails = stochastic.hist(Array(261).fill().map(e => stochastic.poissP(10, 8, true).length));
7272
```
7373

7474
Returns **[Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array)&lt;[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)>** times of each arrival in a Poisson Process
@@ -85,11 +85,28 @@ Returns the average.
8585
**Examples**
8686

8787
```javascript
88-
const avg = stoch.average([1, 2, 3]);
88+
const avg = stochastic.average([1, 2, 3]);
8989
```
9090

9191
Returns **[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)** average
9292

93+
### mode
94+
95+
Returns the mode.
96+
97+
**Parameters**
98+
99+
- `data`
100+
- `values` **[Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array)&lt;[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)>**
101+
102+
**Examples**
103+
104+
```javascript
105+
const mode = stochastic.mode([1, 2, 3]);
106+
```
107+
108+
Returns **[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)** mode
109+
93110
### std
94111

95112
Returns the standard deviation.
@@ -101,7 +118,7 @@ Returns the standard deviation.
101118
**Examples**
102119

103120
```javascript
104-
const std = stoch.std([2, 3, 4, 4, 4, 5, 6]);
121+
const std = stochastic.std([2, 3, 4, 4, 4, 5, 6]);
105122
```
106123

107124
Returns **[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)** standard deviation as positive number
@@ -117,7 +134,7 @@ Provides a summary of a set of data.
117134
**Examples**
118135

119136
```javascript
120-
const summary = stoch.summary([1, 2, 3]);
137+
const summary = stochastic.summary([1, 2, 3]);
121138
```
122139

123140
Returns **[object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)** R-like summary of values
@@ -136,11 +153,31 @@ Returns a mock data set that uses the same standard deviation and average.
136153
**Examples**
137154

138155
```javascript
139-
const mock = stoch.mock(stoch.norm(1, 1, 100));
156+
const mock = stochastic.mock(stochastic.norm(1, 1, 100));
140157
```
141158

142159
Returns **[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)** standard deviation as positive number
143160

161+
### rsn
162+
163+
Returns the Skew-Normal (SN) probability distribution.
164+
<http://azzalini.stat.unipd.it/SN/>
165+
166+
**Parameters**
167+
168+
- `n` **[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)**
169+
- `location` **[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)**
170+
- `scale` **[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)**
171+
- `shape` **[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)** 0 is the normal distribution (optional, default `/*: number */0`)
172+
173+
**Examples**
174+
175+
```javascript
176+
const rsn = stochastic.rsn(10000, 1.256269, 1.605681, 5);
177+
```
178+
179+
Returns **[Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array)&lt;[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)>** average
180+
144181
### norm
145182

146183
Returns an array with `num` normal random variables in a [normal distribution](http://en.wikipedia.org/wiki/Normal_distribution) of mean `mu` and standard deviation `sigma`.
@@ -152,11 +189,12 @@ Returns an array with `num` normal random variables in a [normal distribution](h
152189
- `mu` **[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)** the mean or expectation of the distribution (and also its median and mode) (optional, default `1`)
153190
- `sigma` **[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)** standard deviation as positive number (optional, default `0`)
154191
- `num` **[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)** a positive integer (optional, default `1`)
192+
- `xi`
155193

156194
**Examples**
157195

158196
```javascript
159-
const norm = stoch.norm(1, 1, 100);
197+
const norm = stochastic.norm(1, 1, 100);
160198
```
161199

162200
Returns **[Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array)&lt;[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)>** normal random values
@@ -178,7 +216,7 @@ Returns an array corresponding to the path of [Brownian motion](http://en.wikipe
178216
**Examples**
179217

180218
```javascript
181-
const brown = stoch.brown(1.0, -0.1, +0.1, 100, true);
219+
const brown = stochastic.brown(1.0, -0.1, +0.1, 100, true);
182220
```
183221

184222
Returns **[Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array)&lt;[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)>** Brownian motion path
@@ -201,7 +239,7 @@ Returns an array corresponding to the path of [geometric Brownian motion](http:/
201239
**Examples**
202240

203241
```javascript
204-
const GBM = stoch.GBM(1.0, -0.1, 0.1, 1.0, 100, true);
242+
const GBM = stochastic.GBM(1.0, -0.1, 0.1, 1.0, 100, true);
205243
```
206244

207245
Returns **[Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array)&lt;[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)>** geometric Brownian motion
@@ -217,12 +255,12 @@ Returns an array with the states at each step of the [discrete-time Markov Chain
217255
- `transMatrix` **[Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array)&lt;[Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array)&lt;[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)>>**
218256
- `steps` **[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)** (positive integer)
219257
- `start` **[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)**
220-
- `path` **[boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean)**
258+
- `path` **[boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** (optional, default `true`)
221259

222260
**Examples**
223261

224262
```javascript
225-
const DTMC = stoch.DTMC([[0,1,0],[0,0,1],[1,0,0]], 20, 0, true);
263+
const DTMC = stochastic.DTMC([[0,1,0],[0,0,1],[1,0,0]], 20, 0, true);
226264
```
227265

228266
Returns **[Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array)&lt;[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)>**
@@ -238,7 +276,7 @@ Returns the `transMatrix` for an array of mapped `states` to numerical values.
238276
**Examples**
239277

240278
```javascript
241-
const collate = stoch.collate([0,1,0,0,0,1,1,0,0]);
279+
const collate = stochastic.collate([0,1,0,0,0,1,1,0,0]);
242280
```
243281

244282
Returns **[Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array)&lt;[Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array)&lt;[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)>>** transMatrix
@@ -259,7 +297,7 @@ Returns an object with the {key:value} pair {time:state} at each step of the [co
259297
**Examples**
260298

261299
```javascript
262-
const CTMC = stoch.CTMC([[0,1,0],[0,0,1],[1,0,0]], 20, 0, true);
300+
const CTMC = stochastic.CTMC([[0,1,0],[0,0,1],[1,0,0]], 20, 0, true);
263301
```
264302

265303
Returns **[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)** Continuous-time Markov chain
@@ -276,7 +314,7 @@ Generates a random sample (with replacement) from array `arr` of observations. N
276314
**Examples**
277315

278316
```javascript
279-
const sample = stoch.sample([1,2,3,4,5], +10);
317+
const sample = stochastic.sample([1,2,3,4,5], +10);
280318
```
281319

282320
Returns **[Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array)&lt;[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)>** random sample
@@ -292,7 +330,7 @@ Generates an exponential random variable with rate parameter `lambda`.
292330
**Examples**
293331

294332
```javascript
295-
const exp = stoch.exp(20);
333+
const exp = stochastic.exp(20);
296334
```
297335

298336
Returns **[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)** variable
@@ -310,7 +348,7 @@ Generates a Pareto random variables with parameters `x_m` and `alpha`.
310348
**Examples**
311349

312350
```javascript
313-
const pareto = stoch.pareto(+20.0, -1.0);
351+
const pareto = stochastic.pareto(+20.0, -1.0);
314352
```
315353

316354
Returns **[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)** distribution
@@ -329,7 +367,7 @@ Generates a histogram object from an array of data. Keys denote the lower bound
329367
**Examples**
330368

331369
```javascript
332-
const hist = stoch.hist([1,1,1,1,2,3,3,4,4,4]);
370+
const hist = stochastic.hist([1,1,1,1,2,3,3,4,4,4]);
333371
```
334372

335373
Returns **[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)** histogram

examples/CTMC.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,16 @@
33
// CTMC(transMatrix, T, start, path)
44
import {plot} from 'plotter';
55

6-
import * as stoch from '../src/index';
6+
import * as stochastic from '../src/index';
77

88
// switch to state 2 90% of the time; otherwise even probablity of staying or leaving state 2
99
const transMatrixTwo = [
1010
[0.1, 0.9],
1111
[0.5, 0.5]
1212
];
1313

14-
// var CTMC = stoch.CTMC(transMatrixTwo, 20, 0, true);
15-
const CTMC = stoch.CTMC([[0,1,0],[0,0,1],[.5,.5,0]], 20, 0, true);
14+
// var CTMC = stochastic.CTMC(transMatrixTwo, 20, 0, true);
15+
const CTMC = stochastic.CTMC([[0,1,0],[0,0,1],[.5,.5,0]], 20, 0, true);
1616

1717
plot({
1818
data: {tick: CTMC},

examples/DTMC-biased-coin.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// Problem: Determine when a biased coin has been switched
2-
import * as stoch from '../src/index';
2+
import * as stochastic from '../src/index';
33

44
// Is the biased or fair coin used
55
const coinMode = [
@@ -9,7 +9,7 @@ const coinMode = [
99

1010
// Visualize the ground true for when a coin has been switch between fair and biased
1111
// Use 1000 as the base example
12-
const activeCoin = stoch.DTMC(coinMode, 1000, 0, true);
12+
const activeCoin = stochastic.DTMC(coinMode, 1000, 0, true);
1313
// console.log(activeCoin);
1414
const stateCoin = ['H', 'T'];
1515

examples/DTMC.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,17 @@
22

33
import {plot} from 'plotter';
44

5-
import * as stoch from '../src/index';
5+
import * as stochastic from '../src/index';
66

77
const transMatrixTwo = [
88
[0, 1, 0],
99
[0.4, 0.2, 0.4],
1010
[0, 1, 0]
1111
];
1212

13-
// var DTMC = stoch.DTMC([[0,1,0],[0,0,1],[1,0,0]], 20, 0, true);
14-
const DTMC = stoch.DTMC([[0,1,0],[0,0,1],[.5,.5,0]], 20, 0, true);
15-
// var DTMC = stoch.DTMC(transMatrixTwo, 20, 0, true);
13+
// var DTMC = stochastic.DTMC([[0,1,0],[0,0,1],[1,0,0]], 20, 0, true);
14+
const DTMC = stochastic.DTMC([[0,1,0],[0,0,1],[.5,.5,0]], 20, 0, true);
15+
// var DTMC = stochastic.DTMC(transMatrixTwo, 20, 0, true);
1616

1717
console.log(DTMC);
1818

examples/GBM.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
// GBM(S0, mu, sigma, T, steps, path)
22
import {plot} from 'plotter';
33

4-
import * as stoch from '../src/index';
4+
import * as stochastic from '../src/index';
55

6-
const GBM = stoch.GBM(1.0, -0.1, 0.1, 1.0, 100, true);
6+
const GBM = stochastic.GBM(1.0, -0.1, 0.1, 1.0, 100, true);
77

88
console.log(GBM);
99

examples/collate.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// Problem: Determine when a biased coin has been switched
2-
import * as stoch from '../src/index';
2+
import * as stochastic from '../src/index';
33

44
// http://www.lipsum.com/
55
const lorem = 'Interdum et malesuada fames ac ante ipsum primis in faucibus. Donec cursus velit ut metus consequat, et consequat nisl lobortis. Donec pellentesque scelerisque tincidunt. Quisque in arcu neque. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Maecenas aliquam ullamcorper mi porta facilisis. Morbi molestie lacus nisi, sit amet sodales mauris suscipit quis. Quisque congue faucibus orci, fermentum dapibus diam auctor et. Curabitur dictum bibendum nisl nec facilisis. Aliquam et pellentesque nisi. Fusce sollicitudin porttitor purus vel pellentesque. Nullam maximus pulvinar massa, et scelerisque nibh bibendum sit amet. Pellentesque vestibulum ultricies felis eu auctor. Maecenas vitae enim a nulla sodales eleifend. Cras interdum augue eu varius tristique. Mauris feugiat semper magna, et tincidunt urna aliquet quis.';
@@ -44,8 +44,8 @@ const lookup = uniques
4444
const states = example
4545
.map((e, i, c) => lookup[e]);
4646

47-
const transMatrix = stoch.collate(states);
47+
const transMatrix = stochastic.collate(states);
4848
// console.log(transMatrix);
4949

50-
const dtmc = stoch.DTMC(transMatrix, 100, 0, true);
50+
const dtmc = stochastic.DTMC(transMatrix, 100, 0, true);
5151
console.log('Example:', dtmc.map((e, i, c) => uniques[e]).join(JOINER));

0 commit comments

Comments
 (0)