Skip to content

feat: add math/base/special/logitf #3367

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 24 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
084c777
feat(math): add math/base/special/logitf
vivekmaurya001 Dec 7, 2024
fba8f2c
Merge branch 'logitf' of https://github.com/vivekmaurya001/stdlib int…
vivekmaurya001 Dec 7, 2024
92cc9c6
chore: update copyright years
stdlib-bot Dec 7, 2024
33ea60a
Merge branch 'stdlib-js:develop' into logitf
vivekmaurya001 Jan 18, 2025
501ef98
add math/base/special/logitf
vivekmaurya001 Jan 18, 2025
2e3dce0
chore: update copyright years
stdlib-bot Jan 18, 2025
1b0a660
add math/base/special/logitf
vivekmaurya001 Jan 18, 2025
30fe769
Merge branch 'logitf' of https://github.com/vivekmaurya001/stdlib int…
vivekmaurya001 Jan 18, 2025
5a0da6c
add math/base/special/logitf
vivekmaurya001 Jan 18, 2025
b600358
add math/base/special/logitf
vivekmaurya001 Jan 18, 2025
41a7874
Apply suggestions from code review
gunjjoshi Mar 7, 2025
4348720
Update lib/node_modules/@stdlib/math/base/special/logitf/docs/types/i…
gunjjoshi Mar 7, 2025
d4d2a4a
Merge branch 'stdlib-js:develop' into logitf
vivekmaurya001 Mar 7, 2025
04761f2
Merge branch 'stdlib-js:develop' into logitf
vivekmaurya001 Mar 8, 2025
7049e2f
feat: add math/base/special/logitf
vivekmaurya001 Mar 8, 2025
3327eed
chore: update copyright years
stdlib-bot Mar 8, 2025
a975a76
Merge remote-tracking branch 'upstream/develop' into logitf
stdlib-bot Apr 17, 2025
ae813a0
chore: clean-up
anandkaranubc Apr 17, 2025
abbfe91
docs: fix function descriptions
anandkaranubc Apr 17, 2025
cb908ea
bench: follow code conventions and fix function return types
anandkaranubc Apr 17, 2025
5c8a985
docs: replace manual for loop in examples
anandkaranubc Apr 17, 2025
ff84d08
chore: re-enable lint rule
anandkaranubc Apr 17, 2025
4d5d7aa
fix: use float64ToFloat32 to avoid elevated precision
anandkaranubc Apr 17, 2025
dc07f16
test: replace equal with strictEqual
anandkaranubc Apr 17, 2025
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
212 changes: 212 additions & 0 deletions lib/node_modules/@stdlib/math/base/special/logitf/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,212 @@
<!--

@license Apache-2.0

Copyright (c) 2025 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.

-->

# logitf

> Compute the [logit][logit] function for a single-precision floating-point number.

<section class="intro">

The [logit][logit] function is defined as the logarithm of the odds `p / (1-p)`; i.e.,

<!-- <equation class="equation" label="eq:logitf_function" align="center" raw="\operatorname{logitf}(p)=\log \left({\frac {p}{1-p}}\right)" alt="Logitf function."> -->

```math
\mathop{\mathrm{logitf}}(p)=\log \left({\frac {p}{1-p}}\right)
```

<!-- </equation> -->

The [logit][logit] function is the inverse of the [standard logistic][standard-logistic] function, sometimes also called the sigmoid function.

</section>

<!-- /.intro -->

<section class="usage">

## Usage

```javascript
var logitf = require( '@stdlib/math/base/special/logitf' );
```

#### logitf( p )

Computes the [logit][logit] function for a single-precision floating-point number.

```javascript
var v = logitf( 0.2 );
// returns ~-1.386

v = logitf( 0.9 );
// returns ~2.197
```

If `p < 0` or `p > 1`, the function returns `NaN`.

```javascript
var v = logitf( 1.3 );
// returns NaN

v = logitf( -0.2 );
// returns NaN
```

</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 logitf = require( '@stdlib/math/base/special/logitf' );

var opts = {
'dtype': 'float32'
};
var p = uniform( 100, 0.0, 1.0, opts );

logEachMap( 'logitf(%0.4f) = %0.4f', p, logitf );
```

</section>

<!-- /.examples -->

<!-- C interface documentation. -->

* * *

<section class="c">

## C APIs

<!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. -->

<section class="intro">

</section>

<!-- /.intro -->

<!-- C usage documentation. -->

<section class="usage">

### Usage

```c
#include "stdlib/math/base/special/logitf.h"
```

#### stdlib_base_logitf( p )

Computes the [logit][logit] function for a single-precision floating-point number.

```c
float out = stdlib_base_logitf( 0.2f );
// returns ~-1.386f

out = stdlib_base_logitf( 0.9f );
// returns ~2.197f
```

The function accepts the following arguments:

- **p**: `[in] float` input value.

```c
float stdlib_base_logitf( const float p );
```

</section>

<!-- /.usage -->

<!-- C API usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->

<section class="notes">

</section>

<!-- /.notes -->

<!-- C API usage examples. -->

<section class="examples">

### Examples

```c
#include "stdlib/math/base/special/logitf.h"
#include <stdlib.h>
#include <stdio.h>

int main( void ) {
float x;
float v;
int i;

for ( i = 0; i < 100; i++ ) {
x = (float)rand() / (float)RAND_MAX;
v = stdlib_base_logitf( x );
printf( "logitf(%f) = %f\n", x, v );
}
}
```

</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">

[logit]: https://en.wikipedia.org/wiki/Logit

[standard-logistic]: https://en.wikipedia.org/wiki/Logistic_function

<!-- <related-links> -->

<!-- </related-links> -->

</section>

<!-- /.links -->
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/**
* @license Apache-2.0
*
* Copyright (c) 2025 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 isnanf = require( '@stdlib/math/base/assert/is-nanf' );
var pkg = require( './../package.json' ).name;
var logitf = require( './../lib' );


// MAIN //

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

x = uniform( 100, 0.0, 1.0, {
'dtype': 'float32'
});

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
y = logitf( x[ i%x.length ] );
if ( isnanf( y ) ) {
b.fail( 'should not return NaN' );
}
}
b.toc();
if ( isnanf( y ) ) {
b.fail( 'should not return NaN' );
}
b.pass( 'benchmark finished' );
b.end();
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/**
* @license Apache-2.0
*
* Copyright (c) 2025 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 resolve = require( 'path' ).resolve;
var bench = require( '@stdlib/bench' );
var uniform = require( '@stdlib/random/array/uniform' );
var isnanf = require( '@stdlib/math/base/assert/is-nanf' );
var tryRequire = require( '@stdlib/utils/try-require' );
var pkg = require( './../package.json' ).name;


// VARIABLES //

var logitf = tryRequire( resolve( __dirname, './../lib/native.js' ) );
var opts = {
'skip': ( logitf instanceof Error )
};


// MAIN //

bench( pkg+'::native', opts, function benchmark( b ) {
var x;
var y;
var i;

x = uniform( 100, 0.0, 1.0, {
'dtype': 'float32'
});

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
y = logitf( x[ i%x.length ] );
if ( isnanf( y ) ) {
b.fail( 'should not return NaN' );
}
}
b.toc();
if ( isnanf( y ) ) {
b.fail( 'should not return NaN' );
}
b.pass( 'benchmark finished' );
b.end();
});
Loading