How to use the expression.Expression.generate_random function in Expression

To help you get started, we’ve selected a few Expression examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github StanislavUshakov / ArtificialImmuneSystem / main.py View on Github external
        lambda: [Expression.generate_random(max_height=max_height, variables=variables)
                for i in range(0, number_of_lymphocytes // 2)])
github StanislavUshakov / ArtificialImmuneSystem / tests.py View on Github external
            lambda: [Expression.generate_random(max_height=2, variables=['x'])
                     for i in range(0, 5)])
github StanislavUshakov / ArtificialImmuneSystem / immune.py View on Github external
"""
        Initializes the immune system with the exact_values, list of variables,
        exchanger object and config object.
        lymphocytes - list that stores current value of the whole system.
        """
        self.exact_values = exact_values
        self.variables = variables
        self.fitness_function = FitnessFunction(exact_values)
        self.exchanger = exchanger

        #config
        self.config = config

        self.lymphocytes = []
        for i in range(0, self.config.number_of_lymphocytes):
            self.lymphocytes.append(Expression.generate_random(
                                        self.config.maximal_height,
                                        variables))

        #Initialize Exchanger with the first generated lymphocytes
        self.exchanger.set_lymphocytes_to_exchange(self.lymphocytes[:])

        random.seed()
github StanislavUshakov / ArtificialImmuneSystem / immune.py View on Github external
def subtree_mutation(self):
        """
        Changes one randomly selected node to the randomly generated subtree.
        The height of the tree isn't changed.
        """
        nodes = self._get_all_nodes_by_filter(lambda n: n.height() > 1 and
                                                        n != self.expression.root)
        if not nodes: return

        selected_node = random.choice(nodes)
        max_height = self.expression.root.height() - selected_node.height()
        new_subtree = Expression.generate_random(max_height, self.expression.variables)
        selected_node.operation = new_subtree.root.operation
        selected_node.value = new_subtree.root.value
        selected_node.left = new_subtree.root.left
        selected_node.right = new_subtree.root.right