Skip to content

Commit

Permalink
feat: Add TypeScript definition
Browse files Browse the repository at this point in the history
  • Loading branch information
DenisCarriere authored and tmcw committed Oct 23, 2017
1 parent 0f86f28 commit 688538b
Show file tree
Hide file tree
Showing 74 changed files with 574 additions and 87 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Expand Up @@ -4,4 +4,5 @@ node_modules
docs/public/
.nyc_output
dist
test/types.js
types.js
*.types.js
112 changes: 56 additions & 56 deletions index.d.ts
Expand Up @@ -2,45 +2,45 @@
//
// A simple, literate statistics system.

// // Linear Regression
// export { default as linearRegression } from './src/linear_regression';
// export { default as linearRegressionLine } from './src/linear_regression_line';
// export { default as standardDeviation } from './src/standard_deviation';
// export { default as rSquared } from './src/r_squared';
// export { default as mode } from './src/mode';
// export { default as modeFast } from './src/mode_fast';
// export { default as modeSorted } from './src/mode_sorted';
// export { default as min } from './src/min';
// export { default as max } from './src/max';
// export { default as minSorted } from './src/min_sorted';
// export { default as maxSorted } from './src/max_sorted';
// export { default as sum } from './src/sum';
// export { default as sumSimple } from './src/sum_simple';
// export { default as product } from './src/product';
// export { default as quantile } from './src/quantile';
// export { default as quantileSorted } from './src/quantile_sorted';
// export { default as interquartileRange, default as iqr } from './src/interquartile_range';
// export { default as medianAbsoluteDeviation, default as mad } from './src/median_absolute_deviation';
// Linear Regression
export { default as linearRegression } from './src/linear_regression';
export { default as linearRegressionLine } from './src/linear_regression_line';
export { default as standardDeviation } from './src/standard_deviation';
export { default as rSquared } from './src/r_squared';
export { default as mode } from './src/mode';
export { default as modeFast } from './src/mode_fast';
export { default as modeSorted } from './src/mode_sorted';
export { default as min } from './src/min';
export { default as max } from './src/max';
export { default as minSorted } from './src/min_sorted';
export { default as maxSorted } from './src/max_sorted';
export { default as sum } from './src/sum';
export { default as sumSimple } from './src/sum_simple';
export { default as product } from './src/product';
export { default as quantile } from './src/quantile';
export { default as quantileSorted } from './src/quantile_sorted';
export { default as interquartileRange, default as iqr } from './src/interquartile_range';
export { default as medianAbsoluteDeviation, default as mad } from './src/median_absolute_deviation';
export { default as chunk } from './src/chunk';
// export { default as sampleWithReplacement } from './src/sample_with_replacement';
// export { default as shuffle } from './src/shuffle';
// export { default as shuffleInPlace } from './src/shuffle_in_place';
// export { default as sample } from './src/sample';
export { default as sampleWithReplacement } from './src/sample_with_replacement';
export { default as shuffle } from './src/shuffle';
export { default as shuffleInPlace } from './src/shuffle_in_place';
export { default as sample } from './src/sample';
export { default as ckmeans } from './src/ckmeans';
// export { default as uniqueCountSorted } from './src/unique_count_sorted';
// export { default as sumNthPowerDeviations } from './src/sum_nth_power_deviations';
// export { default as equalIntervalBreaks } from './src/equal_interval_breaks';
export { default as uniqueCountSorted } from './src/unique_count_sorted';
export { default as sumNthPowerDeviations } from './src/sum_nth_power_deviations';
export { default as equalIntervalBreaks } from './src/equal_interval_breaks';

// // sample statistics
// export { default as sampleCovariance } from './src/sample_covariance';
// export { default as sampleCorrelation } from './src/sample_correlation';
// export { default as sampleVariance } from './src/sample_variance';
// export { default as sampleStandardDeviation } from './src/sample_standard_deviation';
// export { default as sampleSkewness } from './src/sample_skewness';
// export { default as sampleKurtosis } from './src/sample_kurtosis';
// sample statistics
export { default as sampleCovariance } from './src/sample_covariance';
export { default as sampleCorrelation } from './src/sample_correlation';
export { default as sampleVariance } from './src/sample_variance';
export { default as sampleStandardDeviation } from './src/sample_standard_deviation';
export { default as sampleSkewness } from './src/sample_skewness';
export { default as sampleKurtosis } from './src/sample_kurtosis';

