Skip to content
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

Feature/map fun async status #6548

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
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
33 changes: 33 additions & 0 deletions lib/node_modules/@stdlib/math/base/special/betaincinv/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Makefile for betaincinv module

# Default target
all: build

# Build the native module
build:
node-gyp configure
node-gyp build

# Run tests
test:
node test/test.js

# Run tests with coverage
test-cov:
nyc node test/test.js

# Run examples
examples:
node examples/index.js

# Run benchmarks
benchmark:
node benchmark/index.js

# Clean build artifacts
clean:
node-gyp clean
rm -rf build/
rm -rf coverage/

.PHONY: all build test test-cov examples benchmark clean
126 changes: 34 additions & 92 deletions lib/node_modules/@stdlib/math/base/special/betaincinv/README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
<!--

@license Apache-2.0

Copyright (c) 2018 The Stdlib Authors.
Copyright (c) 2024 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.
Expand All @@ -15,15 +14,16 @@ 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.

-->

# betaincinv

> Inverse of the [incomplete beta function][incomplete-beta-function].
> Inverse incomplete beta function.

<section class="intro">

The [inverse incomplete beta function][inverse-incomplete-beta] is the inverse of the [incomplete beta function][incomplete-beta]. It is used in various statistical applications, including hypothesis testing and confidence interval calculations.

</section>

<!-- /.intro -->
Expand All @@ -36,69 +36,35 @@ limitations under the License.
var betaincinv = require( '@stdlib/math/base/special/betaincinv' );
```

#### betaincinv( p, a, b\[, upper] )
#### betaincinv( p, a, b )

Inverts the regularized [incomplete beta function][incomplete-beta-function]. Contrary to the more commonly used definition, in this implementation the first parameter is the probability `p` and the second and third parameter are `a` and `b`. By default, the function inverts the _lower_ regularized [incomplete beta function][incomplete-beta-function]. To invert the _upper_ function instead, set the `upper` argument to `true`.
Evaluates the inverse of the incomplete beta function:

```javascript
var y = betaincinv( 0.2, 3.0, 3.0 );
var y = betaincinv( 0.5, 1.0, 1.0 );
// returns 0.5

y = betaincinv( 0.2, 3.0, 3.0 );
// returns ~0.327

y = betaincinv( 0.4, 3.0, 3.0 );
// returns ~0.446

y = betaincinv( 0.4, 3.0, 3.0, true );
// returns ~0.554

y = betaincinv( 0.4, 1.0, 6.0 );
// returns ~0.082

y = betaincinv( 0.8, 1.0, 6.0 );
// returns ~0.235
```

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

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

y = betaincinv( 0.5, NaN, 1.0 );
// returns NaN

y = betaincinv( 0.5, 1.0, NaN );
// returns NaN
```

If provided a value outside `[0,1]` for `p`, the function returns `NaN`.

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

y = betaincinv( -0.5, 1.0, 1.0 );
// returns NaN
```

If provided a nonpositive `a`, the function returns `NaN`.

```javascript
var y = betaincinv( 0.5, -2.0, 2.0 );
// returns NaN

y = betaincinv( 0.5, 0.0, 2.0 );
// returns NaN
```
The function accepts the following parameters:

If provided a nonpositive `b`, the function returns `NaN`.
- **p**: probability value (input value for the incomplete beta function).
- **a**: first shape parameter (must be positive).
- **b**: second shape parameter (must be positive).

```javascript
var y = betaincinv( 0.5, 2.0, -2.0 );
// returns NaN
The function returns `NaN` if any of the following conditions are met:

y = betaincinv( 0.5, 2.0, 0.0 );
// returns NaN
```
- `p` is outside the interval `[0,1]`
- `a` is not positive
- `b` is not positive

</section>

Expand All @@ -108,58 +74,34 @@ y = betaincinv( 0.5, 2.0, 0.0 );

## Examples

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

```javascript
var uniform = require( '@stdlib/random/array/uniform' );
var logEachMap = require( '@stdlib/console/log-each-map' );
var betaincinv = require( '@stdlib/math/base/special/betaincinv' );

var opts = {
'dtype': 'float64'
};
var p = uniform( 100, 0.0, 1.0, opts );
var a = uniform( 100, 0.0, 10.0, opts );
var b = uniform( 100, 0.0, 10.0, opts );

logEachMap( 'p: %0.4f, \t a: %0.4f, \t b: %0.4f, \t f(p,a,b): %0.4f', p, a, b, betaincinv );
```

</section>

<!-- /.examples -->

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

<section class="related">
var y = betaincinv( 0.5, 1.0, 1.0 );
console.log( y );
// => 0.5

* * *
y = betaincinv( 0.2, 3.0, 3.0 );
console.log( y );
// => ~0.327

## See Also
y = betaincinv( 0.4, 3.0, 3.0 );
console.log( y );
// => ~0.446

- <span class="package-name">[`@stdlib/math/base/special/beta`][@stdlib/math/base/special/beta]</span><span class="delimiter">: </span><span class="description">beta function.</span>
- <span class="package-name">[`@stdlib/math/base/special/betainc`][@stdlib/math/base/special/betainc]</span><span class="delimiter">: </span><span class="description">incomplete beta function.</span>
- <span class="package-name">[`@stdlib/math/base/special/betaln`][@stdlib/math/base/special/betaln]</span><span class="delimiter">: </span><span class="description">natural logarithm of the beta function.</span>
y = betaincinv( 0.4, 1.0, 6.0 );
console.log( y );
// => ~0.082
```

