Пример #1
0
def _remote_bin_iter(iiter, n_iter, dsspec, wt_dsspec, initpoint, binbounds,
                     ignore_out_of_range):

    iter_hist_shape = tuple(len(bounds) - 1 for bounds in binbounds)
    iter_hist = numpy.zeros(iter_hist_shape, dtype=numpy.float64)

    dset = dsspec.get_iter_data(n_iter)
    if dset is None:
        return iiter, n_iter, iter_hist
    else:
        npts = dset.shape[1]
    weights = wt_dsspec.get_iter_data(n_iter)[:, 0, 0]

    #dset = dset[:,initpoint:,:]
    for ipt in range(npts - initpoint):
        histnd(dset[:, ipt, :],
               binbounds,
               weights,
               out=iter_hist,
               binbound_check=False,
               ignore_out_of_range=ignore_out_of_range)

    del weights, dset

    # normalize histogram
    normhistnd(iter_hist, binbounds)
    return iiter, n_iter, iter_hist
Пример #2
0
def _test_uint(npts=1024 * 1024, ndim=3, loops=3):
    from time import time

    mine_times = [None] * loops
    theirs_times = [None] * loops

    binbounds = [[0, 1, 2, 3, 4] for x in range(ndim)]
    # weights = numpy.random.rand(npts)
    weights = numpy.ones((npts,), dtype=numpy.float64)
    print('binbounds: {}'.format(binbounds))
    print('weights')
    print(weights)
    for n in range(loops):
        testdat = numpy.require(numpy.random.randint(0, 4, size=(npts, ndim)), numpy.uint16)
        print('test data')
        print(testdat)
        mstart = time()
        mine = histnd(testdat, binbounds, weights=weights)
        mstop = time()
        tstart = time()
        theirs = numpy.histogramdd(testdat, binbounds, weights=weights)[0]
        tstop = time()
        mine_times[n] = mstop - mstart
        theirs_times[n] = tstop - tstart
        print(mine)
        print(theirs)
        errsum = numpy.abs(mine - theirs).sum()
        errsum_per_item = errsum / npts
        rel_err = errsum / numpy.abs(weights).sum()
        print('sum of the absolute errors: {} ({} relative, {} per entry)'.format(errsum, rel_err, errsum_per_item))

    print('mine, best of {}:   {}'.format(loops, min(mine_times)))
    print('theirs, best of {}: {}'.format(loops, min(theirs_times)))
Пример #3
0
def _test_double(npts=1024 * 1024, loops=3):
    from time import time

    mine_times = [None] * loops
    theirs_times = [None] * loops

    # though 1.0 should be sufficient, weirdness in the boundary conditions
    # for numpy.digitize appears to introduce a discrepancy, so throw something
    # greater than 1.0 in for good measure
    binbounds = [[0, 0.5, 1, 1.1] for x in range(3)]
    weights = numpy.random.rand(npts)
    # weights = numpy.ones((npts,), dtype=numpy.float64)
    for n in range(loops):
        testdat = numpy.random.rand(npts, 3)
        mstart = time()
        mine = histnd(testdat, binbounds, weights=weights)
        mstop = time()
        tstart = time()
        theirs = numpy.histogramdd(testdat, binbounds, weights=weights)[0]
        tstop = time()
        mine_times[n] = mstop - mstart
        theirs_times[n] = tstop - tstart
        print(mine)
        print(theirs)
        errsum = numpy.abs(mine - theirs).sum()
        errsum_per_item = errsum / npts
        rel_err = errsum / numpy.abs(weights).sum()
        print('sum of the absolute errors: {} ({} relative, {} per entry)'.format(errsum, rel_err, errsum_per_item))

    print('mine, best of {}:   {}'.format(loops, min(mine_times)))
    print('theirs, best of {}: {}'.format(loops, min(theirs_times)))
Пример #4
0
def _remote_bin_iter(iiter, n_iter, dsspec, wt_dsspec, initpoint, binbounds, ignore_out_of_range):

    iter_hist_shape = tuple(len(bounds)-1 for bounds in binbounds)
    iter_hist = numpy.zeros(iter_hist_shape, dtype=numpy.float64)

    dset = dsspec.get_iter_data(n_iter)
    npts = dset.shape[1]
    weights = wt_dsspec.get_iter_data(n_iter)

    dset = dset[:,initpoint:,:]
    for ipt in xrange(npts-initpoint):
        histnd(dset[:,ipt,:], binbounds, weights, out=iter_hist, binbound_check = False, ignore_out_of_range=ignore_out_of_range)

    del weights, dset

    # normalize histogram
    normhistnd(iter_hist,binbounds)
    return iiter, n_iter, iter_hist
Пример #5
0
        n_segs = phis.shape[0]

        # stack the phi, psi, and Ntwid (or N) vals for each seg into single array
        vals = np.array([phis, psis, nregs]).T
        assert vals.shape == (n_segs, 3)

        denom = np.dot(phi_vals[:, np.newaxis], ntwids[np.newaxis, :])
        assert denom.shape == (n_windows, n_segs)

        denom -= free_energies[:, np.newaxis]
        denom = np.exp(-denom)
        denom *= n_tots[:, np.newaxis]
        denom = np.sum(denom, axis=0)

        histnd(vals, binbounds, n_segs * weights / denom, out=hist, binbound_check=False)

for dm in data_managers:
    dm.close_backing()

# normalize the f****r
normhistnd(hist, binbounds)

phi_binctrs = phi_binbounds[:-1] + np.diff(phi_binbounds) / 2.0
psi_binctrs = psi_binbounds[:-1] + np.diff(psi_binbounds) / 2.0

vmin, vmax = 0, 10
norm = matplotlib.colors.Normalize(vmin=vmin, vmax=vmax)
extent = (phi_binbounds[0], phi_binbounds[-1], psi_binbounds[0], psi_binbounds[-1])

min_energy = 20.0