// // combinatorics
// export { default as permutationsHeap } from './src/permutations_heap';
// combinatorics
export { default as permutationsHeap } from './src/permutations_heap';
export { default as combinations } from './src/combinations';
export { default as combinationsReplacement } from './src/combinations_replacement';

Expand All @@ -55,38 +55,38 @@ export { default as median } from './src/median';
export { default as medianSorted } from './src/median_sorted';
export { default as subtractFromMean } from './src/subtract_from_mean';

// export { default as rootMeanSquare, default as rms } from './src/root_mean_square';
// export { default as variance } from './src/variance';
// export { default as tTest } from './src/t_test';
// export { default as tTestTwoSample } from './src/t_test_two_sample';
// // ss.jenks = require('./src/jenks');
export { default as rootMeanSquare, default as rms } from './src/root_mean_square';
export { default as variance } from './src/variance';
export { default as tTest } from './src/t_test';
export { default as tTestTwoSample } from './src/t_test_two_sample';
// ss.jenks = require('./src/jenks');

// // Classifiers
export { default as BayesianClassifier, default as bayesian } from './src/bayesian_classifier';
// export { default as PerceptronModel, default as perceptron } from './src/perceptron';
export { default as PerceptronModel, default as perceptron } from './src/perceptron';

// // Distribution-related methods
// export { default as epsilon } from './src/epsilon'; // We make ε available to the test suite.
// export { default as factorial } from './src/factorial';
// Distribution-related methods
export { default as epsilon } from './src/epsilon'; // We make ε available to the test suite.
export { default as factorial } from './src/factorial';
export { default as bernoulliDistribution } from './src/bernoulli_distribution';
export { default as binomialDistribution } from './src/binomial_distribution';
export { default as poissonDistribution } from './src/poisson_distribution';
export { default as chiSquaredDistributionTable } from './src/chi_squared_distribution_table';
export { default as chiSquaredGoodnessOfFit } from './src/chi_squared_goodness_of_fit';
// export { default as kernelDensityEstimation } from './src/kernel_density_estimation';
export { default as kernelDensityEstimation, default as kde } from './src/kernel_density_estimation';

// // Normal distribution
// export { default as zScore } from './src/z_score';
// export { default as cumulativeStdNormalProbability } from './src/cumulative_std_normal_probability';
// export { default as standardNormalTable } from './src/standard_normal_table';
// export { default as errorFunction, default as erf } from './src/error_function';
// export { default as inverseErrorFunction } from './src/inverse_error_function';
// export { default as probit } from './src/probit';
// Normal distribution
export { default as zScore } from './src/z_score';
export { default as cumulativeStdNormalProbability } from './src/cumulative_std_normal_probability';
export { default as standardNormalTable } from './src/standard_normal_table';
export { default as errorFunction, default as erf } from './src/error_function';
export { default as inverseErrorFunction } from './src/inverse_error_function';
export { default as probit } from './src/probit';

// Root-finding methods
export { default as bisect } from './src/bisect';

// // Utils
// export { default as quickselect } from './src/quickselect';
// export { default as sign } from './src/sign';
// export { default as numericSort } from './src/numeric_sort';
// Utils
export { default as quickselect } from './src/quickselect';
export { default as sign } from './src/sign';
export { default as numericSort } from './src/numeric_sort';
2 changes: 1 addition & 1 deletion index.js
Expand Up @@ -75,7 +75,7 @@ export { default as binomialDistribution } from './src/binomial_distribution';
export { default as poissonDistribution } from './src/poisson_distribution';
export { default as chiSquaredDistributionTable } from './src/chi_squared_distribution_table';
export { default as chiSquaredGoodnessOfFit } from './src/chi_squared_goodness_of_fit';
export { default as kernelDensityEstimation } from './src/kernel_density_estimation';
export { default as kernelDensityEstimation, default as kde } from './src/kernel_density_estimation';

