From 3a5dcccaab6bfc5bd2b8a1eac0af84f62fac0082 Mon Sep 17 00:00:00 2001 From: Scott Cooper Date: Sun, 1 Jan 2017 17:34:25 -0800 Subject: [PATCH 1/3] add npm gaussian --- gaussian/gaussian-tests.ts | 14 ++++++++ gaussian/index.d.ts | 65 ++++++++++++++++++++++++++++++++++++++ gaussian/tsconfig.json | 19 +++++++++++ gaussian/tslint.json | 1 + 4 files changed, 99 insertions(+) create mode 100644 gaussian/gaussian-tests.ts create mode 100644 gaussian/index.d.ts create mode 100644 gaussian/tsconfig.json create mode 100644 gaussian/tslint.json diff --git a/gaussian/gaussian-tests.ts b/gaussian/gaussian-tests.ts new file mode 100644 index 0000000000..ecb733eab1 --- /dev/null +++ b/gaussian/gaussian-tests.ts @@ -0,0 +1,14 @@ +const d = gaussian(0, 1); +const _ = d.mean !== d.variance; +const __ = d.mean * d.standardDeviation; +d.pdf(-2); +d.cdf(-1.28155); +d.ppf(0.1); + +gaussian(0, 1).mul(gaussian(0, 1)); +gaussian(1, 1).mul(2); +gaussian(1, 1).add(gaussian(1, 2)); +gaussian(1, 1).sub(gaussian(1, 2)); +gaussian(1, 1).div(gaussian(1, 2)); +gaussian(1, 1).div(2); +gaussian(1, 1).scale(2); diff --git a/gaussian/index.d.ts b/gaussian/index.d.ts new file mode 100644 index 0000000000..1da491c0ed --- /dev/null +++ b/gaussian/index.d.ts @@ -0,0 +1,65 @@ +// Type definitions for gaussian 1.1.0 +// Project: https://github.com/errcw/gaussian +// Definitions by: Scott Cooper +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +declare function gaussian(mean: number, variance: number): gaussian.Gaussian; + +export = gaussian; +export as namespace gaussian; + +declare namespace gaussian { + export interface Gaussian { + /** + * the mean (μ) of the distribution + */ + mean: number; + /** + * the variance (σ^2) of the distribution + */ + variance: number; + /** + * the standard deviation (σ) of the distribution + */ + standardDeviation: number; + /** + * the probability density function, which describes the + * probability of a random variable taking on the value x + */ + pdf(x: number): number; + /** + * the cumulative distribution function, which describes the + * probability of a random variable falling in the interval (−∞, x] + */ + cdf(x: number): number; + /** + * the percent point function, the inverse of cdf + */ + ppf(x: number): number; + /** + * returns the product distribution of this and the given + * distribution; equivalent to scale(d) when d is a constant + */ + mul(x: number | Gaussian): number; + /** + * returns the quotient distribution of this and the given + * distribution; equivalent to scale(1/d) when d is a constant + */ + div(x: number | Gaussian): number; + /** + * returns the result of adding this and the given + * distribution's means and variances + */ + add(x: Gaussian): number; + /** + * returns the result of subtracting this and the given + * distribution's means and variances + */ + sub(x: Gaussian): number; + /** + * returns the result of scaling this distribution by the + * given constant + */ + scale(x: number): number; + } +} diff --git a/gaussian/tsconfig.json b/gaussian/tsconfig.json new file mode 100644 index 0000000000..e09dded027 --- /dev/null +++ b/gaussian/tsconfig.json @@ -0,0 +1,19 @@ +{ + "compilerOptions": { + "module": "commonjs", + "target": "es6", + "noImplicitAny": true, + "strictNullChecks": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "gaussian-tests.ts" + ] +} diff --git a/gaussian/tslint.json b/gaussian/tslint.json new file mode 100644 index 0000000000..377cc837d4 --- /dev/null +++ b/gaussian/tslint.json @@ -0,0 +1 @@ +{ "extends": "../tslint.json" } From 5ab553291508b349723e733f83c63dd2c9119cec Mon Sep 17 00:00:00 2001 From: Scott Cooper Date: Sun, 1 Jan 2017 17:39:29 -0800 Subject: [PATCH 2/3] use MAJOR.MINOR --- gaussian/gaussian-tests.ts | 4 ++-- gaussian/index.d.ts | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/gaussian/gaussian-tests.ts b/gaussian/gaussian-tests.ts index ecb733eab1..74c6cc714b 100644 --- a/gaussian/gaussian-tests.ts +++ b/gaussian/gaussian-tests.ts @@ -1,6 +1,6 @@ const d = gaussian(0, 1); -const _ = d.mean !== d.variance; -const __ = d.mean * d.standardDeviation; +const a = d.mean !== d.variance; +const b = d.mean * d.standardDeviation; d.pdf(-2); d.cdf(-1.28155); d.ppf(0.1); diff --git a/gaussian/index.d.ts b/gaussian/index.d.ts index 1da491c0ed..f0012597cb 100644 --- a/gaussian/index.d.ts +++ b/gaussian/index.d.ts @@ -1,4 +1,4 @@ -// Type definitions for gaussian 1.1.0 +// Type definitions for gaussian 1.1 // Project: https://github.com/errcw/gaussian // Definitions by: Scott Cooper // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped From a785cc706516e662c43ce71ed0307ee7451ed078 Mon Sep 17 00:00:00 2001 From: Scott Cooper Date: Sun, 1 Jan 2017 17:52:12 -0800 Subject: [PATCH 3/3] add no implicit this and import statement to tests --- gaussian/gaussian-tests.ts | 2 ++ gaussian/tsconfig.json | 1 + 2 files changed, 3 insertions(+) diff --git a/gaussian/gaussian-tests.ts b/gaussian/gaussian-tests.ts index 74c6cc714b..bd2a226e88 100644 --- a/gaussian/gaussian-tests.ts +++ b/gaussian/gaussian-tests.ts @@ -1,3 +1,5 @@ +import * as gaussian from "."; + const d = gaussian(0, 1); const a = d.mean !== d.variance; const b = d.mean * d.standardDeviation; diff --git a/gaussian/tsconfig.json b/gaussian/tsconfig.json index e09dded027..f76c6bacc2 100644 --- a/gaussian/tsconfig.json +++ b/gaussian/tsconfig.json @@ -3,6 +3,7 @@ "module": "commonjs", "target": "es6", "noImplicitAny": true, + "noImplicitThis": true, "strictNullChecks": true, "baseUrl": "../", "typeRoots": [