Skip to content

Commit 874fd5c

Browse files
committed
feat: add JavaScript implementation and documentation for math/base/special/boxcoxf
--- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: passed - task: lint_package_json status: na - task: lint_repl_help status: passed - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: passed - task: lint_javascript_tests status: passed - task: lint_javascript_benchmarks status: passed - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: passed - task: lint_typescript_tests status: passed - task: lint_license_headers status: passed ---
1 parent 055e192 commit 874fd5c

10 files changed

Lines changed: 822 additions & 42 deletions

File tree

Lines changed: 254 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,254 @@
1+
<!--
2+
3+
@license Apache-2.0
4+
5+
Copyright (c) 2025 The Stdlib Authors.
6+
7+
Licensed under the Apache License, Version 2.0 (the "License");
8+
you may not use this file except in compliance with the License.
9+
You may obtain a copy of the License at
10+
11+
http://www.apache.org/licenses/LICENSE-2.0
12+
13+
Unless required by applicable law or agreed to in writing, software
14+
distributed under the License is distributed on an "AS IS" BASIS,
15+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
See the License for the specific language governing permissions and
17+
limitations under the License.
18+
19+
-->
20+
21+
# boxcoxf
22+
23+
> Compute a one-parameter [Box-Cox transformation][box-cox-transformation] for single-precision floating-point number.
24+
25+
<!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. -->
26+
27+
<section class="intro">
28+
29+
The one-parameter [Box-Cox transformation][box-cox-transformation] is defined as
30+
31+
<!-- <equation class="equation" label="eq:boxcox_transformation_one_parameter" align="center" raw="y^{\lambda} = \begin{cases}\frac{y^{\lambda} - 1}{\lambda} & \textrm{if}\ \lambda \neq 0 \\ \ln(y) & \textrm{if}\ \lambda = 0 \end{cases}" alt="One-Parameter Box-Cox Transformation"> -->
32+
33+
<div class="equation" align="center" data-raw-text="y^{\lambda} = \begin{cases}\frac{y^{\lambda} - 1}{\lambda} & \textrm{if}\ \lambda \neq 0 \\ \ln(y) & \textrm{if}\ \lambda = 0 \end{cases}" data-equation="eq:boxcox_transformation_one_parameter">
34+
<img src="https://cdn.jsdelivr.net/gh/stdlib-js/stdlib@1cd982bdbe87913bbb66e9d6a79b0acb0fb89616/lib/node_modules/@stdlib/math/base/special/boxcox/docs/img/equation_boxcox_transformation_one_parameter.svg" alt="One-Parameter Box-Cox Transformation" />
35+
<br>
36+
</div>
37+
38+
<!-- </equation> -->
39+
40+
</section>
41+
42+
<!-- /.intro -->
43+
44+
<!-- Package usage documentation. -->
45+
46+
<section class="usage">
47+
48+
## Usage
49+
50+
```javascript
51+
var boxcoxf = require( '@stdlib/math/base/special/boxcoxf' );
52+
```
53+
54+
#### boxcoxf( x, lambda )
55+
56+
Computes a one-parameter [Box-Cox transformation][box-cox-transformation] for a single-precision floating-point number.
57+
58+
```javascript
59+
var v = boxcoxf( 1.0, 2.5 );
60+
// returns 0.0
61+
62+
v = boxcoxf( 4.0, 2.5 );
63+
// returns ~12.4
64+
65+
v = boxcoxf( 10.0, 2.5 );
66+
// returns ~126.0911
67+
68+
v = boxcoxf( 2.0, 0.0 );
69+
// returns ~0.6931
70+
71+
v = boxcoxf( -1.0, 2.5 );
72+
// returns NaN
73+
74+
v = boxcoxf( 0.0, -1.0 );
75+
// returns -Infinity
76+
```
77+
78+
</section>
79+
80+
<!-- /.usage -->
81+
82+
<!-- Package usage examples. -->
83+
84+
<section class="examples">
85+
86+
## Examples
87+
88+
<!-- eslint no-undef: "error" -->
89+
90+
```javascript
91+
var incrspace = require( '@stdlib/array/base/incrspace' );
92+
var boxcoxf = require( '@stdlib/math/base/special/boxcoxf' );
93+
94+
var x = incrspace( -1.0, 10.0, 1.0 );
95+
var l = incrspace( -0.5, 5.0, 0.5 );
96+
97+
var b;
98+
var i;
99+
var j;
100+
for ( i = 0; i < x.length; i++ ) {
101+
for ( j = 0; j < l.length; j++ ) {
102+
b = boxcoxf( x[ i ], l[ j ] );
103+
console.log( 'boxcoxf(%d, %d) = %d', x[ i ], l[ j ], b );
104+
}
105+
}
106+
```
107+
108+
</section>
109+
110+
<!-- /.examples -->
111+
112+
<!-- C interface documentation. -->
113+
114+
* * *
115+
116+
<section class="c">
117+
118+
## C APIs
119+
120+
<!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. -->
121+
122+
<section class="intro">
123+
124+
</section>
125+
126+
<!-- /.intro -->
127+
128+
<!-- C usage documentation. -->
129+
130+
<section class="usage">
131+
132+
### Usage
133+
134+
```c
135+
#include "stdlib/math/base/special/boxcoxf.h"
136+
```
137+
138+
#### stdlib_base_boxcoxf( x, lambda )
139+
140+
Computes a one-parameter [Box-Cox transformation][box-cox-transformation] for a single-precision floating-point number.
141+
142+
```c
143+
float out = stdlib_base_boxcoxf( 1.0f, 2.5f );
144+
// returns 0.0f
145+
146+
out = stdlib_base_boxcoxf( 4.0f, 2.5f );
147+
// returns ~12.4f
148+
```
149+
150+
The function accepts the following arguments:
151+
152+
- **x**: `[in] float` input value.
153+
- **lambda**: `[in] float` power parameter.
154+
155+
```c
156+
float stdlib_base_boxcoxf( const float x, const float lambda );
157+
```
158+
159+
</section>
160+
161+
<!-- /.usage -->
162+
163+
<!-- C API usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
164+
165+
<section class="notes">
166+
167+
</section>
168+
169+
<!-- /.notes -->
170+
171+
<!-- C API usage examples. -->
172+
173+
<section class="examples">
174+
175+
### Examples
176+
177+
```c
178+
#include "stdlib/math/base/special/boxcoxf.h"
179+
#include <stdio.h>
180+
181+
int main( void ) {
182+
const float x[] = { -1.0f, 10.0f, 1.0f };
183+
const float y[] = { -0.5f, 5.0f, 0.5f };
184+
185+
float out;
186+
int i;
187+
int j;
188+
for ( i = 0; i < 3; i++ ) {
189+
for ( j = 0; j < 3; j++ ) {
190+
out = stdlib_base_boxcoxf( x[ i ], y[ j ] );
191+
printf( "x: %f, y: %f, out: %f\n", x[ i ], y[ j ], out );
192+
}
193+
}
194+
}
195+
```
196+
197+
</section>
198+
199+
<!-- /.examples -->
200+
201+
</section>
202+
203+
<!-- /.c -->
204+
205+
<!-- Section to include cited references. If references are included, add a horizontal rule *before* the section. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
206+
207+
<section class="references">
208+
209+
## References
210+
211+
- Box, G. E. P., and D. R. Cox. 1964. "An Analysis of Transformations." _Journal of the Royal Statistical Society. Series B (Methodological)_ 26 (2). \[Royal Statistical Society, Wiley]: 211–52. <http://www.jstor.org/stable/2984418>.
212+
213+
</section>
214+
215+
<!-- /.references -->
216+
217+
<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->
218+
219+
<section class="related">
220+
221+
* * *
222+
223+
## See Also
224+
225+
- <span class="package-name">[`@stdlib/math/base/special/boxcox`][@stdlib/math/base/special/boxcox]</span><span class="delimiter">: </span><span class="description">compute a one-parameter Box-Cox transformation.</span>
226+
- <span class="package-name">[`@stdlib/math/base/special/boxcoxinv`][@stdlib/math/base/special/boxcoxinv]</span><span class="delimiter">: </span><span class="description">compute the inverse of a one-parameter Box-Cox transformation.</span>
227+
- <span class="package-name">[`@stdlib/math/base/special/boxcox1p`][@stdlib/math/base/special/boxcox1p]</span><span class="delimiter">: </span><span class="description">compute a one-parameter Box-Cox transformation of 1+x.</span>
228+
- <span class="package-name">[`@stdlib/math/base/special/boxcox1pinv`][@stdlib/math/base/special/boxcox1pinv]</span><span class="delimiter">: </span><span class="description">compute the inverse of a one-parameter Box-Cox transformation for 1+x.</span>
229+
230+
</section>
231+
232+
<!-- /.related -->
233+
234+
<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
235+
236+
<section class="links">
237+
238+
[box-cox-transformation]: https://en.wikipedia.org/wiki/Power_transform#Box-Cox_transformation
239+
240+
<!-- <related-links> -->
241+
242+
[@stdlib/math/base/special/boxcox]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/math/base/special/boxcox
243+
244+
[@stdlib/math/base/special/boxcoxinv]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/math/base/special/boxcoxinv
245+
246+
[@stdlib/math/base/special/boxcox1p]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/math/base/special/boxcox1p
247+
248+
[@stdlib/math/base/special/boxcox1pinv]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/math/base/special/boxcox1pinv
249+
250+
<!-- </related-links> -->
251+
252+
</section>
253+
254+
<!-- /.links -->
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2025 The Stdlib Authors.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
'use strict';
20+
21+
// MODULES //
22+
23+
var bench = require( '@stdlib/bench' );
24+
var uniform = require( '@stdlib/random/array/uniform' );
25+
var isnanf = require( '@stdlib/math/base/assert/is-nanf' );
26+
var pkg = require( './../package.json' ).name;
27+
var boxcoxf = require( './../lib' );
28+
29+
30+
// VARIABLES //
31+
32+
var options = {
33+
'dtype': 'float32'
34+
};
35+
36+
37+
// MAIN //
38+
39+
bench( pkg, function benchmark( b ) {
40+
var x;
41+
var y;
42+
var r;
43+
var i;
44+
45+
x = uniform( 100, 1.0, 11.0, options );
46+
y = uniform( 100, 1.0, 11.0, options );
47+
48+
b.tic();
49+
for ( i = 0; i < b.iterations; i++ ) {
50+
r = boxcoxf( x[ i%x.length ], y[ i%y.length ] );
51+
if ( isnanf( r ) ) {
52+
b.fail( 'should not return NaN' );
53+
}
54+
}
55+
b.toc();
56+
if ( isnanf( r ) ) {
57+
b.fail( 'should not return NaN' );
58+
}
59+
b.pass( 'benchmark finished' );
60+
b.end();
61+
});
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
2+
{{alias}}( x, lambda )
3+
Computes a one-parameter Box-Cox transformation for single-precision
4+
floating-point number.
5+
6+
Parameters
7+
----------
8+
x: number
9+
Input value.
10+
11+
lambda: number
12+
Power parameter.
13+
14+
Returns
15+
-------
16+
b: number
17+
Function value.
18+
19+
Examples
20+
--------
21+
> var v = {{alias}}( 1.0, 2.5 )
22+
0.0
23+
> v = {{alias}}( 4.0, 2.5 )
24+
~12.4
25+
> v = {{alias}}( 10.0, 2.5 )
26+
~126.0911
27+
> v = {{alias}}( 2.0, 0.0 )
28+
~0.6931
29+
> v = {{alias}}( -1.0, 2.5 )
30+
NaN
31+
> v = {{alias}}( 0.0, -1.0 )
32+
-Infinity
33+
34+
See Also
35+
--------

0 commit comments

Comments
 (0)