Exemplo n.º 1
0
def run_trials():
    numTrials = 3000
    gens = 1000
    from multiprocessing.pool import ThreadPool as Pool
    pool = Pool(50)

    jids = pool.map(f,[gens]*numTrials)
    print "Done spawning trials. Retrieving results..."

    results = pool.map(cloud_result, jids)
    firstLocusFreqsHists = zeros((numTrials,gens+1), dtype='float')
    lastLocusFreqsHists = zeros((numTrials,gens+1), dtype='float')
    print "Done retrieving results. Press Enter to serialize..."

    raw_input()

    for i, result in enumerate(results):
        firstLocusFreqsHists[i, :], lastLocusFreqsHists[i, :] = result

    with closing(FileStorage("soda_results.durus")) as durus:
        conn = Connection(durus)
        conn.get_root()[str(int(floor(time.time())))] = (firstLocusFreqsHists, lastLocusFreqsHists)
        conn.commit()

    pool.close()
    pool.join()
Exemplo n.º 2
0
def run_trials():
    numTrials = 3000
    gens = 1000
    from multiprocessing.pool import ThreadPool as Pool
    pool = Pool(50)

    jids = pool.map(f, [gens] * numTrials)
    print "Done spawning trials. Retrieving results..."

    results = pool.map(cloud_result, jids)
    firstLocusFreqsHists = zeros((numTrials, gens + 1), dtype='float')
    lastLocusFreqsHists = zeros((numTrials, gens + 1), dtype='float')
    print "Done retrieving results. Press Enter to serialize..."

    raw_input()

    for i, result in enumerate(results):
        firstLocusFreqsHists[i, :], lastLocusFreqsHists[i, :] = result

    with closing(FileStorage("soda_results.durus")) as durus:
        conn = Connection(durus)
        conn.get_root()[str(int(floor(time.time())))] = (firstLocusFreqsHists,
                                                         lastLocusFreqsHists)
        conn.commit()

    pool.close()
    pool.join()
Exemplo n.º 3
0
def neap_uga(m,
             n,
             gens,
             probMutation,
             effectiveAttrIndices,
             probMisclassification,
             bitFreqVisualizer=None):
    """ neap = "noisy effective attribute parity"
    """
    pop = rand(m, n) < 0.5
    bitFreqHist = zeros((n, gens + 1))
    for t in range(gens + 1):

        print "Generation %s" % t

        bitFreqs = pop.astype('float').sum(axis=0) / m
        bitFreqHist[:, t] = transpose(bitFreqs)

        if bitFreqVisualizer:
            bitFreqVisualizer(bitFreqs, t)

        fitnessVals = mod(
            pop[:, effectiveAttrIndices].astype('byte').sum(axis=1) +
            (rand(m) < probMisclassification).astype('byte'), 2)
        totalFitness = sum(fitnessVals)
        cumNormFitnessVals = cumsum(fitnessVals).astype('float') / totalFitness

        parentIndices = zeros(2 * m, dtype='int16')
        markers = sort(rand(2 * m))
        ctr = 0
        for idx in xrange(2 * m):
            while markers[idx] > cumNormFitnessVals[ctr]:
                ctr += 1
            parentIndices[idx] = ctr
        shuffle(parentIndices)

        crossoverMasks = rand(m, n) < 0.5
        newPop = zeros((m, n), dtype='bool')
        newPop[crossoverMasks] = pop[parentIndices[:m], :][crossoverMasks]
        newPop[logical_not(crossoverMasks)] = pop[parentIndices[m:], :][
            logical_not(crossoverMasks)]

        mutationMasks = rand(m, n) < probMutation
        pop = logical_xor(newPop, mutationMasks)

    return bitFreqHist[0, :], bitFreqHist[-1, :]
Exemplo n.º 4
0
def neap_uga(m, n, gens, probMutation, effectiveAttrIndices, probMisclassification, bitFreqVisualizer=None):
    """ neap = "noisy effective attribute parity"
    """
    pop = rand(m,n)<0.5
    bitFreqHist= zeros((n,gens+1))
    for t in range(gens+1):

        print "Generation %s" % t

        bitFreqs = pop.astype('float').sum(axis=0)/m
        bitFreqHist[:,t] = transpose(bitFreqs)

        if bitFreqVisualizer:
            bitFreqVisualizer(bitFreqs,t)

        fitnessVals = mod(pop[:, effectiveAttrIndices].astype('byte').sum(axis=1) +
                          (rand(m) < probMisclassification).astype('byte'),2)
        totalFitness = sum (fitnessVals)
        cumNormFitnessVals = cumsum(fitnessVals).astype('float')/totalFitness

        parentIndices = zeros(2*m, dtype='int16')
        markers = sort(rand(2*m))
        ctr = 0
        for idx in xrange(2*m):
            while markers[idx]>cumNormFitnessVals[ctr]:
                ctr += 1
            parentIndices[idx] = ctr
        shuffle(parentIndices)

        crossoverMasks = rand(m, n) < 0.5
        newPop = zeros((m, n), dtype='bool')
        newPop[crossoverMasks] = pop[parentIndices[:m], :][crossoverMasks]
        newPop[logical_not(crossoverMasks)] = pop[parentIndices[m:], :][logical_not(crossoverMasks)]

        mutationMasks = rand(m, n)<probMutation
        pop = logical_xor(newPop,mutationMasks)

    return bitFreqHist[0, :], bitFreqHist[-1, :]