Weibull
===
[![NPM version][npm-image]][npm-url] [![Build Status][travis-image]][travis-url] [![Coverage Status][coveralls-image]][coveralls-url] [![Dependencies][dependencies-image]][dependencies-url]
> Weibull distribution.
## Installation
``` bash
$ npm install distributions-weibull
```
For use in the browser, use [browserify](https://github.com/substack/node-browserify).
## Usage
``` javascript
var createDist = require( 'distributions-weibull' );
```
To create a Weibull distribution,
``` javascript
var dist = createDist();
```
The constructor function takes two input arguments, `lambda` and `k`, the shape and scale parameters of the Weibull distribution. By default, a distribution with `lambda = 1` and `k = 1` is created.
The distribution is configurable and has the following methods...
#### dist.support()
Returns the distribution support, which is all numbers in the interval `(0,∞)`.
``` javascript
var support = dist.support();
// returns [ 0,+Infinity ]
```
#### dist.lambda( [value] )
This method is a setter/getter. If no `value` is provided, returns the shape parameter `lambda`. To set `lambda`,
``` javascript
dist.lambda( 10 );
```
The default shape parameter is 1.
#### dist.k( [value] )
This method is a setter/getter. If no `value` is provided, returns the scale parameter `k`. To set `k`,
``` javascript
dist.k( 100 );
```
The default scale parameter is 1.
#### dist.mean()
Returns the distribution `mean`.
``` javascript
var mean = dist.mean();
```
#### dist.variance()
Returns the distribution `variance`.
``` javascript
var variance = dist.variance();
```
#### dist.median()
Returns the distribution `median`.
``` javascript
var median = dist.median();
```
#### dist.skewness()
Returns the distribution `skewness`.
``` javascript
var skewness = dist.skewness();
```
#### dist.ekurtosis()
Returns the distribution `excess kurtosis`.
``` javascript
var excess = dist.ekurtosis();
```
#### dist.entropy()
Returns the distribution's [differential entropy](http://en.wikipedia.org/wiki/Differential_entropy).
``` javascript
var entropy = dist.entropy();
```
#### dist.pdf( [x] )
If no argument is provided, returns the probability density function (PDF). If a [`number`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number), an [`array`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array), a [`typed array`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Typed_arrays), or a [`matrix`](https://github.com/dstructs/matrix) is provided, evaluates the PDF for each element.
``` javascript
var data = [ 0, 0.2, 0.5, 0.8 ];
var pdf = dist.pdf( data );
// returns [...]
```
#### dist.cdf( [x] )
If no argument is provided, returns the cumulative distribution function (CDF). If a [`number`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number), an [`array`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array), a [`typed array`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Typed_arrays), or a [`matrix`](https://github.com/dstructs/matrix) is provided, evaluates the CDF for each element.
``` javascript
var data = [ 0, 0.2, 0.5, 0.8 ];
var cdf = dist.cdf( data );
// returns [...]
```
#### dist.quantile( [p] )
If no argument is provided, returns the inverse cumulative distribution (quantile) function. If a [`number`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number), an [`array`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array), a [`typed array`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Typed_arrays), or a [`matrix`](https://github.com/dstructs/matrix) of probabilities is provided, evaluates the quantile function for each element.
``` javascript
var probs = [ 0.025, 0.5, 0.975 ];
var quantiles = dist.quantile( probs );
// returns [...]
```
Note: all values must exist on the interval `[0, 1]`. The function returns `NaN` for a value not satisfying this condition.
#### dist.mgf( [t] )
If no argument is provided, returns the moment generating function (MGF) of the distribution. If a [`number`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number), an [`array`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array), a [`typed array`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Typed_arrays), or a [`matrix`](https://github.com/dstructs/matrix) is provided, evaluates the MGF for each input element.
## Examples
``` javascript
var createDist = require( 'distributions-weibull' );
// Define the distribution parameters...
var lambda = 10,
k = 20;
// Create a vector...
var vec = new Array( 1000 ),
len = vec.length;
for ( var i = 0; i < len; i++ ) {
vec[ i ] = lambda * Math.pow( -Math.log( 1 - Math.random() ) , 1/k );
}
// Create a Weibull distribution and configure...
var dist = createDist( lambda, k );
// Evaluate the probability density function over the vector...
var pdf = dist.pdf( vec );
var arr = new Array( 100 );
for ( var j = 0; j < arr.length; j++ ) {
arr[ j ] = [ vec[j], pdf[j] ];
}
console.log( arr );
// Evaluate the quantile function for canonical cumulative probability values...
var quantiles = dist.quantile( [ 0.025, 0.5, 0.975 ] );
console.log( quantiles );
```
To run the example code from the top-level application directory,
``` bash
$ node ./examples/index.js
```
## Tests
### Unit
Unit tests use the [Mocha](http://mochajs.org) test framework with [Chai](http://chaijs.com) assertions. To run the tests, execute the following command in the top-level application directory:
``` bash
$ make test
```
All new feature development should have corresponding unit tests to validate correct functionality.
### Test Coverage
This repository uses [Istanbul](https://github.com/gotwarlost/istanbul) as its code coverage tool. To generate a test coverage report, execute the following command in the top-level application directory:
``` bash
$ make test-cov
```
Istanbul creates a `./reports/coverage` directory. To access an HTML version of the report,
``` bash
$ open reports/coverage/lcov-report/index.html
```
---
## License
[MIT license](http://opensource.org/licenses/MIT).
## Copyright
Copyright © 2015. The [Distributions.io](https://github.com/distributions-io) Authors.
[npm-image]: http://img.shields.io/npm/v/distributions-weibull.svg
[npm-url]: https://npmjs.org/package/distributions-weibull
[travis-image]: http://img.shields.io/travis/distributions-io/weibull/master.svg
[travis-url]: https://travis-ci.org/distributions-io/weibull
[coveralls-image]: https://img.shields.io/coveralls/distributions-io/weibull/master.svg
[coveralls-url]: https://coveralls.io/r/distributions-io/weibull?branch=master
[dependencies-image]: http://img.shields.io/david/distributions-io/weibull.svg
[dependencies-url]: https://david-dm.org/distributions-io/weibull
[dev-dependencies-image]: http://img.shields.io/david/dev/distributions-io/weibull.svg
[dev-dependencies-url]: https://david-dm.org/dev/distributions-io/weibull
[github-issues-image]: http://img.shields.io/github/issues/distributions-io/weibull.svg
[github-issues-url]: https://github.com/distributions-io/weibull/issues
没有合适的资源?快使用搜索试试~ 我知道了~
weibull:威布尔分布
共20个文件
js:7个
json:2个
md:2个
需积分: 50 13 下载量 62 浏览量
2021-05-22
23:33:38
上传
评论
收藏 16KB ZIP 举报
温馨提示
威布尔 威布尔分布。 安装 $ npm install distributions-weibull 要在浏览器中使用,请使用 。 用法 var createDist = require ( 'distributions-weibull' ) ; 要创建威布尔分布, var dist = createDist ( ) ; 构造函数使用两个输入参数lambda和k ,这是Weibull分布的shape和scale参数。 默认情况下,将创建lambda = 1和k = 1的分布。 该发行版是可配置的,并具有以下方法... dist.support() 返回分布支持,它是区间(0,∞)中的所有数字。 var support = dist . support ( ) ; // returns [ 0,+Infinity ] dist.lambda([value]) 此方法是设
资源详情
资源评论
资源推荐
收起资源包目录
weibull-master.zip (20个子文件)
weibull-master
.jshintrc 1KB
.gitattributes 12B
.jshintignore 117B
lib
apply.js 1KB
cdf.js 759B
quantile.js 763B
factorials.json 6KB
pdf.js 883B
mgf.js 1KB
index.js 7KB
.npmignore 458B
examples
index.js 770B
TODO.md 10B
.travis.yml 155B
LICENSE 1KB
README.md 7KB
Makefile 2KB
.editorconfig 170B
.gitignore 711B
package.json 1KB
共 20 条
- 1
蕾拉聊以色列
- 粉丝: 20
- 资源: 4696
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
评论0