From 2d5bc81771eee41c60550765166af74018997771 Mon Sep 17 00:00:00 2001 From: Marco Lanaro Date: Mon, 31 Dec 2018 18:29:48 +0000 Subject: [PATCH] Add types for distributions (#31472) * Add types for distributions * Fix import --- types/distributions/distributions-tests.ts | 17 +++++++++++++++ types/distributions/index.d.ts | 18 ++++++++++++++++ types/distributions/tsconfig.json | 24 ++++++++++++++++++++++ types/distributions/tslint.json | 1 + 4 files changed, 60 insertions(+) create mode 100644 types/distributions/distributions-tests.ts create mode 100644 types/distributions/index.d.ts create mode 100644 types/distributions/tsconfig.json create mode 100644 types/distributions/tslint.json diff --git a/types/distributions/distributions-tests.ts b/types/distributions/distributions-tests.ts new file mode 100644 index 0000000000..04cb1b65bb --- /dev/null +++ b/types/distributions/distributions-tests.ts @@ -0,0 +1,17 @@ +import * as distributions from 'distributions'; + +const normal = distributions.Normal(); +normal.cdf(0); +normal.pdf(0); +normal.inv(0); +normal.mean(); +normal.median(); +normal.variance(); + +const uniform = distributions.Uniform(); +uniform.cdf(0); +uniform.pdf(0); +uniform.inv(0); +uniform.mean(); +uniform.median(); +uniform.variance(); diff --git a/types/distributions/index.d.ts b/types/distributions/index.d.ts new file mode 100644 index 0000000000..cdfbc93c6b --- /dev/null +++ b/types/distributions/index.d.ts @@ -0,0 +1,18 @@ +// Type definitions for distributions 2.0 +// Project: https://github.com/AndreasMadsen/distributions +// Definitions by: Marco Lanaro +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +export function Normal(mean?: number, sd?: number): Distribution; +export function Studentt(df: number): Distribution; +export function Uniform(a?: number, b?: number): Distribution; +export function Binomial(properbility: number, size: number): Distribution; + +export interface Distribution { + pdf: (x: number) => number; + cdf: (x: number) => number; + inv: (p: number) => number; + mean: () => number; + median: () => number; + variance: () => number; +} diff --git a/types/distributions/tsconfig.json b/types/distributions/tsconfig.json new file mode 100644 index 0000000000..995b1007ef --- /dev/null +++ b/types/distributions/tsconfig.json @@ -0,0 +1,24 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "strictFunctionTypes": true, + "esModuleInterop": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "distributions-tests.ts" + ] +} diff --git a/types/distributions/tslint.json b/types/distributions/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/distributions/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" }