Lognormal distribution.
$ npm install distributions-lognormal
For use in the browser, use browserify.
To use the module,
var createDist = require( 'distributions-lognormal' );
To create a lognormal distribution,
var dist = createDist();
The distribution is configurable and has the following methods...
This method is a setter/getter. If no value
is provided, returns the distribution location
parameter. To set the distribution location
parameter,
dist.location( 10 );
The default location
is 0.
This method is a setter/getter. If no value
is provided, returns the distribution scale
parameter. To set the distribution scale
parameter,
dist.scale( 5 );
The default scale
is 1.
Returns the distribution support, which is all positive real numbers.
var support = dist.support();
// returns [5e-324, +inf]
Returns the distribution mean
.
var mean = dist.mean();
Returns the distribution variance
.
var variance = dist.variance();
Returns the distribution median
.
var median = dist.median();
Returns the distribution mode
.
var mode = dist.mode();
Returns the distribution skewness
.
var skewness = dist.skewness();
Returns the distribution excess kurtosis
.
var excess = dist.ekurtosis();
Returns the Fisher information.
var info = dist.information();
// returns [...]
Returns the distribution's differential entropy.
var entropy = dist.entropy();
If a vector is not provided, returns the probability density function (PDF). If a vector is provided, evaluates the PDF for each vector element.
var data = [ 5e-324, 0.5, 1, 1.5, 2, 5, 10 ];
var pdf = dist.pdf( data );
// returns [...]
If a vector is not provided, returns the cumulative density function (CDF). If a vector is provided, evaluates the CDF for each vector element.
var data = [ 5e-324, 0.5, 1, 1.5, 2, 5, 10 ];
var cdf = dist.cdf( data );
// returns [...]
var createDist = require( 'distributions-lognormal' );
// Define the distribution parameters...
var loc = 0,
scale = 0.25,
xLow = 0,
xHigh = 200;
// Create a vector...
var vec = new Array( 1000 ),
len = vec.length,
inc;
inc = ( xHigh - xLow ) / len;
for ( var i = 0; i < len; i++ ) {
vec[ i ] = inc*i + xLow;
}
// Create a lognormal distribution and configure...
var lognormal = createDist()
.location( loc )
.scale( scale );
// Evaluate the probability density function over the vector...
var pdf = lognormal.pdf( vec );
// Find the max...
var max = pdf[ 0 ],
idx = 0;
for ( var j = 1; j < pdf.length; j++ ) {
if ( pdf[ j ] > max ) {
max = pdf[ j ];
idx = j;
}
}
console.log( 'Max: ' + vec[ idx ] );
To run the example code from the top-level application directory,
$ node ./examples/index.js
Unit tests use the Mocha test framework with Chai assertions. To run the tests, execute the following command in the top-level application directory:
$ make test
All new feature development should have corresponding unit tests to validate correct functionality.
This repository uses Istanbul as its code coverage tool. To generate a test coverage report, execute the following command in the top-level application directory:
$ make test-cov
Istanbul creates a ./reports/coverage
directory. To access an HTML version of the report,
$ open reports/coverage/lcov-report/index.html
Copyright © 2014. Athan Reines.