コード例 #1
0
def learn_DNF__recombination():
    dnf = DNF()
    length = 58
    epsilon = (2**-53)
    tau = (epsilon / length)**3 * log(1 / epsilon)

    tolerance = ConjunctionTolerance(length, epsilon)
    conjunction_performance_oracle = OneSidedPerformanceOracleWithTolerance(
        dnf, tau)
    performance_oracle = DNFOneSidePerformanceOracleWithTolerance(
        dnf, tau, epsilon, conjunction_performance_oracle)
    mutation_neighborhood = MonotoneConjunctionNeighborhood()

    recomb_rate = 0.176
    natural_process = RecombinationProcess(recomb_rate)

    neighborhood = NeighborhoodWithOtherRepresentations(
        length, mutation_neighborhood, 0.1, natural_process)

    recombinator = Recombinator(neighborhood, performance_oracle, tolerance,
                                epsilon)
    algorithm = ConstantPopulationMutationConjunctionAlgorithm(
        recombinator, length, epsilon, performance_oracle, 75)

    print algorithm.learn_ideal_function_until_match()
コード例 #2
0
    def __init__(self, is_neigh_precomp=True, is_using_output_one_neigh=True):
        self.length = 100
        self.epsilon = Fraction(2**-55)
        self.number_of_activations = 20
        self.number_of_mutations_from_mutator = 50
        self.population_size = 75

        self.tolerance = ConjunctionTolerance(self.length, self.epsilon)
        self.tau = 0  # (self.epsilon / Decimal(self.length))**Decimal(3) * log(1/self.epsilon)

        self.representation_class = None

        if is_neigh_precomp:
            self.representation_class = get_set_of_all_representations_with_length(
                self.length)
            self.mutation_neighborhood = PrecompMonotoneConjunctionNeighborhood(
                self.representation_class)
        elif is_using_output_one_neigh:
            self.mutation_neighborhood = ConjunctionNeighborhoodOutputOne()
        else:
            self.mutation_neighborhood = MonotoneConjunctionNeighborhood()

        self.mutation_probability = ConjunctionMutationProbability(
            self.mutation_neighborhood)

        self.recombination_factor = 1
コード例 #3
0
def test_speed_of_rep_plus_minus():
    pr = cProfile.Profile()
    neighbors_finder = MonotoneConjunctionNeighborhood()

    pr.enable()

    for i in xrange(100):
        neighbors_finder.get_neighborhood_of_rep(
            (1, 0, 1, 0, 1, 0, 1, 1, 0, 0, 0, 1, 1, 0, 1, 0, 1, 0, 1, 1, 0, 0,
             0, 1, 1, 0, 1, 0, 1, 0, 1, 1, 0, 0, 0, 1, 1, 0, 1, 0, 1, 0, 1, 1,
             0, 0, 0, 1, 1, 0, 1, 0, 1, 0, 1, 1, 0, 0, 0, 1, 1, 0, 1, 0, 1, 0,
             1, 1, 0, 0, 0, 1, 1, 0, 1, 0, 1, 0, 1, 1, 0, 0, 0, 1, 1, 0, 1, 0,
             1, 0, 1, 1, 0, 0, 0, 1))

    pr.disable()

    pstats.Stats(pr).sort_stats("time").print_stats()
コード例 #4
0
def learn_DNF__basic_model():
    dnf = DNF()
    length = 58
    epsilon = (2**-53)
    tau = (epsilon / length)**3 * log(1 / epsilon)

    tolerance = ConjunctionTolerance(length, epsilon)
    conjunction_performance_oracle = OneSidedPerformanceOracleWithTolerance(
        dnf, tau)
    performance_oracle = DNFOneSidePerformanceOracleWithTolerance(
        dnf, tau, epsilon, conjunction_performance_oracle)
    mutation_neighborhood = MonotoneConjunctionNeighborhood()
    mutation_probability = ConjunctionMutationProbability(
        mutation_neighborhood)

    mutator = Mutator(mutation_neighborhood, performance_oracle, tolerance,
                      mutation_probability, epsilon)
    algorithm = ConjunctionEvolvabilityAlgorithm(mutator, length, epsilon,
                                                 performance_oracle)

    print algorithm.learn_ideal_function_until_match()
