1.1.1 • Published 4 years ago

pan-node v1.1.1

Weekly downloads
10
License
ISC
Repository
github
Last release
4 years ago

pan-node

A Statistics and Linear Algebra Library

Installation

npm install pan-node --save

Tests

npm run test

Contributing

Add unit tests for any new or changed functionality. Lint and test your code.

Release History

  • 0.1.0 Initial release
  • 0.2.0 Bug Fixes And Test update
  • 0.3.0 Updated Statistics and Linear Algebra library
  • 1.0.0 Updated Syntax to current standard
  • 1.1.1 Bug Fixes and Documentation Update

Documentation

Usage Example: (pan-node.mean)

const pan = require("pan-node");
const arrays = [1, 2, 3, 4, 5, 6, 7, 8, 9];
pan.mean(arrays);

Statistics:

pan-node.mergeSort(array) - Divide and Conquer algorithm for sorting numerical elements in an array

By: Tim Han: https://medium.com/javascript-in-plain-english/javascript-merge-sort-3205891ac060
const pan = require("pan-node");
const myData = [1,6,2,4,9,8];
pan.mergeSort(myData); // returns [1,2,4,6,8,9];

pan-node.mean(array) - Find the average number in an array

const pan = require("pan-node");
const myData = [1,6,2,4,9,8,10];
pan.mean(myData); // returns 5.714;

pan-node.median(sortedArray) - The middle number in an array

const pan = require("pan-node");
const myData = [1,6,2,4,9,8,10];
const sortedData = pan.mergeSort(myData);
pan.median(sortedData); // returns 6;

pan-node.mode(array) - The most listed element in an array

const pan = require("pan-node");
const modeArray = [1,6,2,4,9,6,8,10];
pan.mode(modeArray); // returns 6;

pan-node.dataRange(array) - Geting the data range of an array by subtracting the lowest element from the highest element in the array

const pan = require("pan-node");
const modeArray = [1,6,2,4,9,6,8,10];
pan.dataRange(modeArray); // returns 9;

pan-node.iqrRange(array) - Interquartile Range of an array: The middle 50% of values when ordered from lowest to highest. (mergeSort() is used already in this algorithm. sorting your data before hand may be redundent when using this algorithm)

const pan = require("pan-node");
let khanArray1 = [4,4,10,11,15,7,14,12,6];
let khanArray2 = [7,9,9,10,10,10,11,12,12,14];
pan.iqrRange(khanArray1); // returns 8
pan.iqrRange(khanArray2); // returns 3

pan-node.sampleVariance(array) - Calculate how varied a sample Dataset is.

const pan = require("pan-node");
let khanArray1 = [4,4,10,11,15,7,14,12,6];
pan.sampleVariance(khanArray1); // 15.28

pan-node.standardDeviation(array) - Measures the dispersion of a dataset relative to its mean and is calculated as the square root of the variance

const pan = require("pan-node");
let khanArray1 = [4,4,10,11,15,7,14,12,6];
pan.standardDeviation(khanArray1); // 3.90

pan-node.variance(array) - Measures how far each number in the set is from the mean and therefore from every other number in the array.

const pan = require("pan-node");
let khanArray1 = [4,4,10,11,15,7,14,12,6];
pan.variance(khanArray1); // 17.19

pan-node.coVariance(array, array2) - Measure of how much two random arrays vary together. It's similar to variance, but where variance tells you how a single array varies, coVariance() tells you how two arrays vary together.

const pan = require("pan-node");
let khanArray1 = [4,4,10,11,15,7,14,12,6];
let khanArray2 = [7,9,9,10,10,10,11,12,12,14];
pan.coVariance(khanArray1, khanArray2); // 17.19

pan-node.correlation(array1, array2) - Show whether and how strongly pairs of arrays are related (Arrays must be equal length) (1 is the strongest correlation 0.000 is the weakest correlation)

const pan = require("pan-node");
let khanArray1 = [4,4,10,11,15,7,14,12,6];
let khanArray3 = [7,9,9,10,10,10,11,12,12];
pan.correlation(khanArray1, khanArray3); // 0.514

Linear Algebra (Vectors / Matrix / Arrays):

pan-node.getShape(matrix) - Get the rows and columns count of a mtrix

const pan = require("pan-node");
let myMatrix = [[1,2,3], [4,5,6]];
pan.getShape(myMatrix); // [2,3]

pan-node.getRow(matrix, row) - Get a specific row of a matrix

const pan = require("pan-node");
let myMatrix = [[1,2,3], [4,5,6]];
pan.getRow(myMatrix, 0); // [1,2,3]

pan-node.getColumn(matrix, column) - Get a specific column of a matrix

const pan = require("pan-node");
let myMatrix = [[1,2,3], [4,5,6]];
pan.getcolumn(myMatrix, 0); // [1,4]

pan-node.add(array1, array2) - Adds corresponding elements between two arrays

const pan = require("pan-node");
let add1 = [1,2,3];
let add2 = [4,5,6];
pan.add(add1, add2); // [5,7,9]

pan-node.subtract(array1, array2) - Subtracts corresponding vector elements between two arrays

const pan = require("pan-node");
let add1 = [1,2,3];
let add2 = [4,5,6];
pan.subtract(add1, add2); // [-3, -3, -3]

pan-node.dot(array1, array2) - Takes two equal-length sequences of numbers (usually coordinate vectors (arrays in this case)) and returns a single number. ...it is the product of the Euclidean magnitudes of the two vectors and the cosine of the angle between them.

const pan = require("pan-node");
let add1 = [1,2,3];
let add2 = [4,5,6];
pan.dot(add1, add2); // 32

pan-node.sumOfSquares(array) - Square all of the elements in a set and then taking the sum of those squares

const pan = require("pan-node");
let add1 = [1,2,3];
pan.dot(add1); // 14

pan-node.magnitude(array) - The length of the vector

const pan = require("pan-node");
let add1 = [1,2,3];
pan.magnitude(add1); // 3.74

pan-node.squaredDistance(array1, array2) -

const pan = require("pan-node");
let add1 = [1,2,3];
let add2 = [4,5,6];
pan.squaredDistance(add1, add2); // 27

pan-node.distance(array1, array2) -

const pan = require("pan-node");
let add1 = [1,2,3];
let add2 = [4,5,6];
pan.distance(add1, add2); // 5.19

pan-node.multiplyBy(array, number) - multiply a vector (array) by a scalar (Number)

const pan = require("pan-node");
let add1 = [1,2,3];
let add3 = 5;
pan.multiplyBy(add1, add3); // [5,10,15]

pan-node.deMean(array) -

const pan = require("pan-node");
let add1 = [1,2,3];
pan.deMean(add1); // [-1,0,1]
1.1.1

4 years ago

1.1.0

4 years ago

1.0.0

4 years ago

0.9.0

4 years ago

0.1.3

6 years ago

0.1.2

7 years ago

0.1.1

7 years ago

0.1.0

7 years ago