|
| 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 --> |
0 commit comments