def score_function(genome): # Loop over the training set and calculate the output for each. actual_output = [] for input_data in training_input: genome.set_variable_value(["x"], input_data) output_data = genome.eval() actual_output.append([output_data]) result = ErrorCalculation.mse(np.array(actual_output), training_ideal) return result
def score_funct(x): """ The score function. Calculate the MSE error between the actual network output and the ideal values for the XOR. @param x: The long term memory that we are to score. @return: The MSE error. """ network.copy_memory(x) actual_output = [] for input_data in training_input: output_data = network.compute_regression(input_data) actual_output.append(output_data) return ErrorCalculation.mse(np.array(actual_output), training_ideal)
def score_funct(x): """ The score function. Calculate the MSE error between the actual network output and the ideal values for the XOR. @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)
def score_funct(x): global best_score global input_data global output_data network.copy_memory(x) actual_output = [] for input_data in training_input: output_data = network.compute_regression(input_data) actual_output.append(output_data) result = ErrorCalculation.mse(np.array(actual_output), training_ideal) if result < best_score: best_score = result print("Score: " + str(result)) return result
def score_funct(coeff): """ Calculate the score with the specified coefficients. Use MSE error calculation. @param coeff: The coefficients. @return: The score. We are trying to minimize this score. """ global input_data global output_data # Calculate the actual output of the polynomial with the specified coefficients. actual_output = [] for input_data in training_input: x = input_data[0] output_data = poly(coeff, x) actual_output.append(output_data) return ErrorCalculation.sse(np.array(actual_output), training_ideal)
def score_funct(x): """ The score function for Iris anneal. @param x: @return: """ global best_score global input_data global output_data # Update the network's long term memory to the vector we need to score. network.copy_memory(x) # Loop over the training set and calculate the output for each. actual_output = [] for input_data in training_input: output_data = network.compute_regression(input_data) actual_output.append(output_data) # Calculate the error with MSE. result = ErrorCalculation.mse(np.array(actual_output), training_ideal) return result
def test_rms(self): actual = np.array(TestError.ACTUAL) ideal = np.array(TestError.IDEAL) self.assertAlmostEqual(ErrorCalculation.rms(actual, ideal), 12.3134, 3)
for row in xrange(0, rows): for col in xrange(0, cols): d = float(np.random.randint(low, high)) ideal[row][col] = d actual[row][col] = d + (np.random.normal() * distort) return result # Generate data sets. smallErrors = generate(SEED, ROWS, COLS, LOW, HIGH, 0.1) mediumErrors = generate(SEED, ROWS, COLS, LOW, HIGH, 0.5) largeErrors = generate(SEED, ROWS, COLS, LOW, HIGH, 1.0) hugeErrors = generate(SEED, ROWS, COLS, LOW, HIGH, 10.0) small_sse = ErrorCalculation.sse(smallErrors['actual'], smallErrors['ideal']) small_mse = ErrorCalculation.mse(smallErrors['actual'], smallErrors['ideal']) small_rms = ErrorCalculation.rms(smallErrors['actual'], smallErrors['ideal']) medium_sse = ErrorCalculation.sse(mediumErrors['actual'], mediumErrors['ideal']) medium_mse = ErrorCalculation.mse(mediumErrors['actual'], mediumErrors['ideal']) medium_rms = ErrorCalculation.rms(mediumErrors['actual'], mediumErrors['ideal']) large_sse = ErrorCalculation.sse(largeErrors['actual'], largeErrors['ideal']) large_mse = ErrorCalculation.mse(largeErrors['actual'], largeErrors['ideal']) large_rms = ErrorCalculation.rms(largeErrors['actual'], largeErrors['ideal']) huge_sse = ErrorCalculation.sse(hugeErrors['actual'], hugeErrors['ideal'])
def test_mse(self): actual = np.array(TestError.ACTUAL) ideal = np.array(TestError.IDEAL) self.assertAlmostEqual(ErrorCalculation.mse(actual, ideal), 151.6205, 3)
for row in xrange(0, rows): for col in xrange(0, cols): d = float(np.random.randint(low, high)) ideal[row][col] = d actual[row][col] = d + (np.random.normal() * distort) return result # Generate data sets. smallErrors = generate(SEED, ROWS, COLS, LOW, HIGH, 0.1) mediumErrors = generate(SEED, ROWS, COLS, LOW, HIGH, 0.5) largeErrors = generate(SEED, ROWS, COLS, LOW, HIGH, 1.0) hugeErrors = generate(SEED, ROWS, COLS, LOW, HIGH, 10.0) small_sse = ErrorCalculation.sse(smallErrors['actual'], smallErrors['ideal']) small_mse = ErrorCalculation.mse(smallErrors['actual'], smallErrors['ideal']) small_rms = ErrorCalculation.rms(smallErrors['actual'], smallErrors['ideal']) medium_sse = ErrorCalculation.sse(mediumErrors['actual'], mediumErrors['ideal']) medium_mse = ErrorCalculation.mse(mediumErrors['actual'], mediumErrors['ideal']) medium_rms = ErrorCalculation.rms(mediumErrors['actual'], mediumErrors['ideal']) large_sse = ErrorCalculation.sse(largeErrors['actual'], largeErrors['ideal']) large_mse = ErrorCalculation.mse(largeErrors['actual'], largeErrors['ideal']) large_rms = ErrorCalculation.rms(largeErrors['actual'], largeErrors['ideal']) huge_sse = ErrorCalculation.sse(hugeErrors['actual'], hugeErrors['ideal']) huge_mse = ErrorCalculation.mse(hugeErrors['actual'], hugeErrors['ideal']) huge_rms = ErrorCalculation.rms(hugeErrors['actual'], hugeErrors['ideal'])
def test_rss(self): actual = np.array(TestError.ACTUAL) ideal = np.array(TestError.IDEAL) self.assertAlmostEqual(ErrorCalculation.rss(actual, ideal), 3032.4099, 3)