Esempio n. 1
0
    def eval_s(self, s, out=None):

        from interpolation.splines.eval_cubic import vec_eval_cubic_splines

        if s.ndim == 1:
            return self.eval_s(s[None, :])[0, :]

        s = np.atleast_2d(s)
        if out is None:
            out = np.zeros((s.shape[0], self.n_x))

        if isinstance(self.exo_grid,
                      (EmptyGrid, CartesianGrid)) and isinstance(
                          self.endo_grid, CartesianGrid):
            full_grid = self.full_grid
            min = self.full_grid.min
            max = self.full_grid.max
            n = self.full_grid.n
            coeffs = self.coefficients
            vec_eval_cubic_splines(min, max, n, coeffs, s, out)
        elif isinstance(self.exo_grid, EmptyGrid) and isinstance(
                self.endo_grid, SmolyakGrid):
            trans_points = self.sg.dom2cube(s)
            Phi = build_B(self.sg.d, self.sg.mu, trans_points, self.sg.pinds)
            theta = self.thetas
            out[...] = Phi @ theta
        else:
            raise Exception("Not Implemented.")

        return out
Esempio n. 2
0
    def eval_ms(self, m, s, out=None):

        from interpolation.splines.eval_cubic import vec_eval_cubic_splines

        if s.ndim == 1 and m.ndim == 1:
            return self.eval_ms(m[None, :], s[None, :], out=out)[0, :]

        s = np.atleast_2d(s)
        m = np.atleast_2d(m)
        if s.shape[0] == 1 and m.shape[0] > 1:
            s = s.repeat(m.shape[0], axis=0)
        elif m.shape[0] == 1 and s.shape[0] > 1:
            m = m.repeat(s.shape[0], axis=0)

        if out is None:
            out = np.zeros((s.shape[0], self.n_x))

        if isinstance(self.exo_grid, (EmptyGrid)) and isinstance(
                self.endo_grid, CartesianGrid):
            self.eval_s(s, out=out)
        elif isinstance(self.exo_grid, CartesianGrid) and isinstance(
                self.endo_grid, CartesianGrid):
            v = np.concatenate([m, s], axis=1)
            full_grid = self.full_grid
            min = full_grid.min
            max = full_grid.max
            n = full_grid.n
            coeffs = self.coefficients
            vec_eval_cubic_splines(min, max, n, coeffs, v, out)
        else:
            raise Exception("Not Implemented.")

        return out
    def __call__(self, i_m, points, out=None):

        n_x = self.__values__.shape[-1]

        assert (1 <= points.ndim <= 2)

        if points.ndim == 2:
            N = points.shape[0]

            out = zeros((N, n_x))
            if numpy.isscalar(i_m):
                coefs = self.__coefs__[i_m, ...]
                vec_eval_cubic_splines(self.a, self.b, self.orders, coefs,
                                       points, out)
            else:
                assert (len(i_m) == N)
                for n in range(N):
                    coefs = self.__coefs__[i_m[n]]
                    vec_eval_cubic_splines(self.a, self.b, self.orders, coefs,
                                           points[n:n + 1, :], out[n:n + 1, :])

            return out

        elif points.ndim == 1:

            pp = numpy.atleast_2d(points)
            out = self.__call__(i_m, pp)
            return out.ravel()
Esempio n. 4
0
    def __call__(self, i_m, points, out=None):

        n_x = self.__values__.shape[-1]

        assert(1<=points.ndim<=2)

        if points.ndim == 2:
            N = points.shape[0]

            out = zeros((N,n_x))
            if numpy.isscalar(i_m):
                coefs = self.__coefs__[i_m,...]
                vec_eval_cubic_splines(self.a, self.b, self.orders, coefs, points, out)
            else:
                assert(len(i_m)==N)
                for n in range(N):
                    coefs = self.__coefs__[i_m[n]]
                    vec_eval_cubic_splines(self.a, self.b, self.orders, coefs, points[n:n+1,:], out[n:n+1,:])

            return out

        elif points.ndim == 1:

            pp = numpy.atleast_2d(points)
            out = self.__call__(i_m, pp)
            return out.ravel()
def test_cubic_multi_spline():

    from interpolation.splines.filter_cubic import filter_mcoeffs
    from interpolation.splines.eval_cubic import eval_cubic_splines, vec_eval_cubic_splines

    cc = filter_mcoeffs(a,b,orders,mvals)
    assert(tuple(cc.shape) == tuple([o+2 for o in orders]+[mvals.shape[1]]))

    ii = eval_cubic_splines(a, b, orders, cc, point)
    iii = vec_eval_cubic_splines(a, b, orders, cc, points)

    assert(ii.ndim==1)
    assert(iii.ndim==2)
Esempio n. 6
0
def test_cubic_multi_spline():

    from interpolation.splines.filter_cubic import filter_mcoeffs
    from interpolation.splines.eval_cubic import eval_cubic_splines, vec_eval_cubic_splines

    cc = filter_mcoeffs(a, b, orders, mvals)
    assert (tuple(cc.shape) == tuple([o + 2
                                      for o in orders] + [mvals.shape[1]]))

    ii = eval_cubic_splines(a, b, orders, cc, point)
    iii = vec_eval_cubic_splines(a, b, orders, cc, points)

    assert (ii.ndim == 1)
    assert (iii.ndim == 2)