</section>

<!-- /.related -->

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

<section class="links">

[incomplete-beta-function]: https://en.wikipedia.org/wiki/Incomplete_beta_function

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

[@stdlib/math/base/special/beta]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/math/base/special/beta

[@stdlib/math/base/special/betainc]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/math/base/special/betainc

[@stdlib/math/base/special/betaln]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/math/base/special/betaln

<!-- </related-links> -->
[incomplete-beta]: https://en.wikipedia.org/wiki/Beta_function#Incomplete_beta_function
[inverse-incomplete-beta]: https://en.wikipedia.org/wiki/Beta_function#Incomplete_beta_function

</section>

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/**
* @license Apache-2.0
*
* Copyright (c) 2024 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 randu = require( '@stdlib/random/base/randu' );
var betaincinv = require( './../lib' );

var p;
var a;
var b;
var i;

console.log( 'Running benchmarks...\n' );

// Benchmark 1: Basic usage
console.log( 'Benchmark 1: Basic usage' );
console.time( 'betaincinv' );
for ( i = 0; i < 1e6; i++ ) {
p = randu();
a = randu() * 10.0 + 1.0;
b = randu() * 10.0 + 1.0;
betaincinv( p, a, b );
}
console.timeEnd( 'betaincinv' );

// Benchmark 2: Edge cases
console.log( '\nBenchmark 2: Edge cases' );
console.time( 'betaincinv (edge cases)' );
for ( i = 0; i < 1e6; i++ ) {
p = (i % 2 === 0) ? 0.0 : 1.0;
a = 1.0;
b = 1.0;
betaincinv( p, a, b );
}
console.timeEnd( 'betaincinv (edge cases)' );

// Benchmark 3: Invalid inputs
console.log( '\nBenchmark 3: Invalid inputs' );
console.time( 'betaincinv (invalid inputs)' );
for ( i = 0; i < 1e6; i++ ) {
p = (i % 2 === 0) ? -0.5 : 1.5;
a = 1.0;
b = 1.0;
betaincinv( p, a, b );
}
console.timeEnd( 'betaincinv (invalid inputs)' );
42 changes: 42 additions & 0 deletions lib/node_modules/@stdlib/math/base/special/betaincinv/binding.gyp
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
{
"targets": [
{
"target_name": "betaincinv",
"sources": [
"src/betaincinv.c"
],
"include_dirs": [
"<!@(node -p \"require('node-addon-api').include\")"
],
"dependencies": [
"<!(node -p \"require('node-addon-api').gyp\")"
],
"cflags!": [
"-fno-exceptions"
],
"cflags_cc!": [
"-fno-exceptions"
],
"xcode_settings": {
"GCC_ENABLE_CPP_EXCEPTIONS": "YES",
"CLANG_CXX_LIBRARY": "libc++",
"MACOSX_DEPLOYMENT_TARGET": "10.7"
},
"msvs_settings": {
"VCCLCompilerTool": {
"ExceptionHandling": 1
}
},
"defines": [
"NAPI_DISABLE_CPP_EXCEPTIONS"
],
"conditions": [
['OS=="win"', {
"defines": [
"NOMINMAX"
]
}]
]
}
]
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* @license Apache-2.0
*
* Copyright (c) 2018 The Stdlib Authors.
* Copyright (c) 2024 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.
Expand All @@ -18,15 +18,23 @@

'use strict';

var uniform = require( '@stdlib/random/array/uniform' );
var logEachMap = require( '@stdlib/console/log-each-map' );
var betaincinv = require( './../lib' );

var opts = {
'dtype': 'float64'
};
var p = uniform( 100, 0.0, 1.0, opts );
var a = uniform( 100, 0.0, 10.0, opts );
var b = uniform( 100, 0.0, 10.0, opts );
// Example 1: Basic usage
console.log( '\nExample 1: Basic usage' );
console.log( 'betaincinv(0.5, 1.0, 1.0) =', betaincinv( 0.5, 1.0, 1.0 ) );
console.log( 'betaincinv(0.2, 3.0, 3.0) =', betaincinv( 0.2, 3.0, 3.0 ) );
console.log( 'betaincinv(0.4, 3.0, 3.0) =', betaincinv( 0.4, 3.0, 3.0 ) );
console.log( 'betaincinv(0.4, 1.0, 6.0) =', betaincinv( 0.4, 1.0, 6.0 ) );

logEachMap( 'p: %0.4f, \t a: %0.4f, \t b: %0.4f, \t f(p,a,b): %0.4f', p, a, b, betaincinv );
// Example 2: Edge cases
console.log( '\nExample 2: Edge cases' );
console.log( 'betaincinv(0.0, 1.0, 1.0) =', betaincinv( 0.0, 1.0, 1.0 ) );
console.log( 'betaincinv(1.0, 1.0, 1.0) =', betaincinv( 1.0, 1.0, 1.0 ) );

// Example 3: Invalid inputs
console.log( '\nExample 3: Invalid inputs' );
console.log( 'betaincinv(-0.5, 1.0, 1.0) =', betaincinv( -0.5, 1.0, 1.0 ) );
console.log( 'betaincinv(1.5, 1.0, 1.0) =', betaincinv( 1.5, 1.0, 1.0 ) );
console.log( 'betaincinv(0.5, 0.0, 1.0) =', betaincinv( 0.5, 0.0, 1.0 ) );
console.log( 'betaincinv(0.5, 1.0, -1.0) =', betaincinv( 0.5, 1.0, -1.0 ) );
Loading
Loading