main.js (1625B)
1 /** 2 * @license Apache-2.0 3 * 4 * Copyright (c) 2018 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 isnan = require( '@stdlib/math/base/assert/is-nan' ); 24 var ln = require( '@stdlib/math/base/special/ln' ); 25 var FOURTH_PI = require( '@stdlib/constants/float64/fourth-pi' ); 26 27 28 // VARIABLES // 29 30 var LN_FOURTH_PI = ln( FOURTH_PI ); 31 32 33 // MAIN // 34 35 /** 36 * Returns the differential entropy of an arcsine distribution. 37 * 38 * @param {number} a - minimum support 39 * @param {number} b - maximum support 40 * @returns {number} entropy 41 * 42 * @example 43 * var v = entropy( 0.0, 1.0 ); 44 * // returns ~-0.242 45 * 46 * @example 47 * var v = entropy( 4.0, 12.0 ); 48 * // returns ~1.838 49 * 50 * @example 51 * var v = entropy( -4.0, 4.0 ); 52 * // returns ~1.838 53 * 54 * @example 55 * var v = entropy( 1.0, -0.1 ); 56 * // returns NaN 57 * 58 * @example 59 * var v = entropy( 2.0, NaN ); 60 * // returns NaN 61 * 62 * @example 63 * var v = entropy( NaN, 2.0 ); 64 * // returns NaN 65 */ 66 function entropy( a, b ) { 67 if ( 68 isnan( a ) || 69 isnan( b ) || 70 a >= b 71 ) { 72 return NaN; 73 } 74 return LN_FOURTH_PI + ln( b - a ); 75 } 76 77 78 // EXPORTS // 79 80 module.exports = entropy;