Skip to content

distributions-io/lognormal

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

lognormal

NPM version Build Status Coverage Status Dependencies

Lognormal distribution.

Installation

$ npm install distributions-lognormal

For use in the browser, use browserify.

Usage

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

dist.location( [value] )

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.

dist.scale( [value] )

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.

dist.support()

Returns the distribution support, which is all positive real numbers.

var support = dist.support();
// returns [5e-324, +inf]

dist.mean()

Returns the distribution mean.

var mean = dist.mean();

dist.variance()

Returns the distribution variance.

var variance = dist.variance();

dist.median()

Returns the distribution median.

var median = dist.median();

dist.mode()

Returns the distribution mode.

var mode = dist.mode();

dist.skewness()

Returns the distribution skewness.

var skewness = dist.skewness();

dist.ekurtosis()

Returns the distribution excess kurtosis.

var excess = dist.ekurtosis();

dist.information()

Returns the Fisher information.

var info = dist.information();
// returns [...]

dist.entropy()

Returns the distribution's differential entropy.

var entropy = dist.entropy();

dist.pdf( [arr] )

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 [...]

dist.cdf( [arr] )

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 [...]

Examples

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

Tests

Unit

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.

Test Coverage

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

License

MIT license.


Copyright

Copyright © 2014. Athan Reines.

Releases

No releases published

Packages

No packages published