Ejemplo n.º 1
0
    def setup(self):
        np.random.seed(1234)
        m, k = 55, 3
        x = np.sort(np.random.random(m + 1))
        c = np.random.random((3, m))
        self.pp = interpolate.PPoly(c, x)

        npts = 100
        self.xp = np.linspace(0, 1, npts)
Ejemplo n.º 2
0
    def setup(self):
        rng = np.random.default_rng(1234)
        m, k = 55, 3
        x = np.sort(rng.random(m+1))
        c = rng.random((k, m))
        self.pp = interpolate.PPoly(c, x)

        npts = 100
        self.xp = np.linspace(0, 1, npts)
Ejemplo n.º 3
0
    def omega(self, deg, equalize=False):
        """
        Calculate matrix of second derivatives for regularization matrix.

        Parameters
        ----------
        deg       : int
            Number of differentiations in omega operator
        equalize : (optional) bool
            If set to true integral will be weighted to ensure that
            they contribute equally
        """
        # Calculate derivatives of polynomials
        pp = [p.derivative(deg) for p in self.basisFun]
        # Calculate matrix
        pdeg = 2 * (3 - deg) + 1
        n = len(self)
        omega = np.zeros((n, n))
        for i in range(n):
            for j in range(i + 1):
                # Build piecewise product of derivarives of spline
                # basis functions
                c1 = pp[i].c
                c2 = pp[j].c
                c = np.zeros((pdeg, c1.shape[1]))
                for k1 in range(3 - deg + 1):
                    for k2 in range(3 - deg + 1):
                        c[k1 + k2] = c[k1 + k2] + c1[k1] * c2[k2]
                p = inp.PPoly(c, pp[0].x)
                # Calculate integral
                if not equalize:
                    r = p.integrate(self.knots[0], self.knots[-1])
                else:
                    r = 0
                    for a, b in zip(self.knots, self.knots[1:]):
                        r += (b - a)**(2 * deg - 1) * p.integrate(a, b)
                omega[i, j] = r
                omega[j, i] = r
        return omega
Ejemplo n.º 4
0
def timeSampleInterpolationPolinomial(x_y_t_array, new_time_frequency):
    if len(x_y_t_array) < 4: return None

    x = x_y_t_array[:, 0]
    y = x_y_t_array[:, 1]
    t = x_y_t_array[:, 2]

    #    f = interp1d(x, y, kind='cubic')
    f = interp.PPoly(x, y)

    new_x_array = []
    new_t_array = []
    for i in range(1, x.size):
        delta_x = x[i] - x[i - 1]
        delta_t = t[i] - t[i - 1]

        new_x_array.append(x[i - 1])
        new_t_array.append(t[i - 1])

        if delta_t > new_time_frequency:
            current_x_velocity = delta_x / delta_t
            actual_x = x[i - 1] + new_time_frequency * current_x_velocity
            actual_t = t[i - 1] + new_time_frequency
            while actual_x < x[i]:
                new_x_array.append(actual_x)
                new_t_array.append(actual_t)
                actual_x += new_time_frequency * current_x_velocity
                actual_t += new_time_frequency

    new_x_array.append(x[:1])
    new_t_array.append(t[:1])

    new_y_array = f(new_x_array)

    result_array = np.column_stack(
        (np.array(new_x_array), np.array(new_y_array), np.array(new_t_array)))

    return result_array