def _apply_config(self, neural_net):
        """
        This function actually does the work.

        """

        if not isinstance(neural_net, NeuralNet):
            raise ValueError("neural_net must be of the NeuralNet class.")
        for snode in self.get_source_nodes(neural_net):
            prev_copy_node = None
            for level in xrange(self.copy_levels):
                copy_node = CopyNode()
                if level == 0:
                    copy_node.set_source_node(snode)
                else:
                    copy_node.set_source_node(prev_copy_node)

                copy_node.source_update_config(self.source_type,
                                               self.incoming_weight,
                                               self.existing_weight)

                copy_node.set_activation_type(self.activation_type)

                if self.connection_type == 'm':
                    self._fully_connect(copy_node,
                                        self.get_upper_nodes(neural_net))
                elif self.connection_type == 's':
                    copy_node.add_input_connection(Connection(
                        copy_node, snode))
                else:
                    raise ValueError("Invalid connection_type")

                neural_net.layers[self.copy_nodes_layer].add_node(copy_node)
                prev_copy_node = copy_node
Exemple #2
0
    def _fully_connect(lower_node, upper_nodes):
        """
        This function creates connections to each of the upper nodes.

        This is a separate function from the one in layers, because using this
        version does not require ALL of the nodes on a layer to be used.

        """

        for upper_node in upper_nodes:
            upper_node.add_input_connection(Connection(lower_node, upper_node))