Ejemplo n.º 1
0
    @param x: The long term memory that we are to score.
    @return: The MSE error.
    """
    # Setup the long-term memory that we would like to test.
    network.copy_memory(x)
    # Present all inputs to the network and accumulate the output for each.
    actual_output = []
    for input_data in training_input:
        output_data = network.compute_regression(input_data)
        actual_output.append(output_data)
    # Compare the actual output with the ideal expected output and calculate the MSE error.
    return ErrorCalculation.mse(np.array(actual_output), training_ideal)

# Use the initial long term memory of the network as the starting state.
x0 = list(network.long_term_memory)

# Train with greedy random.
train = TrainGreedRandom(-1, 1)
train.display_iteration = True
train.max_iterations = 100000
train.stop_score = 0.05
result = train.train(x0, score_funct)

# Copy the final trained long-term memory to the network so we can use it for evaluation.
network.copy_memory(result)

# Display the output for the XOR.  XOR will not be trained perfectly.  You should see that the (0,1) and (1,0) inputs
# are both close to 1.0, whereas the (1,1) and (0,0) are close to 0.0.
for input_data in training_input:
    output_data = network.compute_regression(input_data)
    print(str(input_data) + " -> " + str(output_data))
Ejemplo n.º 2
0
    @return: The MSE error.
    """
    # Setup the long-term memory that we would like to test.
    network.copy_memory(x)
    # Present all inputs to the network and accumulate the output for each.
    actual_output = []
    for input_data in training_input:
        output_data = network.compute_regression(input_data)
        actual_output.append(output_data)
    # Compare the actual output with the ideal expected output and calculate the MSE error.
    return ErrorCalculation.mse(np.array(actual_output), training_ideal)


# Use the initial long term memory of the network as the starting state.
x0 = list(network.long_term_memory)

# Train with greedy random.
train = TrainGreedRandom(-1, 1)
train.display_iteration = True
train.max_iterations = 100000
train.stop_score = 0.05
result = train.train(x0, score_funct)

# Copy the final trained long-term memory to the network so we can use it for evaluation.
network.copy_memory(result)

# Display the output for the XOR.  XOR will not be trained perfectly.  You should see that the (0,1) and (1,0) inputs
# are both close to 1.0, whereas the (1,1) and (0,0) are close to 0.0.
for input_data in training_input:
    output_data = network.compute_regression(input_data)
    print(str(input_data) + " -> " + str(output_data))