當前位置: 首頁>>代碼示例>>Python>>正文


Python linalg.pinv方法代碼示例

本文整理匯總了Python中numpy.linalg.pinv方法的典型用法代碼示例。如果您正苦於以下問題:Python linalg.pinv方法的具體用法?Python linalg.pinv怎麽用?Python linalg.pinv使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在numpy.linalg的用法示例。


在下文中一共展示了linalg.pinv方法的12個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_byteorder_check

# 需要導入模塊: from numpy import linalg [as 別名]
# 或者: from numpy.linalg import pinv [as 別名]
def test_byteorder_check():
    # Byte order check should pass for native order
    if sys.byteorder == 'little':
        native = '<'
    else:
        native = '>'

    for dtt in (np.float32, np.float64):
        arr = np.eye(4, dtype=dtt)
        n_arr = arr.newbyteorder(native)
        sw_arr = arr.newbyteorder('S').byteswap()
        assert_equal(arr.dtype.byteorder, '=')
        for routine in (linalg.inv, linalg.det, linalg.pinv):
            # Normal call
            res = routine(arr)
            # Native but not '='
            assert_array_equal(res, routine(n_arr))
            # Swapped
            assert_array_equal(res, routine(sw_arr)) 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:21,代碼來源:test_linalg.py

示例2: _compute_a

# 需要導入模塊: from numpy import linalg [as 別名]
# 或者: from numpy.linalg import pinv [as 別名]
def _compute_a(self):
        """fixed effects parameters

        Display (3.1) of
        Laird, Lange, Stram (see help(Mixed)).

        """

        for unit in self.units:
            unit.fit(self.a, self.D, self.sigma)

        S = sum([unit.compute_xtwx() for unit in self.units])
        Y = sum([unit.compute_xtwy() for unit in self.units])

        self.Sinv = L.pinv(S)
        self.a = np.dot(self.Sinv, Y) 
開發者ID:birforce,項目名稱:vnpy_crypto,代碼行數:18,代碼來源:mixed.py

示例3: __init__

# 需要導入模塊: from numpy import linalg [as 別名]
# 或者: from numpy.linalg import pinv [as 別名]
def __init__(self, A, B, offset, scale, px_offset, px_scale, gsd=None, proj=None, default_z=0):
        self.proj = proj
        self._A = A
        self._B = B
        self._offset = offset
        self._scale = scale
        self._px_offset = px_offset
        self._px_scale = px_scale
        self._gsd = gsd
        self._offscl = np.vstack([offset, scale])
        self._offscl_rev = np.vstack([-offset/scale, 1.0/scale])
        self._px_offscl_rev = np.vstack([px_offset, px_scale])
        self._px_offscl = np.vstack([-px_offset/px_scale, 1.0/px_scale])

        self._default_z = default_z

        self._A_rev = np.dot(pinv(np.dot(np.transpose(A), A)), np.transpose(A))
        # only using the numerator (more dynamic range for the fit?)
        # self._B_rev = np.dot(pinv(np.dot(np.transpose(B), B)), np.transpose(B)) 
開發者ID:DigitalGlobe,項目名稱:gbdxtools,代碼行數:21,代碼來源:util.py

示例4: algorithm_1

# 需要導入模塊: from numpy import linalg [as 別名]
# 或者: from numpy.linalg import pinv [as 別名]
def algorithm_1(y, u, l, m, f, N, U_n, S_n, V_n, W1, O_i, threshold, max_order, D_required):
    U_n, S_n, V_n = reducingOrder(U_n, S_n, V_n, threshold, max_order)
    V_n = V_n.T
    n = S_n.size
    S_n = np.diag(S_n)
    if W1 is None: #W1 is identity
        Ob = np.dot(U_n, sc.linalg.sqrtm(S_n))
    else:
        Ob = np.dot(np.linalg.inv(W1), np.dot(U_n, sc.linalg.sqrtm(S_n)))
    X_fd = np.dot(np.linalg.pinv(Ob), O_i)
    Sxterm = impile(X_fd[:, 1:N], y[:, f:f + N - 1])
    Dxterm = impile(X_fd[:, 0:N - 1], u[:, f:f + N - 1])
    if D_required == True:
        M = np.dot(Sxterm, np.linalg.pinv(Dxterm))
    else:
        M = np.zeros((n + l, n + m))
        M[0:n, :] = np.dot(Sxterm[0:n], np.linalg.pinv(Dxterm))
        M[n::, 0:n] = np.dot(Sxterm[n::], np.linalg.pinv(Dxterm[0:n, :]))
    residuals = Sxterm - np.dot(M, Dxterm)
    return Ob, X_fd, M, n, residuals 
開發者ID:CPCLAB-UNIPI,項目名稱:SIPPY,代碼行數:22,代碼來源:OLSims_methods.py

示例5: do

# 需要導入模塊: from numpy import linalg [as 別名]
# 或者: from numpy.linalg import pinv [as 別名]
def do(self, a, b, tags):
        a_ginv = linalg.pinv(a)
        # `a @ a_ginv == I` does not hold if a is singular
        dot = dot_generalized
        assert_almost_equal(dot(dot(a, a_ginv), a), a, single_decimal=5, double_decimal=11)
        assert_(consistent_subclass(a_ginv, a)) 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:8,代碼來源:test_linalg.py

