def rw_experiment_with_op(basedir, space, n, op):
    """Proportion of unique individuals in a random walk: run many walks
     and calculate the proportion of unique individuals
     encountered. use a rw of length equal to sqrt of size of space.
     expect many duplicates even with explorative operators, but many
     more with exploitative ones

    """

    if space == "tree":
        raise NotImplementedError
    if space == "permutation":
        N = tsp.count_permutations(n)
    elif space == "bitstring":
        N = 2**n
    walklen = int(math.ceil(math.sqrt(N)))
    print "walklen", walklen
    results = []
    reps = 30
    for rep in range(reps):
        if space == "permutation":
            samples = walk_permutation(n, op, walklen)
        elif space == "bitstring":
            samples = walk_bitstring(n, op, walklen)
        elif space == "tree":
            raise NotImplementedError()

        x = float(len(set(samples))) / len(samples)
        results.append(x)
    return results
Example #2
0
def rw_experiment_with_op(n, op):
    """Proportion of unique individuals in a random walk: run many walks
     and calculate the proportion of unique individuals
     encountered. use a rw of length equal to sqrt of size of space.
     expect many duplicates even with explorative operators, but many
     more with exploitative ones

    """
    N = tsp.count_permutations(n)
    walklen = int(math.ceil(math.sqrt(N)))
    print "walklen", walklen
    results = []
    reps = 30
    for rep in range(reps):
        samples = tsp_walk(n, op, walklen)
        x = float(len(set(samples))) / len(samples)
        results.append(x)
    return np.mean(results), np.std(results)