Пример #1
0
    def encode(self, data):
        points = []
        x = 0
        for y in data:
            points.append([x, y])
            x = x + 1

        points.append([x, 0])
        first_poly = Polynomial.Lagrangian(points)

        x_coords = []
        y_coords = []
        pure_y_coords = []
        min_y = 0

        for point in points:
            x_coords.append(point[0])
            pure_y_coords.append(point[1])

        for x_index in range(self.data_encoding_points):
            x = x_index * self.degree / (self.data_encoding_points - 1)
            y = first_poly.value_at(x)
            x_coords.append(x)
            pure_y_coords.append(y)

        coordinate_encoding_start = self.degree - self.coordinate_encoding_length

        for x_index in range(self.coordinate_encoding_points):
            x = coordinate_encoding_start + x_index * self.coordinate_encoding_length / (
                self.coordinate_encoding_points - 1)
            y = first_poly.value_at(x)
            x_coords.append(x)
            pure_y_coords.append(y)

        min_y = 0

        for i in range(len(pure_y_coords)):
            poly_y = (pure_y_coords[i] - min_y)
            # y_coords.append(poly_y * random.gauss(1, scatter))
            y_coords.append(poly_y)

        return y_coords