Beispiel #1
0
def splmake(xk,yk,order=3,kind='smoothest',conds=None):
    """Return a (xk, cvals, k) representation of a spline given
    data-points where the (internal) knots are at the data-points.

    yk can be an N-d array to represent more than one curve, through
    the same xk points. The first dimension is assumed to be the
    interpolating dimension.

    kind can be 'smoothest', 'not_a_knot', 'fixed',
                'clamped', 'natural', 'periodic', 'symmetric',
                'user', 'mixed'

                it is ignored if order < 2
    """
    yk = np.asanyarray(yk)
    N = yk.shape[0]-1

    order = int(order)
    if order < 0:
        raise ValueError("order must not be negative")        
    if order == 0:
        return xk, yk[:-1], order
    elif order == 1:
        return xk, yk, order

    try:
        func = eval('_find_%s' % kind)
    except:
        raise NotImplementedError

    # the constraint matrix
    B = _fitpack._bsplmat(order, xk)
    coefs = func(xk, yk, order, conds, B)
    return xk, coefs, order
def splmake(xk, yk, order=3, kind='smoothest', conds=None):
    """Return a (xk, cvals, k) representation of a spline given
    data-points where the (internal) knots are at the data-points.

    yk can be an N-d array to represent more than one curve, through
    the same xk points. The first dimension is assumed to be the
    interpolating dimension.

    kind can be 'smoothest', 'not_a_knot', 'fixed',
                'clamped', 'natural', 'periodic', 'symmetric',
                'user', 'mixed'

                it is ignored if order < 2
    """
    yk = np.asanyarray(yk)
    N = yk.shape[0] - 1

    order = int(order)
    if order < 0:
        raise ValueError("order must not be negative")
    if order == 0:
        return xk, yk[:-1], order
    elif order == 1:
        return xk, yk, order

    try:
        func = eval('_find_%s' % kind)
    except:
        raise NotImplementedError

    # the constraint matrix
    B = _fitpack._bsplmat(order, xk)
    coefs = func(xk, yk, order, conds, B)
    return xk, coefs, order
Beispiel #3
0
def _find_smoothest(xk, yk, order, conds=None, B=None):
    # construct Bmatrix, and Jmatrix
    # e = J*c
    # minimize norm(e,2) given B*c=yk
    # if desired B can be given
    # conds is ignored
    N = len(xk)-1
    K = order
    if B is None:
        B = _fitpack._bsplmat(order, xk)
    J = _fitpack._bspldismat(order, xk)
    u,s,vh = np.dual.svd(B)
    ind = K-1
    V2 = vh[-ind:,:].T
    V1 = vh[:-ind,:].T
    A = dot(J.T,J)
    tmp = dot(V2.T,A)
    Q = dot(tmp,V2)
    p = np.dual.solve(Q,tmp)
    tmp = dot(V2,p)
    tmp = np.eye(N+K) - tmp
    tmp = dot(tmp,V1)
    tmp = dot(tmp,np.diag(1.0/s))
    tmp = dot(tmp,u.T)
    return dot(tmp, yk)
def _find_smoothest(xk, yk, order, conds=None, B=None):
    # construct Bmatrix, and Jmatrix
    # e = J*c
    # minimize norm(e,2) given B*c=yk
    # if desired B can be given
    # conds is ignored
    N = len(xk) - 1
    K = order
    if B is None:
        B = _fitpack._bsplmat(order, xk)
    J = _fitpack._bspldismat(order, xk)
    u, s, vh = np.dual.svd(B)
    ind = K - 1
    V2 = vh[-ind:, :].T
    V1 = vh[:-ind, :].T
    A = dot(J.T, J)
    tmp = dot(V2.T, A)
    Q = dot(tmp, V2)
    p = np.dual.solve(Q, tmp)
    tmp = dot(V2, p)
    tmp = np.eye(N + K) - tmp
    tmp = dot(tmp, V1)
    tmp = dot(tmp, np.diag(1.0 / s))
    tmp = dot(tmp, u.T)
    return _dot0(tmp, yk)