Ejemplo n.º 1
0
    def evaluate(self, test_data):
        if len(self.model) == 0:
            raise RuntimeError('PolyACO must be trained before evaluation')
        inside = np.empty((len(self.planes), len(self.class_indices), test_data.shape[0]), dtype=bool)
        for i, plane in enumerate(self.model):
            plane_data = np.take(test_data, list(self.planes[i]), axis=1)
            for j, poly in enumerate(plane):
                inside[i, j, :] = is_points_inside_cuda(plane_data, polygon_to_array(poly))

        aggregated_scores = np.mean(inside, axis=0)
        predictions = np.empty((test_data.shape[0]), dtype=int)
        max_elements = np.argmax(aggregated_scores, axis=0)
        for i in range(test_data.shape[0]):
            predictions[i] = self.class_indices[max_elements[i]]
        return predictions
Ejemplo n.º 2
0
    def evaluate(self, test_data):
        if len(self.model) == 0:
            raise RuntimeError('PolyACO must be trained before evaluation')
        inside = np.empty(
            (len(self.planes), len(self.class_indices), test_data.shape[0]),
            dtype=bool)
        for i, plane in enumerate(self.model):
            plane_data = np.take(test_data, list(self.planes[i]), axis=1)
            for j, poly in enumerate(plane):
                inside[i,
                       j, :] = is_points_inside_cuda(plane_data,
                                                     polygon_to_array(poly))

        aggregated_scores = np.mean(inside, axis=0)
        predictions = np.empty((test_data.shape[0]), dtype=int)
        max_elements = np.argmax(aggregated_scores, axis=0)
        for i in range(test_data.shape[0]):
            predictions[i] = self.class_indices[max_elements[i]]
        return predictions
Ejemplo n.º 3
0
def cost_function_gpu(points, edges):
    is_inside = ray_cast.is_points_inside_cuda(points, edges)
    score = np.sum(np.logical_xor(is_inside, points[:, 2]))
    return score / points.shape[0]
Ejemplo n.º 4
0
 def test_function_returns_1_true_rest_false(self):
     data = np.array([[0, 0], [1, 1], [2, 2], [3, 3]])
     result = rc.is_points_inside_cuda(data, self.polygon)
     self.assertEqual(np.sum(result), 1)
     self.assertEqual(np.sum(np.invert(result)), 3)
Ejemplo n.º 5
0
 def test_function_returns_array_of_size_equal_to_number_of_input_points(self):
     data = np.array([[0, 0], [1, 1], [2, 2], [3, 3]])
     result = rc.is_points_inside_cuda(data, self.polygon)
     self.assertEqual(result.shape[0], data.shape[0])
Ejemplo n.º 6
0
def cost_function_gpu(points, edges):
    is_inside = ray_cast.is_points_inside_cuda(points, edges)
    score = np.sum(np.logical_xor(is_inside, points[:, 2]))
    return score / points.shape[0]
Ejemplo n.º 7
0
 def test_function_returns_1_true_rest_false(self):
     data = np.array([[0, 0], [1, 1], [2, 2], [3, 3]])
     result = rc.is_points_inside_cuda(data, self.polygon)
     self.assertEqual(np.sum(result), 1)
     self.assertEqual(np.sum(np.invert(result)), 3)
Ejemplo n.º 8
0
 def test_function_returns_array_of_size_equal_to_number_of_input_points(
         self):
     data = np.array([[0, 0], [1, 1], [2, 2], [3, 3]])
     result = rc.is_points_inside_cuda(data, self.polygon)
     self.assertEqual(result.shape[0], data.shape[0])