-
Notifications
You must be signed in to change notification settings - Fork 7
/
ebisu.min.js
2 lines (2 loc) · 6.31 KB
/
ebisu.min.js
1
2
"use strict";var ebisu=(()=>{var q=Object.defineProperty;var ie=Object.getOwnPropertyDescriptor;var oe=Object.getOwnPropertyNames;var ae=Object.prototype.hasOwnProperty;var O=(n,e)=>()=>(e||n((e={exports:{}}).exports,e),e.exports),ue=(n,e)=>{for(var r in e)q(n,r,{get:e[r],enumerable:!0})},me=(n,e,r,t)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of oe(e))!ae.call(n,i)&&i!==r&&q(n,i,{get:()=>e[i],enumerable:!(t=ie(e,i))||t.enumerable});return n};var le=n=>me(q({},"__esModule",{value:!0}),n);var X=O((Ae,W)=>{"use strict";var T=2/(1+Math.sqrt(5));W.exports=fe;function fe(n,e,r,t,i,m){for(var u,l,a=0,o=r-T*(r-e),c=e+T*(r-e),h=n(o),s=n(c),f=n(e),x=n(r),b=e,N=r;++a<i&&Math.abs(r-e)>t;)s>h?(r=c,c=o,s=h,o=r-T*(r-e),h=n(o)):(e=o,o=c,h=s,c=e+T*(r-e),s=n(c));return u=.5*(r+e),l=.5*(h+s),m&&(m.iterations=a,m.argmin=u,m.minimum=l,m.converged=!0),isNaN(s)||isNaN(h)||a===i?(m&&(m.converged=!1),NaN):f<l?b:x<l?N:u}});var Z=O((Fe,Y)=>{"use strict";Y.exports=ce;function ce(n,e,r,t,i,m,u){var l,a,o,c,h,s,f;for(c=1,h=r,s=r,o=a=l=e(r);!f&&isFinite(t)&&!isNaN(t);)if(++c,f=!0,a<=o&&(o=a,h=Math.max(i,h-t),a=e(h),f=!1),l<=o&&(o=l,s=Math.min(m,s+t),l=e(s),f=!1),o=Math.min(o,a,l),(a===o&&h===i||l===o&&s===m)&&(f=!0),t*=c<4?2:Math.exp(c*.5),!isFinite(t))return n[0]=-1/0,n[1]=1/0,n;return n[0]=h,n[1]=s,n}});var z=O((_e,$)=>{"use strict";var se=X(),he=Z(),P=[0,0];$.exports=function(e,r,t){r=r||{};var i,m=r.tolerance===void 0?1e-8:r.tolerance,u=r.initialIncrement===void 0?1:r.initialIncrement,l=r.lowerBound===void 0?-1/0:r.lowerBound,a=r.upperBound===void 0?1/0:r.upperBound,o=r.maxIterations===void 0?100:r.maxIterations;if(t&&(t.iterations=0,t.argmin=NaN,t.minimum=1/0,t.converged=!1),isFinite(a)&&isFinite(l))P[0]=l,P[1]=a;else if(r.guess===void 0?l>-1/0?i=a<1/0?.5*(l+a):l:i=a<1/0?a:0:i=r.guess,he(P,e,i,u,l,a,o),isNaN(P[0])||isNaN(P[1]))return NaN;return se(e,P[0],P[1],m,o,t)}});var ee=O((Se,K)=>{var U=7,L=[.9999999999998099,676.5203681218851,-1259.1392167224028,771.3234287776531,-176.6150291621406,12.507343278686905,-.13857109526572012,9984369578019572e-21,15056327351493116e-23],de=607/128,J=[.9999999999999971,57.15623566586292,-59.59796035547549,14.136097974741746,-.4919138160976202,3399464998481189e-20,4652362892704858e-20,-9837447530487956e-20,.0001580887032249125,-.00021026444172410488,.00021743961811521265,-.0001643181065367639,8441822398385275e-20,-26190838401581408e-21,36899182659531625e-22];function k(n){if(n<0)return Number("0/0");for(var e=J[0],r=J.length-1;r>0;--r)e+=J[r]/(n+r);var t=n+de+.5;return .5*Math.log(2*Math.PI)+(n+.5)*Math.log(t)-t+Math.log(e)-Math.log(n)}K.exports=function n(e){if(e<.5)return Math.PI/(Math.sin(Math.PI*e)*n(1-e));if(e>100)return Math.exp(k(e));e-=1;for(var r=L[0],t=1;t<U+2;t++)r+=L[t]/(e+t);var i=e+U+.5;return Math.sqrt(2*Math.PI)*Math.pow(i,e+.5)*Math.exp(-i)*r};K.exports.log=k});var Ee={};ue(Ee,{customizeMath:()=>xe,defaultModel:()=>Ne,modelToPercentileDecay:()=>te,predictRecall:()=>Ie,rescaleHalflife:()=>Pe,updateRecall:()=>Be});var S=z();var H=ee(),E=H.log;var Me=Math.exp,ge=Math.log,be=Math.sign,ve=Math.max;function j(n,e){let r=ve(...n),t=0;for(let u=n.length-1;u>=0;u--)t+=e[u]*Me(n[u]-r);let i=be(t);return t*=i,[ge(t)+r,i]}var ne=new Map;function D(n){let e=ne.get(n);return e!==void 0||(e=E(n),ne.set(n,e)),e}function pe(n,e,r){return E(n)-E(n+r)+D(e+r)-D(e)}var B=(n,e)=>D(n)+D(e)-D(n+e),C=(n,e)=>E(n)+E(e)-E(n+e),F=(n,e)=>H(n)*H(e)/H(n+e);function we(n,e){return-B(1+n-e,1+e)-Math.log(n+1)}function xe(n){let e={betaln:B,betafn:F};return n.betaln&&(B=n.betaln),n.betafn&&(F=n.betafn),e}function re(n,e){var r=n*(1-n)/e-1,t=n*r,i=(1-n)*r;return[t,i]}function Ie(n,e,r=!1){let[t,i,m]=n,u=e/m,l=pe(t+u,t,i);return r?Math.exp(l):l}function Be(n,e,r,t,i,m=!0,u,{useLog:l=!1,tolerance:a=1e-8}={}){if(0>e||e>r||r<1)throw new Error("0 <= successes and successes <= total and 1 <= total must be true");if(r===1)return Q(n,e,t,i,m,u,{useLog:l,tolerance:a});if(!(e===Math.trunc(e)&&r===Math.trunc(r)))throw new Error("expecting integer successes and total");let[o,c,h]=n,s=t/h,f=r-e,x=[];for(let w=0;w<=f;w++)x.push(we(f,w));function b(w,M){let d=[];for(let g=0;g<=f;g++)d.push(x[g]+B(o+s*(e+g)+w*s*M,c));let v=[];for(let g=0;g<=f;g++)v.push(Math.pow(-1,g));return j(d,v)[0]}let N=b(0,0),I;if(m){let w=Math.log(.5),M=g=>b(1,g)-N-w,d={},v=S(g=>Math.abs(M(g)),{tolerance:a},d);if(!("converged"in d)||!d.converged)throw console.log(d),new Error("failed to converge: binomial");I=v,u=I*t}u||(u=h),I=u/t;let y=b(1,I)-N,A=Math.exp(y),p=Math.exp(b(2,I)-N);if(A<=0)throw new Error("negative mean encountered");if(p<=0)throw new Error("negative 2nd moment encountered");let _=Math.exp(2*y),G=p-_;if(G<=0)throw new Error("negative variance encountered");let[V,R]=re(A,G);return[V,R,u]}function Q(n,e,r,t,i=!0,m,{useLog:u=!1,tolerance:l=1e-8}={}){if(!(0<=e&&e<=1))throw new Error("expecting result between 0 and 1 inclusive");let[a,o,c]=n,h=e>.5,s=h?e:1-e;t===void 0&&(t=1-s);let f=r/c,[x,b]=h?[s-t,t]:[t-s,1-t],N=x*F(a+f,o)+b*(F(a,o)||0),I=u?j([C(a+f,o),C(a,o)||-1/0],[x,b])[0]:0;function y(M,d){let v=x*F(a+f+M*f*d,o);return b!==0&&(v+=b*F(a+M*f*d,o)),v/N}function A(M,d){return b!==0?j([C(a+f+M*f*d,o),C(a+M*f*d,o)],[x,b])[0]-I:Math.log(x)+C(a+f+M*f*d,o)-I}let p;if(i){let M={},d;if(u){let v=Math.log(.5);d=S(g=>Math.abs(A(1,g)-v),{lowerBound:0,tolerance:l},M)}else d=S(v=>Math.abs(y(1,v)-.5),{lowerBound:0},M);if(!("converged"in M)||!M.converged){if(!u)return Q(n,e,r,t,i,m,{tolerance:l,useLog:!u});throw console.error(M,{prior:n,result:e,tnow:r,q0:t,rebalance:i,tback:m}),new Error("failed to converge")}p=d,m=p*r}else m||(m=c),p=m/r;let _=u?Math.exp(A(1,p)):y(1,p),V=(u?Math.exp(A(2,p)):y(2,p))-_*_,[R,w]=re(_,V);if(!(R>0&&w>0&&isFinite(R)&&isFinite(w))){if(!u)return Q(n,e,r,t,i,m,{tolerance:l,useLog:!u});throw new Error("newAlpha and newBeta must be finite and greater than zero")}return[R,w,m]}function Ne(n,e=4,r=e){return[e,r,n]}function te(n,e=.5,r=1e-4){if(e<0||e>1)throw new Error("percentiles must be between (0, 1) exclusive");let[t,i,m]=n,u=B(t,i),l=Math.log(e);function a(h){let s=B(t+h,i)-u;return Math.abs(s-l)}let o={},c=S(a,{lowerBound:0,tolerance:r},o);if(!("converged"in o)||!o.converged)throw new Error("failed to converge");return c*m}function Pe(n,e=1){let[r,t,i]=n,m=te(n),u=m/i,l=B(r,t),a=B(r+2*u,t)-l,c=1/(8*Math.exp(a)-2)-.5;if(c<=0)throw new Error("non-positive alpha, beta encountered");return[c,c,m*e]}return le(Ee);})();
//# sourceMappingURL=ebisu.min.js.map