# you mistype something #end from pylab import * import current as pc rc("figure", figsize=[8., 4.]) rc("figure.subplot", left=.08, top=.95, right=.95) seed(1000) Uniform_min = pc.construct(cdf=lambda self, q, a, b: (q - a) / (b - a), bnd=lambda self, a, b: (a, b)) Q = Uniform_min(a=0, b=1) #end Uniform = pc.construct(cdf=lambda self, q, a, b: (q - a) / (b - a), bnd=lambda self, a, b: (a, b), pdf=lambda self, q, a, b: 1. / (b - a), ppf=lambda self, u, a, b: u * (b - a) + a, mom=lambda self, k, a, b: (b**(k + 1) - a**(k + 1)) / (k + 1) / (b - a), ttr=lambda self, k, a, b: (0.5 * (a + b), n * n * (b - a)**2 / (16 * n * n - 4)), defaults=dict(a=0., b=1.), str=lambda self, a, b: "U(%s,%s)" % (a, b), doc="An uniform distribution on the interval [a,b]") Q = Uniform(a=0, b=2) #end
#end def val(self, G): if len(G.K) == 2: return G.K["par1"] + G.K["par2"] return self #end Addition = pc.construct(cdf=cdf, bnd=bnd, val=val, advance=True, defaults=dict(par1=0., par2=0.)) add = Addition(par1=U1, par2=U2) Q = pc.J(U1, add) #end subplot(121) R = Q.sample(1000) scatter(R[0], R[1], marker="s", color="k", alpha=.7) xlabel(r"$Q_0$") ylabel(r"$Q_1$") axis([0, 1, 0, 2]) title("Scatter")
# you mistype something #end from pylab import * import current as pc rc("figure", figsize=[8., 4.]) rc("figure.subplot", left=.09, top=.93, right=.95, wspace=.24) seed(1000) cdf = lambda self, q: e**q / (1 + e**q) bnd = lambda self: (-30, 30) Cauchy = pc.construct(cdf=cdf, bnd=bnd) Q = Cauchy() #end print Q.inv([0.1, 0.2, 0.3]) # [-2.19722267 -1.38626822 -0.84729574] print Q.pdf([-1, 0, 1]) # [ 0.19661217 0.25000002 0.19661273] print Q.sample(4) # [ 0.63485527 -2.04053293 2.95040998 -0.07126454] #end print Q.inv([0.1, 0.2, 0.3], tol=1e-3, maxiter=10) # [-2.19503823 -1.38626822 -0.8440303 ] print Q.pdf([-1, 0, 1], step=1e-1) # [ 0.20109076 0.24979187 0.20109076] #end subplot(121)
# you mistype something #end from pylab import * import current as pc rc("figure", figsize=[8.,4.]) rc("figure.subplot", left=.08, top=.95, right=.95) seed(1000) Uniform_min = pc.construct( cdf=lambda self,q,a,b: (q-a)/(b-a), bnd=lambda self,a,b: (a,b)) Q = Uniform_min(a=0,b=1) #end Uniform = pc.construct( cdf=lambda self,q,a,b: (q-a)/(b-a), bnd=lambda self,a,b: (a,b), pdf=lambda self,q,a,b: 1./(b-a), ppf=lambda self,u,a,b: u*(b-a)+a, mom=lambda self,k,a,b: (b**(k+1)-a**(k+1))/(k+1)/(b-a), ttr=lambda self,k,a,b: (0.5*(a+b),n*n*(b-a)**2/(16*n*n-4)), defaults=dict(a=0., b=1.), str=lambda self,a,b: "U(%s,%s)" % (a,b), doc="An uniform distribution on the interval [a,b]") Q = Uniform(a=0, b=2) #end
def pdf(self, x): out = 9/16.*(x+1)*(x<1/3.) out += 3/4.*(x>=1/3.) return out def cdf(self, x): out = 9/32.*(x+1)**2*(x<1/3.) out += (3*x+1)/4.*(x>=1/3.) return out def bnd(self): return -1,1 MyDist = pc.construct( pdf=pdf, cdf=cdf, bnd=bnd) #end dist = MyDist() print dist.mom(1, order=100) # 0.277778240534 #end print dist.mom(1, order=5, composite=1/3.) # 0.277777777778 #end mom = pc.momgen( order=100, domain=dist, composite=1/3.)
# you mistype something #end from pylab import * import current as pc rc("figure", figsize=[8.,4.]) rc("figure.subplot", left=.09, top=.93, right=.95, wspace=.24) seed(1000) cdf = lambda self, q: e**q/(1+e**q) bnd = lambda self: (-30,30) Cauchy = pc.construct(cdf=cdf, bnd=bnd) Q = Cauchy() #end print Q.inv([0.1, 0.2, 0.3]) # [-2.19722267 -1.38626822 -0.84729574] print Q.pdf([-1, 0, 1]) # [ 0.19661217 0.25000002 0.19661273] print Q.sample(4) # [ 0.63485527 -2.04053293 2.95040998 -0.07126454] #end print Q.inv([0.1, 0.2, 0.3], tol=1e-3, maxiter=10) # [-2.19503823 -1.38626822 -0.8440303 ] print Q.pdf([-1, 0, 1], step=1e-1) # [ 0.20109076 0.24979187 0.20109076] #end subplot(121)