Comparing version 0.2.3 to 0.2.4
@@ -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,n=1;e>=n;n++)r*=t--,r/=n;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 n(t){return 0>t?NaN:0==t?1:t*n(t-1)}function a(t){if(0>t)return NaN;for(var e=C[0],r=C.length-1;r>0;--r)e+=C[r]/(t+r);var n=t+N+.5;return.5*Math.log(2*Math.PI)+(t+.5)*Math.log(n)-n+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(a(e));e-=1;for(var r=E[0],n=1;O+2>n;n++)r+=E[n]/(e+n);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,n=void 0,o=void 0;for(o=1,r=1,n=1;100>o&&(r+=n*=e/(t+o),!(D>n/r));++o);return Math.exp(t*Math.log(e)-e-a(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 n=r-e,a=t+n;return e=a-t-n,a},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),n=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]==n}).map(function(t){return Number(t)})}}();return"object"===("undefined"==typeof e?"undefined":g["typeof"](e))?e.v:void 0}function f(t,e,r,n){var a=t.slice(0);if(0==a.length||e>=a.length)return NaN;var o=r||0,i=n||a.length-1;if(o==i)return a[o];for(;i>o;){if(i-o>q){var u=i-o+1,s=e-o+1,l=Math.log(u),h=j*Math.exp(2*l/3),c=j*Math.sqrt(l*h*(u-h)/u),d=Math.max(o,Math.floor(e-s*h/u+c)),p=Math.min(i,Math.floor(e+(u-s)*h/u+c));f(a,e,d,p)}var m=a[e],y=o,b=i;for(v(a,y,e),a[b]>m&&v(a,y,b);b>y;){for(v(a,y,b),y++,b--;a[y]<m;)y++;for(;a[b]>m;)b--}a[o]===m?v(a,o,b):(b++,v(a,b,i)),b>e?i=b-1:(o=b+1,i=b-1)}return a[e]}function v(t,e,r){var n=t[e];t[e]=t[r],t[r]=n}function h(t){var e=void 0;if(0==t.length)e=NaN;else{var r=t.length%2==0;r?(e=f(t,t.length/2),e+=f(t,t.length/2-1),e/=2):e=f(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),f(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 n=e[0];if(0==n)return t[0];if(1==n)return t[t.length-1];var a=t.length*n;return a%1?f(t,Math.floor(a)):t.length%2?f(t,a):(f(t,a-1)+f(t,a))/2}function p(t){return 0==t.length?NaN:Math.max.apply(Math,g.toConsumableArray(t))-Math.min.apply(Math,g.toConsumableArray(t))}function m(t,e,r){if(0==t.length)return NaN;var n=function(){var n=s(t);return{v:t.reduce(function(t,a){var o=a-n;return r&&(o=Math.abs(o)),t+Math.pow(o,e)},0)}}();return"object"===("undefined"==typeof n?"undefined":g["typeof"](n))?n.v:void 0}function y(t){return 0==t.length?NaN:m(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 M(t,e,r){return(t-e)/r}function w(t,e,r){if(!t)return NaN;if(e){var n=r||0,a=((t.size-1)*t.variance+(e.size-1)*e.variance)/(t.size+e.size-2);return(t.mean-e.mean-n)/Math.sqrt(a*(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 n=e[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,n.key,n)}}return function(e,r,n){return r&&t(e.prototype,r),n&&t(e,n),e}}(),g["extends"]=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var r=arguments[e];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(t[n]=r[n])}return t},g.get=function Y(t,e,r){null===t&&(t=Function.prototype);var n=Object.getOwnPropertyDescriptor(t,e);if(void 0===n){var a=Object.getPrototypeOf(t);return null===a?void 0:Y(a,e,r)}if("value"in n)return n.value;var o=n.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],D=1e-14,q=600,j=.5,x=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}();x.covariates=0,x.discrete=!1;var P=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),n=r.a,a=r.b,o=void 0;!o||.5==o;)o=g.get(Object.getPrototypeOf(e),"random",this).call(this);return n+a*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),n=r.a,a=r.b;return a/(Math.pow(t-n,2)+Math.pow(a,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),n=r.a,a=r.b;return Math.atan((t-n)/a)/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}(x);P.covariates=1,P.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),n=r.mu,a=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 n+o*a}},{key:"pdf",value:function(t,e){if("number"!=typeof t)throw new Error("x must be a number.");var r=this.validate(e),n=r.mu,a=r.sigma;t/Math.abs(a);return 1/(Math.sqrt(2*Math.PI)*Math.abs(a))*Math.exp(-1*Math.pow(t-n,2)/(2*a*a))}},{key:"cdf",value:function(t,e){if("number"!=typeof t)throw new Error("x must be a number.");var n=this.validate(e),a=n.mu,o=n.sigma;return.5*(1+r((t-a)/(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,n=e.sigma;return n/r}},{key:"skewness",value:function(t){return 0}},{key:"kurtosis",value:function(t){return 3}}]),e}(x);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),n=r.mu;return-n*Math.log1p(-g.get(Object.getPrototypeOf(e),"random",this).call(this))}},{key:"pdf",value:function(t,e){var r=this.validate(e),n=r.mu;if("number"!=typeof t)throw new Error("x must be a number.");return 0>t?0:Math.exp(-t/n)/n}},{key:"cdf",value:function(t,e){var r=this.validate(e),n=r.mu;if("number"!=typeof t)throw new Error("x must be a number.");return 0>=t?0:1-Math.exp(-t/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*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}(x);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),n=r.a,a=r.b;if(1>n){var o=g.get(Object.getPrototypeOf(e),"random",this).call(this);return this.random({a:1+n,b:a})*Math.pow(o,1/n)}for(var i=void 0,u=void 0,s=void 0,l=n-1/3,f=1/Math.sqrt(9*l);;){do i=S.random({mu:0,sigma:1}),u=1+f*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/a}},{key:"pdf",value:function(t,e){var r=this.validate(e),n=r.a,o=r.b;if("number"!=typeof t)throw new Error("x must be a number.");return 0>t?0:0==t?1==n?o:0:1==n?Math.exp(-t*o)*o:Math.exp((n-1)*Math.log(t*o)-t*o-a(n))*o}},{key:"cdf",value:function(t,e){var r=this.validate(e),n=r.a,a=r.b;if("number"!=typeof t)throw new Error("x must be a number.");return 0>=t?0:i(n,t*a)}},{key:"mean",value:function(t){var e=this.validate(t),r=e.a,n=e.b;return r/n}},{key:"variance",value:function(t){var e=this.validate(t),r=e.a,n=e.b;return r/(n*n)}},{key:"stdDev",value:function(t){var e=this.validate(t),r=e.a,n=e.b;return Math.sqrt(r/(n*n))}},{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}(x);A.covariates=2;var I=14,T=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,n=this.validate(t),a=n.n,o=n.p;if(0==a)return 0;var i=!1,u=0,s=void 0;o>.5?(i=!0,s=1-o):s=o;var l=1-s,f=s/l,v=a*s;if(I>v)for(var h=Math.pow(l,a),c=g.get(Object.getPrototypeOf(r),"random",this).call(this);a>=u&&c>=h;)c-=h,h*=f*(a-u)/(u+1),u++;else!function(){var t=v+s,n=Math.floor(t),o=n+.5,i=v*l,f=Math.floor(2.195*Math.sqrt(i)-4.6*l)+.5,h=o-f,c=o+f,d=.134+20.5/(15.3+n),p=f*(1+d+d),m=(t-h)/(t-h*s),y=m*(1+.5*m),b=(c-t)/(c*l),M=b*(1.5+b),w=p+d/y,N=w+d/M,C=void 0,O=void 0,E=void 0,D=void 0,q=function j(){if(E=g.get(Object.getPrototypeOf(r),"random",e).call(e)*N,D=g.get(Object.getPrototypeOf(r),"random",e).call(e),f>=E)u=Math.floor(o-f*D+E);else if(p>=E){var t=h+(E-f)/d;D=D*d+1-Math.abs(t-o)/f,D>1||0>=D?j():u=t}else w>=E?(u=Math.floor(h+Math.log(D)/y),D*=(E-p)*y):(u=Math.floor(c-Math.log(D)/M),D*=(E-w)*M);C=Math.log(D);var i=u+1,v=a-u-1,m=n+1,b=a+1-n;O=o*Math.log(m/i)+(a-n+.5)*Math.log(b/v)+(u-n)*Math.log(v*s/(i*l))+k(m)+k(b)-k(i)-k(v),C>O&&j()};q()}();return Math.floor(i?a-u:u)}},{key:"pdf",value:function(t,r){var n=this.validate(r),a=n.n,o=n.p;if("number"!=typeof t)throw new Error("k must be a number.");if(0>t||t>a)return 0;var i=void 0;if(0==o)i=0==t?1:0;else{if(1!=o){var u=e(a,t),s=Math.pow(o,t)*Math.pow(1-o,a-t);return"Infinity"==u?0==s?0:u:u*s}i=t==a?1:0}return i}},{key:"cdf",value:function(t,r){var n=this.validate(r),a=n.n,o=n.p;if("number"!=typeof t)throw new Error("k must be a number.");return 0>t?0:t>a?1:Array.apply(null,Array(Math.floor(t)+1)).map(function(t,r){return e(a,r)*Math.pow(o,r)*Math.pow(1-o,a-r)}).reduce(function(t,e){return t+e},0)}},{key:"mean",value:function(t){var e=this.validate(t),r=e.n,n=e.p;return r*n}},{key:"variance",value:function(t){var e=this.validate(t),r=e.n,n=e.p;return r*n*(1-n)}},{key:"stdDev",value:function(t){var e=this.validate(t),r=e.n,n=e.p;return Math.sqrt(r*n*(1-n))}},{key:"relStdDev",value:function(t){var e=this.validate(t),r=e.n,n=e.p;return Math.sqrt((1-n)/(r*n))}},{key:"skewness",value:function(t){var e=this.validate(t),r=e.n,n=e.p;return(1-2*n)/Math.sqrt(r*n*(1-n))}},{key:"kurtosis",value:function(t){var e=this.validate(t),r=e.n,n=e.p;return 3-6/r+1/(r*n*(1-n))}}]),r}(x);T.covariates=2,T.discrete=!0;var _=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,n=x.random();return r>n?1:0}},{key:"pdf",value:function(t,e){var r=this.validate(g["extends"]({},e,{n:1})),n=r.p;if("number"!=typeof t)throw new Error("k must be a number.");return 0==t?1-n:1==t?n:0}},{key:"cdf",value:function(t,e){var r=this.validate(g["extends"]({},e,{n:1})),n=r.p;if("number"!=typeof t)throw new Error("k must be a number.");return 1==t?n:0==t?1-n:NaN}}]),e}(T);_.covariates=1;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.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),n=r.df;if("number"!=typeof t)throw new TypeError("x must be a number");return 0>t?0:2==n?Math.exp(-t/2)/2:Math.exp((n/2-1)*Math.log(t/2)-t/2-a(n/2))/2}},{key:"cdf",value:function(t,e){var r=this.validate(e),n=r.df;if("number"!=typeof t)throw new TypeError("x must be a number");return 0>t?0:2==n?1-Math.exp(-t/2):i(n/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}(x);B.covariates=1;var F=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 n=S.random({mu:0,sigma:1}),a=B.random({df:r});return n/Math.sqrt(a/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),n=r.df,o=a(n/2),i=a((n+1)/2);return Math.exp(i-o)/Math.sqrt(Math.PI*n)*Math.pow(1+t*t/n,-(n+1)/2)}},{key:"cdf",value:function(t,e){if("number"!=typeof t)throw TypeError("t must be a number.");var r=this.validate(e),n=r.df,a=void 0,o=void 0,i=void 0,u=void 0,s=void 0,l=void 0,f=void 0,v=void 0,h=void 0,c=void 0,d=1/Math.PI;if(i=n,a=t/Math.sqrt(i),o=i/(i+t*t),u=n-2,s=i%2,l=1,f=1,i=1,v=2+s,h=v,u>=2)for(c=v;u>=c;c+=2)f=f*o*(h-1)/h,l+=f,i=l,h+=2;return 1!=s?.5+.5*a*Math.sqrt(o)*l:(1==n&&(l=0),.5+(a*o*l+Math.atan(a))*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}(x);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.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),n=r.a,a=r.b;return n*Math.pow(-Math.log(g.get(Object.getPrototypeOf(e),"random",this).call(this)),1/a)}},{key:"pdf",value:function(t,e){if("number"!=typeof t)throw new TypeError("x must be a number");var r=this.validate(e),n=r.a,a=r.b;return 0>t?0:a/n*Math.pow(t/n,a-1)*Math.exp(-Math.pow(t/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),n=r.a,a=r.b;return 0>t?0:1-Math.exp(-Math.pow(t/n,a))}},{key:"mean",value:function(t){var e=this.validate(t),r=e.a,n=e.b;return r*o(1+1/n)}},{key:"variance",value:function(t){var e=this.validate(t),r=e.a,n=e.b;return r*r*(o(1+2/n)-Math.pow(o(1+1/n),2))}},{key:"skewness",value:function(t){var e=t.a,r=t.b,n=this.stdDev(t),a=this.mean(t);return(o(1+3/r)*Math.pow(e,3)-3*a*n*n-Math.pow(a,3))/Math.pow(n,3)}},{key:"kurtosis",value:function(t){var e=t.a,r=t.b,n=this.stdDev(t),a=this.mean(t),i=this.skewness(t);return(o(1+4/r)*Math.pow(e,4)-4*i*Math.pow(n,3)*a-6*Math.pow(a,2)*Math.pow(n,2)-Math.pow(a,4))/Math.pow(n,4)-3}}]),e}(x);G.covariates=1,G.discrete=!1;var W=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 m(t,2)/(t.length-1)}},{key:"sqrdMeanDev",value:function(t){return m(t,2)}},{key:"meanDev",value:function(t){return m(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,n=Math.pow(e,3),a=m(t,3);return r*a/((r-1)*(r-2)*n)}},{key:"kurtosis",value:function(t){var e=this.stdDev(t);if(isNaN(e)||t.length<3)return NaN;var r=(t.length,m(t,2)),n=m(t,4);return n/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,n){return(t.data[n]-t.mean)*(e.data[n]-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=n,t.gamma=o,t.gammainc_lower=i,t.lngamma=a,t.median=h,t.mean=s,t.mode=l,t.percentile=c,t.quantile=d,t.range=p,t.select=f,t.std=b,t.stirling=k,t.sum=u,t.sumNthPowerDev=m,t.variance=y,t.zscore=M,t.Normal=S,t.Binomial=T,t.Bernoulli=_,t.StudentsT=F,t.Gamma=A,t.ChiSquared=B,t.Exponential=R,t.Cauchy=P,t.Weibull=G,t.Sample=W,t.ttest=w}); | ||
!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,n=1;e>=n;n++)r*=t--,r/=n;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 n(t){return 0>t?NaN:0==t?1:t*n(t-1)}function a(t){if(0>t)return NaN;for(var e=C[0],r=C.length-1;r>0;--r)e+=C[r]/(t+r);var n=t+N+.5;return.5*Math.log(2*Math.PI)+(t+.5)*Math.log(n)-n+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(a(e));e-=1;for(var r=E[0],n=1;O+2>n;n++)r+=E[n]/(e+n);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,n=void 0,o=void 0;for(o=1,r=1,n=1;100>o&&(r+=n*=e/(t+o),!(j>n/r));++o);return Math.exp(t*Math.log(e)-e-a(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 n=r-e,a=t+n;return e=a-t-n,a},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),n=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]==n}).map(function(t){return Number(t)})}}();return"object"===("undefined"==typeof e?"undefined":g["typeof"](e))?e.v:void 0}function f(t,e,r,n){var a=t.slice(0);if(0==a.length||e>=a.length)return NaN;var o=r||0,i=n||a.length-1;if(o==i)return a[o];for(;i>o;){if(i-o>x){var u=i-o+1,s=e-o+1,l=Math.log(u),h=D*Math.exp(2*l/3),c=D*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));f(a,e,d,m)}var p=a[e],y=o,b=i;for(v(a,y,e),a[b]>p&&v(a,y,b);b>y;){for(v(a,y,b),y++,b--;a[y]<p;)y++;for(;a[b]>p;)b--}a[o]===p?v(a,o,b):(b++,v(a,b,i)),b>e?i=b-1:(o=b+1,i=b-1)}return a[e]}function v(t,e,r){var n=t[e];t[e]=t[r],t[r]=n}function h(t){var e=void 0;if(0==t.length)e=NaN;else{var r=t.length%2==0;r?(e=f(t,t.length/2),e+=f(t,t.length/2-1),e/=2):e=f(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),f(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 n=e[0];if(0==n)return t[0];if(1==n)return t[t.length-1];var a=t.length*n;return a%1?f(t,Math.floor(a)):t.length%2?f(t,a):(f(t,a-1)+f(t,a))/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 n=function(){var n=s(t);return{v:t.reduce(function(t,a){var o=a-n;return r&&(o=Math.abs(o)),t+Math.pow(o,e)},0)}}();return"object"===("undefined"==typeof n?"undefined":g["typeof"](n))?n.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 n=r||0,a=((t.size-1)*t.variance+(e.size-1)*e.variance)/(t.size+e.size-2);return(t.mean-e.mean-n)/Math.sqrt(a*(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 n=e[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,n.key,n)}}return function(e,r,n){return r&&t(e.prototype,r),n&&t(e,n),e}}(),g["extends"]=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var r=arguments[e];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(t[n]=r[n])}return t},g.get=function Y(t,e,r){null===t&&(t=Function.prototype);var n=Object.getOwnPropertyDescriptor(t,e);if(void 0===n){var a=Object.getPrototypeOf(t);return null===a?void 0:Y(a,e,r)}if("value"in n)return n.value;var o=n.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,D=.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 P=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),n=r.a,a=r.b,o=void 0;!o||.5==o;)o=g.get(Object.getPrototypeOf(e),"random",this).call(this);return n+a*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),n=r.a,a=r.b;return a/(Math.pow(t-n,2)+Math.pow(a,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),n=r.a,a=r.b;return Math.atan((t-n)/a)/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);P.covariates=1,P.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),n=r.mu,a=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 n+o*a}},{key:"pdf",value:function(t,e){if("number"!=typeof t)throw new Error("x must be a number.");var r=this.validate(e),n=r.mu,a=r.sigma;t/Math.abs(a);return 1/(Math.sqrt(2*Math.PI)*Math.abs(a))*Math.exp(-1*Math.pow(t-n,2)/(2*a*a))}},{key:"cdf",value:function(t,e){if("number"!=typeof t)throw new Error("x must be a number.");var n=this.validate(e),a=n.mu,o=n.sigma;return.5*(1+r((t-a)/(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,n=e.sigma;return n/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),n=r.mu;return-n*Math.log1p(-g.get(Object.getPrototypeOf(e),"random",this).call(this))}},{key:"pdf",value:function(t,e){var r=this.validate(e),n=r.mu;if("number"!=typeof t)throw new Error("x must be a number.");return 0>t?0:Math.exp(-t/n)/n}},{key:"cdf",value:function(t,e){var r=this.validate(e),n=r.mu;if("number"!=typeof t)throw new Error("x must be a number.");return 0>=t?0:1-Math.exp(-t/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*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),n=r.a,a=r.b;if(1>n){var o=g.get(Object.getPrototypeOf(e),"random",this).call(this);return this.random({a:1+n,b:a})*Math.pow(o,1/n)}for(var i=void 0,u=void 0,s=void 0,l=n-1/3,f=1/Math.sqrt(9*l);;){do i=S.random({mu:0,sigma:1}),u=1+f*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/a}},{key:"pdf",value:function(t,e){var r=this.validate(e),n=r.a,o=r.b;if("number"!=typeof t)throw new Error("x must be a number.");return 0>t?0:0==t?1==n?o:0:1==n?Math.exp(-t*o)*o:Math.exp((n-1)*Math.log(t*o)-t*o-a(n))*o}},{key:"cdf",value:function(t,e){var r=this.validate(e),n=r.a,a=r.b;if("number"!=typeof t)throw new Error("x must be a number.");return 0>=t?0:i(n,t*a)}},{key:"mean",value:function(t){var e=this.validate(t),r=e.a,n=e.b;return r/n}},{key:"variance",value:function(t){var e=this.validate(t),r=e.a,n=e.b;return r/(n*n)}},{key:"stdDev",value:function(t){var e=this.validate(t),r=e.a,n=e.b;return Math.sqrt(r/(n*n))}},{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=14,T=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,n=this.validate(t),a=n.n,o=n.p;if(0==a)return 0;var i=!1,u=0,s=void 0;o>.5?(i=!0,s=1-o):s=o;var l=1-s,f=s/l,v=a*s;if(I>v)for(var h=Math.pow(l,a),c=g.get(Object.getPrototypeOf(r),"random",this).call(this);a>=u&&c>=h;)c-=h,h*=f*(a-u)/(u+1),u++;else!function(){var t=v+s,n=Math.floor(t),o=n+.5,i=v*l,f=Math.floor(2.195*Math.sqrt(i)-4.6*l)+.5,h=o-f,c=o+f,d=.134+20.5/(15.3+n),m=f*(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 D(){if(E=g.get(Object.getPrototypeOf(r),"random",e).call(e)*N,j=g.get(Object.getPrototypeOf(r),"random",e).call(e),f>=E)u=Math.floor(o-f*j+E);else if(m>=E){var t=h+(E-f)/d;j=j*d+1-Math.abs(t-o)/f,j>1||0>=j?D():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,v=a-u-1,p=n+1,b=a+1-n;O=o*Math.log(p/i)+(a-n+.5)*Math.log(b/v)+(u-n)*Math.log(v*s/(i*l))+k(p)+k(b)-k(i)-k(v),C>O&&D()};x()}();return Math.floor(i?a-u:u)}},{key:"pdf",value:function(t,r){var n=this.validate(r),a=n.n,o=n.p;if("number"!=typeof t)throw new Error("k must be a number.");if(0>t||t>a)return 0;var i=void 0;if(0==o)i=0==t?1:0;else{if(1!=o){var u=e(a,t),s=Math.pow(o,t)*Math.pow(1-o,a-t);return"Infinity"==u?0==s?0:u:u*s}i=t==a?1:0}return i}},{key:"cdf",value:function(t,r){var n=this.validate(r),a=n.n,o=n.p;if("number"!=typeof t)throw new Error("k must be a number.");return 0>t?0:t>a?1:Array.apply(null,Array(Math.floor(t)+1)).map(function(t,r){return e(a,r)*Math.pow(o,r)*Math.pow(1-o,a-r)}).reduce(function(t,e){return t+e},0)}},{key:"mean",value:function(t){var e=this.validate(t),r=e.n,n=e.p;return r*n}},{key:"variance",value:function(t){var e=this.validate(t),r=e.n,n=e.p;return r*n*(1-n)}},{key:"stdDev",value:function(t){var e=this.validate(t),r=e.n,n=e.p;return Math.sqrt(r*n*(1-n))}},{key:"relStdDev",value:function(t){var e=this.validate(t),r=e.n,n=e.p;return Math.sqrt((1-n)/(r*n))}},{key:"skewness",value:function(t){var e=this.validate(t),r=e.n,n=e.p;return(1-2*n)/Math.sqrt(r*n*(1-n))}},{key:"kurtosis",value:function(t){var e=this.validate(t),r=e.n,n=e.p;return 3-6/r+1/(r*n*(1-n))}}]),r}(q);T.covariates=2,T.discrete=!0;var _=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,n=q.random();return r>n?1:0}},{key:"pdf",value:function(t,e){var r=this.validate(g["extends"]({},e,{n:1})),n=r.p;if("number"!=typeof t)throw new Error("k must be a number.");return 0==t?1-n:1==t?n:0}},{key:"cdf",value:function(t,e){var r=this.validate(g["extends"]({},e,{n:1})),n=r.p;if("number"!=typeof t)throw new Error("k must be a number.");return 1==t?n:0==t?1-n:NaN}}]),e}(T);_.covariates=1;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.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),n=r.df;if("number"!=typeof t)throw new TypeError("x must be a number");return 0>t?0:2==n?Math.exp(-t/2)/2:Math.exp((n/2-1)*Math.log(t/2)-t/2-a(n/2))/2}},{key:"cdf",value:function(t,e){var r=this.validate(e),n=r.df;if("number"!=typeof t)throw new TypeError("x must be a number");return 0>t?0:2==n?1-Math.exp(-t/2):i(n/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);B.covariates=1;var F=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 n=S.random({mu:0,sigma:1}),a=B.random({df:r});return n/Math.sqrt(a/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),n=r.df,o=a(n/2),i=a((n+1)/2);return Math.exp(i-o)/Math.sqrt(Math.PI*n)*Math.pow(1+t*t/n,-(n+1)/2)}},{key:"cdf",value:function(t,e){if("number"!=typeof t)throw TypeError("t must be a number.");var r=this.validate(e),n=r.df,a=void 0,o=void 0,i=void 0,u=void 0,s=void 0,l=void 0,f=void 0,v=void 0,h=void 0,c=void 0,d=1/Math.PI;if(i=n,a=t/Math.sqrt(i),o=i/(i+t*t),u=n-2,s=i%2,l=1,f=1,i=1,v=2+s,h=v,u>=2)for(c=v;u>=c;c+=2)f=f*o*(h-1)/h,l+=f,i=l,h+=2;return 1!=s?.5+.5*a*Math.sqrt(o)*l:(1==n&&(l=0),.5+(a*o*l+Math.atan(a))*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);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.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),n=r.a,a=r.b;return n*Math.pow(-Math.log(g.get(Object.getPrototypeOf(e),"random",this).call(this)),1/a)}},{key:"pdf",value:function(t,e){if("number"!=typeof t)throw new TypeError("x must be a number");var r=this.validate(e),n=r.a,a=r.b;return 0>t?0:a/n*Math.pow(t/n,a-1)*Math.exp(-Math.pow(t/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),n=r.a,a=r.b;return 0>t?0:1-Math.exp(-Math.pow(t/n,a))}},{key:"mean",value:function(t){var e=this.validate(t),r=e.a,n=e.b;return r*o(1+1/n)}},{key:"variance",value:function(t){var e=this.validate(t),r=e.a,n=e.b;return r*r*(o(1+2/n)-Math.pow(o(1+1/n),2))}},{key:"skewness",value:function(t){var e=t.a,r=t.b,n=this.stdDev(t),a=this.mean(t);return(o(1+3/r)*Math.pow(e,3)-3*a*n*n-Math.pow(a,3))/Math.pow(n,3)}},{key:"kurtosis",value:function(t){var e=t.a,r=t.b,n=this.stdDev(t),a=this.mean(t),i=this.skewness(t);return(o(1+4/r)*Math.pow(e,4)-4*i*Math.pow(n,3)*a-6*Math.pow(a,2)*Math.pow(n,2)-Math.pow(a,4))/Math.pow(n,4)-3}}]),e}(q);G.covariates=1,G.discrete=!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.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),n=r.a,a=r.b;return n+g.get(Object.getPrototypeOf(e),"random",this).call(this)*(a-n)}},{key:"pdf",value:function(t,e){if("number"!=typeof t)throw new TypeError("x must be a number");var r=this.validate(e),n=r.a,a=r.b;return n>t||t>a?0:1/(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),n=r.a,a=r.b;return n>t?0:t>=a?1:(t-n)/(a-n)}},{key:"mean",value:function(t){var e=this.validate(t),r=e.a,n=e.b;return(r+n)/2}},{key:"variance",value:function(t){var e=this.validate(t),r=e.a,n=e.b;return Math.pow(n-r,2)/12}},{key:"skewness",value:function(t){return 0}},{key:"kurtosis",value:function(t){return-1.2}}]),e}(q);U.covariates=1,U.discrete=!1;var W=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,n=Math.pow(e,3),a=p(t,3);return r*a/((r-1)*(r-2)*n)}},{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)),n=p(t,4);return n/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,n){return(t.data[n]-t.mean)*(e.data[n]-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=n,t.gamma=o,t.gammainc_lower=i,t.lngamma=a,t.median=h,t.mean=s,t.mode=l,t.percentile=c,t.quantile=d,t.range=m,t.select=f,t.std=b,t.stirling=k,t.sum=u,t.sumNthPowerDev=p,t.variance=y,t.zscore=w,t.Normal=S,t.Binomial=T,t.Bernoulli=_,t.StudentsT=F,t.Gamma=A,t.ChiSquared=B,t.Exponential=R,t.Cauchy=P,t.Weibull=G,t.Uniform=U,t.Sample=W,t.ttest=M}); |
@@ -12,2 +12,3 @@ /* @flow */ | ||
import Weibull from './distributions/weibull'; | ||
import Uniform from './distributions/uniform'; | ||
@@ -26,2 +27,3 @@ | ||
Weibull, | ||
Uniform, | ||
}; |
@@ -17,3 +17,3 @@ /* @flow */ | ||
static mean(params: Object): number { return NaN; }; | ||
/** @private */npm | ||
/** @private */ | ||
static variance(params: Object): number { return NaN; }; | ||
@@ -20,0 +20,0 @@ /** @private */ |
@@ -5,3 +5,3 @@ { | ||
"author": "Jack Shira <jack@atg.io> (http://www.atg.io)", | ||
"version": "0.2.3", | ||
"version": "0.2.4", | ||
"license": "ISC", | ||
@@ -8,0 +8,0 @@ "repository" : { |
@@ -20,2 +20,3 @@ # Sampson.js | ||
- Weibull | ||
- Uniform | ||
@@ -22,0 +23,0 @@ #### Statistics |
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
321370
78
8129
56