示例#1
0
    def _test_invgamma_pdf(self):
        """Test inverse gamma PDF/CDF functions"""

        prep_dir("test/output/train-invgamma-pdf/")
        
        #a = 23.0
        #b = 53.0
        a = 3
        b = .5
        n = 10000

        data = [1 / random.gammavariate(a, 1.0/b) for i in xrange(n)]

        x, y = distrib(data, 200)
        y2 = [spidir.invgamma(i, a, b) for i in x]
        
        rplot_start("test/output/train-invgamma-pdf/invgamma-pdf.pdf")
        rplot("plot", x, y, t="l")
        rp.lines(x, y2, t="l", col="red")
        rplot_end(True)


        x, y = cdf(data)
        y2 = [spidir.invgammaCdf(i, a, b) for i in x]

        rplot_start("test/output/train-invgamma-pdf/invgamma-cdf.pdf")
        rplot("plot", x, y, t="l")
        rp.lines(x, y2, t="l", col="red")
        rplot_end(True)


        s = 2
        x = list(frange(0, 10, .1))
        y = [spidir.incompleteGammaC(s, i) for i in x]

        rplot_start("test/output/train-invgamma-pdf/incompletegammac.pdf")
        rplot("plot", x, y, t="l")
        #rp.lines(x, y2, t="l", col="red")
        rplot_end(True)
示例#2
0
    def _test_invgamma(self):
        """Test inverse gamma quantile function"""
        a = 2
        b = 3 #34

        x = list(frange(.001, 5, .01))
        y = [invgammaPdf(i, (a, b)) for i in x]
        y2 = [spidir.invgamma(i, a, b) for i in x]
        y3 = [spidir.invgammaCdf(i, a, b) for i in x]
        y4 = [spidir.quantInvgamma(i, a, b) for i in x]

        #print spidir.quantInvgamma(.5, a, b)
        #print spidir.gammaDerivA(145.166061, 1.000000, 1.000000), \
        #      spidir.gammaPdf(145.166061, 1.000000, 1.000000), \
        #      spidir.gammalog(145.166061, 1.000000, 1.000000)

        prep_dir("test/output/train-invgamma/")

        rplot_start("test/output/train-invgamma/invgamma.pdf")
        rplot("plot", x, y, t="l") #, ylim=[min(x), max(x)])
        rp.lines(x, y2, t="l", col="red")
        rp.lines(x, y3, t="l", col="blue")
        rp.lines(y4, x, t="l", col="green") # show overlay CDF
        rplot_end(True)