Exemplo n.º 1
0
 def test_decode(self):
     eq = Equilateral(3, -1, 1)
     d0 = [0.866, 0.5]
     d1 = [-0.866, 0.5]
     d2 = [0, -1]
     self.assertEqual(2, eq.decode(d0))
     self.assertEqual(2, eq.decode(d1))
     self.assertEqual(0, eq.decode(d2))
Exemplo n.º 2
0
    def norm_col_equilateral(self, data_set, col, classes, normalized_low, normalized_high):
        """ Normalize a column using equilateral.  The classes parameter contains a map of the unique items in the
            specified column.  Typically this value is obtained by calling build_class_map.
        """
        col = self.resolve_column(col)
        eq = Equilateral(len(classes), normalized_low, normalized_high)

        for row in data_set:
            key = row[col]
            value = classes[key]
            row.pop(col)
            vec = eq.encode(value)
            for i in range(0, len(vec)):
                row.insert(col + i, vec[i])
Exemplo n.º 3
0
    def test_all_equal(self):
        eq = Equilateral(10, -1, 1)
        compare_dist = -1

        for x in range(0, 10):
            base_class = eq.encode(x)
            for y in range(0, 10):
                if x != y:
                    otherClass = eq.encode(y)
                    dist = distance.euclidean(base_class, otherClass)
                    if compare_dist < 0:
                        compare_dist = dist
                    else:
                        self.assertAlmostEqual(dist, compare_dist, 7)
Exemplo n.º 4
0
    def norm_col_equilateral(self, data_set, col, classes, normalized_low, normalized_high):
        """ Normalize a column using equilateral.  The classes parameter contains a map of the unique items in the
            specified column.  Typically this value is obtained by calling build_class_map.
        """
        col = self.resolve_column(col)
        eq = Equilateral(len(classes), normalized_low, normalized_high)

        for row in data_set:
            key = row[col]
            value = classes[key]
            row.pop(col)
            vec = eq.encode(value)
            for i in range(0, len(vec)):
                row.insert(col + i, vec[i])
Exemplo n.º 5
0
 def test_equilateral(self):
     eq = Equilateral(3, -1, 1)
     d = eq.encode(1);
     self.assertAlmostEqual(0.8660254037844386, d[0], 7)
     self.assertAlmostEqual(-0.5, d[1], 7)
Exemplo n.º 6
0

# Initial state is current long term memory.
x0 = list(network.long_term_memory)

# Train the network.
res = minimize(score_funct,
               x0,
               method='nelder-mead',
               tol=0.0001,
               options={
                   'disp': True,
                   'maxiter': 5000
               })

# Create an equilateral table for 3 classes (species of iris) and between the range 0 to 1.  This is used
# to decide the two output nodes into a species number.
eq = Equilateral(3, 0, 1)

# Display the final validation.  We show all of the iris data as well as the predicted species.
for i in xrange(0, len(training_input)):
    input_data = training_input[i]
    # Compute the output from the RBF network
    output_data = network.compute_regression(input_data)
    ideal_data = training_ideal[i]
    # Decode the two output neurons into a class number.
    class_id = eq.decode(output_data)
    print(
        str(input_data) + " -> " + inv_classes[class_id] + ", Ideal: " +
        ideal_species[i])
Exemplo n.º 7
0
    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

# Initial state is current long term memory.
x0 = list(network.long_term_memory)

# Train the network.
res = minimize(score_funct, x0, method='nelder-mead', tol=0.0001, options={'disp': True, 'maxiter': 5000})

# Create an equilateral table for 3 classes (species of iris) and between the range 0 to 1.  This is used
# to decide the two output nodes into a species number.
eq = Equilateral(3, 0, 1)

# Display the final validation.  We show all of the iris data as well as the predicted species.
for i in range(0, len(training_input)):
    input_data = training_input[i]
    # Compute the output from the RBF network
    output_data = network.compute_regression(input_data)
    ideal_data = training_ideal[i]
    # Decode the two output neurons into a class number.
    class_id = eq.decode(output_data)
    print(str(input_data) + " -> " + inv_classes[class_id] + ", Ideal: " + ideal_species[i])