You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: doc/md/overview.md
+40-20Lines changed: 40 additions & 20 deletions
Original file line number
Diff line number
Diff line change
@@ -6,29 +6,49 @@ jStat is a statistical library written in JavaScript that allows you to perform
6
6
7
7
### Architecture
8
8
9
-
All functionality breaks into one of either static or instance methods. Static methods have been written to be as quick an simple as possible, which means they can be quite inflexible. They also work with native JavaScript data types (e.g. Array's). Static methods were written with other developers in mind. It provides as low-level access to the calculations engine as possible. This way developers can use jStat in their programs without causing a significant amount of overhead.
9
+
All methods that execute from the jStat prototype (instance methods) simply pass their parameters to the static method counterpart to do the actual calculation.
10
+
Here is a pseudo example of what is happening in `core.js`:
10
11
11
-
Instance methods work from first creating a jStat Object, then doing all calculations on that object. While the instance methods cannot perform the calculations as quickly as the static methods, the added flexibility allows for for easy statistical analysis on one or many data sets. They were created for those who will be using jStat for statistical analysis.
12
+
jStat.min = function( arr ) {
13
+
return Math.min.apply( null, arr );
14
+
}
12
15
13
-
Here is a simple example on the difference in usage between the static and instance methods:
`jStat.min` does the actual calculation on the array, while `jStat.prototype.min` is a wrapper to help work with the jStat object.
25
+
The reason for this approach is to allow for maxium flexibility to other developers who want to extend jStat, while allowing for easy creation of wrappers.
26
+
This way extending jStat requires minimal performance overhead and allows for more unique wrappers to be created.
21
27
22
-
Now say we want to do several operations on the vector (e.g. sum, min, max, and standard deviation). This can be accomplished using the static methods, but each will need to be called separately. By using the jStat object we can pass callback functions and chain the execution of each operation:
28
+
**Remember: Static methods always return native JavaScript types. Instance methods almost always return a jStat object.**
23
29
24
-
jObj.sum( function( val ) {
25
-
// val === sum
26
-
}).min( function( val ) {
27
-
// val === min
28
-
}).max( function( val ) {
29
-
// val === max
30
-
}).stdev( function( val ) {
31
-
// val === st. dev.
32
-
});
30
+
Here is a simple example on the difference in usage between the static and instance methods:
33
31
34
-
This method sets each calculation to be executed in an asynchronous queue. Very useful method of preventing blocking when working with large data sets.
32
+
var myVect = [2,6,4,7,2,7,4],
33
+
jObj = jStat( myVect );
34
+
35
+
// calculate the sum of the the vector
36
+
jStat.sum( myVect ) === 32;
37
+
jObj.sum() === 32;
38
+
39
+
Now say we want to do several operations on the vector (e.g. sum, min, max, and standard deviation).
40
+
This can be accomplished using the static methods, but each will need to be called separately.
41
+
By using the jStat object we can pass callback functions and chain the execution of each operation:
42
+
43
+
jObj.sum( function( val ) {
44
+
// val === sum
45
+
}).min( function( val ) {
46
+
// val === min
47
+
}).max( function( val ) {
48
+
// val === max
49
+
}).stdev( function( val ) {
50
+
// val === st. dev.
51
+
});
52
+
53
+
This method sets each calculation to be executed in an asynchronous queue.
54
+
Very useful method of preventing blocking when working with large data sets.
0 commit comments