예제 #1
0
def bidiag_unpack_diag(diag, superdiag):
    """
    returns B

    This functions unpacks the bidiagonal matrix T of the diagonal
    and superdiagonal obtained from gsl_linalg_bidiag_unpack[_B]
    """
    n = diag.shape[0]
    B = numx.identity(n) * diag
    sub = numx.identity(n - 1) * superdiag
    sub2 = numx.concatenate((numx.concatenate((zeros([n - 1, 1]), sub),
                                              1), zeros([1, n])))
    B = sub2 + B
    return B
예제 #2
0
def bidiag_unpack_diag(diag, superdiag):
    """
    returns B

    This functions unpacks the bidiagonal matrix T of the diagonal
    and superdiagonal obtained from gsl_linalg_bidiag_unpack[_B]
    """
    n = diag.shape[0]
    B = numx.identity(n)*diag
    sub = numx.identity(n-1)*superdiag
    sub2 = numx.concatenate(
        (numx.concatenate((zeros([n-1,1]),sub), 1), zeros([1,n])))
    B = sub2 + B
    return B
예제 #3
0
def symmtd_unpack_diag(diag, subdiag):
    """
    returns T

    This functions unpacks the tridiagonal matrix T of the diagonal
    and subdiagonal obtained from gsl_linalg_symmtd_unpack[_T]
    """
    n = diag.shape[0]
    T = numx.identity(n) * diag
    sub = numx.identity(n - 1) * subdiag
    sub1 = numx.concatenate((zeros(
        (1, n)), numx.concatenate((sub, zeros((n - 1, 1))), 1)))
    sub2 = numx.concatenate((numx.concatenate((zeros([n - 1, 1]), sub),
                                              1), zeros([1, n])))
    T = sub1 + sub2 + T
    return T
예제 #4
0
def symmtd_unpack_diag(diag, subdiag):
    """
    returns T

    This functions unpacks the tridiagonal matrix T of the diagonal
    and subdiagonal obtained from gsl_linalg_symmtd_unpack[_T]
    """
    n = diag.shape[0]
    T = numx.identity(n)*diag
    sub = numx.identity(n-1)*subdiag
    sub1 = numx.concatenate(
        (zeros((1,n)), numx.concatenate((sub, zeros((n-1,1))), 1)))
    sub2 = numx.concatenate(
        (numx.concatenate((zeros([n-1,1]),sub), 1), zeros([1,n])))
    T = sub1 + sub2 + T
    return T
예제 #5
0
def run():
    r = rng.rng()

    # slope
    a = 1.45
    # intercept
    b = 3.88

    # Generate the data
    n = 20
    i = numx.arange(n - 3)
    dx = 10.0 / (n - 1.0)
    e = r.uniform(n)
    x = -5.0 + i * dx
    y = a * x + b

    #outliers
    xo = numx.array([4.1, 3.5, 4.7])
    yo = numx.array([-6.0, -6.7, -8.3])

    x = numx.concatenate((x, xo))
    y = numx.concatenate((y, yo))

    X = numx.array([x * 0 + 1, x]).transpose()
    ws = fr.workspace(*((fr.ols, ) + X.shape))
    c_ols, cov_ols = ws.fit(X, y)
    ws = fr.workspace(*((fr.bisquare, ) + X.shape))
    c, cov = ws.fit(X, y)

    y_rob = numx.zeros(n, numx.float_)
    y_ols = numx.zeros(n, numx.float_)

    yerr_rob = numx.zeros(n, numx.float_)
    yerr_ols = numx.zeros(n, numx.float_)

    pygsl.set_debug_level(0)
    fr.est(X[0, :], c, cov)
    y_rob, yerr_rob = fr.est_vector(X, c, cov)
    pygsl.set_debug_level(0)
    y_ols, yerr_ols = fr.est_vector(X, c_ols, cov_ols)

    return x, y, (y_rob, yerr_rob), (y_ols, yerr_ols)