-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
cdbfafd
commit 08e0078
Showing
32 changed files
with
2,304 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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,181 @@ | ||
<!-- | ||
@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. | ||
--> | ||
|
||
# Normalized Hermite Polynomial | ||
|
||
> Evaluate a normalized [Hermite polynomial][hermite-polynomial] using single-precision floating-point arithmetic. | ||
<!-- 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 normalized (aka "probabilist") [Hermite polynomials][hermite-polynomial] are given by | ||
|
||
<!-- <equation class="equation" label="eq:normalized_hermite_polynomials" align="center" raw="He_{n}(x)=(-1)^{n} e^{\frac{x^2}{2}} \frac{\mathrm d^{n}}{\mathrm d x^{n}} e^{-\frac{x^2}{2}}" alt="Equation for normalized Hermite polynomials."> --> | ||
|
||
```math | ||
He_{n}(x)=(-1)^{n} e^{\frac{x^2}{2}} \frac{\mathrm d^{n}}{\mathrm d x^{n}} e^{-\frac{x^2}{2}} | ||
``` | ||
|
||
<!-- <div class="equation" align="center" data-raw-text="He_{n}(x)=(-1)^{n} e^{\frac{x^2}{2}} \frac{\mathrm{d}^{n}}{\mathrm{d}x^n} e^{-\frac{x^2}{2}}" data-equation="eq:normalized_hermite_polynomials"> | ||
<img src="https://cdn.jsdelivr.net/gh/stdlib-js/stdlib@bea0101eb61892f160eec8d97dc79188fd937523/lib/node_modules/@stdlib/math/base/tools/normhermitepoly/docs/img/equation_normalized_hermite_polynomials.svg" alt="Equation for normalized Hermite polynomials."> | ||
<br> | ||
</div> --> | ||
|
||
<!-- </equation> --> | ||
|
||
</section> | ||
|
||
<!-- /.intro --> | ||
|
||
<!-- Package usage documentation. --> | ||
|
||
<section class="usage"> | ||
|
||
## Usage | ||
|
||
```javascript | ||
var normhermitepolyf = require( '@stdlib/math/base/tools/normhermitepolyf' ); | ||
``` | ||
|
||
#### normhermitepolyf( n, x ) | ||
|
||
Evaluates a normalized [Hermite polynomial][hermite-polynomial] of degree `n` using single-precision floating-point arithmetic. | ||
|
||
```javascript | ||
var v = normhermitepolyf( 1, 1.0 ); | ||
// returns 1.0 | ||
|
||
v = normhermitepolyf( 1, 0.5 ); | ||
// returns 0.5 | ||
|
||
v = normhermitepolyf( 0, 0.5 ); | ||
// returns 1.0 | ||
|
||
v = normhermitepolyf( 2, 0.5 ); | ||
// returns -0.75 | ||
|
||
v = normhermitepolyf( -1, 0.5 ); | ||
// returns NaN | ||
``` | ||
|
||
#### normhermitepolyf.factory( n ) | ||
|
||
Returns a function for evaluating a normalized [Hermite polynomial][hermite-polynomial] of degree `n` using single-precision floating-point arithmetic. | ||
|
||
```javascript | ||
var polyval = normhermitepolyf.factory( 2 ); | ||
|
||
var v = polyval( 0.5 ); | ||
// returns -0.75 | ||
``` | ||
|
||
</section> | ||
|
||
<!-- /.usage --> | ||
|
||
<!-- Package usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> | ||
|
||
<section class="notes"> | ||
|
||
</section> | ||
|
||
<!-- /.notes --> | ||
|
||
<!-- Package usage examples. --> | ||
|
||
<section class="examples"> | ||
|
||
## Examples | ||
|
||
<!-- eslint no-undef: "error" --> | ||
|
||
```javascript | ||
var uniform = require( '@stdlib/random/array/uniform' ); | ||
var zeros = require( '@stdlib/array/zeros' ); | ||
var smap = require( '@stdlib/strided/base/smap' ); | ||
var logEach = require( '@stdlib/console/log-each' ); | ||
var normhermitepolyf = require( '@stdlib/math/base/tools/normhermitepolyf' ); | ||
|
||
// Generate random values at which to evaluate a polynomial: | ||
var x = uniform( 10, -50.0, 50.0, { | ||
'dtype': 'float32' | ||
}); | ||
|
||
// Create a polynomial function of degree 1: | ||
var f = normhermitepolyf.factory( 1 ); | ||
|
||
// Allocate an output array: | ||
var y = zeros( x.length, 'float32' ); | ||
|
||
// Evaluate the polynomial: | ||
smap( x.length, x, 1, y, 1, f ); | ||
logEach( 'He_%d(%.3f) = %.3f', 1, x, y ); | ||
|
||
// Create a polynomial function of degree 2: | ||
f = normhermitepolyf.factory( 2 ); | ||
|
||
// Allocate an output array: | ||
y = zeros( x.length, 'float32' ); | ||
|
||
// Evaluate the polynomial: | ||
smap( x.length, x, 1, y, 1, f ); | ||
logEach( 'He_%d(%.3f) = %.3f', 2, x, y ); | ||
|
||
// Create a polynomial function of degree 3: | ||
f = normhermitepolyf.factory( 3 ); | ||
|
||
// Allocate an output array: | ||
y = zeros( x.length, 'float32' ); | ||
|
||
// Evaluate the polynomial: | ||
smap( x.length, x, 1, y, 1, f ); | ||
logEach( 'He_%d(%.3f) = %.3f', 3, x, y ); | ||
``` | ||
|
||
</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 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"> | ||
|
||
[hermite-polynomial]: https://en.wikipedia.org/wiki/Hermite_polynomials | ||
|
||
</section> | ||
|
||
<!-- /.links --> |
81 changes: 81 additions & 0 deletions
81
base/tools/normhermitepolyf/benchmark/benchmark.factory.js
This file contains 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,81 @@ | ||
/** | ||
* @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'; | ||
|
||
// MODULES // | ||
|
||
var bench = require( '@stdlib/bench' ); | ||
var uniform = require( '@stdlib/random/array/uniform' ); | ||
var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); | ||
var isnanf = require( './../../../../base/assert/is-nanf' ); | ||
var pkg = require( './../package.json' ).name; | ||
var factory = require( './../lib/factory.js' ); | ||
|
||
|
||
// MAIN // | ||
|
||
bench( pkg+'::create:factory', function benchmark( b ) { | ||
var n; | ||
var f; | ||
var i; | ||
|
||
n = discreteUniform( 10, 1, 10, { | ||
'dtype': 'float32' | ||
}); | ||
|
||
b.tic(); | ||
for ( i = 0; i < b.iterations; i++ ) { | ||
f = factory( n[ i%n.length ] ); | ||
if ( typeof f !== 'function' ) { | ||
b.fail( 'should return a function' ); | ||
} | ||
} | ||
b.toc(); | ||
if ( typeof f !== 'function' ) { | ||
b.fail( 'should return a function' ); | ||
} | ||
b.pass( 'benchmark finished' ); | ||
b.end(); | ||
}); | ||
|
||
bench( pkg+'::evaluate:factory', function benchmark( b ) { | ||
var x; | ||
var v; | ||
var f; | ||
var i; | ||
|
||
f = factory( 2 ); | ||
x = uniform( 10, -5.0, 5.0, { | ||
'dtype': 'float32' | ||
}); | ||
|
||
b.tic(); | ||
for ( i = 0; i < b.iterations; i++ ) { | ||
v = f( x[ i%x.length ] ); | ||
if ( isnanf( v ) ) { | ||
b.fail( 'should not return NaN' ); | ||
} | ||
} | ||
b.toc(); | ||
if ( isnanf( v ) ) { | ||
b.fail( 'should not return NaN' ); | ||
} | ||
b.pass( 'benchmark finished' ); | ||
b.end(); | ||
}); |
This file contains 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,56 @@ | ||
/** | ||
* @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'; | ||
|
||
// MODULES // | ||
|
||
var bench = require( '@stdlib/bench' ); | ||
var uniform = require( '@stdlib/random/array/uniform' ); | ||
var isnanf = require( './../../../../base/assert/is-nanf' ); | ||
var pkg = require( './../package.json' ).name; | ||
var normhermitepolyf = require( './../lib' ); | ||
|
||
|
||
// MAIN // | ||
|
||
bench( pkg, function benchmark( b ) { | ||
var opts; | ||
var x; | ||
var y; | ||
var i; | ||
|
||
opts = { | ||
'dtype': 'float32' | ||
}; | ||
x = uniform( 10, -5.0, 5.0, opts ); | ||
|
||
b.tic(); | ||
for ( i = 0; i < b.iterations; i++ ) { | ||
y = normhermitepolyf( 2, x[ i%x.length ] ); | ||
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.