Пример #1
0
def build_feedforward_multilayered(input_number = 2, hidden_numbers = [2], output_number = 1, hidden_function = "tanh", output_function = "logsig"):
    net = network()
    net.num_of_inputs = input_number
    inputs = range(input_number)
    
    biasnode = net.bias_node

    #Hidden layers
    prev_layer = inputs
    for hidden_number in hidden_numbers:
        current_layer = []
        for i in xrange(int(hidden_number)):
            hidden = node(hidden_function)
            connect_node(hidden, biasnode)
            connect_nodes(hidden, prev_layer)
            net.hidden_nodes.append(hidden)
            current_layer.append(hidden)
        prev_layer = current_layer

    #Output nodes
    for i in xrange(int(output_number)):
        output = node(output_function)
        connect_node(output, biasnode)
        connect_nodes(output, prev_layer)
        net.output_nodes.append(output)

    return net
Пример #2
0
                population.append(network())
                population[child_index].num_of_inputs = mother.num_of_inputs
                bias_child = population[child_index].bias_node
                #Hidden layer
                for mother_node, father_node in zip(mother.hidden_nodes, father.hidden_nodes):
                    hidden = node(mother_node.activation_function, random_range)
                    weights = {}
                    for input_number in xrange(mother.num_of_inputs):
                        choice = sample([mother_node, father_node], 1)[0]
                        weights[input_number] = choice.weights[input_number]
                    choice = sample([(mother, mother_node), (father, father_node)], 1)[0]
                    weights[bias_child] = choice[1].weights[choice[0].bias_node]
                    
                    _all = range(mother.num_of_inputs)
                    _all.append(bias_child)
                    connect_nodes(hidden, _all, weights)
                    population[child_index].hidden_nodes.append(hidden)

                hidden_nodes = population[child_index].hidden_nodes

                #Output nodes
                #for mother_node, father_node in zip(mother.output_nodes, father.output_nodes):
                for output_number in xrange(len(mother.output_nodes)):
                    output = node(mother.output_nodes[output_number].activation_function)
                    weights = {}
                    for hidden_number in xrange(len(mother.hidden_nodes)):
                        choice = sample([mother, father], 1)[0]
                        weights[hidden_nodes[hidden_number]] = choice.output_nodes[output_number].weights[choice.hidden_nodes[hidden_number]]
                    choice = sample([mother, father], 1)[0]
                    weights[bias_child] = choice.output_nodes[output_number].weights[choice.bias_node]