示例6: do

# 需要導入模塊: from numpy import linalg [as 別名]
# 或者: from numpy.linalg import pinv [as 別名]
def do(self, a, b):
        a_ginv = linalg.pinv(a)
        assert_almost_equal(dot(a, a_ginv), identity(asarray(a).shape[0]))
        assert_(imply(isinstance(a, matrix), isinstance(a_ginv, matrix))) 
開發者ID:ryfeus,項目名稱:lambda-packs,代碼行數:6,代碼來源:test_linalg.py

示例7: do

# 需要導入模塊: from numpy import linalg [as 別名]
# 或者: from numpy.linalg import pinv [as 別名]
def do(self, a, b, tags):
        a_ginv = linalg.pinv(a)
        # `a @ a_ginv == I` does not hold if a is singular
        dot = dot_generalized
        assert_almost_equal(dot(dot(a, a_ginv), a), a, single_decimal=5, double_decimal=11)
        assert_(imply(isinstance(a, matrix), isinstance(a_ginv, matrix))) 
開發者ID:birforce,項目名稱:vnpy_crypto,代碼行數:8,代碼來源:test_linalg.py

示例8: initialize

# 需要導入模塊: from numpy import linalg [as 別名]
# 或者: from numpy.linalg import pinv [as 別名]
def initialize(self):
        S = sum([np.dot(unit.X.T, unit.X) for unit in self.units])
        Y = sum([np.dot(unit.X.T, unit.Y) for unit in self.units])
        self.a = L.lstsq(S, Y, rcond=-1)[0]

        D = 0
        t = 0
        sigmasq = 0
        for unit in self.units:
            unit.r = unit.Y - np.dot(unit.X, self.a)
            if self.q > 1:
                unit.b = L.lstsq(unit.Z, unit.r, rcond=-1)[0]
            else:
                Z = unit.Z.reshape((unit.Z.shape[0], 1))
                unit.b = L.lstsq(Z, unit.r, rcond=-1)[0]

            sigmasq += (np.power(unit.Y, 2).sum() -
                        (self.a * np.dot(unit.X.T, unit.Y)).sum() -
                        (unit.b * np.dot(unit.Z.T, unit.r)).sum())
            D += np.multiply.outer(unit.b, unit.b)
            t += L.pinv(np.dot(unit.Z.T, unit.Z))

        #TODO: JP added df_resid check
        self.df_resid = (self.N - (self.m - 1) * self.q - self.p)
        sigmasq /= (self.N - (self.m - 1) * self.q - self.p)
        self.sigma = np.sqrt(sigmasq)
        self.D = (D - sigmasq * t) / self.m 
開發者ID:birforce,項目名稱:vnpy_crypto,代碼行數:29,代碼來源:mixed.py

示例9: compute_matrix

# 需要導入模塊: from numpy import linalg [as 別名]
# 或者: from numpy.linalg import pinv [as 別名]
def compute_matrix(self, *args, **kw):
        """
        Construct a contrast matrix C so that

        colspan(dot(D, C)) = colspan(dot(D, dot(pinv(D), T)))

        where pinv(D) is the generalized inverse of D=self.D=self.formula().

        If the design, self.D is already set,
        then evaldesign can be set to False.
        """

        t = copy.copy(self.term)
        t.namespace = self.formula.namespace
        T = np.transpose(np.array(t(*args, **kw)))

        if T.ndim == 1:
            T.shape = (T.shape[0], 1)

        self.T = utils.clean0(T)

        self.D = self.formula.design(*args, **kw)

        self._matrix = contrastfromcols(self.T, self.D)
        try:
            self.rank = self.matrix.shape[1]
        except:
            self.rank = 1 
開發者ID:birforce,項目名稱:vnpy_crypto,代碼行數:30,代碼來源:contrast_old.py

示例10: generalized_inverse

# 需要導入模塊: from numpy import linalg [as 別名]
# 或者: from numpy.linalg import pinv [as 別名]
def generalized_inverse(a, rcond = 1.e-10):
    return linalg.pinv(a, rcond)

# Determinant 
開發者ID:ktraunmueller,項目名稱:Computable,代碼行數:6,代碼來源:linear_algebra.py

示例11: solve

# 需要導入模塊: from numpy import linalg [as 別名]
# 或者: from numpy.linalg import pinv [as 別名]
def solve(a, b):
    """Returns the solution of A X = B."""
    try:
        return linalg.solve(a, b)
    except linalg.LinAlgError:
        return np.dot(linalg.pinv(a), b) 
開發者ID:ktraunmueller,項目名稱:Computable,代碼行數:8,代碼來源:math.py

示例12: inv

# 需要導入模塊: from numpy import linalg [as 別名]
# 或者: from numpy.linalg import pinv [as 別名]
def inv(a):
    """Returns the inverse of A."""
    try:
        return np.linalg.inv(a)
    except linalg.LinAlgError:
        return np.linalg.pinv(a) 
開發者ID:ktraunmueller,項目名稱:Computable,代碼行數:8,代碼來源:math.py


注:本文中的numpy.linalg.pinv方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。