def fan_wrapper(fold='None', n=10, dens=.2, sst=.9):
    scipy.random.seed()
    msl_time = None
    sat_time = None
    s = None
    c = None
    k = bfutils.dens2edgenum(dens, n=nodes)
    output = {}
    while True:
        try:
            output['gt'] = gk.ringmore(n, k)
            gdens = traversal.density(output['gt'])
            gu = bfutils.increment(output['gt'])
            output['transition'] = lm.transitionMatrix4(output['gt'],
                                                        minstrength=.9)
            if estimate_gu:
                data = lm.drawsamplesLG(output['transition'],
                                        nstd=np.double(NOISE_STD),
                                        samples=BURNIN + NSAMPLES * URATE)
                data = data[:, BURNIN:]
                if np.max(data) > 1000.:
                    raise NameError()
                gu_est, gu_time = gu_estimate(data[:, ::URATE], ALG)
            else:
                gu_est = None
                gu_time = None
            if estimate_g1:
                try:
                    s, msl_time = msl_caller(gu_est)
                except TimeoutError:
                    s = None
                    msl_time = None
                try:
                    c, sat_time = sat_caller(gu_est, fold)
                except TimeoutError:
                    c = None
                    sat_time = None
                if msl_time is not None:
                    print "msl: {:2}: {:8} : {:4}  {:10} seconds".\
                        format(fold, round(sst,3), len(s),
                           round(msl_time/1000.,3))
                if sat_time is not None:
                    print "sat: {:2}: {:8} : {:4}  {:10} seconds".\
                        format(fold, round(sst,3), len(c),
                           round(sat_time/1000.,3))
            else:
                s = None
                c = None
                msl_time = None
                sat_time = None
            output['gu'] = {'est': gu_est, 'truth': gu, 'ms': gu_time}
            output['MSL'] = {'eq': s, 'ms': msl_time}
            output['SAT'] = {'eq': c, 'ms': sat_time}
        except MemoryError:
            print 'memory error... retrying'
            continue
        break
    return output
def fan_wrapper(fold='None', n=10, dens=.2, sst=.9, card=2):
    scipy.random.seed()
    msl_time = None
    sat_time = None
    s = None
    c = None
    k = bfutils.dens2edgenum(dens, n=nodes)
    output = {}
    while True:
        try:
            output['gt'] = gk.ringmore(n, k)
            gdens = traversal.density(output['gt'])
            gu = bfutils.increment(output['gt'])
            if estimate_gu:
                data = dg.ConstructDynBN(output['gt'], [card] * n, sst,
                                         BURNIN + NSAMPLES * URATE)
                data = data[:, BURNIN:]
                gu_est, gu_time = gu_estimate(data[:, ::URATE], ALG)
            else:
                gu_est = None
                gu_time = None
            if estimate_g1:
                try:
                    s, msl_time = msl_caller(gu_est)
                except TimeoutError:
                    s = None
                    msl_time = None
                try:
                    c, sat_time = sat_caller(gu_est, fold)
                except TimeoutError:
                    c = None
                    sat_time = None
                if msl_time is not None:
                    print "msl: {:2}: {:8} : {:4}  {:10} seconds".\
                        format(fold, round(sst,3), len(s),
                           round(msl_time/1000.,3))
                if sat_time is not None:
                    print "sat: {:2}: {:8} : {:4}  {:10} seconds".\
                        format(fold, round(sst,3), len(c),
                           round(sat_time/1000.,3))
            else:
                s = None
                c = None
                msl_time = None
                sat_time = None
            output['gu'] = {'est': gu_est, 'truth': gu, 'ms': gu_time}
            output['MSL'] = {'eq': s, 'ms': msl_time}
            output['SAT'] = {'eq': c, 'ms': sat_time}
        except MemoryError:
            print 'memory error... retrying'
            continue
        break
    return output
示例#3
0
def getAring(n, density=0.1, st=0.5, verbose=True, dist='flatsigned'):
    keeptrying = True
    plusedges = bfutils.dens2edgenum(density, n)
    while keeptrying:
        G = gk.ringmore(n, plusedges)
        try:
            A = transitionMatrix4(G, minstrength=st, distribution=dist)
            try:
                s = A.shape
                keeptrying = False
            except AttributeError:
                keeptrying = True
        except ValueError:
            if verbose:
                print "!!! Unable to find strong links for a stable matrix !!!"
                print "*** trying a different graph"
    return {'graph':      G,
            'transition': A,
            'converges':  len(bfutils.call_undersamples(G))}
示例#4
0
    densities = {6: [0.2, 0.25, 0.3, 0.35],
                 8: [0.3],
                 10: [0.1],  # 0.15, 0.2, 0.25, 0.3],
                 15: [0.25, 0.3],
                 20: [0.1],  # 0.15, 0.2, 0.25, 0.3],
                 25: [0.1],
                 30: [0.1],
                 35: [0.1],
                 40: [0.1],
                 50: [0.05, 0.1],
                 60: [0.05, 0.1]}

    for nodes in [15]:
        z = {}
        pool = Pool(processes=PNUM)
        for dens in densities[nodes]:
            print "{:2}: {:8} : {:10}  {:10}".format('id', 'density', 'eq class', 'time')
            e = bfutils.dens2edgenum(dens, n=nodes)
            eqclasses = pool.map(functools.partial(fan_wrapper, n=nodes, k=e),
                                 range(REPEATS))
            z[dens] = eqclasses
            zkl.save(z[dens],
                     socket.gethostname().split('.')[0] +
                     '_nodes_' + str(nodes) + '_density_' + str(dens) + '_newp_.zkl')
            print ''
            print '----'
            print ''
        pool.close()
        pool.join()
        zkl.save(z, socket.gethostname().split('.')[0] + '_nodes_' + str(nodes) + '_newp_.zkl')