-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcore.html
506 lines (320 loc) · 16.1 KB
/
core.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Core - jStat Documentation</title>
<link rel="stylesheet" href="assets/style.css" />
<link rel="stylesheet" href="assets/sh.css" />
</head>
<body>
<div id="container">
<header>
<h1>jStat v1.9.3 Documentation</h1>
<div id="gtoc">
<p><a href="index.html">Index</a> | <a href="all.html">View on single page</a></p>
</div>
<hr />
</header>
<div id="toc"><h2>Table Of Contents</h2><ul><li><a href="#core_Functionality">Core Functionality</a><ul><li><a href="#jStat">jStat()</a></li><li><a href="#rows">rows()</a></li><li><a href="#rowa">rowa()</a></li><li><a href="#cols">cols()</a></li><li><a href="#cola">cola()</a></li><li><a href="#slice">slice()</a></li><li><a href="#sliceAssign">sliceAssign()</a></li><li><a href="#dimensions">dimensions()</a></li><li><a href="#row">row()</a></li><li><a href="#col">col()</a></li><li><a href="#diag">diag()</a></li><li><a href="#antidiag">antidiag()</a></li><li><a href="#diagonal">diagonal()</a></li><li><a href="#transpose">transpose()</a></li><li><a href="#map">map( func )</a></li><li><a href="#cumreduce">cumreduce( func )</a></li><li><a href="#alter">alter( func )</a></li><li><a href="#create">create()</a></li><li><a href="#zeros">zeros()</a></li><li><a href="#ones">ones()</a></li><li><a href="#rand">rand()</a></li><li><a href="#copy">copy()</a></li><li><a href="#identity">identity()</a></li><li><a href="#seq">seq()</a></li><li><a href="#arange">arange()</a></li><li><a href="#clear">clear()</a></li><li><a href="#symmetric">symmetric()</a></li></ul></li><li><a href="#jStat_Utility_Methods">jStat Utility Methods</a><ul><li><a href="#utils.calcRdx">utils.calcRdx( num0, num1 )</a></li><li><a href="#utils.isArray">utils.isArray( arg )</a></li><li><a href="#utils.isFunction">utils.isFunction( arg )</a></li><li><a href="#utils.isNumber">utils.isNumber( arg )</a></li></ul></li></ul><hr /></div>
<h2 id="core_Functionality">Core Functionality</h2>
<p>Core functionality include methods that generate and analyse vectors or matrices.</p>
<h3 id="jStat">jStat()</h3>
<p>The jStat object can function in several capacities, as demonstrated below.
In all cases, jStat will always return an instance of itself.</p>
<p><strong>jStat( array[, fn] )</strong></p>
<p>Creates a new jStat object from either an existing array or jStat object.
For example, create a new jStat matrix by doing the following:</p>
<pre><code>var matrix = jStat([[ 1, 2, 3 ],[ 4, 5, 6 ],[ 7, 8, 9 ]]);</code></pre>
<p>If an existing jStat object is passed as an argument then it will be cloned into a new object:</p>
<pre><code>var stat1 = jStat([[ 1, 2 ],[ 3, 4 ]]),
stat2 = jStat( stat1 );</code></pre>
<p>To transform the data on creation, pass a function as the final argument:</p>
<pre><code>jStat([[ 1, 2 ],[ 3, 4 ]], function( x ) {
return x * 2;
});</code></pre>
<p><strong>jStat( start, stop, count[, fn ])</strong></p>
<p>To create a sequence then pass numeric values in the same form <code>jStat.seq()</code> would be used:</p>
<pre><code>var vector = jStat( 0, 1, 5 );
// vector === [[ 0, 0.25, 0.5, 0.75, 1 ]]</code></pre>
<p>By passing a function the sequence value can be manipulated:</p>
<pre><code>var vector = jStat( 0, 1, 5, function( x ) {
return x * 2;
});
// vector === [[ 0, 0.5, 1, 1.5, 2 ]];</code></pre>
<p>The second argument passed to the function is the count (starting from 0).
Using this we can create a multidimensional array (useful for plotting data):</p>
<pre><code>var betaGraph = jStat( 0, 1, 11, function( x, cnt ) {
return [ jStat.beta.pdf( x, alpha, beta ), cnt ];
});</code></pre>
<p><strong>jStat()</strong></p>
<p>A chainable shortcut in the API exists to allow for filling in the data after object creation.
So creating <code>jStat</code> objects from methods like <code>rand()</code> can be accomplished in one of the following ways:</p>
<pre><code>// pass the generated random 3x3 matrix to jStat
jStat( jStat.rand( 3 ));
// or create an empty instance that is filled in afterwards
jStat().rand( 3 );</code></pre>
<h3 id="rows">rows()</h3>
<p>Returns the count of rows in a matrix.</p>
<p><strong>rows( array )</strong></p>
<pre><code>var matrix = [[1,2,3],[4,5,6]];
jStat.rows( matrix ) === 2;</code></pre>
<p><strong>fn.rows( [callback] )</strong></p>
<pre><code>jStat( matrix ).rows() === 2;</code></pre>
<p>Or pass a callback to run the calculation asynchronously and pass on the calculation.
This allows for continued chaining of methods to the jStat object.
Also note <code>this</code> within the callback refers to the calling jStat object.</p>
<pre><code>jStat( matrix ).rows(function( d ) {
// d === 2
});</code></pre>
<h3 id="rowa">rowa()</h3>
<p>Returns a array from matrix row.</p>
<pre><code>rowa([[1,2],[3,4]]) === [1,2];</code></pre>
<h3 id="cols">cols()</h3>
<p>Returns the number of columns in a matrix.</p>
<p><strong>cols( array )</strong></p>
<pre><code>var matrix = [[1,2,3],[4,5,6]];
jStat.cols( matrix ) === 3;</code></pre>
<p><strong>fn.cols( [callback] )</strong></p>
<pre><code>jStat( matrix ).cols() === 3;</code></pre>
<p>Or pass a callback to run the calculation asynchronously and pass on the calculation.
This allows for continued chaining of methods to the jStat object.
Also note <code>this</code> within the callback refers to the calling jStat object.</p>
<pre><code>jStat( matrix ).cols(function( d ) {
// d === 3
});</code></pre>
<h3 id="cola">cola()</h3>
<p>Returns an array from matrix column (<code>col()</code> will return a matrix form instead of an array form).</p>
<pre><code>cola([[1,2],[3,4]]) === [1,3];</code></pre>
<h3 id="slice">slice()</h3>
<p>Slices matrix as numpy style.</p>
<pre><code>A=[[1,2,3],[4,5,6],[7,8,9]];
slice(A,{row:{end:2},col:{start:1}}) === [[2,3],[5,6]];
slice(A,1,{start:1}) === [5,6];</code></pre>
<h3 id="sliceAssign">sliceAssign()</h3>
<p>Do slice assign as numpy style.</p>
<pre><code>A = [[1,2,3],[4,5,6],[7,8,9]];
sliceAssign(A,{row : {start : 1}, col : {start : 1}},[[0,0],[0,0]]);
A = [[1,2,3],[4,0,0],[7,0,0]];</code></pre>
<h3 id="dimensions">dimensions()</h3>
<p>Returns an object with the dimensions of a matrix.</p>
<p><strong>dimensions( array )</strong></p>
<pre><code>var matrix = [[1,2,3],[4,5,6]];
jStat.dimensions( matrix ) === { cols: 3, rows: 2 };</code></pre>
<p><strong>fn.dimensions( [callback] )</strong></p>
<pre><code>jStat( matrix ).dimensions() === { cols: 3, rows: 2 };</code></pre>
<p>Or pass a callback to run the calculation asynchronously and pass on the calculation.
This allows for continued chaining of methods to the jStat object.
Also note <code>this</code> within the callback refers to the calling jStat object.</p>
<pre><code>jStat( matrix ).dimensions(function( d ) {
// d === { cols: 3, rows: 2 }
});</code></pre>
<h3 id="row">row()</h3>
<p>Returns a specified row of a matrix.</p>
<p><strong>row( array, index )</strong></p>
<pre><code>var matrix = [[1,2,3],[4,5,6],[7,8,9]];
jStat.row( matrix, 0 ) === [1,2,3];
jStat.row( matrix, [0,1] ) === [[1,2,3],[4,5,6]]</code></pre>
<p><strong>fn.row( index[, callback] )</strong></p>
<pre><code>jStat( matrix ).row( 0 ) === jStat([1,2,3]);</code></pre>
<p>Or pass a callback to run the calculation asynchronously and pass on the calculation.
This allows for continued chaining of methods to the jStat object.
Also note <code>this</code> within the callback refers to the calling jStat object.</p>
<pre><code>jStat( matrix ).row( 0, function( d ) {
// d === jStat([1,2,3])
});</code></pre>
<h3 id="col">col()</h3>
<p>Returns the specified column as a column vector.</p>
<p><strong>col( index )</strong></p>
<pre><code>var matrix = [[1,2,3],[4,5,6],[7,8,9]];
jStat.col( matrix, 0 ) === [[1],[4],[7]];
jStat.col( matrix,[0,1] ) === [[1,2],[4,5],[7,8]]</code></pre>
<p><strong>fn.col( index[, callback] )</strong></p>
<pre><code>jStat( matrix ).col( 0 ) === jStat([[1],[4],[7]]);</code></pre>
<p>Or pass a callback to run the calculation asynchronously and pass on the calculation.
This allows for continued chaining of methods to the jStat object.
Also note <code>this</code> within the callback refers to the calling jStat object.</p>
<pre><code>jStat( matrix ).col( 0, function( d ) {
// d === jStat([[1],[3]])
})</code></pre>
<h3 id="diag">diag()</h3>
<p>Returns the diagonal of a matrix.</p>
<p><strong>diag( array )</strong></p>
<pre><code>var matrix = [[1,2,3],[4,5,6],[7,8,9]];
jStat.diag( matrix ) === [[1],[5],[9]];</code></pre>
<p><strong>fn.diag( [callback] )</strong></p>
<pre><code>jStat( matrix ).diag() === jStat([[1],[5],[9]]);</code></pre>
<p>Or pass a callback to run the calculation asynchronously and pass on the calculation.
This allows for continued chaining of methods to the jStat object.
Also note <code>this</code> within the callback refers to the calling jStat object.</p>
<pre><code>jStat( matrix ).diag(function( d ) {
// d === jStat([[1],[5],[9]])
});</code></pre>
<h3 id="antidiag">antidiag()</h3>
<p>Returns the anti-diagonal of the matrix.</p>
<p><strong>antidiag( array )</strong></p>
<pre><code>var matrix = [[1,2,3],[4,5,6],[7,8,9]];
jStat.antidiag( matrix ) === [[3],[5],[7]];</code></pre>
<p><strong>fn.antidiag( [callback] )</strong></p>
<pre><code>jStat( matrix ).antidiag() === jStat([[3],[5],[7]]);</code></pre>
<p>Or pass a callback to run the calculation asynchronously and pass on the calculation.
This allows for continued chaining of methods to the jStat object.
Also note <code>this</code> within the callback refers to the calling jStat object.</p>
<pre><code>jStat( matrix ).antidiag(function( d ) {
// d === jStat([[3],[5],[7]])
});</code></pre>
<h3 id="diagonal">diagonal()</h3>
<p>Creates a new diagonal matrix by given 1d diag array.</p>
<pre><code>jStat.diagonal([1,2,3]) === [[1,0,0],[0,2,0],[0,0,3]];</code></pre>
<h3 id="transpose">transpose()</h3>
<p>Transposes a matrix.</p>
<p><strong>transpose( array )</strong></p>
<pre><code>var matrix = [[1,2],[3,4]];
jStat.transpose( matrix ) === [[1,3],[2,4]];</code></pre>
<p><strong>fn.transpose( [callback] )</strong></p>
<pre><code>jStat( matrix ).transpose() === [[1,3],[2,4]];</code></pre>
<p>Or pass a callback to run the calculation asynchronously and pass on the calculation.
This allows for continued chaining of methods to the jStat object.
Also note <code>this</code> within the callback refers to the calling jStat object.</p>
<pre><code>jStat( matrix ).transpose(function( d ) {
// d === jStat([[1,3],[2,4]])
})</code></pre>
<h3 id="map">map( func )</h3>
<p>Maps a function to all values and return a new object.</p>
<p><strong>map( array, fn )</strong></p>
<pre><code>var matrix = [[1,2],[3,4]];
jStat.map( matrix, function( x ) {
return x * 2;
});
// returns [[2,4],[6,8]]</code></pre>
<p><strong>fn.map( fn )</strong></p>
<pre><code>jStat( matrix ).map(function( x ) {
return x * 2;
});</code></pre>
<h3 id="cumreduce">cumreduce( func )</h3>
<p>Cumulatively reduces values using a function and return a new object.</p>
<p><strong>cumreduce( array, fn )</strong></p>
<pre><code>var matrix = [[1,2],[3,4]];
jStat.cumreduce( matrix, function( a, b ) {
return a + b;
});
// returns [[1,3],[3,7]]</code></pre>
<p><strong>fn.cumreduce( fn )</strong></p>
<pre><code>jStat( matrix ).cumreduce(function( a, b ) {
return a + b;
});</code></pre>
<h3 id="alter">alter( func )</h3>
<p>Destructively maps to an array.</p>
<p><strong>alter( array, fn )</strong></p>
<pre><code>var matrix = [[1,2],[3,4]];
jStat.alter( matrix, function( x ) {
return x * 2;
});
// matrix === [[2,4],[6,8]]</code></pre>
<p><strong>fn.alter( fn )</strong></p>
<pre><code>var matrix = [[1,2],[3,4]];
jStat( matrix ).alter( function( x ) {
return x * 2;
});</code></pre>
<h3 id="create">create()</h3>
<p>Creates a row by col matrix using the supplied function.
If <code>col</code> is omitted then it will default to value <code>row</code>.</p>
<p><strong>create( row[, col], fn )</strong></p>
<pre><code>jStat.create( 2, function( row, col ) {
return row + col;
});
// returns [[0,1],[1,2]]</code></pre>
<p><strong>fn.create( row[, col], fn )</strong></p>
<p>Use this technique to create matrices in jStat instances.</p>
<pre><code>jStat().create( 2, function( row, col ) {
return row + col;
});
// returns jStat([[0,1],[1,2]])</code></pre>
<h3 id="zeros">zeros()</h3>
<p>Creates a row by col matrix of all zeros.
If <code>col</code> is omitted then it will default to value <code>row</code>.</p>
<p><strong>zeros( row[, col] )</strong></p>
<pre><code>jStat.zeros( 2 );
// returns [[0,0],[0,0]]</code></pre>
<p><strong>fn.zeros( row[, col] )</strong></p>
<p>Use this technique to create matrices in jStat instances.</p>
<pre><code>jStat().zeros( 2 );
// returns jStat([[0,0],[0,0]])</code></pre>
<h3 id="ones">ones()</h3>
<p>Creates a row by col matrix of all ones.
If <code>col</code> is omitted then it will default to value <code>row</code>.</p>
<p><strong>ones( row[, col] )</strong></p>
<pre><code>jStat.zeros( 2 );
// returns [[0,0],[0,0]]</code></pre>
<p><strong>fn.ones( row[, col] )</strong></p>
<p>Use this technique to create matrices in jStat instances.</p>
<pre><code>jStat().ones( 2 );
// returns jStat([[0,0],[0,0]])</code></pre>
<h3 id="rand">rand()</h3>
<p>Creates a matrix of normally distributed random numbers.
If <code>col</code> is omitted then it will default to value <code>row</code>.</p>
<p><strong>rand( row[, col] )</strong></p>
<pre><code>jStat.rand( 3 );</code></pre>
<p><strong>fn.rand( row[, col] )</strong></p>
<p>Use this technique to create matrices in jStat instances.</p>
<pre><code>jStat().rand( 3 );</code></pre>
<h3 id="copy">copy()</h3>
<p>Returns a copy of given matrix.</p>
<h3 id="identity">identity()</h3>
<p>Creates an identity matrix of row by col.
If <code>col</code> is omitted then it will default to value <code>row</code>.</p>
<p><strong>identity( row[, col] )</strong></p>
<pre><code>jStat.identity( 2 );
// returns [[1,0],[0,1]]</code></pre>
<p><strong>fn.identity( row[, col] )</strong></p>
<p>Use this technique to create matrices in jStat instances.</p>
<pre><code>jStat().identity( 2 );</code></pre>
<h3 id="seq">seq()</h3>
<p>Creates an arithmetic sequence by given length.</p>
<pre><code>jStat.seq(1,5,9) === [1, 1.5, 2, 2.5, 3, 3.5, 4, 4.5, 5];</code></pre>
<h3 id="arange">arange()</h3>
<p>Creates an arithmetic sequence by given step.</p>
<pre><code>arange(5) === [0,1,2,3,4]
arange(1,5) === [1,2,3,4]
arange(5,1,-1) === [5,4,3,2]</code></pre>
<h3 id="clear">clear()</h3>
<p>Sets all values in the vector or matrix to zero.</p>
<p><strong>clear( array )</strong></p>
<pre><code>var tmp = [1,2,3];
jStat.clear( tmp );
// tmp === [0,0,0]</code></pre>
<p><strong>fn.clear( [callback] )</strong></p>
<pre><code>jStat( 0, 1, 3 ).clear();
// returns [[0,0,0]]</code></pre>
<p>If a callback is passed then the original object is not altered.</p>
<pre><code>var obj = jStat( 0, 1, 3 );
obj.clear(function() {
// this === [ 0, 0, 0 ]
});
// obj === [ 0, 0.5, 1 ]</code></pre>
<h3 id="symmetric">symmetric()</h3>
<p>Tests if a matrix is symmetric.</p>
<p><strong>symmetric( array )</strong></p>
<pre><code>jStat.symmetric([[1,2],[2,1]]) === true</code></pre>
<p><strong>fn.symmetric( [callback] )</strong></p>
<pre><code>jStat([[1,2],[2,1]]).symmetric() === true</code></pre>
<p>Can pass a callback to maintain chainability.</p>
<pre><code>jStat([[1,2],[2,1]]).symmetric(function( result ) {
// result === true
});</code></pre>
<h2 id="jStat_Utility_Methods">jStat Utility Methods</h2>
<p>Utilities that are used throughout the jStat library.</p>
<h3 id="utils.calcRdx">utils.calcRdx( num0, num1 )</h3>
<p>Calculates the decimal shift for the IEEE 754 floating point calculation correction.</p>
<h3 id="utils.isArray">utils.isArray( arg )</h3>
<p>Tests if <code>arg</code> is an array.</p>
<h3 id="utils.isFunction">utils.isFunction( arg )</h3>
<p>Tests if <code>arg</code> is a function.</p>
<h3 id="utils.isNumber">utils.isNumber( arg )</h3>
<p>Tests if <code>arg</code> is a number and not <code>NaN</code>.</p>
</div>
<script src="assets/sh_main.js"></script>
<script src="assets/sh_javascript.min.js"></script>
<script src="//cdn.jsdelivr.net/npm/jstat@latest/dist/jstat.min.js"></script>
<script>highlight(undefined, undefined, 'pre');</script>
</body>
</html>