probability

A set of tools that probably help out with probability

``npm install probability``

node-probability

A set of tools that probably help out with probability.

overview

This is a general tool box for discrete probability theory. It is capable of handling complex numbers or just plain sequences of numbers. Numbers are represented in one of two ways:

``````// the normal way to have a sequence of numbers
x = [0, 1, 2, 3, ...];
// a simple way to use complex numbers
y = {
// real part
real: [0, 1, 2, ...],
// imaginary part
img: [3, 4, 5, ...]
}
``````

Functions will always return numbers in the second format since most operations will involve some sort of complex math. There are several utility functions included to help restore these objects to traditional arrays.

methods

``````var prob = require('probability');
``````

FFT

fft

Takes the fft of a given signal. Will zero-pad the signal to the next power of two.

``````// fft of a real valued signal
X = prob.fft([0, 1, 2, 3]);
// fft of a complex valued signal with real and imaginary parts
// NOTE: arrays must be equal length
Y = prob.fft([0, 1, 2, 3], [4, 5, 6, 7]);
// fft of a complexvalued signal
Z = prob.fft({
real: [0, 1, 2, 3],
img: [4, 5, 6, 7]
});
`
``````

ifft

Takes the ifft of a given signal. Has the same input format as `prob.fft`, but referenced as `prob.ifft`.

Moments

expectation / E

Calculates the expectation of a given input

``````// two ways to call the method
m = prob.expectation(x);
m = prob.E(x);

// you can also set the index of the 0th element of x
// i.e. this will calculate the expectation as if x[0] corresponds to time t = -10
m = prob.expectation(x, -10);
``````

variance / VAR

Calculates the variance of an input in a similar way to expectation

``````// two ways to call the method
sigma = prob.variance(x);
sigma = prob.VAR(x);

// you can also set the index of the 0th element of x
sigma = prob.VAR(x, -10);
``````

moment

Calculates the nth moment of x

``````// calculate the 3th moment
skew = prob.moment(x, 3);

// you can also set the index of the 0th element of x
skew = prob.expectation(x, 3, -10);
``````

lotus

Calculate E[g(x)] for a provided function g.

``````prob.lotus(x, function(val, i, x) {
// val is current value for processing
// i is the index of the value
// x is the original array (val = x[i])

// ... do some math here ...

// you must return a single number
return newVal;
});
``````

Convolution

convolution / conv

Performs a convolution of two signals

``````y = prob.convolution(x, h);
y = prob.conv(x, h);
``````

correlation / R

Calculates the correlation of two signals. If only one input is given, then the autocorrelation is returned.

``````Rxy = prob.correlation(x, y);
Rx = prob.R(x);
``````

spectralDensity / S

Calculates the spectral density of one of two signals.

``````Sxy = prob.spectralDensity(x, y);
Sx = prob.S(x);
``````

Complex

``````z = prob.complex.add(x, y);
``````

complex.mul

Multiplies two complex vectors

``````z = prob.complex.mul(x, y);
``````

complex.magnitude

Returns |x|

``````y = prob.complex.magnitude(x);
``````

todo

Need to create basic tests that verify that these methods match up with something like Matlab.

history

0.0.1: Initial release with no tests