예제 #1
0
    def test_create_mutated_model_removal(self):
        # Given
        expected = CnnBaseArchitecture()
        expected = expected.build_from_file(
            'test/resources/mutated_architecture_removal.txt')

        architecture = CnnBaseArchitecture()
        architecture.build_from_file('test/resources/complex_architecture.txt')

        # When
        generator = ModelGenerator(architecture,
                                   'keras',
                                   removal_rate=0.5,
                                   duplication_rate=0,
                                   amendment_rate=0,
                                   seed=13)
        actual = generator.create_mutated_model()
        mutated_arch = generator.get_last_mutation()

        # Then
        self.assertEqual(9, len(actual.model._layers))
        self.assertEqual(str(expected), str(mutated_arch))
예제 #2
0
    def test_populate_builder_history(self):
        # Given
        expected = CnnBaseArchitecture()
        expected = expected.build_from_file(
            'test/resources/mutated_architecture_history_duplicate.txt')

        architecture = CnnBaseArchitecture()
        architecture.build_from_file('test/resources/complex_architecture.txt')

        # When
        generator = ModelGenerator(architecture,
                                   'keras',
                                   removal_rate=0,
                                   duplication_rate=0.8,
                                   amendment_rate=0,
                                   seed=14)
        generator.populate_history('test/resources/history', 'test-arch-', 3)
        actual = generator.create_mutated_model()
        mutated_arch = generator.get_last_mutation()

        # Then
        self.assertEqual(24, len(actual.model._layers))
        self.assertEqual(str(expected), str(mutated_arch))