-
-
Notifications
You must be signed in to change notification settings - Fork 907
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
Merged
Merged
Changes from 10 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 fba8f2c
Merge branch 'logitf' of https://github.com/vivekmaurya001/stdlib int…
vivekmaurya001 92cc9c6
chore: update copyright years
stdlib-bot 33ea60a
Merge branch 'stdlib-js:develop' into logitf
vivekmaurya001 501ef98
add math/base/special/logitf
vivekmaurya001 2e3dce0
chore: update copyright years
stdlib-bot 1b0a660
add math/base/special/logitf
vivekmaurya001 30fe769
Merge branch 'logitf' of https://github.com/vivekmaurya001/stdlib int…
vivekmaurya001 5a0da6c
add math/base/special/logitf
vivekmaurya001 b600358
add math/base/special/logitf
vivekmaurya001 41a7874
Apply suggestions from code review
gunjjoshi 4348720
Update lib/node_modules/@stdlib/math/base/special/logitf/docs/types/i…
gunjjoshi d4d2a4a
Merge branch 'stdlib-js:develop' into logitf
vivekmaurya001 04761f2
Merge branch 'stdlib-js:develop' into logitf
vivekmaurya001 7049e2f
feat: add math/base/special/logitf
vivekmaurya001 3327eed
chore: update copyright years
stdlib-bot a975a76
Merge remote-tracking branch 'upstream/develop' into logitf
stdlib-bot ae813a0
chore: clean-up
anandkaranubc abbfe91
docs: fix function descriptions
anandkaranubc cb908ea
bench: follow code conventions and fix function return types
anandkaranubc 5c8a985
docs: replace manual for loop in examples
anandkaranubc ff84d08
chore: re-enable lint rule
anandkaranubc 4d5d7aa
fix: use float64ToFloat32 to avoid elevated precision
anandkaranubc dc07f16
test: replace equal with strictEqual
anandkaranubc File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
216 changes: 216 additions & 0 deletions
216
lib/node_modules/@stdlib/math/base/special/logitf/README.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,216 @@ | ||
<!-- | ||
|
||
@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 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) | ||
``` | ||
|
||
<!-- <div class="equation" align="center" data-raw-text="\operatorname{logitf}(p)=\log \left({\frac {p}{1-p}}\right)" data-equation="eq:logitf_function"> | ||
<img src="https://cdn.jsdelivr.net/gh/stdlib-js/stdlib@bb29798906e119fcb2af99e94b60407a270c9b32/lib/node_modules/@stdlib/math/base/special/logitf/docs/img/equation_logitf_function.svg" alt="Logitf function."> | ||
<br> | ||
</div> --> | ||
|
||
<!-- </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 single precision-floating point number. | ||
gunjjoshi marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
||
```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 logitf = require( '@stdlib/math/base/special/logitf' ); | ||
|
||
var len = 100; | ||
var opts = { | ||
'dtype': 'float32' | ||
}; | ||
var p = uniform( len, 0, 1, opts ); | ||
gunjjoshi marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
var i; | ||
|
||
for ( i = 0; i < 100; i++ ) { | ||
console.log( 'logitf(%f) = %f', p[ i ], logitf( p[ i ] ) ); | ||
gunjjoshi marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
} | ||
``` | ||
|
||
</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 single precision-floating point number. | ||
gunjjoshi marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
||
```c | ||
float out = stdlib_base_logitf( 0.2 ); | ||
gunjjoshi marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
// returns ~-1.386 | ||
gunjjoshi marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
||
out = stdlib_base_logitf( 0.9 ); | ||
gunjjoshi marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
// returns ~2.197 | ||
gunjjoshi marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
``` | ||
|
||
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; | ||
gunjjoshi marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
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 | ||
|
||
</section> | ||
|
||
<!-- /.links --> |
59 changes: 59 additions & 0 deletions
59
lib/node_modules/@stdlib/math/base/special/logitf/benchmark/benchmark.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
/** | ||
* @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 opts; | ||
var len; | ||
var x; | ||
var y; | ||
var i; | ||
|
||
opts = { | ||
'dtype': 'float32' | ||
}; | ||
|
||
len = 100; | ||
x = uniform( len, 0, 1, opts ); | ||
gunjjoshi marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
||
b.tic(); | ||
for ( i = 0; i < b.iterations; i++ ) { | ||
y = logitf( x[ i % len ] ); | ||
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(); | ||
}); |
68 changes: 68 additions & 0 deletions
68
lib/node_modules/@stdlib/math/base/special/logitf/benchmark/benchmark.native.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
/** | ||
* @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 opts; | ||
var len; | ||
var x; | ||
var y; | ||
var i; | ||
|
||
opts = { | ||
'dtype': 'float32' | ||
}; | ||
|
||
len = 100; | ||
x = uniform( len, 0, 1, opts ); | ||
gunjjoshi marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
||
b.tic(); | ||
for ( i = 0; i < b.iterations; i++ ) { | ||
y = logitf( x[ i % len ] ); | ||
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(); | ||
}); |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.