Esempio n. 1
0
    def test_plot_prob_bounded_coal(self):
        n = 1000
        k = 4
        t = 800
        alltimes = []

        # sample times
        for i in xrange(5000):
            while True:
                times = [0]
                for j in xrange(k, 1, -1):
                    times.append(times[-1] + coal.sample_coal(j, n))
                    if times[-1] >= t:
                        break
                if times[-1] < t:
                    break
            alltimes.append(times)

        p = Gnuplot()
        for i in range(1, 2):
            x, y = distrib([q[i] - q[i-1] for q in alltimes], width=20)
            p.plot(x, y, style="lines", xmax=500)

        x = list(frange(0, 500, 10))
        #for i in range(1, 2): #k):
        y2 = [coal.prob_bounded_coal(j, k, n, t) for j in x]
        p.plot(x, y2, style="lines", xmax=500)

        fequals(y, y2, rel=.05, eabs=.01)
Esempio n. 2
0
def plotdistrib(array, ndivs=None, low=None, width=None, **options):
    """Plot a distribution of array"""
    from rasmus import util
    d = util.distrib(array, ndivs, low, width)
    p = options.setdefault("plot", Gnuplot())
    options.setdefault("style", "boxes")
    
    p.plot(util.histbins(d[0]), d[1], **options)
    return p
Esempio n. 3
0
    def test_fast_sample_bounded_coal(self):

        # sample bounded coal times efficiently
        n = 1000
        k = 5
        t = 500
        alltimes = []

        # sample times
        for i in xrange(5000):
            while True:
                times = [0]
                for j in xrange(k, 1, -1):
                    times.append(times[-1] + coal.sample_coal(j, n))
                    if times[-1] >= t:
                        break
                if times[-1] < t:
                    break
            alltimes.append(times)

        p = Gnuplot()
        for i in range(1, k):
            x, y = distrib([q[i] - q[i-1] for q in alltimes], width=30)
            p.plot(x, y, style="lines", xmax=500)
        p.enableOutput(True)
        p.replot()

        # sample times efficently
        alltimes2 = []
        for i in xrange(5000):
            times = [0]
            for j in xrange(k, 1, -1):
                times.append(times[-1] +
                             coal.sample_bounded_coal(j, n, t-times[-1]))
            alltimes2.append(times)

        #p = Gnuplot()
        for i in range(1, k):
            x, y = distrib([q[i] - q[i-1] for q in alltimes2], width=30)
            p.plot(x, y, style="lines", xmax=500)
        p.enableOutput(True)
        p.replot()
Esempio n. 4
0
def plotdistribFit(func,
                   paramsInit,
                   data,
                   start,
                   end,
                   step,
                   plot=None,
                   **options):
    xdata, ydata = util.distrib(data, low=start, width=step)
    return plotfuncFit(func, paramsInit, xdata, ydata, start, end, step / 10,
                       plot, **options)
Esempio n. 5
0
def fitDistrib(func, paramsInit, data, start, end, step, perc=1.0):
    xdata, ydata = util.distrib(data, low=start, width=step)
    ydata = [i / perc for i in ydata]
    xdata = util.histbins(xdata)
    params, resid = fitCurve(xdata, ydata, func, paramsInit)
    return params, resid
Esempio n. 6
0
def plotdistribFit(func, paramsInit, data, start, end, step, plot = None,
                   **options):
    xdata, ydata = util.distrib(data, low=start, width=step)
    return plotfuncFit(func, paramsInit, xdata, ydata, start, end, step/10, plot,
                       **options)
Esempio n. 7
0
def fitDistrib(func, paramsInit, data, start, end, step, perc=1.0):
    xdata, ydata = util.distrib(data, low=start, width=step)
    ydata = [i / perc for i in ydata]
    xdata = util.histbins(xdata)
    params, resid = fitCurve(xdata, ydata, func, paramsInit)
    return params, resid