diff --git a/lib/node_modules/@stdlib/stats/base/dists/wald/ctor/README.md b/lib/node_modules/@stdlib/stats/base/dists/wald/ctor/README.md new file mode 100644 index 000000000000..e0835d014843 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/wald/ctor/README.md @@ -0,0 +1,331 @@ + + +# Wald + +> Wald distribution constructor. + + + +
+ +
+ + + + + +
+ +## Usage + +```javascript +var Wald = require( '@stdlib/stats/base/dists/wald/ctor' ); +``` + +#### Wald( \[mu, lambda] ) + +Returns a [Wald][wald-distribution] (inverse Gaussian) distribution object. + +```javascript +var wald = new Wald(); + +var mu = wald.mean; +// returns 1.0 +``` + +By default, `mu = 1.0` and `lambda = 1.0`. To create a distribution having a different `mu` (mean parameter) and `lambda` (shape parameter), provide the corresponding arguments. + +```javascript +var wald = new Wald( 2.0, 4.0 ); + +var mu = wald.mean; +// returns 2.0 +``` + +* * * + +## wald + +A [Wald][wald-distribution] distribution object has the following properties and methods... + +### Writable Properties + +#### wald.mu + +Mean parameter of the distribution. `mu` **must** be a positive number. + +```javascript +var wald = new Wald(); + +var mu = wald.mu; +// returns 1.0 + +wald.mu = 3.0; + +mu = wald.mu; +// returns 3.0 +``` + +#### wald.lambda + +Shape parameter of the distribution. `lambda` **must** be a positive number. + +```javascript +var wald = new Wald( 2.0, 4.0 ); + +var lambda = wald.lambda; +// returns 4.0 + +wald.lambda = 3.0; + +lambda = wald.lambda; +// returns 3.0 +``` + +* * * + +### Computed Properties + +#### Wald.prototype.kurtosis + +Returns the [excess kurtosis][kurtosis]. + +```javascript +var wald = new Wald( 4.0, 12.0 ); + +var kurtosis = wald.kurtosis; +// returns 5.0 +``` + +#### Wald.prototype.mean + +Returns the [expected value][expected-value]. + +```javascript +var wald = new Wald( 4.0, 12.0 ); + +var mu = wald.mean; +// returns 4.0 +``` + +#### Wald.prototype.mode + +Returns the [mode][mode]. + +```javascript +var wald = new Wald( 4.0, 12.0 ); + +var mode = wald.mode; +// returns ~2.472 +``` + +#### Wald.prototype.skewness + +Returns the [skewness][skewness]. + +```javascript +var wald = new Wald( 4.0, 12.0 ); + +var skewness = wald.skewness; +// returns ~1.732 +``` + +#### Wald.prototype.stdev + +Returns the [standard deviation][standard-deviation]. + +```javascript +var wald = new Wald( 4.0, 12.0 ); + +var s = wald.stdev; +// returns ~2.309 +``` + +#### Wald.prototype.variance + +Returns the [variance][variance]. + +```javascript +var wald = new Wald( 4.0, 12.0 ); + +var s2 = wald.variance; +// returns ~5.333 +``` + +* * * + +### Methods + +#### Wald.prototype.cdf( x ) + +Evaluates the [cumulative distribution function][cdf] (CDF). + +```javascript +var wald = new Wald( 2.0, 4.0 ); + +var y = wald.cdf( 0.5 ); +// returns ~0.028 +``` + +#### Wald.prototype.logcdf( x ) + +Evaluates the natural logarithm of the [cumulative distribution function][cdf] (CDF). + +```javascript +var wald = new Wald( 2.0, 4.0 ); + +var y = wald.logcdf( 0.5 ); +// returns ~-3.574 +``` + +#### Wald.prototype.logpdf( x ) + +Evaluates the natural logarithm of the [probability density function][pdf] (PDF). + +```javascript +var wald = new Wald( 2.0, 4.0 ); + +var y = wald.logpdf( 0.8 ); +// returns ~-0.791 +``` + +#### Wald.prototype.mgf( t ) + +Evaluates the [moment-generating function][mgf] (MGF). + +```javascript +var wald = new Wald( 2.0, 4.0 ); + +var y = wald.mgf( 0.01 ); +// returns ~1.02 +``` + +#### Wald.prototype.pdf( x ) + +Evaluates the [probability density function][pdf] (PDF). + +```javascript +var wald = new Wald( 2.0, 4.0 ); + +var y = wald.pdf( 0.8 ); +// returns ~0.453 +``` + +#### Wald.prototype.quantile( p ) + +Evaluates the [quantile function][quantile-function] at probability `p`. + +```javascript +var wald = new Wald( 2.0, 4.0 ); + +var y = wald.quantile( 0.5 ); +// returns ~1.609 + +y = wald.quantile( 1.9 ); +// returns NaN +``` + +
+ + + + + +
+ +
+ + + + + +* * * + +
+ +## Examples + + + +```javascript +var Wald = require( '@stdlib/stats/base/dists/wald/ctor' ); + +var wald = new Wald( 2.0, 4.0 ); + +var mean = wald.mean; +// returns 2.0 + +var s2 = wald.variance; +// returns 2.0 + +var y = wald.cdf( 0.8 ); +// returns ~0.137 +``` + +
+ + + + + +
+ +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/stats/base/dists/wald/ctor/benchmark/benchmark.js b/lib/node_modules/@stdlib/stats/base/dists/wald/ctor/benchmark/benchmark.js new file mode 100644 index 000000000000..a1ae6aa7e88e --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/wald/ctor/benchmark/benchmark.js @@ -0,0 +1,554 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var bench = require( '@stdlib/bench' ); +var uniform = require( '@stdlib/random/array/uniform' ); +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var EPS = require( '@stdlib/constants/float64/eps' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var Wald = require( './../lib' ); + + +// MAIN // + +bench( format( '%s::instantiation', pkg ), function benchmark( b ) { + var lambda; + var dist; + var opts; + var mu; + var i; + + opts = { + 'dtype': 'float64' + }; + mu = uniform( 100, EPS, 10.0, opts ); + lambda = uniform( 100, EPS, 10.0, opts ); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + dist = new Wald( mu[ i % mu.length ], lambda[ i % lambda.length ] ); + if ( !( dist instanceof Wald ) ) { + b.fail( 'should return a distribution instance' ); + } + } + b.toc(); + if ( !( dist instanceof Wald ) ) { + b.fail( 'should return a distribution instance' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( format( '%s::get:mu', pkg ), function benchmark( b ) { + var lambda; + var dist; + var mu; + var y; + var i; + + mu = 2.0; + lambda = 3.0; + dist = new Wald( mu, lambda ); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + y = dist.mu; + if ( y !== mu ) { + b.fail( 'should return set value' ); + } + } + b.toc(); + if ( isnan( y ) ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( format( '%s::set:mu', pkg ), function benchmark( b ) { + var lambda; + var dist; + var mu; + var x; + var y; + var i; + + mu = 2.0; + lambda = 3.0; + dist = new Wald( mu, lambda ); + + x = uniform( 100, EPS, 100.0, { + 'dtype': 'float64' + }); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + y = x[ i % x.length ]; + dist.mu = y; + if ( dist.mu !== y ) { + b.fail( 'should return set value' ); + } + } + b.toc(); + if ( isnan( y ) ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( format( '%s::get:lambda', pkg ), function benchmark( b ) { + var lambda; + var dist; + var mu; + var y; + var i; + + mu = 2.0; + lambda = 3.0; + dist = new Wald( mu, lambda ); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + y = dist.lambda; + if ( y !== lambda ) { + b.fail( 'should return set value' ); + } + } + b.toc(); + if ( isnan( y ) ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( format( '%s::set:lambda', pkg ), function benchmark( b ) { + var lambda; + var dist; + var mu; + var x; + var y; + var i; + + mu = 2.0; + lambda = 3.0; + dist = new Wald( mu, lambda ); + + x = uniform( 100, EPS, 100.0, { + 'dtype': 'float64' + }); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + y = x[ i % x.length ]; + dist.lambda = y; + if ( dist.lambda !== y ) { + b.fail( 'should return set value' ); + } + } + b.toc(); + if ( isnan( y ) ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( format( '%s:kurtosis', pkg ), function benchmark( b ) { + var lambda; + var dist; + var mu; + var x; + var y; + var i; + + mu = 2.0; + lambda = 3.0; + dist = new Wald( mu, lambda ); + + x = uniform( 100, EPS, 100.0, { + 'dtype': 'float64' + }); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + dist.mu = x[ i % x.length ]; + y = dist.kurtosis; + if ( isnan( y ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnan( y ) ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( format( '%s:mean', pkg ), function benchmark( b ) { + var lambda; + var dist; + var mu; + var x; + var y; + var i; + + mu = 2.0; + lambda = 3.0; + dist = new Wald( mu, lambda ); + + x = uniform( 100, EPS, 100.0, { + 'dtype': 'float64' + }); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + dist.mu = x[ i % x.length ]; + y = dist.mean; + if ( isnan( y ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnan( y ) ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( format( '%s:mode', pkg ), function benchmark( b ) { + var lambda; + var dist; + var mu; + var x; + var y; + var i; + + mu = 2.0; + lambda = 3.0; + dist = new Wald( mu, lambda ); + + x = uniform( 100, EPS, 100.0, { + 'dtype': 'float64' + }); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + dist.mu = x[ i % x.length ]; + y = dist.mode; + if ( isnan( y ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnan( y ) ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( format( '%s:skewness', pkg ), function benchmark( b ) { + var lambda; + var dist; + var mu; + var x; + var y; + var i; + + mu = 2.0; + lambda = 3.0; + dist = new Wald( mu, lambda ); + + x = uniform( 100, EPS, 100.0, { + 'dtype': 'float64' + }); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + dist.mu = x[ i % x.length ]; + y = dist.skewness; + if ( isnan( y ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnan( y ) ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( format( '%s:stdev', pkg ), function benchmark( b ) { + var lambda; + var dist; + var mu; + var x; + var y; + var i; + + mu = 2.0; + lambda = 3.0; + dist = new Wald( mu, lambda ); + + x = uniform( 100, EPS, 100.0, { + 'dtype': 'float64' + }); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + dist.mu = x[ i % x.length ]; + y = dist.stdev; + if ( isnan( y ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnan( y ) ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( format( '%s:variance', pkg ), function benchmark( b ) { + var lambda; + var dist; + var mu; + var x; + var y; + var i; + + mu = 2.0; + lambda = 3.0; + dist = new Wald( mu, lambda ); + + x = uniform( 100, EPS, 100.0, { + 'dtype': 'float64' + }); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + dist.mu = x[ i % x.length ]; + y = dist.variance; + if ( isnan( y ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnan( y ) ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( format( '%s:cdf', pkg ), function benchmark( b ) { + var lambda; + var dist; + var mu; + var x; + var y; + var i; + + mu = 2.0; + lambda = 3.0; + dist = new Wald( mu, lambda ); + + x = uniform( 100, EPS, 3.0, { + 'dtype': 'float64' + }); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + y = dist.cdf( x[ i % x.length ] ); + if ( isnan( y ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnan( y ) ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( format( '%s:logpdf', pkg ), function benchmark( b ) { + var lambda; + var dist; + var mu; + var x; + var y; + var i; + + mu = 2.0; + lambda = 3.0; + dist = new Wald( mu, lambda ); + + x = uniform( 100, EPS, 3.0, { + 'dtype': 'float64' + }); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + y = dist.logpdf( x[ i % x.length ] ); + if ( isnan( y ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnan( y ) ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( format( '%s:logcdf', pkg ), function benchmark( b ) { + var lambda; + var dist; + var mu; + var x; + var y; + var i; + + mu = 2.0; + lambda = 3.0; + dist = new Wald( mu, lambda ); + + x = uniform( 100, EPS, 3.0, { + 'dtype': 'float64' + }); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + y = dist.logcdf( x[ i % x.length ] ); + if ( isnan( y ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnan( y ) ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( format( '%s:mgf', pkg ), function benchmark( b ) { + var lambda; + var dist; + var mu; + var x; + var y; + var i; + + mu = 2.0; + lambda = 20.0; + dist = new Wald( mu, lambda ); + + x = uniform( 100, 0.0, 1.0, { + 'dtype': 'float64' + }); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + y = dist.mgf( x[ i % x.length ] ); + if ( isnan( y ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnan( y ) ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( format( '%s:pdf', pkg ), function benchmark( b ) { + var lambda; + var dist; + var mu; + var x; + var y; + var i; + + mu = 2.0; + lambda = 3.0; + dist = new Wald( mu, lambda ); + + x = uniform( 100, EPS, 3.0, { + 'dtype': 'float64' + }); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + y = dist.pdf( x[ i % x.length ] ); + if ( isnan( y ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnan( y ) ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( format( '%s:quantile', pkg ), function benchmark( b ) { + var lambda; + var dist; + var mu; + var x; + var y; + var i; + + mu = 2.0; + lambda = 3.0; + dist = new Wald( mu, lambda ); + + x = uniform( 100, 0.0, 1.0, { + 'dtype': 'float64' + }); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + y = dist.quantile( x[ i % x.length ] ); + if ( isnan( y ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnan( y ) ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); diff --git a/lib/node_modules/@stdlib/stats/base/dists/wald/ctor/benchmark/python/benchmark.scipy.py b/lib/node_modules/@stdlib/stats/base/dists/wald/ctor/benchmark/python/benchmark.scipy.py new file mode 100644 index 000000000000..36c610d31093 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/wald/ctor/benchmark/python/benchmark.scipy.py @@ -0,0 +1,162 @@ +#!/usr/bin/env python +# +# @license Apache-2.0 +# +# Copyright (c) 2026 The Stdlib Authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +"""Benchmark scipy.stats.invgauss. + +Note: scipy parameterizes the inverse Gaussian (Wald) distribution +differently than stdlib. For a Wald distribution with mean `mu` and shape +parameter `lambda`, the equivalent scipy distribution is +`invgauss(mu/lambda, scale=lambda)`. +""" + +from __future__ import print_function +import timeit + +REPEATS = 3 +COUNT = [0] # use a list to allow modification within nested scopes + + +def print_version(): + """Print the TAP version.""" + print("TAP version 13") + + +def print_summary(total, passing): + """Print the benchmark summary. + + # Arguments + + * `total`: total number of tests + * `passing`: number of passing tests + + """ + print("#") + print("1.." + str(total)) # TAP plan + print("# total " + str(total)) + print("# pass " + str(passing)) + print("#") + print("# ok") + + +def print_results(iterations, elapsed): + """Print benchmark results. + + # Arguments + + * `iterations`: number of iterations + * `elapsed`: elapsed time (in seconds) + + # Examples + + ``` python + python> print_results(1000000, 0.131009101868) + ``` + """ + rate = iterations / elapsed + + print(" ---") + print(" iterations: " + str(iterations)) + print(" elapsed: " + str(elapsed)) + print(" rate: " + str(rate)) + print(" ...") + + +def benchmark(name, setup, stmt, iterations): + """Run the benchmark and print benchmark results. + + # Arguments + + * `name`: benchmark name + * `setup`: benchmark setup + * `stmt`: statement to benchmark + * `iterations`: number of iterations + + # Examples + + ``` python + python> benchmark("random", "from random import random;", "y = random()", 1000000) + ``` + """ + t = timeit.Timer(stmt, setup=setup) + + print_version() + + i = 0 + while i < REPEATS: + print("# python::" + name) + COUNT[0] += 1 + elapsed = t.timeit(number=iterations) + print_results(iterations, elapsed) + print("ok " + str(COUNT[0]) + " benchmark finished") + i += 1 + + +def main(): + """Run the benchmarks.""" + setup = "from scipy.stats import invgauss; from random import random; rv = invgauss(2.0/3.0, scale=3.0);" + + name = "wald:kurtosis" + stmt = "y = rv.stats(moments='k')" + iterations = 1000 + benchmark(name, setup, stmt, iterations) + + name = "wald:mean" + stmt = "y = rv.mean()" + iterations = 1000 + benchmark(name, setup, stmt, iterations) + + name = "wald:skewness" + stmt = "y = rv.stats(moments='s')" + iterations = 1000 + benchmark(name, setup, stmt, iterations) + + name = "wald:stdev" + stmt = "y = rv.std()" + iterations = 1000 + benchmark(name, setup, stmt, iterations) + + name = "wald:variance" + stmt = "y = rv.var()" + iterations = 1000 + benchmark(name, setup, stmt, iterations) + + name = "wald:cdf" + stmt = "y = rv.cdf(random())" + iterations = 1000 + benchmark(name, setup, stmt, iterations) + + name = "wald:logpdf" + stmt = "y = rv.logpdf(random())" + iterations = 1000 + benchmark(name, setup, stmt, iterations) + + name = "wald:pdf" + stmt = "y = rv.pdf(random())" + iterations = 1000 + benchmark(name, setup, stmt, iterations) + + name = "wald:quantile" + stmt = "y = rv.ppf(random())" + iterations = 1000 + benchmark(name, setup, stmt, iterations) + + print_summary(COUNT[0], COUNT[0]) + + +if __name__ == "__main__": + main() diff --git a/lib/node_modules/@stdlib/stats/base/dists/wald/ctor/docs/repl.txt b/lib/node_modules/@stdlib/stats/base/dists/wald/ctor/docs/repl.txt new file mode 100644 index 000000000000..4ffb21310911 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/wald/ctor/docs/repl.txt @@ -0,0 +1,96 @@ + +{{alias}}( [μ, λ] ) + Returns a Wald (inverse Gaussian) distribution object. + + Parameters + ---------- + μ: number (optional) + Mean parameter. Must be greater than `0`. Default: `1.0`. + + λ: number (optional) + Shape parameter. Must be greater than `0`. Default: `1.0`. + + Returns + ------- + wald: Object + Distribution instance. + + wald.mu: number + Mean parameter. If set, the value must be greater than `0`. + + wald.lambda: number + Shape parameter. If set, the value must be greater than `0`. + + wald.kurtosis: number + Read-only property which returns the excess kurtosis. + + wald.mean: number + Read-only property which returns the expected value. + + wald.mode: number + Read-only property which returns the mode. + + wald.skewness: number + Read-only property which returns the skewness. + + wald.stdev: number + Read-only property which returns the standard deviation. + + wald.variance: number + Read-only property which returns the variance. + + wald.cdf: Function + Evaluates the cumulative distribution function (CDF). + + wald.logcdf: Function + Evaluates the natural logarithm of the cumulative distribution function + (CDF). + + wald.logpdf: Function + Evaluates the natural logarithm of the probability density function + (PDF). + + wald.mgf: Function + Evaluates the moment-generating function (MGF). + + wald.pdf: Function + Evaluates the probability density function (PDF). + + wald.quantile: Function + Evaluates the quantile function at probability `p`. + + Examples + -------- + > var wald = {{alias}}( 2.0, 3.0 ); + > wald.mu + 2.0 + > wald.lambda + 3.0 + > wald.kurtosis + 10.0 + > wald.mean + 2.0 + > wald.mode + ~0.828 + > wald.skewness + ~2.449 + > wald.stdev + ~1.633 + > wald.variance + ~2.667 + > wald.cdf( 0.8 ) + ~0.19 + > wald.logcdf( 0.8 ) + ~-1.661 + > wald.logpdf( 2.0 ) + ~-1.409 + > wald.mgf( 0.2 ) + ~1.609 + > wald.pdf( 2.0 ) + ~0.244 + > wald.quantile( 0.9 ) + ~3.985 + + See Also + -------- + diff --git a/lib/node_modules/@stdlib/stats/base/dists/wald/ctor/docs/types/index.d.ts b/lib/node_modules/@stdlib/stats/base/dists/wald/ctor/docs/types/index.d.ts new file mode 100644 index 000000000000..191856b4e59b --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/wald/ctor/docs/types/index.d.ts @@ -0,0 +1,153 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +// TypeScript Version: 4.1 + +/** +* Wald distribution. +*/ +declare class Wald { + /** + * Wald distribution constructor. + * + * @param mu - mean (default: 1.0) + * @param lambda - shape parameter (default: 1.0) + * @throws `mu` must be a positive number + * @throws `lambda` must be a positive number + * @returns distribution instance + * + * @example + * var wald = new Wald( 1.0, 1.0 ); + * + * var y = wald.cdf( 1.5 ); + * // returns ~0.811 + * + * var mu = wald.mean; + * // returns 1.0 + */ + constructor( mu: number, lambda: number ); + + /** + * Wald distribution constructor. + * + * @returns distribution instance + * + * @example + * var wald = new Wald(); + * + * var y = wald.cdf( 1.5 ); + * // returns ~0.811 + * + * var mu = wald.mean; + * // returns 1.0 + */ + constructor(); + + /** + * Mean. If set, the value must be greater than `0`. + */ + mu: number; + + /** + * Shape parameter. If set, the value must be greater than `0`. + */ + lambda: number; + + /** + * Read-only property which returns the excess kurtosis. + */ + readonly kurtosis: number; + + /** + * Read-only property which returns the expected value. + */ + readonly mean: number; + + /** + * Read-only property which returns the mode. + */ + readonly mode: number; + + /** + * Read-only property which returns the skewness. + */ + readonly skewness: number; + + /** + * Read-only property which returns the standard deviation. + */ + readonly stdev: number; + + /** + * Read-only property which returns the variance. + */ + readonly variance: number; + + /** + * Evaluates the cumulative distribution function (CDF). + * + * @param x - input value + * @returns evaluated CDF + */ + cdf( x: number ): number; + + /** + * Evaluates the natural logarithm of the cumulative distribution function (CDF). + * + * @param x - input value + * @returns evaluated logCDF + */ + logcdf( x: number ): number; + + /** + * Evaluates the natural logarithm of the probability density function (PDF). + * + * @param x - input value + * @returns evaluated logPDF + */ + logpdf( x: number ): number; + + /** + * Evaluates the moment-generating function (MGF). + * + * @param t - input value + * @returns evaluated MGF + */ + mgf( t: number ): number; + + /** + * Evaluates the probability density function (PDF). + * + * @param x - input value + * @returns evaluated PDF + */ + pdf( x: number ): number; + + /** + * Evaluates the quantile function at probability `p`. + * + * @param p - input probability + * @returns evaluated quantile function + */ + quantile( p: number ): number; +} + + +// EXPORTS // + +export = Wald; diff --git a/lib/node_modules/@stdlib/stats/base/dists/wald/ctor/docs/types/test.ts b/lib/node_modules/@stdlib/stats/base/dists/wald/ctor/docs/types/test.ts new file mode 100644 index 000000000000..8e5586e72bff --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/wald/ctor/docs/types/test.ts @@ -0,0 +1,53 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +/* eslint-disable @typescript-eslint/no-unused-expressions */ + +import Wald = require( './index' ); + + +// TESTS // + +// The function returns a distribution instance... +{ + new Wald(); // $ExpectType Wald + new Wald( 1.0, 2.0 ); // $ExpectType Wald +} + +// The compiler throws an error if the function is provided values other than two numbers... +{ + new Wald( true, 2.0 ); // $ExpectError + new Wald( false, 2.0 ); // $ExpectError + new Wald( '5', 2.0 ); // $ExpectError + new Wald( [], 2.0 ); // $ExpectError + new Wald( {}, 2.0 ); // $ExpectError + new Wald( ( x: number ): number => x, 2.0 ); // $ExpectError + + new Wald( 1.0, true ); // $ExpectError + new Wald( 1.0, false ); // $ExpectError + new Wald( 1.0, '5' ); // $ExpectError + new Wald( 1.0, [] ); // $ExpectError + new Wald( 1.0, {} ); // $ExpectError + new Wald( 1.0, ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the function is provided an unsupported number of arguments... +{ + new Wald( 1.0 ); // $ExpectError + new Wald( 1.0, 1.0, 2.0 ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/stats/base/dists/wald/ctor/examples/index.js b/lib/node_modules/@stdlib/stats/base/dists/wald/ctor/examples/index.js new file mode 100644 index 000000000000..d984deab4f64 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/wald/ctor/examples/index.js @@ -0,0 +1,35 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +var Wald = require( './../lib' ); + +var wald = new Wald( 2.0, 4.0 ); + +var mu = wald.mean; +console.log( 'Mean = %d', mu ); +// => 'Mean = 2' + +var s2 = wald.variance; +console.log( 'Variance = %d', s2 ); +// => 'Variance = 2' + +var y = wald.cdf( 0.8 ); +console.log( 'F(0.8) = %d', y ); +// => 'F(0.8) = 0.1374963737307623' diff --git a/lib/node_modules/@stdlib/stats/base/dists/wald/ctor/lib/index.js b/lib/node_modules/@stdlib/stats/base/dists/wald/ctor/lib/index.js new file mode 100644 index 000000000000..3a81fdd7e21c --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/wald/ctor/lib/index.js @@ -0,0 +1,45 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +/** +* Wald distribution constructor. +* +* @module @stdlib/stats/base/dists/wald/ctor +* +* @example +* var Wald = require( '@stdlib/stats/base/dists/wald/ctor' ); +* +* var wald = new Wald( 1.0, 1.0 ); +* +* var y = wald.cdf( 1.5 ); +* // returns ~0.811 +* +* var mu = wald.mean; +* // returns 1.0 +*/ + +// MODULES // + +var main = require( './main.js' ); + + +// EXPORTS // + +module.exports = main; diff --git a/lib/node_modules/@stdlib/stats/base/dists/wald/ctor/lib/main.js b/lib/node_modules/@stdlib/stats/base/dists/wald/ctor/lib/main.js new file mode 100644 index 000000000000..4278dc7bc6ad --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/wald/ctor/lib/main.js @@ -0,0 +1,404 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +/* eslint-disable no-restricted-syntax, no-invalid-this */ + +'use strict'; + +// MODULES // + +var defineProperty = require( '@stdlib/utils/define-property' ); +var setReadOnly = require( '@stdlib/utils/define-nonenumerable-read-only-property' ); +var setReadOnlyAccessor = require( '@stdlib/utils/define-nonenumerable-read-only-accessor' ); +var isPositive = require( '@stdlib/assert/is-positive-number' ).isPrimitive; +var kurtosis = require( '@stdlib/stats/base/dists/wald/kurtosis' ); +var mean = require( '@stdlib/stats/base/dists/wald/mean' ); +var mode = require( '@stdlib/stats/base/dists/wald/mode' ); +var skewness = require( '@stdlib/stats/base/dists/wald/skewness' ); +var stdev = require( '@stdlib/stats/base/dists/wald/stdev' ); +var variance = require( '@stdlib/stats/base/dists/wald/variance' ); +var cdf = require( '@stdlib/stats/base/dists/wald/cdf' ); +var logcdf = require( '@stdlib/stats/base/dists/wald/logcdf' ); +var logpdf = require( '@stdlib/stats/base/dists/wald/logpdf' ); +var mgf = require( '@stdlib/stats/base/dists/wald/mgf' ); +var pdf = require( '@stdlib/stats/base/dists/wald/pdf' ); +var quantile = require( '@stdlib/stats/base/dists/wald/quantile' ); +var format = require( '@stdlib/string/format' ); + + +// FUNCTIONS // + +/** +* Evaluates the cumulative distribution function (CDF). +* +* @private +* @param {number} x - input value +* @returns {Probability} evaluated CDF +*/ +function waldCDF( x ) { + return cdf( x, this.mu, this.lambda ); +} + +/** +* Evaluates the natural logarithm of the cumulative distribution function (CDF). +* +* @private +* @param {number} x - input value +* @returns {number} evaluated logCDF +*/ +function waldLogCDF( x ) { + return logcdf( x, this.mu, this.lambda ); +} + +/** +* Evaluates the natural logarithm of the probability density function (PDF). +* +* @private +* @param {number} x - input value +* @returns {number} evaluated logPDF +*/ +function waldLogPDF( x ) { + return logpdf( x, this.mu, this.lambda ); +} + +/** +* Evaluates the moment-generating function (MGF). +* +* @private +* @param {number} t - input value +* @returns {number} evaluated MGF +*/ +function waldMGF( t ) { + return mgf( t, this.mu, this.lambda ); +} + +/** +* Evaluates the probability density function (PDF). +* +* @private +* @param {number} x - input value +* @returns {number} evaluated PDF +*/ +function waldPDF( x ) { + return pdf( x, this.mu, this.lambda ); +} + +/** +* Evaluates the quantile function. +* +* @private +* @param {Probability} p - input probability +* @returns {number} evaluated quantile function +*/ +function waldQuantile( p ) { + return quantile( p, this.mu, this.lambda ); +} + + +// MAIN // + +/** +* Wald distribution constructor. +* +* @constructor +* @param {PositiveNumber} [mu=1.0] - mean +* @param {PositiveNumber} [lambda=1.0] - shape parameter +* @throws {TypeError} `mu` must be a positive number +* @throws {TypeError} `lambda` must be a positive number +* @returns {Wald} distribution instance +* +* @example +* var wald = new Wald( 1.0, 1.0 ); +* +* var y = wald.cdf( 1.5 ); +* // returns ~0.811 +* +* var mu = wald.mean; +* // returns 1.0 +*/ +function Wald() { + var lambda; + var mu; + if ( !(this instanceof Wald) ) { + if ( arguments.length === 0 ) { + return new Wald(); + } + return new Wald( arguments[ 0 ], arguments[ 1 ] ); + } + if ( arguments.length ) { + mu = arguments[ 0 ]; + lambda = arguments[ 1 ]; + if ( !isPositive( mu ) ) { + throw new TypeError( format( 'invalid argument. Mean parameter must be a positive number. Value: `%s`.', mu ) ); + } + if ( !isPositive( lambda ) ) { + throw new TypeError( format( 'invalid argument. Shape parameter must be a positive number. Value: `%s`.', lambda ) ); + } + } else { + mu = 1.0; + lambda = 1.0; + } + defineProperty( this, 'mu', { + 'configurable': false, + 'enumerable': true, + 'get': function get() { + return mu; + }, + 'set': function set( value ) { + if ( !isPositive( value ) ) { + throw new TypeError( format( 'invalid assignment. Must be a positive number. Value: `%s`.', value ) ); + } + mu = value; + } + }); + defineProperty( this, 'lambda', { + 'configurable': false, + 'enumerable': true, + 'get': function get() { + return lambda; + }, + 'set': function set( value ) { + if ( !isPositive( value ) ) { + throw new TypeError( format( 'invalid assignment. Must be a positive number. Value: `%s`.', value ) ); + } + lambda = value; + } + }); + return this; +} + +/** +* Wald distribution excess kurtosis. +* +* @name kurtosis +* @memberof Wald.prototype +* @type {number} +* @see [kurtosis]{@link https://en.wikipedia.org/wiki/Kurtosis} +* +* @example +* var wald = new Wald( 4.0, 12.0 ); +* +* var v = wald.kurtosis; +* // returns 5.0 +*/ +setReadOnlyAccessor( Wald.prototype, 'kurtosis', function get() { + return kurtosis( this.mu, this.lambda ); +}); + +/** +* Wald distribution expected value. +* +* @name mean +* @memberof Wald.prototype +* @type {number} +* @see [expected value]{@link https://en.wikipedia.org/wiki/Expected_value} +* +* @example +* var wald = new Wald( 4.0, 12.0 ); +* +* var v = wald.mean; +* // returns 4.0 +*/ +setReadOnlyAccessor( Wald.prototype, 'mean', function get() { + return mean( this.mu, this.lambda ); +}); + +/** +* Wald distribution mode. +* +* @name mode +* @memberof Wald.prototype +* @type {number} +* @see [mode]{@link https://en.wikipedia.org/wiki/Mode_%28statistics%29} +* +* @example +* var wald = new Wald( 4.0, 12.0 ); +* +* var v = wald.mode; +* // returns ~2.472 +*/ +setReadOnlyAccessor( Wald.prototype, 'mode', function get() { + return mode( this.mu, this.lambda ); +}); + +/** +* Wald distribution skewness. +* +* @name skewness +* @memberof Wald.prototype +* @type {number} +* @see [skewness]{@link https://en.wikipedia.org/wiki/Skewness} +* +* @example +* var wald = new Wald( 4.0, 12.0 ); +* +* var v = wald.skewness; +* // returns ~1.732 +*/ +setReadOnlyAccessor( Wald.prototype, 'skewness', function get() { + return skewness( this.mu, this.lambda ); +}); + +/** +* Wald distribution standard deviation. +* +* @name stdev +* @memberof Wald.prototype +* @type {PositiveNumber} +* @see [standard deviation]{@link https://en.wikipedia.org/wiki/Standard_deviation} +* +* @example +* var wald = new Wald( 4.0, 12.0 ); +* +* var v = wald.stdev; +* // returns ~2.309 +*/ +setReadOnlyAccessor( Wald.prototype, 'stdev', function get() { + return stdev( this.mu, this.lambda ); +}); + +/** +* Wald distribution variance. +* +* @name variance +* @memberof Wald.prototype +* @type {PositiveNumber} +* @see [variance]{@link https://en.wikipedia.org/wiki/Variance} +* +* @example +* var wald = new Wald( 4.0, 12.0 ); +* +* var v = wald.variance; +* // returns ~5.333 +*/ +setReadOnlyAccessor( Wald.prototype, 'variance', function get() { + return variance( this.mu, this.lambda ); +}); + +/** +* Evaluates the cumulative distribution function (CDF). +* +* @name cdf +* @memberof Wald.prototype +* @type {Function} +* @param {number} x - input value +* @returns {number} evaluated CDF +* @see [cdf]{@link https://en.wikipedia.org/wiki/Cumulative_distribution_function} +* +* @example +* var wald = new Wald( 2.0, 4.0 ); +* +* var v = wald.cdf( 0.5 ); +* // returns ~0.028 +*/ +setReadOnly( Wald.prototype, 'cdf', waldCDF ); + +/** +* Evaluates the natural logarithm of the cumulative distribution function (CDF). +* +* @name logcdf +* @memberof Wald.prototype +* @type {Function} +* @param {number} x - input value +* @returns {number} evaluated logarithm of the CDF +* @see [cdf]{@link https://en.wikipedia.org/wiki/Cumulative_distribution_function} +* +* @example +* var wald = new Wald( 2.0, 4.0 ); +* +* var v = wald.logcdf( 0.5 ); +* // returns ~-3.574 +*/ +setReadOnly( Wald.prototype, 'logcdf', waldLogCDF ); + +/** +* Evaluates the natural logarithm of the probability density function (PDF). +* +* @name logpdf +* @memberof Wald.prototype +* @type {Function} +* @param {number} x - input value +* @returns {number} evaluated logPDF +* @see [pdf]{@link https://en.wikipedia.org/wiki/Probability_density_function} +* +* @example +* var wald = new Wald( 2.0, 4.0 ); +* +* var v = wald.logpdf( 0.8 ); +* // returns ~-0.791 +*/ +setReadOnly( Wald.prototype, 'logpdf', waldLogPDF ); + +/** +* Evaluates the moment-generating function (MGF). +* +* @name mgf +* @memberof Wald.prototype +* @type {Function} +* @param {number} t - input value +* @returns {number} evaluated MGF +* @see [mgf]{@link https://en.wikipedia.org/wiki/Moment-generating_function} +* +* @example +* var wald = new Wald( 2.0, 4.0 ); +* +* var v = wald.mgf( 0.01 ); +* // returns ~1.02 +*/ +setReadOnly( Wald.prototype, 'mgf', waldMGF ); + +/** +* Evaluates the probability density function (PDF). +* +* @name pdf +* @memberof Wald.prototype +* @type {Function} +* @param {number} x - input value +* @returns {number} evaluated PDF +* @see [pdf]{@link https://en.wikipedia.org/wiki/Probability_density_function} +* +* @example +* var wald = new Wald( 2.0, 4.0 ); +* +* var v = wald.pdf( 0.8 ); +* // returns ~0.453 +*/ +setReadOnly( Wald.prototype, 'pdf', waldPDF ); + +/** +* Evaluates the quantile function. +* +* @name quantile +* @memberof Wald.prototype +* @type {Function} +* @param {Probability} p - input probability +* @returns {number} evaluated quantile function +* @see [quantile function]{@link https://en.wikipedia.org/wiki/Quantile_function} +* +* @example +* var wald = new Wald( 2.0, 4.0 ); +* +* var v = wald.quantile( 0.5 ); +* // returns ~1.609 +*/ +setReadOnly( Wald.prototype, 'quantile', waldQuantile ); + + +// EXPORTS // + +module.exports = Wald; diff --git a/lib/node_modules/@stdlib/stats/base/dists/wald/ctor/package.json b/lib/node_modules/@stdlib/stats/base/dists/wald/ctor/package.json new file mode 100644 index 000000000000..51856b850fed --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/wald/ctor/package.json @@ -0,0 +1,75 @@ +{ + "name": "@stdlib/stats/base/dists/wald/ctor", + "version": "0.0.0", + "description": "Wald distribution constructor.", + "license": "Apache-2.0", + "author": { + "name": "The Stdlib Authors", + "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" + }, + "contributors": [ + { + "name": "The Stdlib Authors", + "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" + } + ], + "main": "./lib", + "directories": { + "benchmark": "./benchmark", + "doc": "./docs", + "example": "./examples", + "lib": "./lib", + "test": "./test" + }, + "types": "./docs/types", + "scripts": {}, + "homepage": "https://github.com/stdlib-js/stdlib", + "repository": { + "type": "git", + "url": "git://github.com/stdlib-js/stdlib.git" + }, + "bugs": { + "url": "https://github.com/stdlib-js/stdlib/issues" + }, + "dependencies": {}, + "devDependencies": {}, + "engines": { + "node": ">=0.10.0", + "npm": ">2.7.0" + }, + "os": [ + "aix", + "darwin", + "freebsd", + "linux", + "macos", + "openbsd", + "sunos", + "win32", + "windows" + ], + "keywords": [ + "stdlib", + "stdmath", + "statistics", + "stats", + "distribution", + "dist", + "object", + "class", + "constructor", + "ctor", + "probability", + "prob", + "wald", + "inverse-gaussian", + "inverse gaussian", + "cdf", + "pdf", + "quantile", + "properties", + "props", + "univariate", + "continuous" + ] +} diff --git a/lib/node_modules/@stdlib/stats/base/dists/wald/ctor/test/test.js b/lib/node_modules/@stdlib/stats/base/dists/wald/ctor/test/test.js new file mode 100644 index 000000000000..2423bab7c7d7 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/wald/ctor/test/test.js @@ -0,0 +1,381 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var isFunction = require( '@stdlib/assert/is-function' ); +var hasOwnProp = require( '@stdlib/assert/has-own-property' ); +var quantile = require( '@stdlib/stats/base/dists/wald/quantile' ); +var cdf = require( '@stdlib/stats/base/dists/wald/cdf' ); +var logcdf = require( '@stdlib/stats/base/dists/wald/logcdf' ); +var logpdf = require( '@stdlib/stats/base/dists/wald/logpdf' ); +var mgf = require( '@stdlib/stats/base/dists/wald/mgf' ); +var pdf = require( '@stdlib/stats/base/dists/wald/pdf' ); +var kurtosis = require( '@stdlib/stats/base/dists/wald/kurtosis' ); +var skewness = require( '@stdlib/stats/base/dists/wald/skewness' ); +var stdev = require( '@stdlib/stats/base/dists/wald/stdev' ); +var variance = require( '@stdlib/stats/base/dists/wald/variance' ); +var mode = require( '@stdlib/stats/base/dists/wald/mode' ); +var mean = require( '@stdlib/stats/base/dists/wald/mean' ); +var Wald = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof Wald, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function throws an error if provided a `mu` argument which is not a positive number', function test( t ) { + var values; + var i; + + values = [ + '5', + -5.0, + 0.0, + NaN, + true, + false, + void 0, + null, + {}, + [], + function noop() {} + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + // eslint-disable-next-line no-new + new Wald( value, 1.0 ); + }; + } +}); + +tape( 'the function throws an error if provided a `lambda` argument which is not a positive number', function test( t ) { + var values; + var i; + + values = [ + '5', + -5.0, + 0.0, + NaN, + true, + false, + void 0, + null, + {}, + [], + function noop() {} + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + // eslint-disable-next-line no-new + new Wald( 2.0, value ); + }; + } +}); + +tape( 'if provided arguments, the function requires both `mu` and `lambda`', function test( t ) { + t.throws( foo, TypeError, 'throws an error' ); + t.end(); + + function foo() { + // eslint-disable-next-line no-new + new Wald( 2.0 ); + } +}); + +tape( 'the function returns a new distribution instance (default parameters)', function test( t ) { + var wald = new Wald(); + t.strictEqual( wald instanceof Wald, true, 'returns expected value' ); + t.end(); +}); + +tape( 'the function returns a new distribution instance (custom parameters)', function test( t ) { + var wald = new Wald( 2.0, 4.0 ); + t.strictEqual( wald instanceof Wald, true, 'returns expected value' ); + t.end(); +}); + +tape( 'the function can be invoked without the new operator', function test( t ) { + // eslint-disable-next-line new-cap + var wald = Wald(); + t.strictEqual( wald instanceof Wald, true, 'returns expected value' ); + + // eslint-disable-next-line new-cap + wald = Wald( 2.0, 4.0 ); + t.strictEqual( wald instanceof Wald, true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the created distribution has a property for getting and setting `mu`', function test( t ) { + var wald; + + wald = new Wald( 2.0, 4.0 ); + t.strictEqual( hasOwnProp( wald, 'mu' ), true, 'has property' ); + t.strictEqual( wald.mu, 2.0, 'returns expected value' ); + + wald.mu = 3.0; + t.strictEqual( wald.mu, 3.0, 'returns expected value' ); + + t.end(); +}); + +tape( 'the created distribution throws an error if one attempts to set `mu` to a value which is not a positive number', function test( t ) { + var values; + var i; + + values = [ + '5', + -5.0, + 0.0, + NaN, + true, + false, + void 0, + null, + {}, + [], + function noop() {} + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + var wald = new Wald(); + wald.mu = value; + }; + } +}); + +tape( 'the created distribution has a property for getting and setting `lambda`', function test( t ) { + var wald; + + wald = new Wald( 2.0, 4.0 ); + t.strictEqual( hasOwnProp( wald, 'lambda' ), true, 'has property' ); + t.strictEqual( wald.lambda, 4.0, 'returns expected value' ); + + wald.lambda = 3.0; + t.strictEqual( wald.lambda, 3.0, 'returns expected value' ); + + t.end(); +}); + +tape( 'the created distribution throws an error if one attempts to set `lambda` to a value which is not a positive number', function test( t ) { + var values; + var i; + + values = [ + '5', + -5.0, + 0.0, + NaN, + true, + false, + void 0, + null, + {}, + [], + function noop() {} + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + var wald = new Wald(); + wald.lambda = value; + }; + } +}); + +tape( 'the distribution prototype has a property for retrieving the distribution kurtosis', function test( t ) { + var wald; + + t.strictEqual( hasOwnProp( Wald.prototype, 'kurtosis' ), true, 'has property' ); + + wald = new Wald( 2.0, 4.0 ); + t.strictEqual( wald.kurtosis, kurtosis( 2.0, 4.0 ), 'returns expected value' ); + + t.end(); +}); + +tape( 'the distribution prototype has a property for retrieving the distribution mean', function test( t ) { + var wald; + + t.strictEqual( hasOwnProp( Wald.prototype, 'mean' ), true, 'has property' ); + + wald = new Wald(); + t.strictEqual( wald.mean, mean( 1.0, 1.0 ), 'returns expected value' ); + + t.end(); +}); + +tape( 'the distribution prototype has a property for retrieving the distribution mode', function test( t ) { + var wald; + + t.strictEqual( hasOwnProp( Wald.prototype, 'mode' ), true, 'has property' ); + + wald = new Wald( 2.0, 3.0 ); + t.strictEqual( wald.mode, mode( 2.0, 3.0 ), 'returns expected value' ); + + t.end(); +}); + +tape( 'the distribution prototype has a property for retrieving the distribution skewness', function test( t ) { + var wald; + + t.strictEqual( hasOwnProp( Wald.prototype, 'skewness' ), true, 'has property' ); + + wald = new Wald( 0.5, 0.5 ); + t.strictEqual( wald.skewness, skewness( 0.5, 0.5 ), 'returns expected value' ); + + t.end(); +}); + +tape( 'the distribution prototype has a property for retrieving the distribution standard deviation', function test( t ) { + var wald; + + t.strictEqual( hasOwnProp( Wald.prototype, 'stdev' ), true, 'has property' ); + + wald = new Wald( 3.0, 1.0 ); + t.strictEqual( wald.stdev, stdev( 3.0, 1.0 ), 'returns expected value' ); + + t.end(); +}); + +tape( 'the distribution prototype has a property for retrieving the distribution variance', function test( t ) { + var wald; + + t.strictEqual( hasOwnProp( Wald.prototype, 'variance' ), true, 'has property' ); + + wald = new Wald( 3.0, 1.0 ); + t.strictEqual( wald.variance, variance( 3.0, 1.0 ), 'returns expected value' ); + + t.end(); +}); + +tape( 'the distribution prototype has a method for evaluating the cumulative distribution function (CDF)', function test( t ) { + var wald; + var y; + + t.strictEqual( hasOwnProp( Wald.prototype, 'cdf' ), true, 'has property' ); + t.strictEqual( isFunction( Wald.prototype.cdf ), true, 'has method' ); + + wald = new Wald(); + y = wald.cdf( 0.5 ); + + t.strictEqual( y, cdf( 0.5, 1.0, 1.0 ), 'returns expected value' ); + t.end(); +}); + +tape( 'the distribution prototype has a method for evaluating the natural logarithm of the probability density function (PDF)', function test( t ) { + var wald; + var y; + + t.strictEqual( hasOwnProp( Wald.prototype, 'logpdf' ), true, 'has property' ); + t.strictEqual( isFunction( Wald.prototype.logpdf ), true, 'has method' ); + + wald = new Wald(); + y = wald.logpdf( 0.2 ); + + t.strictEqual( y, logpdf( 0.2, 1.0, 1.0 ), 'returns expected value' ); + t.end(); +}); + +tape( 'the distribution prototype has a method for evaluating the natural logarithm of the cumulative distribution function (CDF)', function test( t ) { + var wald; + var y; + + t.strictEqual( hasOwnProp( Wald.prototype, 'logcdf' ), true, 'has property' ); + t.strictEqual( isFunction( Wald.prototype.logcdf ), true, 'has method' ); + + wald = new Wald(); + y = wald.logcdf( 0.5 ); + + t.strictEqual( y, logcdf( 0.5, 1.0, 1.0 ), 'returns expected value' ); + t.end(); +}); + +tape( 'the distribution prototype has a method for evaluating the moment-generating function (MGF)', function test( t ) { + var wald; + var y; + + t.strictEqual( hasOwnProp( Wald.prototype, 'mgf' ), true, 'has property' ); + t.strictEqual( isFunction( Wald.prototype.mgf ), true, 'has method' ); + + wald = new Wald(); + y = wald.mgf( 0.01 ); + + t.strictEqual( y, mgf( 0.01, 1.0, 1.0 ), 'returns expected value' ); + t.end(); +}); + +tape( 'the distribution prototype has a method for evaluating the probability density function (PDF)', function test( t ) { + var wald; + var y; + + t.strictEqual( hasOwnProp( Wald.prototype, 'pdf' ), true, 'has property' ); + t.strictEqual( isFunction( Wald.prototype.pdf ), true, 'has method' ); + + wald = new Wald(); + y = wald.pdf( 0.2 ); + + t.strictEqual( y, pdf( 0.2, 1.0, 1.0 ), 'returns expected value' ); + t.end(); +}); + +tape( 'the distribution prototype has a method for evaluating the quantile function', function test( t ) { + var wald; + var y; + + t.strictEqual( hasOwnProp( Wald.prototype, 'quantile' ), true, 'has property' ); + t.strictEqual( isFunction( Wald.prototype.quantile ), true, 'has method' ); + + wald = new Wald(); + y = wald.quantile( 0.8 ); + + t.strictEqual( y, quantile( 0.8, 1.0, 1.0 ), 'returns expected value' ); + t.end(); +});