Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
245 changes: 245 additions & 0 deletions lib/node_modules/@stdlib/stats/base/dists/bradford/logpdf/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,245 @@
<!--

@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.

-->

# Logarithm of Probability Density Function

> [Bradford][bradford-distribution] distribution logarithm of the [probability density function][pdf] (logPDF).

<section class="intro">

The logarithm of the [probability density function][pdf] (logPDF) for a [Bradford][bradford-distribution] random variable is

<!-- <equation class="equation" label="eq:bradford_logpdf" align="center" raw="\ln f(x;c)=\ln(c)-\ln(1+cx)-\ln(\ln(1+c))" alt="Logarithm of Probability density function (PDF) for a Bradford distribution."> -->

```math
\ln f(x;c) = \ln(c) - \ln(1+cx) - \ln(\ln(1+c))
```

<!-- <div class="equation" align="center" data-raw-text="\ln f(x;c)=\ln(c)-\ln(1+cx)-\ln(\ln(1+c))" data-equation="eq:bradford_pdf">
<img src="https://cdn.jsdelivr.net/gh/stdlib-js/stdlib@51534079fef45e990850102147e8945fb023d1d0/lib/node_modules/@stdlib/stats/base/dists/bradford/pdf/docs/img/equation_bradford_pdf.svg" alt="Probability density function (PDF) for a Bradford distribution.">
<br>
</div> -->

<!-- </equation> -->

where `c > 0` is the shape parameter of the distribution.

</section>

<!-- /.intro -->

<section class="usage">

## Usage

```javascript
var logpdf = require( '@stdlib/stats/base/dists/bradford/logpdf' );
```

#### logpdf( x, c )

Evaluates the logarithm of [probability density function][pdf] (PDF) for a [Bradford][bradford-distribution] distribution with shape parameter `c` at a value `x`.

```javascript
var y = logpdf( 0.1, 0.1 );
// returns ~0.038

y = logpdf( 0.5, 5.0 );
// returns ~-0.227

y = logpdf( 1.0, 10.0 );
// returns ~-0.970
```

If provided `NaN` as any argument, the function returns `NaN`.

```javascript
var y = logpdf( NaN, 1.0 );
// returns NaN

y = logpdf( 0.0, NaN );
// returns NaN
```

If provided an `x` value which is outside the support `[0,1]`, the function returns `-Infinity`.

```javascript
var y = logpdf( 2.0, 1.0 );
// returns -Infinity

y = logpdf( -0.5, 1.0 );
// returns -Infinity
```

If provided a shape parameter `c <= 0`, the function returns `NaN`.

```javascript
var y = logpdf( 0.5, 0.0 );
// returns NaN

y = logpdf( 0.5, -5.0 );
// returns NaN
```

#### logpdf.factory( c )

Returns a function for evaluating the logarithm of a [PDF][pdf] for a [Bradford][bradford-distribution] distribution with shape parameter `c`.

```javascript
var myLogPDF = logpdf.factory( 5.0 );
var y = myLogPDF( 0.5 );
// returns ~-0.227

y = myLogPDF( 1.0 );
// returns ~-0.766
```

</section>

<!-- /.usage -->

<section class="examples">

## Examples

<!-- eslint no-undef: "error" -->

```javascript
var uniform = require( '@stdlib/random/array/uniform' );
var logEachMap = require( '@stdlib/console/log-each-map' );
var logpdf = require( '@stdlib/stats/base/dists/bradford/logpdf' );

var opts = {
'dtype': 'float64'
};
var c = uniform( 10, 0.1, 10.0, opts );
var x = uniform( 10, 0.0, 1.0, opts );

logEachMap( 'x: %0.4f, c: %0.4f, ln(f(x;c)): %0.4f', x, c, logpdf );
```

</section>

<!-- /.examples -->

<!-- C interface documentation. -->

<section class="c">

## C APIs

<section class="intro">

</section>

<!-- /.intro -->

<section class="usage">

### Usage

```c
#include "stdlib/stats/base/dists/bradford/logpdf.h"
```

#### stdlib_base_dists_bradford_logpdf( x, c )

Evaluates the logarithm of the probability density function for a Bradford distribution.

```c
double out = stdlib_base_dists_bradford_logpdf( 0.5, 5.0 );
// returns ~-0.227
```

The function accepts the following arguments:

- **x**: `[in] double` input value.
- **c**: `[in] double` shape parameter.

```c
double stdlib_base_dists_bradford_logpdf( const double x, const double c );
```

</section>

<!-- /.usage -->

<section class="notes">

</section>

<!-- /.notes -->

<section class="examples">

### Examples

```c
#include "stdlib/stats/base/dists/bradford/logpdf.h"
#include <stdlib.h>
#include <stdio.h>

static double random_uniform( const double min, const double max ) {
double v = (double)rand() / ( (double)RAND_MAX + 1.0 );
return min + ( v*(max-min) );
}

int main( void ) {
double x;
double c;
double y;
int i;

for ( i = 0; i < 10; i++ ) {
x = random_uniform( 0.0, 1.0 );
c = random_uniform( 0.01, 10.0 );
y = stdlib_base_dists_bradford_logpdf( x, c );
printf( "x: %lf, c: %lf, ln(f(x;c)): %lf\n", x, c, y );
}
}
```

</section>

<!-- /.examples -->

</section>

<!-- /.c -->

<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->

<section class="related">

</section>

<!-- /.related -->

<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->

<section class="links">

[pdf]: https://en.wikipedia.org/wiki/Probability_density_function

[bradford-distribution]: https://en.wikipedia.org/wiki/Bradford%27s_law

</section>

<!-- /.links -->
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
/**
* @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 format = require( '@stdlib/string/format' );
var pkg = require( './../package.json' ).name;
var logpdf = require( './../lib' );


// MAIN //

bench( pkg, function benchmark( b ) {
var opts;
var x;
var c;
var y;
var i;

opts = {
'dtype': 'float64'
};
x = uniform( 100, 0.0, 1.0, opts );
c = uniform( 100, 0.1, 10.0, opts );

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
y = logpdf( x[ i % x.length ], c[ i % c.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:factory', pkg ), function benchmark( b ) {
var mylogpdf;
var opts;
var x;
var y;
var i;

opts = {
'dtype': 'float64'
};
x = uniform( 100, 0.0, 1.0, opts );
mylogpdf = logpdf.factory( 5.0 );

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
y = mylogpdf( 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();
});
Loading