Comparing version 0.2.6 to 0.2.7
@@ -1,1 +0,1 @@ | ||
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e(t.sampson=t.sampson||{})}(this,function(t){"use strict";function e(t,e){if(e>t)return NaN;for(var r=1,a=1;e>=a;a++)r*=t--,r/=a;return r}function r(t){var e=1/(1+.5*Math.abs(t)),r=e*Math.exp(-(t*t)-1.26551223+1.00002368*e+.37409196*Math.pow(e,2)+.09678418*Math.pow(e,3)-.18628806*Math.pow(e,4)+.27886807*Math.pow(e,5)-1.13520398*Math.pow(e,6)+1.48851587*Math.pow(e,7)-.82215223*Math.pow(e,8)+.17087277*Math.pow(e,9));return t>=0?1-r:r-1}function a(t){return 0>t?NaN:0==t?1:t*a(t-1)}function n(t){if(0>t)return NaN;for(var e=C[0],r=C.length-1;r>0;--r)e+=C[r]/(t+r);var a=t+N+.5;return.5*Math.log(2*Math.PI)+(t+.5)*Math.log(a)-a+Math.log(e)-Math.log(t)}function o(t){var e=t;if(0>e&&e%1==0)return 1/0;if(.5>e)return Math.PI/(Math.sin(Math.PI*e)*o(1-e));if(e>100)return Math.exp(n(e));e-=1;for(var r=E[0],a=1;O+2>a;a++)r+=E[a]/(e+a);var i=e+O+.5;return Math.sqrt(2*Math.PI)*Math.pow(i,e+.5)*Math.exp(-i)*r}function i(t,e){var r=void 0,a=void 0,o=void 0;for(o=1,r=1,a=1;100>o&&(r+=a*=e/(t+o),!(j>a/r));++o);return Math.exp(t*Math.log(e)-e-n(t+1)+Math.log(r))}function u(t){if(0==t.length)return 0;var e=0;return t.reduce(function(t,r){if(isNaN(r))return t;var a=r-e,n=t+a;return e=n-t-a,n},0)}function s(t){return 0==t.length?NaN:u(t)/t.filter(function(t){return!isNaN(t)}).length}function l(t){if(0==t.length)return NaN;if(1==t.length)return t;var e=function(){var e=t.reduce(function(t,e){return t[e]?t[e]++:t[e]=1,t},{}),r=Object.keys(e),a=r.map(function(t){return e[t]}).reduce(function(t,e){return e>t?e:t});return{v:r.filter(function(t){return e[t]==a}).map(function(t){return Number(t)})}}();return"object"===("undefined"==typeof e?"undefined":g["typeof"](e))?e.v:void 0}function v(t,e,r,a){var n=t.slice(0);if(0==n.length||e>=n.length)return NaN;var o=r||0,i=a||n.length-1;if(o==i)return n[o];for(;i>o;){if(i-o>x){var u=i-o+1,s=e-o+1,l=Math.log(u),h=P*Math.exp(2*l/3),c=P*Math.sqrt(l*h*(u-h)/u),d=Math.max(o,Math.floor(e-s*h/u+c)),m=Math.min(i,Math.floor(e+(u-s)*h/u+c));v(n,e,d,m)}var p=n[e],y=o,b=i;for(f(n,y,e),n[b]>p&&f(n,y,b);b>y;){for(f(n,y,b),y++,b--;n[y]<p;)y++;for(;n[b]>p;)b--}n[o]===p?f(n,o,b):(b++,f(n,b,i)),b>e?i=b-1:(o=b+1,i=b-1)}return n[e]}function f(t,e,r){var a=t[e];t[e]=t[r],t[r]=a}function h(t){var e=void 0;if(0==t.length)e=NaN;else{var r=t.length%2==0;r?(e=v(t,t.length/2),e+=v(t,t.length/2-1),e/=2):e=v(t,(t.length-1)/2)}return e}function c(t,e){if(void 0==e||e>1||0>e)throw new Error("p must be between zero and one inclusive.");if(void 0==t)throw new Error("need a list to provide a percentile.");if(0==t.length)return NaN;var r=Math.floor(t.length*e);return r>=t.length&&(r=t.length-1),v(t,r)}function d(t,e){if(!Array.isArray(t)||0==t.length)throw new Error("you must provide an array.");if(!Array.isArray(e)||0==e.length)throw new Error("you must provide some quantiles.");var r=e.reduce(function(t,e){return e>=0&&1>=e&&t},!0);if(!r)throw new Error("quantiles must be between zero and one inclusive.");if(e.length>1)return e.map(function(e){return d(t,[e])});var a=e[0];if(0==a)return t[0];if(1==a)return t[t.length-1];var n=t.length*a;return n%1?v(t,Math.floor(n)):t.length%2?v(t,n):(v(t,n-1)+v(t,n))/2}function m(t){return 0==t.length?NaN:Math.max.apply(Math,g.toConsumableArray(t))-Math.min.apply(Math,g.toConsumableArray(t))}function p(t,e,r){if(0==t.length)return NaN;var a=function(){var a=s(t);return{v:t.reduce(function(t,n){var o=n-a;return r&&(o=Math.abs(o)),t+Math.pow(o,e)},0)}}();return"object"===("undefined"==typeof a?"undefined":g["typeof"](a))?a.v:void 0}function y(t){return 0==t.length?NaN:p(t,2)/t.length}function b(t){var e=y(t);return isNaN(e)?0:Math.sqrt(e)}function k(t){return(t+.5)*Math.log(t)-t+Math.log(2*Math.PI)/2}function w(t,e,r){return(t-e)/r}function M(t,e,r){if(!t)return NaN;if(e){var a=r||0,n=((t.size-1)*t.variance+(e.size-1)*e.variance)/(t.size+e.size-2);return(t.mean-e.mean-a)/Math.sqrt(n*(1/t.size+1/e.size))}return(t.mean-r)/(t.std/Math.sqrt(t.size))}var g={};g["typeof"]="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol?"symbol":typeof t},g.classCallCheck=function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")},g.createClass=function(){function t(t,e){for(var r=0;r<e.length;r++){var a=e[r];a.enumerable=a.enumerable||!1,a.configurable=!0,"value"in a&&(a.writable=!0),Object.defineProperty(t,a.key,a)}}return function(e,r,a){return r&&t(e.prototype,r),a&&t(e,a),e}}(),g["extends"]=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var r=arguments[e];for(var a in r)Object.prototype.hasOwnProperty.call(r,a)&&(t[a]=r[a])}return t},g.get=function J(t,e,r){null===t&&(t=Function.prototype);var a=Object.getOwnPropertyDescriptor(t,e);if(void 0===a){var n=Object.getPrototypeOf(t);return null===n?void 0:J(n,e,r)}if("value"in a)return a.value;var o=a.get;if(void 0!==o)return o.call(r)},g.inherits=function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function, not "+typeof e);t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,enumerable:!1,writable:!0,configurable:!0}}),e&&(Object.setPrototypeOf?Object.setPrototypeOf(t,e):t.__proto__=e)},g.possibleConstructorReturn=function(t,e){if(!t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!e||"object"!=typeof e&&"function"!=typeof e?t:e},g.toConsumableArray=function(t){if(Array.isArray(t)){for(var e=0,r=Array(t.length);e<t.length;e++)r[e]=t[e];return r}return Array.from(t)};var N=607/128,C=[.9999999999999971,57.15623566586292,-59.59796035547549,14.136097974741746,-.4919138160976202,3399464998481189e-20,4652362892704858e-20,-9837447530487956e-20,.0001580887032249125,-.00021026444172410488,.00021743961811521265,-.0001643181065367639,8441822398385275e-20,-26190838401581408e-21,36899182659531625e-22],O=7,E=[.9999999999998099,676.5203681218851,-1259.1392167224028,771.3234287776531,-176.6150291621406,12.507343278686905,-.13857109526572012,9984369578019572e-21,1.5056327351493116e-7],j=1e-14,x=600,P=.5,q=function(){function t(e){g.classCallCheck(this,t);var r=Object.assign({},e);this.params=this.constructor.validate(r),this.mean=this.constructor.mean(r),this.stdDev=this.constructor.stdDev(r),this.relStdDev=this.constructor.relStdDev(r),this.variance=this.constructor.variance(r),this.skewness=this.constructor.skewness(r),this.kurtosis=this.constructor.kurtosis(r)}return g.createClass(t,null,[{key:"validate",value:function(){throw new Error("You must define a validation function for your distribution.")}},{key:"mean",value:function(t){return NaN}},{key:"variance",value:function(t){return NaN}},{key:"stdDev",value:function(t){return Math.sqrt(this.variance(t))}},{key:"relStdDev",value:function(t){return this.stdDev(t)/this.mean(t)}},{key:"skewness",value:function(t){return NaN}},{key:"kurtosis",value:function(t){return NaN}},{key:"pdf",value:function(){return NaN}},{key:"cdf",value:function(){return NaN}},{key:"random",value:function(){return Math.random()}},{key:"sample",value:function(t,e){var r=this;return Array.apply(null,Array(t)).map(function(){return r.random(e)})}}]),g.createClass(t,[{key:"pdf",value:function(t){return this.constructor.pdf(t,this.params)}},{key:"cdf",value:function(t){return this.constructor.cdf(t,this.params)}},{key:"random",value:function(){return this.constructor.random(this.params)}},{key:"sample",value:function(t){return this.constructor.sample(t,this.params)}}]),t}();q.covariates=0,q.discrete=!1;var D=function(t){function e(){return g.classCallCheck(this,e),g.possibleConstructorReturn(this,Object.getPrototypeOf(e).apply(this,arguments))}return g.inherits(e,t),g.createClass(e,null,[{key:"validate",value:function(t){if(!t||void 0===t.a||void 0===t.b)throw new Error("need a parameter object of shape { a: number, b: number }.");var e=t.a,r=t.b;if("number"!=typeof e)throw Error("a must be a number.");if("number"!=typeof r||0>=r)throw RangeError("b must be greater than zero.");return t}},{key:"random",value:function(t){for(var r=this.validate(t),a=r.a,n=r.b,o=void 0;!o||.5==o;)o=g.get(Object.getPrototypeOf(e),"random",this).call(this);return a+n*Math.tan(Math.PI*o)}},{key:"pdf",value:function(t,e){if("number"!=typeof t)throw new TypeError("x must be a number");var r=this.validate(e),a=r.a,n=r.b;return n/(Math.pow(t-a,2)+Math.pow(n,2))/Math.PI}},{key:"cdf",value:function(t,e){if("number"!=typeof t)throw new TypeError("x must be a number");var r=this.validate(e),a=r.a,n=r.b;return Math.atan((t-a)/n)/Math.PI+.5}},{key:"mean",value:function(t){return NaN}},{key:"variance",value:function(t){return NaN}},{key:"stdDev",value:function(t){return NaN}},{key:"relStdDev",value:function(t){return NaN}},{key:"skewness",value:function(t){return NaN}},{key:"kurtosis",value:function(t){return NaN}}]),e}(q);D.covariates=1,D.discrete=!1;var z=NaN,S=function(t){function e(){return g.classCallCheck(this,e),g.possibleConstructorReturn(this,Object.getPrototypeOf(e).apply(this,arguments))}return g.inherits(e,t),g.createClass(e,null,[{key:"validate",value:function(t){if(!t||void 0===t.mu||void 0==t.sigma)throw new Error("need a parameter object of shape { mu: number, simga: number }.");var e=t.mu,r=t.sigma;if("number"!=typeof e||"number"!=typeof r)throw new Error("Need mu and sigma for the normal distribution.");return t}},{key:"random",value:function(t){var r=this.validate(t),a=r.mu,n=r.sigma,o=z;if(z=NaN,!o){var i=2*g.get(Object.getPrototypeOf(e),"random",this).call(this)*Math.PI,u=Math.sqrt(-2*Math.log(1-g.get(Object.getPrototypeOf(e),"random",this).call(this)));o=Math.cos(i)*u,z=Math.sin(i)*u}return a+o*n}},{key:"pdf",value:function(t,e){if("number"!=typeof t)throw new Error("x must be a number.");var r=this.validate(e),a=r.mu,n=r.sigma;t/Math.abs(n);return 1/(Math.sqrt(2*Math.PI)*Math.abs(n))*Math.exp(-1*Math.pow(t-a,2)/(2*n*n))}},{key:"cdf",value:function(t,e){if("number"!=typeof t)throw new Error("x must be a number.");var a=this.validate(e),n=a.mu,o=a.sigma;return.5*(1+r((t-n)/(o*Math.sqrt(2))))}},{key:"mean",value:function(t){var e=this.validate(t),r=e.mu;e.sigma;return r}},{key:"variance",value:function(t){var e=this.validate(t),r=(e.mu,e.sigma);return r*r}},{key:"stdDev",value:function(t){var e=this.validate(t),r=(e.mu,e.sigma);return r}},{key:"relStdDev",value:function(t){var e=this.validate(t),r=e.mu,a=e.sigma;return a/r}},{key:"skewness",value:function(t){return 0}},{key:"kurtosis",value:function(t){return 3}}]),e}(q);S.covariates=2,S.discrete=!1;var R=function(t){function e(){return g.classCallCheck(this,e),g.possibleConstructorReturn(this,Object.getPrototypeOf(e).apply(this,arguments))}return g.inherits(e,t),g.createClass(e,null,[{key:"validate",value:function(t){if(!t||void 0===t.mu)throw new Error("need a parameter object of shape { mu: number }.");var e=t.mu;if("number"!=typeof e||0>=e)throw RangeError("mu must be greater than zero.");return t}},{key:"random",value:function(t){var r=this.validate(t),a=r.mu;return-a*Math.log1p(-g.get(Object.getPrototypeOf(e),"random",this).call(this))}},{key:"pdf",value:function(t,e){var r=this.validate(e),a=r.mu;if("number"!=typeof t)throw new Error("x must be a number.");return 0>t?0:Math.exp(-t/a)/a}},{key:"cdf",value:function(t,e){var r=this.validate(e),a=r.mu;if("number"!=typeof t)throw new Error("x must be a number.");return 0>=t?0:1-Math.exp(-t/a)}},{key:"mean",value:function(t){var e=this.validate(t),r=e.mu;return r}},{key:"variance",value:function(t){var e=this.validate(t),r=e.mu;return r*r}},{key:"stdDev",value:function(t){var e=this.validate(t),r=e.mu;return r}},{key:"relStdDev",value:function(t){return 1}},{key:"skewness",value:function(t){return 2}},{key:"kurtosis",value:function(t){return 9}}]),e}(q);R.covariates=1;var A=function(t){function e(){return g.classCallCheck(this,e),g.possibleConstructorReturn(this,Object.getPrototypeOf(e).apply(this,arguments))}return g.inherits(e,t),g.createClass(e,null,[{key:"validate",value:function(t){if(!t||void 0===t.a||void 0===t.b)throw new Error("need a parameter object of shape { a: number, b: number }.");var e=t.a,r=t.b;if("number"!=typeof e||"number"!=typeof r)throw new Error("Need a and b for the gamma distribution.");if(0>=e)throw new Error("a must be greater than zero.");if(0>=r)throw new Error("b must be greater than zero.");return t}},{key:"random",value:function(t){var r=this.validate(t),a=r.a,n=r.b;if(1>a){var o=g.get(Object.getPrototypeOf(e),"random",this).call(this);return this.random({a:1+a,b:n})*Math.pow(o,1/a)}for(var i=void 0,u=void 0,s=void 0,l=a-1/3,v=1/Math.sqrt(9*l);;){do i=S.random({mu:0,sigma:1}),u=1+v*i;while(0>=u);for(u=u*u*u;!s;)s=g.get(Object.getPrototypeOf(e),"random",this).call(this);if(1-.0331*i*i*i*i>s)break;if(Math.log(s)<.5*i*i+l*(1-u+Math.log(u)))break}return l*u/n}},{key:"pdf",value:function(t,e){var r=this.validate(e),a=r.a,o=r.b;if("number"!=typeof t)throw new Error("x must be a number.");return 0>t?0:0==t?1==a?o:0:1==a?Math.exp(-t*o)*o:Math.exp((a-1)*Math.log(t*o)-t*o-n(a))*o}},{key:"cdf",value:function(t,e){var r=this.validate(e),a=r.a,n=r.b;if("number"!=typeof t)throw new Error("x must be a number.");return 0>=t?0:i(a,t*n)}},{key:"mean",value:function(t){var e=this.validate(t),r=e.a,a=e.b;return r/a}},{key:"variance",value:function(t){var e=this.validate(t),r=e.a,a=e.b;return r/(a*a)}},{key:"stdDev",value:function(t){var e=this.validate(t),r=e.a,a=e.b;return Math.sqrt(r/(a*a))}},{key:"relStdDev",value:function(t){var e=this.validate(t),r=e.a;e.b;return 1/Math.sqrt(r)}},{key:"skewness",value:function(t){var e=this.validate(t),r=e.a;e.b;return 2/Math.sqrt(r)}},{key:"kurtosis",value:function(t){var e=this.validate(t),r=e.a;e.b;return 6/r}}]),e}(q);A.covariates=2;var I=function(t){function e(){return g.classCallCheck(this,e),g.possibleConstructorReturn(this,Object.getPrototypeOf(e).apply(this,arguments))}return g.inherits(e,t),g.createClass(e,null,[{key:"validate",value:function(t){if(!t||void 0===t.m||void 0==t.a)throw new Error("need a parameter object of shape { m: number, a: number }.");var e=t.m,r=t.a;if("number"!=typeof e||0>=e)throw RangeError("m must be greater than zero.");if("number"!=typeof r)throw RangeError("a must be a number.");return t}},{key:"random",value:function(t){var r=this.validate(t),a=r.m,n=r.a;return n*Math.pow(g.get(Object.getPrototypeOf(e),"random",this).call(this),-1/a)}},{key:"pdf",value:function(t,e){var r=this.validate(e),a=r.m,n=r.a;if("number"!=typeof t)throw new Error("x must be a number.");return a>t?0:n*Math.pow(a,n)/Math.pow(t,n+1)}},{key:"cdf",value:function(t,e){var r=this.validate(e),a=r.m,n=r.a;if("number"!=typeof t)throw new Error("x must be a number.");return a>t?0:1-Math.pow(a/t,n)}},{key:"mean",value:function(t){var e=this.validate(t),r=e.m,a=e.a;return 1>=a?1/0:a*r/(a-1)}},{key:"variance",value:function(t){var e=this.validate(t),r=e.m,a=e.a;return 2>=a?1/0:a*r*r/((a-1)*(a-1)*(a-2))}},{key:"skewness",value:function(t){var e=this.validate(t),r=(e.m,e.a);return 3>r?NaN:2*(1+r)/(r-3)*Math.sqrt((r-2)/r)}},{key:"kurtosis",value:function(t){var e=this.validate(t),r=(e.m,e.a);return 4>r?NaN:6*(r*r*r+r*r-6*r-2)/(r*(r-3)*(r-4))}}]),e}(q);I.covariates=1;var T=14,_=function(t){function r(){return g.classCallCheck(this,r),g.possibleConstructorReturn(this,Object.getPrototypeOf(r).apply(this,arguments))}return g.inherits(r,t),g.createClass(r,null,[{key:"validate",value:function(t){if(!t||void 0===t.n||void 0===t.p)throw new Error("need a parameter object of shape { n: number, p: number }.");var e=t.n,r=t.p;if("number"!=typeof r||r>1||0>r)throw new Error("p must be between zero and one inclusive.");if("number"!=typeof e||0>e)throw new Error("n must be positive or zero.");return t}},{key:"random",value:function(t){var e=this,a=this.validate(t),n=a.n,o=a.p;if(0==n)return 0;var i=!1,u=0,s=void 0;o>.5?(i=!0,s=1-o):s=o;var l=1-s,v=s/l,f=n*s;if(T>f)for(var h=Math.pow(l,n),c=g.get(Object.getPrototypeOf(r),"random",this).call(this);n>=u&&c>=h;)c-=h,h*=v*(n-u)/(u+1),u++;else!function(){var t=f+s,a=Math.floor(t),o=a+.5,i=f*l,v=Math.floor(2.195*Math.sqrt(i)-4.6*l)+.5,h=o-v,c=o+v,d=.134+20.5/(15.3+a),m=v*(1+d+d),p=(t-h)/(t-h*s),y=p*(1+.5*p),b=(c-t)/(c*l),w=b*(1.5+b),M=m+d/y,N=M+d/w,C=void 0,O=void 0,E=void 0,j=void 0,x=function P(){if(E=g.get(Object.getPrototypeOf(r),"random",e).call(e)*N,j=g.get(Object.getPrototypeOf(r),"random",e).call(e),v>=E)u=Math.floor(o-v*j+E);else if(m>=E){var t=h+(E-v)/d;j=j*d+1-Math.abs(t-o)/v,j>1||0>=j?P():u=t}else M>=E?(u=Math.floor(h+Math.log(j)/y),j*=(E-m)*y):(u=Math.floor(c-Math.log(j)/w),j*=(E-M)*w);C=Math.log(j);var i=u+1,f=n-u-1,p=a+1,b=n+1-a;O=o*Math.log(p/i)+(n-a+.5)*Math.log(b/f)+(u-a)*Math.log(f*s/(i*l))+k(p)+k(b)-k(i)-k(f),C>O&&P()};x()}();return Math.floor(i?n-u:u)}},{key:"pdf",value:function(t,r){var a=this.validate(r),n=a.n,o=a.p;if("number"!=typeof t)throw new Error("k must be a number.");if(0>t||t>n)return 0;var i=void 0;if(0==o)i=0==t?1:0;else{if(1!=o){var u=e(n,t),s=Math.pow(o,t)*Math.pow(1-o,n-t);return"Infinity"==u?0==s?0:u:u*s}i=t==n?1:0}return i}},{key:"cdf",value:function(t,r){var a=this.validate(r),n=a.n,o=a.p;if("number"!=typeof t)throw new Error("k must be a number.");return 0>t?0:t>n?1:Array.apply(null,Array(Math.floor(t)+1)).map(function(t,r){return e(n,r)*Math.pow(o,r)*Math.pow(1-o,n-r)}).reduce(function(t,e){return t+e},0)}},{key:"mean",value:function(t){var e=this.validate(t),r=e.n,a=e.p;return r*a}},{key:"variance",value:function(t){var e=this.validate(t),r=e.n,a=e.p;return r*a*(1-a)}},{key:"stdDev",value:function(t){var e=this.validate(t),r=e.n,a=e.p;return Math.sqrt(r*a*(1-a))}},{key:"relStdDev",value:function(t){var e=this.validate(t),r=e.n,a=e.p;return Math.sqrt((1-a)/(r*a))}},{key:"skewness",value:function(t){var e=this.validate(t),r=e.n,a=e.p;return(1-2*a)/Math.sqrt(r*a*(1-a))}},{key:"kurtosis",value:function(t){var e=this.validate(t),r=e.n,a=e.p;return 3-6/r+1/(r*a*(1-a))}}]),r}(q);_.covariates=2,_.discrete=!0;var B=function(t){function e(){return g.classCallCheck(this,e),g.possibleConstructorReturn(this,Object.getPrototypeOf(e).apply(this,arguments))}return g.inherits(e,t),g.createClass(e,null,[{key:"validate",value:function(t){if(!t||void 0===t.mu)throw new Error("need a parameter object of shape { n: number, p: number }.");var e=t.mu;if("number"!=typeof e||0>=e)throw new Error("n must be greater than zero");return t}},{key:"random",value:function(t){for(var r=this.validate(t),a=r.mu,n=void 0,o=void 0,i=0;a>10;){var u=Math.round(a*(7/8)),s=A.random({a:u,b:1});if(s>=a)return i+_.random({p:a/s,n:u-1});i+=u,a-=s}a=Math.exp(-a);do n*=g.get(Object.getPrototypeOf(e),"random",this).call(this),i++;while(n>o);return i-1}},{key:"pdf",value:function(t,e){var r=this.validate(e),a=r.mu;if("number"!=typeof t)throw new Error("k must be a number.");return Math.exp(Math.log(a)*t-n(t+1)-a)}},{key:"cdf",value:function(t,e){var r=this,a=this.validate(e);a.mu;if("number"!=typeof t)throw new Error("k must be a number.");if(0>t)return 0;var n=Array.apply(null,Array(t+1)).map(function(t,a){return r.pdf(a,e)});return u(n)}},{key:"mean",value:function(t){var e=this.validate(t),r=e.mu;return r}},{key:"variance",value:function(t){var e=this.validate(t),r=e.mu;return r}},{key:"skewness",value:function(t){var e=this.validate(t),r=e.mu;return Math.pow(r,-.5)}},{key:"kurtosis",value:function(t){var e=this.validate(t),r=e.mu;return Math.pow(r,-1)}}]),e}(q);B.covariates=1,B.discrete=!0;var F=function(t){function e(t){return g.classCallCheck(this,e),g.possibleConstructorReturn(this,Object.getPrototypeOf(e).call(this,g["extends"]({},t,{n:1})))}return g.inherits(e,t),g.createClass(e,null,[{key:"random",value:function(t){var e=this.validate(g["extends"]({},t,{n:1})),r=e.p,a=q.random();return r>a?1:0}},{key:"pdf",value:function(t,e){var r=this.validate(g["extends"]({},e,{n:1})),a=r.p;if("number"!=typeof t)throw new Error("k must be a number.");return 0==t?1-a:1==t?a:0}},{key:"cdf",value:function(t,e){var r=this.validate(g["extends"]({},e,{n:1})),a=r.p;if("number"!=typeof t)throw new Error("k must be a number.");return 1==t?a:0==t?1-a:NaN}}]),e}(_);F.covariates=1;var G=function(t){function e(){return g.classCallCheck(this,e),g.possibleConstructorReturn(this,Object.getPrototypeOf(e).apply(this,arguments))}return g.inherits(e,t),g.createClass(e,null,[{key:"validate",value:function(t){if(!t||void 0===t.df)throw new Error("need a parameter object of shape { df: number }.");var e=t.df;if("number"!=typeof e||0>=e)throw RangeError("df must be greater than zero.");return t}},{key:"random",value:function(t){var e=this.validate(t),r=e.df;return 2*A.random({a:r/2,b:1})}},{key:"pdf",value:function(t,e){var r=this.validate(e),a=r.df;if("number"!=typeof t)throw new TypeError("x must be a number");return 0>t?0:2==a?Math.exp(-t/2)/2:Math.exp((a/2-1)*Math.log(t/2)-t/2-n(a/2))/2}},{key:"cdf",value:function(t,e){var r=this.validate(e),a=r.df;if("number"!=typeof t)throw new TypeError("x must be a number");return 0>t?0:2==a?1-Math.exp(-t/2):i(a/2,t/2)}},{key:"mean",value:function(t){var e=this.validate(t),r=e.df;return r}},{key:"variance",value:function(t){var e=this.validate(t),r=e.df;return 2*r}},{key:"stdDev",value:function(t){var e=this.validate(t),r=e.df;return Math.sqrt(2*r)}},{key:"relStdDev",value:function(t){var e=this.validate(t),r=e.df;return Math.sqrt(2/r)}},{key:"skewness",value:function(t){var e=this.validate(t),r=e.df;return Math.pow(2,1.5)/Math.sqrt(r)}},{key:"kurtosis",value:function(t){var e=this.validate(t),r=e.df;return 3+12/r}}]),e}(q);G.covariates=1;var U=function(t){function e(){return g.classCallCheck(this,e),g.possibleConstructorReturn(this,Object.getPrototypeOf(e).apply(this,arguments))}return g.inherits(e,t),g.createClass(e,null,[{key:"validate",value:function(t){if(!t||void 0===t.df)throw new Error("need a parameter object of shape { df: number }.");var e=t.df;if("number"!=typeof e||0>=e)throw RangeError("df must be greater than zero.");return t}},{key:"random",value:function(t){var e=this.validate(t),r=e.df;if(2>=r){var a=S.random({mu:0,sigma:1}),n=G.random({df:r});return a/Math.sqrt(n/r)}var o=void 0,i=void 0,u=void 0;do o=S.random({mu:0,sigma:1}),i=R.random({mu:1/(r/2-1)}),u=o*i/(r-2);while(0>1-u||Math.exp(-i-u)>1-u);return o/Math.sqrt((1-2/r)*(1-u))}},{key:"pdf",value:function(t,e){if("number"!=typeof t)throw TypeError("t must be a number.");var r=this.validate(e),a=r.df,o=n(a/2),i=n((a+1)/2);return Math.exp(i-o)/Math.sqrt(Math.PI*a)*Math.pow(1+t*t/a,-(a+1)/2)}},{key:"cdf",value:function(t,e){if("number"!=typeof t)throw TypeError("t must be a number.");var r=this.validate(e),a=r.df,n=void 0,o=void 0,i=void 0,u=void 0,s=void 0,l=void 0,v=void 0,f=void 0,h=void 0,c=void 0,d=1/Math.PI;if(i=a,n=t/Math.sqrt(i),o=i/(i+t*t),u=a-2,s=i%2,l=1,v=1,i=1,f=2+s,h=f,u>=2)for(c=f;u>=c;c+=2)v=v*o*(h-1)/h,l+=v,i=l,h+=2;return 1!=s?.5+.5*n*Math.sqrt(o)*l:(1==a&&(l=0),.5+(n*o*l+Math.atan(n))*d)}},{key:"mean",value:function(t){var e=this.validate(t),r=e.df;return 1>=r?NaN:0}},{key:"variance",value:function(t){var e=this.validate(t),r=e.df;return 1>r?NaN:2>=r?1/0:r/(r-2)}},{key:"stdDev",value:function(t){var e=this.validate(t),r=e.df;return 1>r?NaN:2>=r?1/0:Math.sqrt(r/(r-2))}},{key:"relStdDev",value:function(t){var e=this.validate(t);e.df;return NaN}},{key:"skewness",value:function(t){var e=this.validate(t),r=e.df;return r>3?0:NaN}},{key:"kurtosis",value:function(t){var e=this.validate(t),r=e.df;return 4>=r?NaN:3*(r-2)/(r-4)}}]),e}(q);U.covariates=1;var W=function(t){function e(){return g.classCallCheck(this,e),g.possibleConstructorReturn(this,Object.getPrototypeOf(e).apply(this,arguments))}return g.inherits(e,t),g.createClass(e,null,[{key:"validate",value:function(t){if(!t||void 0===t.a||void 0===t.b)throw new Error("need a parameter object of shape { a: number, b: number }.");var e=t.a,r=t.b;if("number"!=typeof e||0>=e)throw Error("a must be greater than zero.");if("number"!=typeof r||0>=r)throw RangeError("b must be greater than zero.");return t}},{key:"random",value:function(t){var r=this.validate(t),a=r.a,n=r.b;return a*Math.pow(-Math.log(g.get(Object.getPrototypeOf(e),"random",this).call(this)),1/n)}},{key:"pdf",value:function(t,e){if("number"!=typeof t)throw new TypeError("x must be a number");var r=this.validate(e),a=r.a,n=r.b;return 0>t?0:n/a*Math.pow(t/a,n-1)*Math.exp(-Math.pow(t/a,n))}},{key:"cdf",value:function(t,e){if("number"!=typeof t)throw new TypeError("x must be a number");var r=this.validate(e),a=r.a,n=r.b;return 0>t?0:1-Math.exp(-Math.pow(t/a,n))}},{key:"mean",value:function(t){var e=this.validate(t),r=e.a,a=e.b;return r*o(1+1/a)}},{key:"variance",value:function(t){var e=this.validate(t),r=e.a,a=e.b;return r*r*(o(1+2/a)-Math.pow(o(1+1/a),2))}},{key:"skewness",value:function(t){var e=t.a,r=t.b,a=this.stdDev(t),n=this.mean(t);return(o(1+3/r)*Math.pow(e,3)-3*n*a*a-Math.pow(n,3))/Math.pow(a,3)}},{key:"kurtosis",value:function(t){var e=t.a,r=t.b,a=this.stdDev(t),n=this.mean(t),i=this.skewness(t);return(o(1+4/r)*Math.pow(e,4)-4*i*Math.pow(a,3)*n-6*Math.pow(n,2)*Math.pow(a,2)-Math.pow(n,4))/Math.pow(a,4)-3}}]),e}(q);W.covariates=1,W.discrete=!1;var Y=function(t){function e(){return g.classCallCheck(this,e),g.possibleConstructorReturn(this,Object.getPrototypeOf(e).apply(this,arguments))}return g.inherits(e,t),g.createClass(e,null,[{key:"validate",value:function(t){if(!t||void 0===t.a||void 0===t.b)throw new Error("need a parameter object of shape { a: number, b: number }.");var e=t.a,r=t.b;if("number"!=typeof e)throw Error("a must be a number.");if("number"!=typeof r||e>=r)throw RangeError("b must be greater than a.");return t}},{key:"random",value:function(t){var r=this.validate(t),a=r.a,n=r.b;return a+g.get(Object.getPrototypeOf(e),"random",this).call(this)*(n-a)}},{key:"pdf",value:function(t,e){if("number"!=typeof t)throw new TypeError("x must be a number");var r=this.validate(e),a=r.a,n=r.b;return a>t||t>n?0:1/(n-a)}},{key:"cdf",value:function(t,e){if("number"!=typeof t)throw new TypeError("x must be a number");var r=this.validate(e),a=r.a,n=r.b;return a>t?0:t>=n?1:(t-a)/(n-a)}},{key:"mean",value:function(t){var e=this.validate(t),r=e.a,a=e.b;return(r+a)/2}},{key:"variance",value:function(t){var e=this.validate(t),r=e.a,a=e.b;return Math.pow(a-r,2)/12}},{key:"skewness",value:function(t){return 0}},{key:"kurtosis",value:function(t){return-1.2}}]),e}(q);Y.covariates=1,Y.discrete=!1;var H=function(){function t(e){var r=this;if(g.classCallCheck(this,t),this.covariance=function(t){return r.constructor.covariance(r,t)},this.correlation=function(t){return r.constructor.correlation(r,t)},0==e.length)throw new Error("Sample of size 0 not allowed.");this.data=e,this.size=e.length,this.mean=s(e),this.std=this.constructor.stdDev(e),this.variance=this.constructor.variance(e),this.skewness=this.constructor.skewness(e),this.kurtosis=this.constructor.kurtosis(e),this.sqrdMeanDev=this.constructor.sqrdMeanDev(e),this.meanDev=this.constructor.meanDev(e),this.rootMeanSqrd=this.constructor.rootMeanSqrd(e),this.stdMeanDev=this.constructor.stdMeanDev(e),this.relStdDev=this.constructor.relativeStdDev(e),this.quartiles=this.constructor.quartiles(e)}return g.createClass(t,null,[{key:"variance",value:function(t){return p(t,2)/(t.length-1)}},{key:"sqrdMeanDev",value:function(t){return p(t,2)}},{key:"meanDev",value:function(t){return p(t,1,!0)/t.length}},{key:"stdDev",value:function(t){var e=this.variance(t);return isNaN(e)?0:Math.sqrt(e)}},{key:"rootMeanSqrd",value:function(t){return Math.sqrt(t.map(function(t){return t*t}).reduce(function(t,e){return t+e})/t.length)}},{key:"stdMeanDev",value:function(t){return this.stdDev(t)/Math.sqrt(t.length)}},{key:"relativeStdDev",value:function(t){return this.stdDev(t)/s(t)}},{key:"quartiles",value:function(t){return d(t,[.25,.5,.75])}},{key:"skewness",value:function(t){var e=this.stdDev(t);if(isNaN(e)||t.length<3)return NaN;var r=t.length,a=Math.pow(e,3),n=p(t,3);return r*n/((r-1)*(r-2)*a)}},{key:"kurtosis",value:function(t){var e=this.stdDev(t);if(isNaN(e)||t.length<3)return NaN;var r=(t.length,p(t,2)),a=p(t,4);return a/Math.pow(r,2)}},{key:"covariance",value:function(t,e){if(!t||!e||t.size<=1||t.size!==e.size)return NaN;var r=t.data.map(function(r,a){return(t.data[a]-t.mean)*(e.data[a]-e.mean)}).reduce(function(t,e){return t+e},0);return r/(t.size-1)}},{key:"correlation",value:function(t,e){if(!(t&&t.std&&e&&e.std))return NaN;var r=this.covariance(t,e);return r/t.std/e.std}}]),t}();t.choose=e,t.error=r,t.factorial=a,t.gamma=o,t.gammainc_lower=i,t.lngamma=n,t.median=h,t.mean=s,t.mode=l,t.percentile=c,t.quantile=d,t.range=m,t.select=v,t.std=b,t.stirling=k,t.sum=u,t.sumNthPowerDev=p,t.variance=y,t.zscore=w,t.Normal=S,t.Binomial=_,t.Bernoulli=F,t.StudentsT=U,t.Gamma=A,t.ChiSquared=G,t.Exponential=R,t.Cauchy=D,t.Pareto=I,t.Poisson=B,t.Weibull=W,t.Uniform=Y,t.Sample=H,t.ttest=M}); | ||
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e(t.sampson=t.sampson||{})}(this,function(t){"use strict";function e(t,e){if(e>t)return NaN;for(var r=1,a=1;e>=a;a++)r*=t--,r/=a;return r}function r(t){var e=1/(1+.5*Math.abs(t)),r=e*Math.exp(-(t*t)-1.26551223+1.00002368*e+.37409196*Math.pow(e,2)+.09678418*Math.pow(e,3)-.18628806*Math.pow(e,4)+.27886807*Math.pow(e,5)-1.13520398*Math.pow(e,6)+1.48851587*Math.pow(e,7)-.82215223*Math.pow(e,8)+.17087277*Math.pow(e,9));return t>=0?1-r:r-1}function a(t){return 0>t?NaN:0==t?1:t*a(t-1)}function n(t){if(0>t)return NaN;for(var e=C[0],r=C.length-1;r>0;--r)e+=C[r]/(t+r);var a=t+N+.5;return.5*Math.log(2*Math.PI)+(t+.5)*Math.log(a)-a+Math.log(e)-Math.log(t)}function o(t){var e=t;if(0>e&&e%1==0)return 1/0;if(.5>e)return Math.PI/(Math.sin(Math.PI*e)*o(1-e));if(e>100)return Math.exp(n(e));e-=1;for(var r=E[0],a=1;O+2>a;a++)r+=E[a]/(e+a);var i=e+O+.5;return Math.sqrt(2*Math.PI)*Math.pow(i,e+.5)*Math.exp(-i)*r}function i(t,e){var r=void 0,a=void 0,o=void 0;for(o=1,r=1,a=1;100>o&&(r+=a*=e/(t+o),!(j>a/r));++o);return Math.exp(t*Math.log(e)-e-n(t+1)+Math.log(r))}function u(t){if(0==t.length)return 0;var e=0;return t.reduce(function(t,r){if(isNaN(r))return t;var a=r-e,n=t+a;return e=n-t-a,n},0)}function s(t){return 0==t.length?NaN:u(t)/t.filter(function(t){return!isNaN(t)}).length}function l(t){if(0==t.length)return NaN;if(1==t.length)return t;var e=function(){var e=t.reduce(function(t,e){return t[e]?t[e]++:t[e]=1,t},{}),r=Object.keys(e),a=r.map(function(t){return e[t]}).reduce(function(t,e){return e>t?e:t});return{v:r.filter(function(t){return e[t]==a}).map(function(t){return Number(t)})}}();return"object"===("undefined"==typeof e?"undefined":g["typeof"](e))?e.v:void 0}function v(t,e,r,a){var n=t.slice(0);if(0==n.length||e>=n.length)return NaN;var o=r||0,i=a||n.length-1;if(o==i)return n[o];for(;i>o;){if(i-o>x){var u=i-o+1,s=e-o+1,l=Math.log(u),h=P*Math.exp(2*l/3),c=P*Math.sqrt(l*h*(u-h)/u),d=Math.max(o,Math.floor(e-s*h/u+c)),m=Math.min(i,Math.floor(e+(u-s)*h/u+c));v(n,e,d,m)}var p=n[e],y=o,b=i;for(f(n,y,e),n[b]>p&&f(n,y,b);b>y;){for(f(n,y,b),y++,b--;n[y]<p;)y++;for(;n[b]>p;)b--}n[o]===p?f(n,o,b):(b++,f(n,b,i)),b>e?i=b-1:(o=b+1,i=b-1)}return n[e]}function f(t,e,r){var a=t[e];t[e]=t[r],t[r]=a}function h(t){var e=void 0;if(0==t.length)e=NaN;else{var r=t.length%2==0;r?(e=v(t,t.length/2),e+=v(t,t.length/2-1),e/=2):e=v(t,(t.length-1)/2)}return e}function c(t,e){if(void 0==e||e>1||0>e)throw new Error("p must be between zero and one inclusive.");if(void 0==t)throw new Error("need a list to provide a percentile.");if(0==t.length)return NaN;var r=Math.floor(t.length*e);return r>=t.length&&(r=t.length-1),v(t,r)}function d(t,e){if(!Array.isArray(t)||0==t.length)throw new Error("you must provide an array.");if(!Array.isArray(e)||0==e.length)throw new Error("you must provide some quantiles.");var r=e.reduce(function(t,e){return e>=0&&1>=e&&t},!0);if(!r)throw new Error("quantiles must be between zero and one inclusive.");if(e.length>1)return e.map(function(e){return d(t,[e])});var a=e[0];if(0==a)return t[0];if(1==a)return t[t.length-1];var n=t.length*a;return n%1?v(t,Math.floor(n)):t.length%2?v(t,n):(v(t,n-1)+v(t,n))/2}function m(t){return 0==t.length?NaN:Math.max.apply(Math,g.toConsumableArray(t))-Math.min.apply(Math,g.toConsumableArray(t))}function p(t,e,r){if(0==t.length)return NaN;var a=function(){var a=s(t);return{v:t.reduce(function(t,n){var o=n-a;return r&&(o=Math.abs(o)),t+Math.pow(o,e)},0)}}();return"object"===("undefined"==typeof a?"undefined":g["typeof"](a))?a.v:void 0}function y(t){return 0==t.length?NaN:p(t,2)/t.length}function b(t){var e=y(t);return isNaN(e)?0:Math.sqrt(e)}function k(t){return(t+.5)*Math.log(t)-t+Math.log(2*Math.PI)/2}function w(t,e,r){return(t-e)/r}function M(t,e,r){if(!t)return NaN;if(e){var a=r||0,n=((t.size-1)*t.variance+(e.size-1)*e.variance)/(t.size+e.size-2);return(t.mean-e.mean-a)/Math.sqrt(n*(1/t.size+1/e.size))}return(t.mean-r)/(t.std/Math.sqrt(t.size))}var g={};g["typeof"]="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol?"symbol":typeof t},g.classCallCheck=function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")},g.createClass=function(){function t(t,e){for(var r=0;r<e.length;r++){var a=e[r];a.enumerable=a.enumerable||!1,a.configurable=!0,"value"in a&&(a.writable=!0),Object.defineProperty(t,a.key,a)}}return function(e,r,a){return r&&t(e.prototype,r),a&&t(e,a),e}}(),g["extends"]=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var r=arguments[e];for(var a in r)Object.prototype.hasOwnProperty.call(r,a)&&(t[a]=r[a])}return t},g.get=function J(t,e,r){null===t&&(t=Function.prototype);var a=Object.getOwnPropertyDescriptor(t,e);if(void 0===a){var n=Object.getPrototypeOf(t);return null===n?void 0:J(n,e,r)}if("value"in a)return a.value;var o=a.get;if(void 0!==o)return o.call(r)},g.inherits=function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function, not "+typeof e);t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,enumerable:!1,writable:!0,configurable:!0}}),e&&(Object.setPrototypeOf?Object.setPrototypeOf(t,e):t.__proto__=e)},g.possibleConstructorReturn=function(t,e){if(!t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!e||"object"!=typeof e&&"function"!=typeof e?t:e},g.toConsumableArray=function(t){if(Array.isArray(t)){for(var e=0,r=Array(t.length);e<t.length;e++)r[e]=t[e];return r}return Array.from(t)};var N=607/128,C=[.9999999999999971,57.15623566586292,-59.59796035547549,14.136097974741746,-.4919138160976202,3399464998481189e-20,4652362892704858e-20,-9837447530487956e-20,.0001580887032249125,-.00021026444172410488,.00021743961811521265,-.0001643181065367639,8441822398385275e-20,-26190838401581408e-21,36899182659531625e-22],O=7,E=[.9999999999998099,676.5203681218851,-1259.1392167224028,771.3234287776531,-176.6150291621406,12.507343278686905,-.13857109526572012,9984369578019572e-21,1.5056327351493116e-7],j=1e-14,x=600,P=.5,q=function(){function t(e){g.classCallCheck(this,t);var r=Object.assign({},e);this.params=this.constructor.validate(r),this.mean=this.constructor.mean(r),this.stdDev=this.constructor.stdDev(r),this.relStdDev=this.constructor.relStdDev(r),this.variance=this.constructor.variance(r),this.skewness=this.constructor.skewness(r),this.kurtosis=this.constructor.kurtosis(r)}return g.createClass(t,null,[{key:"validate",value:function(){throw new Error("You must define a validation function for your distribution.")}},{key:"mean",value:function(t){return NaN}},{key:"variance",value:function(t){return NaN}},{key:"stdDev",value:function(t){return Math.sqrt(this.variance(t))}},{key:"relStdDev",value:function(t){return this.stdDev(t)/this.mean(t)}},{key:"skewness",value:function(t){return NaN}},{key:"kurtosis",value:function(t){return NaN}},{key:"pdf",value:function(){return NaN}},{key:"cdf",value:function(){return NaN}},{key:"random",value:function(){return Math.random()}},{key:"sample",value:function(t,e){var r=this;return Array.apply(null,Array(t)).map(function(){return r.random(e)})}}]),g.createClass(t,[{key:"pdf",value:function(t){return this.constructor.pdf(t,this.params)}},{key:"cdf",value:function(t){return this.constructor.cdf(t,this.params)}},{key:"random",value:function(){return this.constructor.random(this.params)}},{key:"sample",value:function(t){return this.constructor.sample(t,this.params)}}]),t}();q.covariates=0,q.discrete=!1;var D=function(t){function e(){return g.classCallCheck(this,e),g.possibleConstructorReturn(this,Object.getPrototypeOf(e).apply(this,arguments))}return g.inherits(e,t),g.createClass(e,null,[{key:"validate",value:function(t){if(!t||void 0===t.a||void 0===t.b)throw new Error("need a parameter object of shape { a: number, b: number }.");var e=t.a,r=t.b;if("number"!=typeof e)throw Error("a must be a number.");if("number"!=typeof r||0>=r)throw RangeError("b must be greater than zero.");return t}},{key:"random",value:function(t){for(var r=this.validate(t),a=r.a,n=r.b,o=void 0;!o||.5==o;)o=g.get(Object.getPrototypeOf(e),"random",this).call(this);return a+n*Math.tan(Math.PI*o)}},{key:"pdf",value:function(t,e){if("number"!=typeof t)throw new TypeError("x must be a number");var r=this.validate(e),a=r.a,n=r.b;return n/(Math.pow(t-a,2)+Math.pow(n,2))/Math.PI}},{key:"cdf",value:function(t,e){if("number"!=typeof t)throw new TypeError("x must be a number");var r=this.validate(e),a=r.a,n=r.b;return Math.atan((t-a)/n)/Math.PI+.5}},{key:"mean",value:function(t){return NaN}},{key:"variance",value:function(t){return NaN}},{key:"stdDev",value:function(t){return NaN}},{key:"relStdDev",value:function(t){return NaN}},{key:"skewness",value:function(t){return NaN}},{key:"kurtosis",value:function(t){return NaN}}]),e}(q);D.covariates=1,D.discrete=!1;var z=NaN,S=function(t){function e(){return g.classCallCheck(this,e),g.possibleConstructorReturn(this,Object.getPrototypeOf(e).apply(this,arguments))}return g.inherits(e,t),g.createClass(e,null,[{key:"validate",value:function(t){if(!t||void 0===t.mu||void 0==t.sigma)throw new Error("need a parameter object of shape { mu: number, simga: number }.");var e=t.mu,r=t.sigma;if("number"!=typeof e||"number"!=typeof r)throw new Error("Need mu and sigma for the normal distribution.");return t}},{key:"random",value:function(t){var r=this.validate(t),a=r.mu,n=r.sigma,o=z;if(z=NaN,!o){var i=2*g.get(Object.getPrototypeOf(e),"random",this).call(this)*Math.PI,u=Math.sqrt(-2*Math.log(1-g.get(Object.getPrototypeOf(e),"random",this).call(this)));o=Math.cos(i)*u,z=Math.sin(i)*u}return a+o*n}},{key:"pdf",value:function(t,e){if("number"!=typeof t)throw new Error("x must be a number.");var r=this.validate(e),a=r.mu,n=r.sigma;t/Math.abs(n);return 1/(Math.sqrt(2*Math.PI)*Math.abs(n))*Math.exp(-1*Math.pow(t-a,2)/(2*n*n))}},{key:"cdf",value:function(t,e){if("number"!=typeof t)throw new Error("x must be a number.");var a=this.validate(e),n=a.mu,o=a.sigma;return.5*(1+r((t-n)/(o*Math.sqrt(2))))}},{key:"mean",value:function(t){var e=this.validate(t),r=e.mu;e.sigma;return r}},{key:"variance",value:function(t){var e=this.validate(t),r=(e.mu,e.sigma);return r*r}},{key:"stdDev",value:function(t){var e=this.validate(t),r=(e.mu,e.sigma);return r}},{key:"relStdDev",value:function(t){var e=this.validate(t),r=e.mu,a=e.sigma;return a/r}},{key:"skewness",value:function(t){return 0}},{key:"kurtosis",value:function(t){return 3}}]),e}(q);S.covariates=2,S.discrete=!1;var R=function(t){function e(){return g.classCallCheck(this,e),g.possibleConstructorReturn(this,Object.getPrototypeOf(e).apply(this,arguments))}return g.inherits(e,t),g.createClass(e,null,[{key:"validate",value:function(t){if(!t||void 0===t.mu)throw new Error("need a parameter object of shape { mu: number }.");var e=t.mu;if("number"!=typeof e||0>=e)throw RangeError("mu must be greater than zero.");return t}},{key:"random",value:function(t){var r=this.validate(t),a=r.mu;return-a*Math.log1p(-g.get(Object.getPrototypeOf(e),"random",this).call(this))}},{key:"pdf",value:function(t,e){var r=this.validate(e),a=r.mu;if("number"!=typeof t)throw new Error("x must be a number.");return 0>t?0:Math.exp(-t/a)/a}},{key:"cdf",value:function(t,e){var r=this.validate(e),a=r.mu;if("number"!=typeof t)throw new Error("x must be a number.");return 0>=t?0:1-Math.exp(-t/a)}},{key:"mean",value:function(t){var e=this.validate(t),r=e.mu;return r}},{key:"variance",value:function(t){var e=this.validate(t),r=e.mu;return r*r}},{key:"stdDev",value:function(t){var e=this.validate(t),r=e.mu;return r}},{key:"relStdDev",value:function(t){return 1}},{key:"skewness",value:function(t){return 2}},{key:"kurtosis",value:function(t){return 9}}]),e}(q);R.covariates=1;var A=function(t){function e(){return g.classCallCheck(this,e),g.possibleConstructorReturn(this,Object.getPrototypeOf(e).apply(this,arguments))}return g.inherits(e,t),g.createClass(e,null,[{key:"validate",value:function(t){if(!t||void 0===t.a||void 0===t.b)throw new Error("need a parameter object of shape { a: number, b: number }.");var e=t.a,r=t.b;if("number"!=typeof e||"number"!=typeof r)throw new Error("Need a and b for the gamma distribution.");if(0>=e)throw new Error("a must be greater than zero.");if(0>=r)throw new Error("b must be greater than zero.");return t}},{key:"random",value:function(t){var r=this.validate(t),a=r.a,n=r.b;if(1>a){var o=g.get(Object.getPrototypeOf(e),"random",this).call(this);return this.random({a:1+a,b:n})*Math.pow(o,1/a)}for(var i=void 0,u=void 0,s=void 0,l=a-1/3,v=1/Math.sqrt(9*l);;){do i=S.random({mu:0,sigma:1}),u=1+v*i;while(0>=u);for(u=u*u*u;!s;)s=g.get(Object.getPrototypeOf(e),"random",this).call(this);if(1-.0331*i*i*i*i>s)break;if(Math.log(s)<.5*i*i+l*(1-u+Math.log(u)))break}return l*u/n}},{key:"pdf",value:function(t,e){var r=this.validate(e),a=r.a,o=r.b;if("number"!=typeof t)throw new Error("x must be a number.");return 0>t?0:0==t?1==a?o:0:1==a?Math.exp(-t*o)*o:Math.exp((a-1)*Math.log(t*o)-t*o-n(a))*o}},{key:"cdf",value:function(t,e){var r=this.validate(e),a=r.a,n=r.b;if("number"!=typeof t)throw new Error("x must be a number.");return 0>=t?0:i(a,t*n)}},{key:"mean",value:function(t){var e=this.validate(t),r=e.a,a=e.b;return r/a}},{key:"variance",value:function(t){var e=this.validate(t),r=e.a,a=e.b;return r/(a*a)}},{key:"stdDev",value:function(t){var e=this.validate(t),r=e.a,a=e.b;return Math.sqrt(r/(a*a))}},{key:"relStdDev",value:function(t){var e=this.validate(t),r=e.a;e.b;return 1/Math.sqrt(r)}},{key:"skewness",value:function(t){var e=this.validate(t),r=e.a;e.b;return 2/Math.sqrt(r)}},{key:"kurtosis",value:function(t){var e=this.validate(t),r=e.a;e.b;return 6/r}}]),e}(q);A.covariates=2;var I=function(t){function e(){return g.classCallCheck(this,e),g.possibleConstructorReturn(this,Object.getPrototypeOf(e).apply(this,arguments))}return g.inherits(e,t),g.createClass(e,null,[{key:"validate",value:function(t){if(!t||void 0===t.m||void 0==t.a)throw new Error("need a parameter object of shape { m: number, a: number }.");var e=t.m,r=t.a;if("number"!=typeof e||0>=e)throw RangeError("m must be greater than zero.");if("number"!=typeof r)throw RangeError("a must be a number.");return t}},{key:"random",value:function(t){var r=this.validate(t),a=r.m,n=r.a;return n*Math.pow(g.get(Object.getPrototypeOf(e),"random",this).call(this),-1/a)}},{key:"pdf",value:function(t,e){var r=this.validate(e),a=r.m,n=r.a;if("number"!=typeof t)throw new Error("x must be a number.");return a>t?0:n*Math.pow(a,n)/Math.pow(t,n+1)}},{key:"cdf",value:function(t,e){var r=this.validate(e),a=r.m,n=r.a;if("number"!=typeof t)throw new Error("x must be a number.");return a>t?0:1-Math.pow(a/t,n)}},{key:"mean",value:function(t){var e=this.validate(t),r=e.m,a=e.a;return 1>=a?1/0:a*r/(a-1)}},{key:"variance",value:function(t){var e=this.validate(t),r=e.m,a=e.a;return 2>=a?1/0:a*r*r/((a-1)*(a-1)*(a-2))}},{key:"skewness",value:function(t){var e=this.validate(t),r=(e.m,e.a);return 3>r?NaN:2*(1+r)/(r-3)*Math.sqrt((r-2)/r)}},{key:"kurtosis",value:function(t){var e=this.validate(t),r=(e.m,e.a);return 4>r?NaN:6*(r*r*r+r*r-6*r-2)/(r*(r-3)*(r-4))}}]),e}(q);I.covariates=1;var T=14,_=function(t){function r(){return g.classCallCheck(this,r),g.possibleConstructorReturn(this,Object.getPrototypeOf(r).apply(this,arguments))}return g.inherits(r,t),g.createClass(r,null,[{key:"validate",value:function(t){if(!t||void 0===t.n||void 0===t.p)throw new Error("need a parameter object of shape { n: number, p: number }.");var e=t.n,r=t.p;if("number"!=typeof r||r>1||0>r)throw new Error("p must be between zero and one inclusive.");if("number"!=typeof e||0>e)throw new Error("n must be positive or zero.");return{n:Math.floor(e),p:r}}},{key:"random",value:function(t){var e=this,a=this.validate(t),n=a.n,o=a.p;if(0==n)return 0;var i=!1,u=0,s=void 0;o>.5?(i=!0,s=1-o):s=o;var l=1-s,v=s/l,f=n*s;if(T>f)for(var h=Math.pow(l,n),c=g.get(Object.getPrototypeOf(r),"random",this).call(this);n>=u&&c>=h;)c-=h,h*=v*(n-u)/(u+1),u++;else!function(){var t=f+s,a=Math.floor(t),o=a+.5,i=f*l,v=Math.floor(2.195*Math.sqrt(i)-4.6*l)+.5,h=o-v,c=o+v,d=.134+20.5/(15.3+a),m=v*(1+d+d),p=(t-h)/(t-h*s),y=p*(1+.5*p),b=(c-t)/(c*l),w=b*(1.5+b),M=m+d/y,N=M+d/w,C=void 0,O=void 0,E=void 0,j=void 0,x=function P(){if(E=g.get(Object.getPrototypeOf(r),"random",e).call(e)*N,j=g.get(Object.getPrototypeOf(r),"random",e).call(e),v>=E)u=Math.floor(o-v*j+E);else if(m>=E){var t=h+(E-v)/d;j=j*d+1-Math.abs(t-o)/v,j>1||0>=j?P():u=t}else M>=E?(u=Math.floor(h+Math.log(j)/y),j*=(E-m)*y):(u=Math.floor(c-Math.log(j)/w),j*=(E-M)*w);C=Math.log(j);var i=u+1,f=n-u-1,p=a+1,b=n+1-a;O=o*Math.log(p/i)+(n-a+.5)*Math.log(b/f)+(u-a)*Math.log(f*s/(i*l))+k(p)+k(b)-k(i)-k(f),C>O&&P()};x()}();return Math.floor(i?n-u:u)}},{key:"pdf",value:function(t,r){var a=this.validate(r),n=a.n,o=a.p;if("number"!=typeof t)throw new Error("k must be a number.");if(0>t||t>n)return 0;var i=void 0,u=Math.floor(t);if(0==o)i=0==u?1:0;else{if(1!=o){var s=e(n,u),l=Math.pow(o,u)*Math.pow(1-o,n-u);return"Infinity"==s?0==l?0:s:s*l}i=u==n?1:0}return i}},{key:"cdf",value:function(t,r){var a=this.validate(r),n=a.n,o=a.p;if("number"!=typeof t)throw new Error("k must be a number.");return 0>t?0:t>n?1:Array.apply(null,Array(Math.floor(t)+1)).map(function(t,r){return e(n,r)*Math.pow(o,r)*Math.pow(1-o,n-r)}).reduce(function(t,e){return t+e},0)}},{key:"mean",value:function(t){var e=this.validate(t),r=e.n,a=e.p;return r*a}},{key:"variance",value:function(t){var e=this.validate(t),r=e.n,a=e.p;return r*a*(1-a)}},{key:"stdDev",value:function(t){var e=this.validate(t),r=e.n,a=e.p;return Math.sqrt(r*a*(1-a))}},{key:"relStdDev",value:function(t){var e=this.validate(t),r=e.n,a=e.p;return Math.sqrt((1-a)/(r*a))}},{key:"skewness",value:function(t){var e=this.validate(t),r=e.n,a=e.p;return(1-2*a)/Math.sqrt(r*a*(1-a))}},{key:"kurtosis",value:function(t){var e=this.validate(t),r=e.n,a=e.p;return 3-6/r+1/(r*a*(1-a))}}]),r}(q);_.covariates=2,_.discrete=!0;var B=function(t){function e(){return g.classCallCheck(this,e),g.possibleConstructorReturn(this,Object.getPrototypeOf(e).apply(this,arguments))}return g.inherits(e,t),g.createClass(e,null,[{key:"validate",value:function(t){if(!t||void 0===t.mu)throw new Error("need a parameter object of shape { n: number, p: number }.");var e=t.mu;if("number"!=typeof e||0>=e)throw new Error("n must be greater than zero");return t}},{key:"random",value:function(t){for(var r=this.validate(t),a=r.mu,n=1,o=0,i=0;a>10;){var u=Math.round(a*(7/8)),s=A.random({a:u,b:1});if(s>=a)return i+_.random({p:a/s,n:u-1});i+=u,a-=s}o=Math.exp(-a);do n*=g.get(Object.getPrototypeOf(e),"random",this).call(this),i++;while(n>o);return i-1}},{key:"pdf",value:function(t,e){var r=this.validate(e),a=r.mu;if("number"!=typeof t)throw new Error("k must be a number.");return Math.exp(Math.log(a)*t-n(t+1)-a)}},{key:"cdf",value:function(t,e){var r=this,a=this.validate(e);a.mu;if("number"!=typeof t)throw new Error("k must be a number.");if(0>t)return 0;var n=Array.apply(null,Array(t+1)).map(function(t,a){return r.pdf(a,e)});return u(n)}},{key:"mean",value:function(t){var e=this.validate(t),r=e.mu;return r}},{key:"variance",value:function(t){var e=this.validate(t),r=e.mu;return r}},{key:"skewness",value:function(t){var e=this.validate(t),r=e.mu;return Math.pow(r,-.5)}},{key:"kurtosis",value:function(t){var e=this.validate(t),r=e.mu;return Math.pow(r,-1)}}]),e}(q);B.covariates=1,B.discrete=!0;var F=function(t){function e(t){return g.classCallCheck(this,e),g.possibleConstructorReturn(this,Object.getPrototypeOf(e).call(this,g["extends"]({},t,{n:1})))}return g.inherits(e,t),g.createClass(e,null,[{key:"random",value:function(t){var e=this.validate(g["extends"]({},t,{n:1})),r=e.p,a=q.random();return r>a?1:0}},{key:"pdf",value:function(t,e){var r=this.validate(g["extends"]({},e,{n:1})),a=r.p;if("number"!=typeof t)throw new Error("k must be a number.");return 0==t?1-a:1==t?a:0}},{key:"cdf",value:function(t,e){var r=this.validate(g["extends"]({},e,{n:1})),a=r.p;if("number"!=typeof t)throw new Error("k must be a number.");return 1==t?a:0==t?1-a:NaN}}]),e}(_);F.covariates=1;var G=function(t){function e(){return g.classCallCheck(this,e),g.possibleConstructorReturn(this,Object.getPrototypeOf(e).apply(this,arguments))}return g.inherits(e,t),g.createClass(e,null,[{key:"validate",value:function(t){if(!t||void 0===t.df)throw new Error("need a parameter object of shape { df: number }.");var e=t.df;if("number"!=typeof e||0>=e)throw RangeError("df must be greater than zero.");return t}},{key:"random",value:function(t){var e=this.validate(t),r=e.df;return 2*A.random({a:r/2,b:1})}},{key:"pdf",value:function(t,e){var r=this.validate(e),a=r.df;if("number"!=typeof t)throw new TypeError("x must be a number");return 0>t?0:2==a?Math.exp(-t/2)/2:Math.exp((a/2-1)*Math.log(t/2)-t/2-n(a/2))/2}},{key:"cdf",value:function(t,e){var r=this.validate(e),a=r.df;if("number"!=typeof t)throw new TypeError("x must be a number");return 0>t?0:2==a?1-Math.exp(-t/2):i(a/2,t/2)}},{key:"mean",value:function(t){var e=this.validate(t),r=e.df;return r}},{key:"variance",value:function(t){var e=this.validate(t),r=e.df;return 2*r}},{key:"stdDev",value:function(t){var e=this.validate(t),r=e.df;return Math.sqrt(2*r)}},{key:"relStdDev",value:function(t){var e=this.validate(t),r=e.df;return Math.sqrt(2/r)}},{key:"skewness",value:function(t){var e=this.validate(t),r=e.df;return Math.pow(2,1.5)/Math.sqrt(r)}},{key:"kurtosis",value:function(t){var e=this.validate(t),r=e.df;return 3+12/r}}]),e}(q);G.covariates=1;var U=function(t){function e(){return g.classCallCheck(this,e),g.possibleConstructorReturn(this,Object.getPrototypeOf(e).apply(this,arguments))}return g.inherits(e,t),g.createClass(e,null,[{key:"validate",value:function(t){if(!t||void 0===t.df)throw new Error("need a parameter object of shape { df: number }.");var e=t.df;if("number"!=typeof e||0>=e)throw RangeError("df must be greater than zero.");return t}},{key:"random",value:function(t){var e=this.validate(t),r=e.df;if(2>=r){var a=S.random({mu:0,sigma:1}),n=G.random({df:r});return a/Math.sqrt(n/r)}var o=void 0,i=void 0,u=void 0;do o=S.random({mu:0,sigma:1}),i=R.random({mu:1/(r/2-1)}),u=o*i/(r-2);while(0>1-u||Math.exp(-i-u)>1-u);return o/Math.sqrt((1-2/r)*(1-u))}},{key:"pdf",value:function(t,e){if("number"!=typeof t)throw TypeError("t must be a number.");var r=this.validate(e),a=r.df,o=n(a/2),i=n((a+1)/2);return Math.exp(i-o)/Math.sqrt(Math.PI*a)*Math.pow(1+t*t/a,-(a+1)/2)}},{key:"cdf",value:function(t,e){if("number"!=typeof t)throw TypeError("t must be a number.");var r=this.validate(e),a=r.df,n=void 0,o=void 0,i=void 0,u=void 0,s=void 0,l=void 0,v=void 0,f=void 0,h=void 0,c=void 0,d=1/Math.PI;if(i=a,n=t/Math.sqrt(i),o=i/(i+t*t),u=a-2,s=i%2,l=1,v=1,i=1,f=2+s,h=f,u>=2)for(c=f;u>=c;c+=2)v=v*o*(h-1)/h,l+=v,i=l,h+=2;return 1!=s?.5+.5*n*Math.sqrt(o)*l:(1==a&&(l=0),.5+(n*o*l+Math.atan(n))*d)}},{key:"mean",value:function(t){var e=this.validate(t),r=e.df;return 1>=r?NaN:0}},{key:"variance",value:function(t){var e=this.validate(t),r=e.df;return 1>r?NaN:2>=r?1/0:r/(r-2)}},{key:"stdDev",value:function(t){var e=this.validate(t),r=e.df;return 1>r?NaN:2>=r?1/0:Math.sqrt(r/(r-2))}},{key:"relStdDev",value:function(t){var e=this.validate(t);e.df;return NaN}},{key:"skewness",value:function(t){var e=this.validate(t),r=e.df;return r>3?0:NaN}},{key:"kurtosis",value:function(t){var e=this.validate(t),r=e.df;return 4>=r?NaN:3*(r-2)/(r-4)}}]),e}(q);U.covariates=1;var W=function(t){function e(){return g.classCallCheck(this,e),g.possibleConstructorReturn(this,Object.getPrototypeOf(e).apply(this,arguments))}return g.inherits(e,t),g.createClass(e,null,[{key:"validate",value:function(t){if(!t||void 0===t.a||void 0===t.b)throw new Error("need a parameter object of shape { a: number, b: number }.");var e=t.a,r=t.b;if("number"!=typeof e||0>=e)throw Error("a must be greater than zero.");if("number"!=typeof r||0>=r)throw RangeError("b must be greater than zero.");return t}},{key:"random",value:function(t){var r=this.validate(t),a=r.a,n=r.b;return a*Math.pow(-Math.log(g.get(Object.getPrototypeOf(e),"random",this).call(this)),1/n)}},{key:"pdf",value:function(t,e){if("number"!=typeof t)throw new TypeError("x must be a number");var r=this.validate(e),a=r.a,n=r.b;return 0>t?0:n/a*Math.pow(t/a,n-1)*Math.exp(-Math.pow(t/a,n))}},{key:"cdf",value:function(t,e){if("number"!=typeof t)throw new TypeError("x must be a number");var r=this.validate(e),a=r.a,n=r.b;return 0>t?0:1-Math.exp(-Math.pow(t/a,n))}},{key:"mean",value:function(t){var e=this.validate(t),r=e.a,a=e.b;return r*o(1+1/a)}},{key:"variance",value:function(t){var e=this.validate(t),r=e.a,a=e.b;return r*r*(o(1+2/a)-Math.pow(o(1+1/a),2))}},{key:"skewness",value:function(t){var e=t.a,r=t.b,a=this.stdDev(t),n=this.mean(t);return(o(1+3/r)*Math.pow(e,3)-3*n*a*a-Math.pow(n,3))/Math.pow(a,3)}},{key:"kurtosis",value:function(t){var e=t.a,r=t.b,a=this.stdDev(t),n=this.mean(t),i=this.skewness(t);return(o(1+4/r)*Math.pow(e,4)-4*i*Math.pow(a,3)*n-6*Math.pow(n,2)*Math.pow(a,2)-Math.pow(n,4))/Math.pow(a,4)-3}}]),e}(q);W.covariates=1,W.discrete=!1;var Y=function(t){function e(){return g.classCallCheck(this,e),g.possibleConstructorReturn(this,Object.getPrototypeOf(e).apply(this,arguments))}return g.inherits(e,t),g.createClass(e,null,[{key:"validate",value:function(t){if(!t||void 0===t.a||void 0===t.b)throw new Error("need a parameter object of shape { a: number, b: number }.");var e=t.a,r=t.b;if("number"!=typeof e)throw Error("a must be a number.");if("number"!=typeof r||e>=r)throw RangeError("b must be greater than a.");return t}},{key:"random",value:function(t){var r=this.validate(t),a=r.a,n=r.b;return a+g.get(Object.getPrototypeOf(e),"random",this).call(this)*(n-a)}},{key:"pdf",value:function(t,e){if("number"!=typeof t)throw new TypeError("x must be a number");var r=this.validate(e),a=r.a,n=r.b;return a>t||t>n?0:1/(n-a)}},{key:"cdf",value:function(t,e){if("number"!=typeof t)throw new TypeError("x must be a number");var r=this.validate(e),a=r.a,n=r.b;return a>t?0:t>=n?1:(t-a)/(n-a)}},{key:"mean",value:function(t){var e=this.validate(t),r=e.a,a=e.b;return(r+a)/2}},{key:"variance",value:function(t){var e=this.validate(t),r=e.a,a=e.b;return Math.pow(a-r,2)/12}},{key:"skewness",value:function(t){return 0}},{key:"kurtosis",value:function(t){return-1.2}}]),e}(q);Y.covariates=1,Y.discrete=!1;var H=function(){function t(e){var r=this;if(g.classCallCheck(this,t),this.covariance=function(t){return r.constructor.covariance(r,t)},this.correlation=function(t){return r.constructor.correlation(r,t)},0==e.length)throw new Error("Sample of size 0 not allowed.");this.data=e,this.size=e.length,this.mean=s(e),this.std=this.constructor.stdDev(e),this.variance=this.constructor.variance(e),this.skewness=this.constructor.skewness(e),this.kurtosis=this.constructor.kurtosis(e),this.sqrdMeanDev=this.constructor.sqrdMeanDev(e),this.meanDev=this.constructor.meanDev(e),this.rootMeanSqrd=this.constructor.rootMeanSqrd(e),this.stdMeanDev=this.constructor.stdMeanDev(e),this.relStdDev=this.constructor.relativeStdDev(e),this.quartiles=this.constructor.quartiles(e)}return g.createClass(t,null,[{key:"variance",value:function(t){return p(t,2)/(t.length-1)}},{key:"sqrdMeanDev",value:function(t){return p(t,2)}},{key:"meanDev",value:function(t){return p(t,1,!0)/t.length}},{key:"stdDev",value:function(t){var e=this.variance(t);return isNaN(e)?0:Math.sqrt(e)}},{key:"rootMeanSqrd",value:function(t){return Math.sqrt(t.map(function(t){return t*t}).reduce(function(t,e){return t+e})/t.length)}},{key:"stdMeanDev",value:function(t){return this.stdDev(t)/Math.sqrt(t.length)}},{key:"relativeStdDev",value:function(t){return this.stdDev(t)/s(t)}},{key:"quartiles",value:function(t){return d(t,[.25,.5,.75])}},{key:"skewness",value:function(t){var e=this.stdDev(t);if(isNaN(e)||t.length<3)return NaN;var r=t.length,a=Math.pow(e,3),n=p(t,3);return r*n/((r-1)*(r-2)*a)}},{key:"kurtosis",value:function(t){var e=this.stdDev(t);if(isNaN(e)||t.length<3)return NaN;var r=(t.length,p(t,2)),a=p(t,4);return a/Math.pow(r,2)}},{key:"covariance",value:function(t,e){if(!t||!e||t.size<=1||t.size!==e.size)return NaN;var r=t.data.map(function(r,a){return(t.data[a]-t.mean)*(e.data[a]-e.mean)}).reduce(function(t,e){return t+e},0);return r/(t.size-1)}},{key:"correlation",value:function(t,e){if(!(t&&t.std&&e&&e.std))return NaN;var r=this.covariance(t,e);return r/t.std/e.std}}]),t}();t.choose=e,t.error=r,t.factorial=a,t.gamma=o,t.gammainc_lower=i,t.lngamma=n,t.median=h,t.mean=s,t.mode=l,t.percentile=c,t.quantile=d,t.range=m,t.select=v,t.std=b,t.stirling=k,t.sum=u,t.sumNthPowerDev=p,t.variance=y,t.zscore=w,t.Normal=S,t.Binomial=_,t.Bernoulli=F,t.StudentsT=U,t.Gamma=A,t.ChiSquared=G,t.Exponential=R,t.Cauchy=D,t.Pareto=I,t.Poisson=B,t.Weibull=W,t.Uniform=Y,t.Sample=H,t.ttest=M}); |
@@ -28,3 +28,3 @@ /* @flow */ | ||
if (typeof n != 'number' || n < 0) throw new Error("n must be positive or zero.") | ||
return params | ||
return { n: Math.floor(n), p } | ||
} | ||
@@ -130,7 +130,8 @@ | ||
let P: number; | ||
if (p == 0) { P = (k == 0) ? 1 : 0 } | ||
else if (p == 1) { P = (k == n) ? 1 : 0 } | ||
let x = Math.floor(k); | ||
if (p == 0) { P = (x == 0) ? 1 : 0 } | ||
else if (p == 1) { P = (x == n) ? 1 : 0 } | ||
else { | ||
let Cnk = choose(n, k); | ||
let pows = Math.pow(p, k) * Math.pow((1-p), (n-k)); | ||
let Cnk = choose(n, x); | ||
let pows = Math.pow(p, x) * Math.pow((1-p), (n-x)); | ||
if (Cnk == 'Infinity') { | ||
@@ -137,0 +138,0 @@ if (pows == 0) return 0 |
@@ -37,3 +37,5 @@ /* @flow */ | ||
let { mu } = this.validate(params); | ||
let prod, emu, k = 0; | ||
let prod = 1; | ||
let emu; | ||
let k = 0; | ||
while (mu > 10) { | ||
@@ -48,3 +50,3 @@ let m = Math.round(mu * (7 / 8)); | ||
}; | ||
mu = Math.exp(-mu) | ||
emu = Math.exp(-mu) | ||
do { | ||
@@ -51,0 +53,0 @@ prod *= super.random() |
@@ -5,3 +5,3 @@ { | ||
"author": "Jack Shira <jack@atg.io> (http://www.atg.io)", | ||
"version": "0.2.6", | ||
"version": "0.2.7", | ||
"license": "ISC", | ||
@@ -13,3 +13,3 @@ "repository" : { | ||
"engine": "node >= 5.8.0", | ||
"main": "lib.js", | ||
"main": "dist/lib.js", | ||
"jsnext:main": "lib.es6.js", | ||
@@ -19,2 +19,3 @@ "scripts": { | ||
"cover": "BABEL_ENV=test node_modules/.bin/istanbul cover babel-tape-runner test/**/*.test.js", | ||
"codecov": "npm run cover && codecov", | ||
"doc": "node_modules/.bin/esdoc -c esdoc.json", | ||
@@ -21,0 +22,0 @@ "build": "BABEL_ENV=build node rollup.js", |
# Sampson.js | ||
[![npm](https://img.shields.io/npm/v/sampson.svg)](https://www.npmjs.com/package/sampson) | ||
[![CircleCI branch](https://img.shields.io/circleci/project/atgJack/sampson/master.svg)](https://github.com/atgJack/sampson/tree/master/test) | ||
[![Codecov](https://img.shields.io/codecov/c/github/atgJack/sampson.svg)](https://codecov.io/github/atgJack/sampson) | ||
@@ -3,0 +6,0 @@ A Statistical Sampling and Distribution Library. |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
356166
83
9019
61