Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
9baa1b7
initial implementation of boxcox transform package
justin1dennison Oct 17, 2018
fff2b8f
added benchmarking
justin1dennison Oct 18, 2018
479e477
added the python benchmark for scipy boxcox
justin1dennison Oct 18, 2018
79cb918
altered to use float64 eps constant
justin1dennison Oct 18, 2018
a803e8f
added tests for boxcox
justin1dennison Oct 18, 2018
0c755ab
fixed tests and test fixtures
justin1dennison Oct 19, 2018
2621037
added negative lambda parameters and removed extraneous new lines
justin1dennison Oct 19, 2018
b14d250
updated keywords and description in package.json
justin1dennison Oct 19, 2018
64c64ff
updated jsdoc for boxcox
justin1dennison Oct 19, 2018
2a1acb1
updated import of boxcox in examples
justin1dennison Oct 19, 2018
64bb683
updated formatting and output of repl.txt
justin1dennison Oct 19, 2018
43b28b8
added end of file newline and removed odd indentation
justin1dennison Oct 19, 2018
b6b5170
fixed formatting of readme including examples and equation
justin1dennison Oct 19, 2018
bd82695
updated benchmarking code
justin1dennison Oct 19, 2018
47908b4
altered the data fixture for testing the implementation of boxcox
justin1dennison Oct 19, 2018
79531f3
updated the threshold for tolerance testing of values
justin1dennison Oct 19, 2018
e8d1d0b
removed equation image
justin1dennison Oct 22, 2018
e3cfbbd
mirrored epsilon usage from scipy instead of float62-eps
justin1dennison Oct 22, 2018
4d705b9
altered testing to testing more random bit arrangements. Had to alter…
justin1dennison Oct 22, 2018
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
130 changes: 130 additions & 0 deletions lib/node_modules/@stdlib/math/base/special/boxcox/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
<!--

@license Apache-2.0

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

-->

# boxcox

> Compute the [Box-Cox transformation][box-cox-transformation].

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

The [Box-Cox transformation][box-cox-transformation] is defined as

<!-- <equation class="equation" label="eq:boxcox_transformation_one_parameter" align="center" raw="y_{i}^{\lambda } = \left\{\begin{matrix}\frac{y_{i}^{\lambda} - 1}{\lambda} & if \lambda \neq 0,\\ln(y) & if \lambda = 0,\end{matrix}\right." alt="One Parameter Box-Cox Transformation"> -->

<div class="equation" align="center" data-raw-text="y_{i}^{\lambda } = \left\{\begin{matrix\frac{y_{i}^{\lambda} - 1}{\lambda} & if \lambda \neq 0,\\ln(y) & if \lambda = 0,
\end{matrix}\right." data-equation="eq:boxcox_transformation_one_parameter">
<img src="" alt="One Parameter Box-Cox Transformation" />
<br>
</div>

<!-- </equation> -->

</section>

<!-- /.intro -->

<!-- Package usage documentation. -->

<section class="usage">

## Usage

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

#### boxcox( x, lambda)

Compute the [Box-Cox transformation][box-cox-transformation].

```javascript
var v = boxcox( 1.0, 2.5 );
// returns 0.0

v = boxcox( 4.0, 2.5 );
// returns 12.4

v = boxcox( 10.0, 2.5 );
// returns ~126.0911

v = boxcox( 2.0, 0.0 );
// returns ~0.6931

v = boxcox( -1.0, 2.5 );
// returns NaN

v = boxcox( 0.0, -1.0 );
// returns -Infinity
```

</section>

<!-- /.usage -->

<!-- Package usage examples. -->

<section class="examples">

## Examples

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

```javascript
var incrspace = require( '@stdlib/math/utils/incrspace' );
var boxcox = require( '@stdlib/math/base/special/boxcox' );

var x = incrspace( -1.0, 10.0, 1.0 );
var l = incrspace( -0.5, 5.0, 0.5 );
var b;
var i;
var j;

for ( i = 0; i < x.length; i++ ) {
for ( j = 0; j < l.length; j++ ) {
b = boxcox( x[ i ], l[ j ] );
console.log( 'x: %d, lambda: %d, b(x, lambda): %d', x[ i ], l[ j ], b );
}
}

```

