UNPKG

ts-math

Version:

A collection of math functions and packages written in Typescript

119 lines (118 loc) 4.38 kB
export declare const sqr: (x: number) => number; export declare function sum(xs: number[]): number; export declare function mean(xs: number[]): number; /** * Calculates the standard deviation of samples in the input array * ``` * \operatorname{stdev}(x)=\sqrt{\frac{\sum{x^2}-\frac{\sum{x}}{n}}{n-1}} * ``` */ export declare function stdev(xs: number[]): number; /** * The corr function returns the correlation coefficient of two * ``` * \operatorname{corr}(x,y)=\frac{n\sum{xy}-\sum{x}\sum{y}}{\sqrt{(n\sum{x^2}-(\sum{x})^2)(n\sum{y^2}-(\sum{y})^2)}} * ``` */ export declare function corr(xs: number[], ys: number[]): number; /** * The cov function calculates the covariance between the two arrays. * ``` * \operatorname{cov}(x,y)=\frac{\sum{xy}-\frac{\sum{x}\sum{y}}{n}}{n-1} * ``` */ export declare function cov(xs: number[], ys: number[]): number; /** * In probability theory and statistics, skewness is a measure of the asymmetry of the probability distribution of a real-valued random * variable about its mean. */ export declare function skew(xs: number[]): number; /** * In probability theory and statistics, kurtosis (from Greek: κυρτός, kyrtos or kurtos, meaning "curved, arching") is a measure of the * "tailedness" of the probability distribution of a real-valued random variable. */ export declare function kurtosis(xs: number[]): number; /** * erf is the "error function" encountered in integrating the normal distribution (which is a normalized form of the Gaussian function). * It is an entire function defined by * ``` * \operatorname{erf}(z) = \frac{2}{\sqrt{\pi}}\int_{0}^z e^{-t^2}dt * ``` */ export declare function erf(z: number): number; /** * The complementary error function */ export declare function erfc(x: number): number; /** * Inverse complementary error function */ export declare function erfcinv(p: number): number; /** * Normal inverse cumulative distribution function * @param {Number} p Probability * @param {Number} mu Mean * @param {Number} sigma Standard deviation */ export declare function normalInv(p: number, mu: number, sigma: number): number; /** * Normal cumulative distribution function * @param {*} x Value * @param {*} mu Mean * @param {*} sigma Standard deviation */ export declare function normalCdf(x: number, mu: number, sigma: number): number; /** * Function that returns the q-th quantile of a dataset (same as numpy.quantile in Python) */ export declare function quantile(xs: number[], q: number): number; /** * Rounds with decimals. It should round away from zero, therefore it rounds absolute amount. It also adds a small amount to avoid * midpoint rounding issues, like 0.4999999999 should round to 1 */ export declare function round(x: number, decimals: number): number; /** * Generates an array of numbers. Values are set to 0 up to n-1, incrementing by 1. * @param n The numbers of array items. * @returns array of numbers */ export declare function range(n: number): number[]; /** * Returns the index of the highest element that is lower or equal to t. The input array must be ordered in ascending order. * @param t * @param vs * @returns */ export declare function indexOf(t: number, vs: number[]): number; /** * Linear regression of xs-values against ys-values. Weighted by ws-values (if included). * @param xs * @param ys * @param ws * @returns */ export declare function linearRegression(xs: number[], ys: number[], ws?: number[] | null): { k: number; b: number; error: number; }; /** * Assumes the vs-values are normally distributed, adds them to a QQ-plot and estimates the mean, stdev by linear regression in the plot. * The values in the QQ-plot can be centrally weighted (useful if data can contain anomalies or non-normally extreme jumps). * @param vs * @param centrallyWeighted true or false * @returns */ export declare function qqRegression(vs: number[], centrallyWeighted?: boolean): { stdev: number; mean: number; error: number; }; /** * Polynomial regression. Estimates the coefficients of the polynomial expression the fits the xs and ys-values. Weighted by ws-values (if included). * @param xs x-values * @param ys y-values * @param ws weights * @returns coefficients array */ export declare function polynomialRegression(xs: number[], ys: number[], ws: number[] | null, n: number): number[];