Skip to content

Commit 47a6dca

Browse files
committed
Add logcdf and logpdf to constructor
1 parent c28d5dc commit 47a6dca

4 files changed

Lines changed: 124 additions & 0 deletions

File tree

lib/node_modules/@stdlib/math/base/dist/exponential/ctor/README.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,28 @@ var y = exponential.cdf( 0.5 );
171171
// returns ~0.632
172172
```
173173

174+
#### Exponential.prototype.logcdf( x )
175+
176+
Evaluates the natural logarithm of the [cumulative distribution function][cdf] (CDF).
177+
178+
```javascript
179+
var exponential = new Exponential( 2.0 );
180+
181+
var y = exponential.logcdf( 0.5 );
182+
// returns ~-0.459
183+
```
184+
185+
#### Exponential.prototype.logpdf( x )
186+
187+
Evaluates the natural logarithm of the [probability density function][pdf] (PDF).
188+
189+
```javascript
190+
var exponential = new Exponential( 2.0 );
191+
192+
var y = exponential.logpdf( 0.8 );
193+
// returns ~-0.906
194+
```
195+
174196
#### Exponential.prototype.mgf( t )
175197

176198
Evaluates the [moment-generating function][mgf] (MGF).

lib/node_modules/@stdlib/math/base/dist/exponential/ctor/docs/repl.txt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,14 @@
4242
exponential.cdf: Function
4343
Evaluates the cumulative distribution function (CDF).
4444

45+
exponential.logcdf: Function
46+
Evaluates the natural logarithm of the cumulative distribution function
47+
(CDF).
48+
49+
exponential.logpdf: Function
50+
Evaluates the natural logarithm of the probability density function
51+
(PDF).
52+
4553
exponential.mgf: Function
4654
Evaluates the moment-generating function (MGF).
4755

@@ -74,6 +82,10 @@
7482
~0.028
7583
> exponential.cdf( 1.0 )
7684
~0.998
85+
> exponential.logcdf( 1.0 )
86+
~-0.002
87+
> exponential.logpdf( 1.5 )
88+
~-6.908
7789
> exponential.mgf( -0.5 )
7890
~0.923
7991
> exponential.pdf( 1.5 )

lib/node_modules/@stdlib/math/base/dist/exponential/ctor/lib/ctor.js

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ var skewness = require( '@stdlib/math/base/dist/exponential/skewness' );
1414
var stdev = require( '@stdlib/math/base/dist/exponential/stdev' );
1515
var variance = require( '@stdlib/math/base/dist/exponential/variance' );
1616
var cdf = require( '@stdlib/math/base/dist/exponential/cdf' );
17+
var logcdf = require( '@stdlib/math/base/dist/exponential/logcdf' );
18+
var logpdf = require( '@stdlib/math/base/dist/exponential/logpdf' );
1719
var mgf = require( '@stdlib/math/base/dist/exponential/mgf' );
1820
var pdf = require( '@stdlib/math/base/dist/exponential/pdf' );
1921
var quantile = require( '@stdlib/math/base/dist/exponential/quantile' );
@@ -32,6 +34,28 @@ function exponentialCDF( x ) {
3234
return cdf( x, this.lambda );
3335
} // end FUNCTION exponentialCDF()
3436

37+
/**
38+
* Evaluates the natural logarithm of the cumulative distribution function (CDF).
39+
*
40+
* @private
41+
* @param {number} x - input value
42+
* @returns {number} evaluated logCDF
43+
*/
44+
function exponentialLogCDF( x ) {
45+
return logcdf( x, this.lambda );
46+
} // end FUNCTION exponentialLogCDF()
47+
48+
/**
49+
* Evaluates the natural logarithm of the probability density function (PDF).
50+
*
51+
* @private
52+
* @param {number} x - input value
53+
* @returns {number} evaluated logPDF
54+
*/
55+
function exponentialLogPDF( x ) {
56+
return logpdf( x, this.lambda );
57+
} // end FUNCTION exponentialLogPDF()
58+
3559
/**
3660
* Evaluates the moment-generating function (MGF).
3761
*
@@ -311,6 +335,42 @@ Object.defineProperty( Exponential.prototype, 'variance', {
311335
*/
312336
setReadOnly( Exponential.prototype, 'cdf', exponentialCDF );
313337

338+
/**
339+
* Evaluates the natural logarithm of the cumulative distribution function (CDF).
340+
*
341+
* @memberof Exponential.prototype
342+
* @name logcdf
343+
* @type {Function}
344+
* @param {number} x - input value
345+
* @returns {number} evaluated logCDF
346+
* @see [cdf]{@link https://en.wikipedia.org/wiki/Cumulative_distribution_function}
347+
*
348+
* @example
349+
* var exponential = new Exponential( 2.0 );
350+
*
351+
* var v = exponential.logcdf( 0.5 );
352+
* // returns ~-0.459
353+
*/
354+
setReadOnly( Exponential.prototype, 'logcdf', exponentialLogCDF );
355+
356+
/**
357+
* Evaluates the natural logarithm of the probability density function (PDF).
358+
*
359+
* @memberof Exponential.prototype
360+
* @name logpdf
361+
* @type {Function}
362+
* @param {number} x - input value
363+
* @returns {number} evaluated logPDF
364+
* @see [pdf]{@link https://en.wikipedia.org/wiki/Probability_density_function}
365+
*
366+
* @example
367+
* var exponential = new Exponential( 2.0 );
368+
*
369+
* var v = exponential.logpdf( 0.8 );
370+
* // returns ~-0.906
371+
*/
372+
setReadOnly( Exponential.prototype, 'logpdf', exponentialLogPDF );
373+
314374
/**
315375
* Evaluates the moment-generating function (MGF).
316376
*

lib/node_modules/@stdlib/math/base/dist/exponential/ctor/test/test.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ var isFunction = require( '@stdlib/assert/is-function' );
77
var hasOwnProp = require( '@stdlib/assert/has-own-property' );
88
var quantile = require( '@stdlib/math/base/dist/exponential/quantile' );
99
var cdf = require( '@stdlib/math/base/dist/exponential/cdf' );
10+
var logcdf = require( '@stdlib/math/base/dist/exponential/logcdf' );
11+
var logpdf = require( '@stdlib/math/base/dist/exponential/logpdf' );
1012
var mgf = require( '@stdlib/math/base/dist/exponential/mgf' );
1113
var pdf = require( '@stdlib/math/base/dist/exponential/pdf' );
1214
var entropy = require( '@stdlib/math/base/dist/exponential/entropy' );
@@ -229,6 +231,34 @@ tape( 'the distribution prototype has a method for evaluating the cumulative dis
229231
t.end();
230232
});
231233

234+
tape( 'the distribution prototype has a method for evaluating the natural logarithm of the cumulative distribution function (CDF)', function test( t ) {
235+
var exponential;
236+
var y;
237+
238+
t.strictEqual( hasOwnProp( Exponential.prototype, 'logcdf' ), true, 'has property' );
239+
t.strictEqual( isFunction( Exponential.prototype.logcdf ), true, 'has method' );
240+
241+
exponential = new Exponential();
242+
y = exponential.logcdf( 0.5 );
243+
244+
t.strictEqual( y, logcdf( 0.5, 1.0 ), 'returns expected value' );
245+
t.end();
246+
});
247+
248+
tape( 'the distribution prototype has a method for evaluating the natural logarithm of the probability density function (PDF)', function test( t ) {
249+
var exponential;
250+
var y;
251+
252+
t.strictEqual( hasOwnProp( Exponential.prototype, 'logpdf' ), true, 'has property' );
253+
t.strictEqual( isFunction( Exponential.prototype.logpdf ), true, 'has method' );
254+
255+
exponential = new Exponential();
256+
y = exponential.logpdf( 0.2 );
257+
258+
t.strictEqual( y, logpdf( 0.2, 1.0 ), 'returns expected value' );
259+
t.end();
260+
});
261+
232262
tape( 'the distribution prototype has a method for evaluating the moment-generating function (MGF)', function test( t ) {
233263
var exponential;
234264
var y;

0 commit comments

Comments
 (0)