// Normal distribution
export { default as zScore } from './src/z_score';
Expand Down
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -34,7 +34,7 @@
"scripts": {
"release": "standard-version && sh ./scripts/update_website.sh",
"pretest": "npm run build",
"test": "npm run lint && tap --coverage test/*.js && npm run jsdoctest",
"test": "npm run lint && tap --coverage test/*.test.js && npm run jsdoctest",
"build": "rm -rf dist && mkdir dist && rollup -c",
"prepublish": "npm run build && ./scripts/update_readme.js",
"prelint": "are-we-flow-yet src && flow check src && tsc",
Expand Down
2 changes: 1 addition & 1 deletion src/combinations.js
Expand Up @@ -8,7 +8,7 @@
* @param {int} k the number of objects in each group (without replacement)
* @returns {Array<Array>} array of permutations
* @example
* ss.combinations([1, 2, 3], 2); // => [[1,2], [1,3], [2,3]]
* combinations([1, 2, 3], 2); // => [[1,2], [1,3], [2,3]]
*/

function combinations(
Expand Down
6 changes: 6 additions & 0 deletions src/cumulative_std_normal_probability.d.ts
@@ -0,0 +1,6 @@
/**
* https://simplestatistics.org/docs/#cumulativestdnormalprobability
*/
declare function cumulativeStdNormalProbability(z: number): number

export default cumulativeStdNormalProbability;
6 changes: 6 additions & 0 deletions src/epsilon.d.ts
@@ -0,0 +1,6 @@
/**
* https://simplestatistics.org/docs/#epsilon
*/
declare const epsilon: number;

export default epsilon;
9 changes: 9 additions & 0 deletions src/equal_interval_breaks.d.ts
@@ -0,0 +1,9 @@
/**
* https://simplestatistics.org/docs/#equalintervalbreaks
*/
declare function equalIntervalBreaks(
x: number[],
nClasses: number
): number[]

export default equalIntervalBreaks;
2 changes: 1 addition & 1 deletion src/equal_interval_breaks.js
Expand Up @@ -14,7 +14,7 @@ import min from './min';
* @param {number} nClasses number of desired classes
* @returns {Array<number>} array of class break positions
* @example
* equalIntervalBreaks([1, 2, 3, 4, 5, 6], 4); //= [1, 2.25, 3.5, 4.75, 6]
* equalIntervalBreaks([1, 2, 3, 4, 5, 6], 4); // => [1, 2.25, 3.5, 4.75, 6]
*/
function equalIntervalBreaks(x/*: Array<number> */, nClasses/*:number*/)/*: Array<number> */ {

Expand Down
8 changes: 8 additions & 0 deletions src/error_function.d.ts
@@ -0,0 +1,8 @@
/**
* https://simplestatistics.org/docs/#errorfunction
*/
declare function errorFunction(
x: number
): number

export default errorFunction;
6 changes: 6 additions & 0 deletions src/factorial.d.ts
@@ -0,0 +1,6 @@
/**
* https://simplestatistics.org/docs/#factorial
*/
declare function factorial(n: number): number

export default factorial;
2 changes: 1 addition & 1 deletion src/geometric_mean.js
Expand Up @@ -22,7 +22,7 @@
* @throws {Error} if x contains a negative number
* @example
* var growthRates = [1.80, 1.166666, 1.428571];
* var averageGrowth = geometricMean(growthRates);
* var averageGrowth = ss.geometricMean(growthRates);
* var averageGrowthRates = [averageGrowth, averageGrowth, averageGrowth];
* var startingValue = 10;
* var startingValueMean = 10;
Expand Down
8 changes: 8 additions & 0 deletions src/interquartile_range.d.ts
@@ -0,0 +1,8 @@
/**
* https://simplestatistics.org/docs/#interquartilerange
*/
declare function interquartileRange(
x: number[]
): number

export default interquartileRange;
8 changes: 8 additions & 0 deletions src/inverse_error_function.d.ts
@@ -0,0 +1,8 @@
/**
* https://simplestatistics.org/docs/#inverseerrorfunction
*/
declare function inverseErrorFunction(
x: number
): number

export default inverseErrorFunction;
13 changes: 13 additions & 0 deletions src/kernel_density_estimation.d.ts
@@ -0,0 +1,13 @@
export type Kernels = 'gaussian'
export type BandwidthMethods = 'nrd'

/**
* https://simplestatistics.org/docs/#kde
*/
declare function kernelDensityEstimation(
X: number[],
kernel?: Kernels | ((u: number) => number),
bandwidthMethod?: BandwidthMethods | number
): (x: number) => number;

export default kernelDensityEstimation;
6 changes: 3 additions & 3 deletions src/kernel_density_estimation.js
Expand Up @@ -46,13 +46,13 @@ var bandwidthMethods /*: {[string]: (Array<number>) => number} */ = {
* is a useful tool for, among other things, estimating the shape of the
* underlying probability distribution from a sample.
*
* @name kde
* @name kernelDensityEstimation
* @param X sample values
* @param kernel The kernel function to use. If a function is provided, it should return non-negative values and integrate to 1. Defaults to 'gaussian'.
* @param bandwidthMethod The "bandwidth selection" method to use, or a fixed bandwidth value. Defaults to "nrd", the commonly-used ["normal reference distribution" rule-of-thumb](https://stat.ethz.ch/R-manual/R-devel/library/MASS/html/bandwidth.nrd.html).
* @returns {Function} An estimated [probability density function](https://en.wikipedia.org/wiki/Probability_density_function) for the given sample. The returned function runs in `O(X.length)`.
*/
function kde(
function kernelDensityEstimation(
X /*: Array<number> */,
kernel /*: $Keys<typeof kernels> | ((number) => number) | void*/,
bandwidthMethod /*: $Keys<typeof bandwidthMethods> | number | void*/
Expand Down Expand Up @@ -91,4 +91,4 @@ function kde(
}
}

export default kde;
export default kernelDensityEstimation;
8 changes: 8 additions & 0 deletions src/linear_regression.d.ts
@@ -0,0 +1,8 @@
/**
* https://simplestatistics.org/docs/#linearregression
*/
declare function linearRegression(
data: number[][]
): { m: number, b: number }

export default linearRegression;
8 changes: 8 additions & 0 deletions src/linear_regression_line.d.ts
@@ -0,0 +1,8 @@
/**
* https://simplestatistics.org/docs/#linearregressionline
*/
declare function linearRegressionLine(
mb: {b: number, m: number}
): (x: number) => number;

export default linearRegressionLine;
8 changes: 8 additions & 0 deletions src/max.d.ts
@@ -0,0 +1,8 @@
/**
* https://simplestatistics.org/docs/#max
*/
declare function max(
x: number[]
): number

export default max;
8 changes: 8 additions & 0 deletions src/max_sorted.d.ts
@@ -0,0 +1,8 @@
/**
* https://simplestatistics.org/docs/#maxsorted
*/
declare function maxSorted(
x: number[]
): number

export default maxSorted;
8 changes: 8 additions & 0 deletions src/median_absolute_deviation.d.ts
@@ -0,0 +1,8 @@
/**
* https://simplestatistics.org/docs/#medianabsolutedeviation
*/
declare function medianAbsoluteDeviation(
x: number[]
): number

export default medianAbsoluteDeviation;
2 changes: 1 addition & 1 deletion src/median_absolute_deviation.js
Expand Up @@ -12,7 +12,7 @@ import median from './median';
* @example
* medianAbsoluteDeviation([1, 1, 2, 2, 4, 6, 9]); // => 1
*/
function medianAbsoluteDeviation(x /*: Array<number> */) {
function medianAbsoluteDeviation(x/*: Array<number> */)/*: number */ {
// The mad of nothing is null
var medianValue = median(x),
medianAbsoluteDeviations = [];
Expand Down
8 changes: 8 additions & 0 deletions src/min.d.ts
@@ -0,0 +1,8 @@
/**
* https://simplestatistics.org/docs/#min
*/
declare function min(
x: number[]
): number

export default min;
8 changes: 8 additions & 0 deletions src/min_sorted.d.ts
@@ -0,0 +1,8 @@
/**
* https://simplestatistics.org/docs/#minsorted
*/
declare function minSorted(
x: number[]
): number

export default minSorted;
8 changes: 8 additions & 0 deletions src/mode.d.ts
@@ -0,0 +1,8 @@
/**
* https://simplestatistics.org/docs/#mode
*/
declare function mode(
x: number[]
): number

export default mode;
8 changes: 8 additions & 0 deletions src/mode_fast.d.ts
@@ -0,0 +1,8 @@
/**
* https://simplestatistics.org/docs/#modefast
*/
declare function modeFast<T extends any>(
x: T[]
): T

export default modeFast;
8 changes: 8 additions & 0 deletions src/mode_sorted.d.ts
@@ -0,0 +1,8 @@
/**
* https://simplestatistics.org/docs/#modesorted
*/
declare function modeSorted(
sorted: number[]
): number

export default modeSorted;
8 changes: 8 additions & 0 deletions src/numeric_sort.d.ts
@@ -0,0 +1,8 @@
/**
* https://simplestatistics.org/docs/#numericsort
*/
declare function numericSort(
x: number[]
): number[]

export default numericSort;

0 comments on commit 688538b

Please sign in to comment.