コード例 #5
0
class TestNeighborsFinder(unittest.TestCase):
    def setUp(self):
        self.neighbors_finder = MonotoneConjunctionNeighborhood()
        self.neighbor_getter = ConjunctionNeighborhoodOutputOne()

    def test_find_for_zero(self):
        neighbors = set()

        neighbors.add((0, 0, 0, 0, 0))
        neighbors.add((1, 0, 0, 0, 0))
        neighbors.add((0, 1, 0, 0, 0))
        neighbors.add((0, 0, 1, 0, 0))
        neighbors.add((0, 0, 0, 1, 0))
        neighbors.add((0, 0, 0, 0, 1))

        self.assertEqual(neighbors, self.neighbors_finder.get_neighborhood_of_rep((0, 0, 0, 0, 0)))
        self.assertIn(self.neighbor_getter.get_one_of_neighborhood_of_rep((0, 0, 0, 0, 0)), neighbors)

    def test_find_for_other(self):
        neighbors = set()

        neighbors.add((0, 0, 0, 0, 0))

        neighbors.add((1, 0, 0, 0, 0))
        neighbors.add((0, 1, 0, 0, 0))
        neighbors.add((0, 0, 1, 0, 0))
        neighbors.add((0, 0, 0, 1, 0))
        neighbors.add((0, 0, 0, 0, 1))

        neighbors.add((1, 0, 1, 0, 0))
        neighbors.add((0, 1, 1, 0, 0))
        neighbors.add((0, 0, 1, 1, 0))
        neighbors.add((0, 0, 1, 0, 1))

        self.assertEqual(neighbors, self.neighbors_finder.get_neighborhood_of_rep((0, 0, 1, 0, 0)))
        self.assertIn(self.neighbor_getter.get_one_of_neighborhood_of_rep((0, 0, 1, 0, 0)), neighbors)

    def test_find_for_another_one(self):
        neighbors = set()

        neighbors.add((1, 1, 1, 1, 0))

        neighbors.add((1, 1, 1, 0, 1))
        neighbors.add((1, 1, 0, 1, 1))
        neighbors.add((1, 0, 1, 1, 1))
        neighbors.add((0, 1, 1, 1, 1))

        neighbors.add((1, 1, 1, 0, 0))
        neighbors.add((1, 1, 0, 1, 0))
        neighbors.add((1, 0, 1, 1, 0))
        neighbors.add((0, 1, 1, 1, 0))
        neighbors.add((1, 1, 1, 1, 1))

        self.assertEqual(neighbors, self.neighbors_finder.get_neighborhood_of_rep((1, 1, 1, 1, 0)))
        self.assertIn(self.neighbor_getter.get_one_of_neighborhood_of_rep((1, 1, 1, 1, 0)), neighbors)

    def test_find_for_unique(self):
        neighbors = set()

        neighbors.add((1, 0))
        neighbors.add((0, 1))
        neighbors.add((0, 0))
        neighbors.add((1, 1))

        self.assertEqual(neighbors, self.neighbors_finder.get_neighborhood_of_rep((0, 1)))
        self.assertIn(self.neighbor_getter.get_one_of_neighborhood_of_rep((0, 1)), neighbors)
コード例 #6
0
 def setUp(self):
     self.neighbors_finder = MonotoneConjunctionNeighborhood()
     self.neighbor_getter = ConjunctionNeighborhoodOutputOne()
コード例 #7
0
class TestNeighborsFinder(unittest.TestCase):
    def setUp(self):
        self.neighbors_finder = MonotoneConjunctionNeighborhood()
        self.neighbor_getter = ConjunctionNeighborhoodOutputOne()

    def test_find_for_zero(self):
        neighbors = set()

        neighbors.add((0, 0, 0, 0, 0))
        neighbors.add((1, 0, 0, 0, 0))
        neighbors.add((0, 1, 0, 0, 0))
        neighbors.add((0, 0, 1, 0, 0))
        neighbors.add((0, 0, 0, 1, 0))
        neighbors.add((0, 0, 0, 0, 1))

        self.assertEqual(
            neighbors,
            self.neighbors_finder.get_neighborhood_of_rep((0, 0, 0, 0, 0)))
        self.assertIn(
            self.neighbor_getter.get_one_of_neighborhood_of_rep(
                (0, 0, 0, 0, 0)), neighbors)

    def test_find_for_other(self):
        neighbors = set()

        neighbors.add((0, 0, 0, 0, 0))

        neighbors.add((1, 0, 0, 0, 0))
        neighbors.add((0, 1, 0, 0, 0))
        neighbors.add((0, 0, 1, 0, 0))
        neighbors.add((0, 0, 0, 1, 0))
        neighbors.add((0, 0, 0, 0, 1))

        neighbors.add((1, 0, 1, 0, 0))
        neighbors.add((0, 1, 1, 0, 0))
        neighbors.add((0, 0, 1, 1, 0))
        neighbors.add((0, 0, 1, 0, 1))

        self.assertEqual(
            neighbors,
            self.neighbors_finder.get_neighborhood_of_rep((0, 0, 1, 0, 0)))
        self.assertIn(
            self.neighbor_getter.get_one_of_neighborhood_of_rep(
                (0, 0, 1, 0, 0)), neighbors)

    def test_find_for_another_one(self):
        neighbors = set()

        neighbors.add((1, 1, 1, 1, 0))

        neighbors.add((1, 1, 1, 0, 1))
        neighbors.add((1, 1, 0, 1, 1))
        neighbors.add((1, 0, 1, 1, 1))
        neighbors.add((0, 1, 1, 1, 1))

        neighbors.add((1, 1, 1, 0, 0))
        neighbors.add((1, 1, 0, 1, 0))
        neighbors.add((1, 0, 1, 1, 0))
        neighbors.add((0, 1, 1, 1, 0))
        neighbors.add((1, 1, 1, 1, 1))

        self.assertEqual(
            neighbors,
            self.neighbors_finder.get_neighborhood_of_rep((1, 1, 1, 1, 0)))
        self.assertIn(
            self.neighbor_getter.get_one_of_neighborhood_of_rep(
                (1, 1, 1, 1, 0)), neighbors)

    def test_find_for_unique(self):
        neighbors = set()

        neighbors.add((1, 0))
        neighbors.add((0, 1))
        neighbors.add((0, 0))
        neighbors.add((1, 1))

        self.assertEqual(neighbors,
                         self.neighbors_finder.get_neighborhood_of_rep((0, 1)))
        self.assertIn(
            self.neighbor_getter.get_one_of_neighborhood_of_rep((0, 1)),
            neighbors)
コード例 #8
0
 def setUp(self):
     self.neighbors_finder = MonotoneConjunctionNeighborhood()
     self.neighbor_getter = ConjunctionNeighborhoodOutputOne()