コード例 #1
0
ファイル: impMC.py プロジェクト: WayneYann/UQ-1
def WritePlotfile(samples, ndim, outFilePrefix, nwalkers, step, nSteps,
                  nDigits, rstate):

    if nDigits > 0:
        fmt = "%0" + str(nDigits) + "d"
        lastStep = step + nSteps - 1
        filename = outFilePrefix + '_' + (fmt % step) + '_' + (fmt % lastStep)
    else:
        filename = outFilePrefix

    if rank == 0:

        print('Writing plotfile: ' + filename)

        C_array_size = nSteps * ndim * nwalkers
        x_for_c = pymc.DoubleVec(C_array_size)

        for walker in range(0, nwalkers):
            for it in range(0, nSteps):
                for dim in range(0, ndim):
                    index = walker + nwalkers * it + nwalkers * nSteps * dim
                    x_for_c[index] = samples[dim, step + it]

        if rstate == None:
            rstateString = ''
        else:
            rstateString = cPickle.dumps(rstate)

        pf = pymc.UqPlotfile(x_for_c, ndim, nwalkers, step, nSteps,
                             rstateString)
        pf.Write(filename)
コード例 #2
0
def WritePlotfile(driver, outFilePrefix, nwalkers, step, nSteps, nDigits,
                  rstate):

    fmt = "%0" + str(nDigits) + "d"
    lastStep = step + nSteps - 1
    filename = outFilePrefix + '_' + (fmt % step) + '_' + (fmt % lastStep)

    if rank == 0:
        print('Writing plotfile: ' + filename)

    x = driver.sampler.chain

    ndim = driver.NumParams()
    C_array_size = nSteps * ndim * nwalkers
    x_for_c = pymc.DoubleVec(C_array_size)

    for walker in range(0, nwalkers):
        for it in range(0, nSteps):
            for dim in range(0, ndim):
                index = walker + nwalkers * it + nwalkers * nSteps * dim
                x_for_c[index] = x[walker, it, dim]

    if rstate == None:
        rstateString = ''
    else:
        rstateString = cPickle.dumps(rstate)

    pf = pymc.UqPlotfile(x_for_c, ndim, nwalkers, step, nSteps, rstateString)
    pf.Write(filename)
コード例 #3
0
ファイル: combinePlt.py プロジェクト: WayneYann/UQ-1
def WritePlotfile(x, filename, ndim, nwalkers, step, nSteps, rstate):

    print('Writing plotfile: ' + filename)

    C_array_size = nSteps * ndim * nwalkers
    x_for_c = pymc.DoubleVec(C_array_size)

    for walker in range(0, nwalkers):
        for it in range(0, nSteps):
            for dim in range(0, ndim):
                index = walker + nwalkers * it + nwalkers * nSteps * dim
                x_for_c[index] = x[walker, it, dim]

    if rstate == None:
        rstateString = ''
    else:
        rstateString = cPickle.dumps(rstate)

    pf = pymc.UqPlotfile(x_for_c, ndim, nwalkers, step, nSteps, rstateString)
    pf.Write(filename)
コード例 #4
0
def WritePlotfile(x, ndim, outFilePrefix, nwalkers, step, nSteps, nDigits,
                  rstate):

    fmt = "%0" + str(nDigits) + "d"
    lastStep = step + nSteps - 1
    filename = outFilePrefix + '_' + (fmt % step) + '_' + (fmt % lastStep)

    C_array_size = nSteps * ndim * nwalkers
    x_for_c = pymc.DoubleVec(C_array_size)

    for walker in range(0, nwalkers):
        for it in range(0, nSteps):
            for dim in range(0, ndim):
                index = walker + nwalkers * it + nwalkers * nSteps * dim
                x_for_c[index] = x[walker, it, dim]

    if rstate is None:
        rstateString = ''
    else:
        rstateString = cPickle.dumps(rstate)

    pf = pymc.UqPlotfile(x_for_c, ndim, nwalkers, step, nSteps, rstateString)
    pf.Write(filename)
コード例 #5
0
ファイル: convertTextSamples.py プロジェクト: WayneYann/UQ-1
    nwalkers = 1
    rstateString = ''
    step = 0
    pf = pymc.UqPlotfile(x, np, nwalkers, step, nSteps, rstateString)
    print 'writing ', filename, nSteps
    pf.Write(filename)


sampleFile = sys.argv[1]
f = open(sampleFile)
ll = f.readlines()
N = 0
x = []
for L in ll:
    t = string.split(string.strip(L))
    if N == 0:
        N = len(t)
    if len(t) != N:
        print 'Input has a line with different number of args than in the first line'
        exit()
    x.append(t)

xd = pymc.DoubleVec(len(x) * N)
for i in range(len(x)):
    for j in range(N):
        idx = j * len(x) + i
        xd[idx] = float(x[i][j])

outfile = sys.argv[2]
WritePlotfile(xd, N, outfile)