当前位置: 首页>>代码示例>>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;未经允许,请勿转载。