</section>

<!-- /.examples -->

<!-- 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. -->

<section class="references">

</section>

<!-- /.references -->

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

<section class="links">

[box-cox-transformation]: https://en.wikipedia.org/wiki/Power_transform#Box-Cox_transformation

</section>

<!-- /.links -->
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/**
* @license Apache-2.0
*
* Copyright (c) 2018 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 randu = require( '@stdlib/random/base/randu' );
var boxcox = require( '@stdlib/math/base/special/boxcox' );
var isnan = require( '@stdlib/math/base/assert/is-nan' );
var pkg = require( './../package.json' ).name;


// MAIN //

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

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
x = ( randu() * 10.0 ) + 1.0;
y = ( randu() * 10.0 ) + 1.0;
r = boxcox( x, y );
if ( isnan( r ) ) {
b.fail( 'should not return NaN' );
}
}
b.toc();
if ( isnan( r ) ) {
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,97 @@
#!/usr/bin/env python
#
# @license Apache-2.0
#
# Copyright (c) 2018 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.

"""Benchmark scipy.special.boxcox."""

from __future__ import print_function
import timeit

NAME = "boxcox"
REPEATS = 3
ITERATIONS = 1000000


def print_version():
"""Print the TAP version."""
print("TAP version 13")


def print_summary(total, passing):
"""Print the benchmark summary.

# Arguments

* `total`: total number of tests
* `passing`: number of passing tests

"""
print("#")
print("1.." + str(total))
print("# total " + str(total))
print("# pass " + str(passing))
print("#")
print("# ok")


def print_results(elapsed):
"""Print benchmark results.

# Arguments

* `elapsed`: elapsed time (in seconds)

# Examples

```python
python> print_results(0.2543188374)
```
"""
rate = ITERATIONS / elapsed

print(" ---")
print(" iterations: " + str(ITERATIONS))
print(" elapsed: " + str(elapsed))
print(" rate: " + str(rate))
print(" ...")


def benchmark():
"""Run the benchmark and print benchmark results."""
setup = "from scipy.special import boxcox; from random import random;"
stmt = "boxcox((100.0 * random()) - 50.0, (100.0 * random()) - 50.0)"

t = timeit.Timer(stmt, setup=setup)

print_version()

for i in range(REPEATS):
print("# python::scipy::special::" + NAME)
elapsed = t.timeit(number=ITERATIONS)
print_results(elapsed)
print("ok " + str(i+1) + " benchmark finished")

print_summary(REPEATS, REPEATS)


def main():
"""Run the benchmark."""
benchmark()


if __name__ == "__main__":
main()
34 changes: 34 additions & 0 deletions lib/node_modules/@stdlib/math/base/special/boxcox/docs/repl.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@

{{alias}}( x, lambda )
Computes the Box-Cox transformation.

Parameters
----------
x: number
Input value.

lambda: number
Power parameter.

Returns
-------
b: number
Function value.

Examples
--------
> var v = {{alias}}( 1.0, 2.5 )
0.0
> v = {{alias}}( 4.0, 2.5 )
12.4
> v = {{alias}}( 10.0, 2.5 )
~126.0911
> v = {{alias}}( 2.0, 0.0 )
~0.6931
> v = {{alias}}( -1.0, 2.5 )
NaN
> v = {{alias}}( 0.0, -1.0 )
-Infinity

See Also
--------
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/**
* @license Apache-2.0
*
* Copyright (c) 2018 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 incrspace = require( '@stdlib/math/utils/incrspace' );
var boxcox = require( './../lib' );

var x = incrspace( -1.0, 10.0, 1.0 );
var l = incrspace( -0.5, 5.0, 0.5 );
var b;
var i;
var j;

for ( i = 0; i < x.length; i++ ) {
for ( j = 0; j < l.length; j++ ) {
b = boxcox( x[ i ], l[ j ] );
console.log( 'x: %d, lambda: %d, b(x, lambda): %d', x[ i ], l[ j ], b );
}
}
Loading