当前位置: 首页>>代码示例>>Python>>正文


Python linalg.eig方法代码示例

本文整理汇总了Python中numpy.linalg.eig方法的典型用法代码示例。如果您正苦于以下问题:Python linalg.eig方法的具体用法?Python linalg.eig怎么用?Python linalg.eig使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在numpy.linalg的用法示例。


在下文中一共展示了linalg.eig方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: getPrincipalAxes

# 需要导入模块: from numpy import linalg [as 别名]
# 或者: from numpy.linalg import eig [as 别名]
def getPrincipalAxes(self):
        X = self.VPos - self.getCentroid()
        XTX = (X.T).dot(X)
        (lambdas, axes) = linalg.eig(XTX)
        #Put the eigenvalues in decreasing order
        idx = lambdas.argsort()[::-1]
        lambdas = lambdas[idx]
        axes = axes[:, idx]
        T = X.dot(axes)
        maxProj = T.max(0)
        minProj = T.min(0)
        axes = axes.T #Put each axis on each row to be consistent with everything else
        return (axes, maxProj, minProj)        
    
    #Delete the parts of the mesh below "plane".  If fillHoles
    #is true, plug up the holes that result from the cut 
开发者ID:bmershon,项目名称:laplacian-meshes,代码行数:18,代码来源:PolyMesh.py

示例2: test_0_size

# 需要导入模块: from numpy import linalg [as 别名]
# 或者: from numpy.linalg import eig [as 别名]
def test_0_size(self):
        # Check that all kinds of 0-sized arrays work
        class ArraySubclass(np.ndarray):
            pass
        a = np.zeros((0, 1, 1), dtype=np.int_).view(ArraySubclass)
        res, res_v = linalg.eig(a)
        assert_(res_v.dtype.type is np.float64)
        assert_(res.dtype.type is np.float64)
        assert_equal(a.shape, res_v.shape)
        assert_equal((0, 1), res.shape)
        # This is just for documentation, it might make sense to change:
        assert_(isinstance(a, np.ndarray))

        a = np.zeros((0, 0), dtype=np.complex64).view(ArraySubclass)
        res, res_v = linalg.eig(a)
        assert_(res_v.dtype.type is np.complex64)
        assert_(res.dtype.type is np.complex64)
        assert_equal(a.shape, res_v.shape)
        assert_equal((0,), res.shape)
        # This is just for documentation, it might make sense to change:
        assert_(isinstance(a, np.ndarray)) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:23,代码来源:test_linalg.py

示例3: test_eig_build

# 需要导入模块: from numpy import linalg [as 别名]
# 或者: from numpy.linalg import eig [as 别名]
def test_eig_build(self):
        # Ticket #652
        rva = array([1.03221168e+02 + 0.j,
                     -1.91843603e+01 + 0.j,
                     -6.04004526e-01 + 15.84422474j,
                     -6.04004526e-01 - 15.84422474j,
                     -1.13692929e+01 + 0.j,
                     -6.57612485e-01 + 10.41755503j,
                     -6.57612485e-01 - 10.41755503j,
                     1.82126812e+01 + 0.j,
                     1.06011014e+01 + 0.j,
                     7.80732773e+00 + 0.j,
                     -7.65390898e-01 + 0.j,
                     1.51971555e-15 + 0.j,
                     -1.51308713e-15 + 0.j])
        a = arange(13 * 13, dtype=float64)
        a.shape = (13, 13)
        a = a % 17
        va, ve = linalg.eig(a)
        va.sort()
        rva.sort()
        assert_array_almost_equal(va, rva) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:24,代码来源:test_regression.py

示例4: do

# 需要导入模块: from numpy import linalg [as 别名]
# 或者: from numpy.linalg import eig [as 别名]
def do(self, a, b):
        # note that eigenvalue arrays returned by eig must be sorted since
        # their order isn't guaranteed.
        ev, evc = linalg.eigh(a)
        evalues, evectors = linalg.eig(a)
        evalues.sort(axis=-1)
        assert_almost_equal(ev, evalues)

        assert_allclose(dot_generalized(a, evc),
                        np.asarray(ev)[..., None, :] * np.asarray(evc),
                        rtol=get_rtol(ev.dtype))

        ev2, evc2 = linalg.eigh(a, 'U')
        assert_almost_equal(ev2, evalues)

        assert_allclose(dot_generalized(a, evc2),
                        np.asarray(ev2)[..., None, :] * np.asarray(evc2),
                        rtol=get_rtol(ev.dtype), err_msg=repr(a)) 
开发者ID:ryfeus,项目名称:lambda-packs,代码行数:20,代码来源:test_linalg.py

示例5: test_eig_build

# 需要导入模块: from numpy import linalg [as 别名]
# 或者: from numpy.linalg import eig [as 别名]
def test_eig_build(self, level = rlevel):
        """Ticket #652"""
        rva = array([1.03221168e+02 +0.j,
               -1.91843603e+01 +0.j,
               -6.04004526e-01+15.84422474j,
               -6.04004526e-01-15.84422474j,
               -1.13692929e+01 +0.j,
               -6.57612485e-01+10.41755503j,
               -6.57612485e-01-10.41755503j,
               1.82126812e+01 +0.j,
               1.06011014e+01 +0.j,
               7.80732773e+00 +0.j,
               -7.65390898e-01 +0.j,
               1.51971555e-15 +0.j,
               -1.51308713e-15 +0.j])
        a = arange(13*13, dtype = float64)
        a.shape = (13, 13)
        a = a%17
        va, ve = linalg.eig(a)
        va.sort()
        rva.sort()
        assert_array_almost_equal(va, rva) 
开发者ID:ktraunmueller,项目名称:Computable,代码行数:24,代码来源:test_regression.py

示例6: spectral_radius

# 需要导入模块: from numpy import linalg [as 别名]
# 或者: from numpy.linalg import eig [as 别名]
def spectral_radius(self):
        """Compute the spectral radius of the matrix of l1 norm of Hawkes
        kernels.

        Notes
        -----
        If the spectral radius is greater that 1, the hawkes process is not
        stable
        """

        get_norm = np.vectorize(lambda kernel: kernel.get_norm())
        norms = get_norm(self.kernels)

        # It might happens that eig returns a complex number but with a
        # negligible complex part, in this case we keep only the real part
        spectral_radius = max(eig(norms)[0])
        spectral_radius = np.real_if_close(spectral_radius)
        return spectral_radius 
开发者ID:X-DataInitiative,项目名称:tick,代码行数:20,代码来源:simu_hawkes.py

示例7: lnc_correction

# 需要导入模块: from numpy import linalg [as 别名]
# 或者: from numpy.linalg import eig [as 别名]
def lnc_correction(tree, points, k, alpha):
    e = 0
    n_sample = points.shape[0]
    for point in points:
        # Find k-nearest neighbors in joint space, p=inf means max norm
        knn = tree.query(point[None, :], k=k+1, return_distance=False)[0]
        knn_points = points[knn]
        # Substract mean of k-nearest neighbor points
        knn_points = knn_points - knn_points[0]
        # Calculate covariance matrix of k-nearest neighbor points, obtain eigen vectors
        covr = knn_points.T @ knn_points / k
        _, v = la.eig(covr)
        # Calculate PCA-bounding box using eigen vectors
        V_rect = np.log(np.abs(knn_points @ v).max(axis=0)).sum()
        # Calculate the volume of original box
        log_knn_dist = np.log(np.abs(knn_points).max(axis=0)).sum()

        # Perform local non-uniformity checking and update correction term
        if V_rect < log_knn_dist + np.log(alpha):
            e += (log_knn_dist - V_rect) / n_sample
    return e


# DISCRETE ESTIMATORS 
开发者ID:gregversteeg,项目名称:NPEET,代码行数:26,代码来源:entropy_estimators.py

示例8: _get_top_eigen_vectors

# 需要导入模块: from numpy import linalg [as 别名]
# 或者: from numpy.linalg import eig [as 别名]
def _get_top_eigen_vectors(data: ndarray, n_components: int) -> ndarray:
        """The eigen vectors according to top n_components large eigen values.

        Arguments:
            data {ndarray} -- Training data.
            n_components {int} -- Number of components to keep.

        Returns:
            ndarray -- eigen vectors with shape(n_cols, n_components).
        """

        # Calculate eigen values and eigen vectors of covariance matrix.
        eigen_values, eigen_vectors = eig(data)
        # The indexes of top n_components large eigen values.
        _indexes = heapq.nlargest(n_components, enumerate(eigen_values),
                                  key=lambda x: x[1])
        indexes = [x[0] for x in _indexes]
        return eigen_vectors[:, indexes] 
开发者ID:tushushu,项目名称:imylu,代码行数:20,代码来源:pca.py

示例9: test_eig_build

# 需要导入模块: from numpy import linalg [as 别名]
# 或者: from numpy.linalg import eig [as 别名]
def test_eig_build(self, level=rlevel):
        # Ticket #652
        rva = array([1.03221168e+02 + 0.j,
                     -1.91843603e+01 + 0.j,
                     -6.04004526e-01 + 15.84422474j,
                     -6.04004526e-01 - 15.84422474j,
                     -1.13692929e+01 + 0.j,
                     -6.57612485e-01 + 10.41755503j,
                     -6.57612485e-01 - 10.41755503j,
                     1.82126812e+01 + 0.j,
                     1.06011014e+01 + 0.j,
                     7.80732773e+00 + 0.j,
                     -7.65390898e-01 + 0.j,
                     1.51971555e-15 + 0.j,
                     -1.51308713e-15 + 0.j])
        a = arange(13 * 13, dtype=float64)
        a.shape = (13, 13)
        a = a % 17
        va, ve = linalg.eig(a)
        va.sort()
        rva.sort()
        assert_array_almost_equal(va, rva) 
开发者ID:awslabs,项目名称:mxnet-lambda,代码行数:24,代码来源:test_regression.py

示例10: _fit_ellipse_to_xy_points

# 需要导入模块: from numpy import linalg [as 别名]
# 或者: from numpy.linalg import eig [as 别名]
def _fit_ellipse_to_xy_points(x, y):
    """Fit an ellipse to a list of x and y points.

    Parameters
    ----------
    x, y : NumPy 2D array

    Returns
    -------
    ellipse_parameters : NumPy array

    """
    xx = x * x
    yy = y * y
    xy = x * y
    ones = np.ones_like(x)
    D = np.vstack((xx, xy, yy, x, y, ones))
    S = np.dot(D, D.T)
    C = np.zeros((6, 6))
    C[0, 2], C[2, 0] = 2, 2
    C[1, 1] = -1
    A, B = la.eig(np.dot(la.inv(S), C))
    i = np.argmax(np.abs(A))
    g = B[:, i]
    return g 
开发者ID:pyxem,项目名称:pyxem,代码行数:27,代码来源:radial_utils.py

示例11: do

# 需要导入模块: from numpy import linalg [as 别名]
# 或者: from numpy.linalg import eig [as 别名]
def do(self, a, b):
        # note that eigenvalue arrays must be sorted since
        # their order isn't guaranteed.
        ev, evc = linalg.eigh(a)
        evalues, evectors = linalg.eig(a)
        ev.sort(axis=-1)
        evalues.sort(axis=-1)
        assert_almost_equal(ev, evalues)

        assert_allclose(dot_generalized(a, evc),
                        np.asarray(ev)[...,None,:] * np.asarray(evc),
                        rtol=get_rtol(ev.dtype))

        ev2, evc2 = linalg.eigh(a, 'U')
        ev2.sort(axis=-1)
        assert_almost_equal(ev2, evalues)

        assert_allclose(dot_generalized(a, evc2),
                        np.asarray(ev2)[...,None,:] * np.asarray(evc2),
                        rtol=get_rtol(ev.dtype), err_msg=repr(a)) 
开发者ID:pfchai,项目名称:ImageFusion,代码行数:22,代码来源:test_linalg.py

示例12: B2q

# 需要导入模块: from numpy import linalg [as 别名]
# 或者: from numpy.linalg import eig [as 别名]
def B2q(B, tol=None):
    ''' Estimate q vector from input B matrix `B`

    We assume the input `B` is symmetric positive definite.

    Because the solution is a square root, the sign of the returned
    vector is arbitrary.  We set the vector to have a positive x
    component by convention.

    Parameters
    ----------
    B : (3,3) array-like
       B matrix - symmetric. We do not check the symmetry.
    tol : None or float
       absolute tolerance below which to consider eigenvalues of the B
       matrix to be small enough not to worry about them being negative,
       in check for positive semi-definite-ness.  None (default) results
       in a fairly tight numerical threshold proportional the maximum
       eigenvalue

    Returns
    -------
    q : (3,) vector
       Estimated q vector from B matrix `B`
    '''
    B = np.asarray(B)
    w, v = npl.eig(B)
    if tol is None:
        tol = np.abs(w.max() * np.finfo(w.dtype).eps)
    non_trivial = np.abs(w) > tol
    if np.any(w[non_trivial] < 0):
        raise ValueError('B not positive semi-definite')
    inds = np.argsort(w)[::-1]
    max_ind = inds[0]
    vector = v[:,max_ind]
    # because the factor is a sqrt, the sign of the vector is arbitrary.
    # We arbitrarily set it to have a positive x value.
    if vector[0] < 0:
        vector *= -1
    return vector * w[max_ind] 
开发者ID:ME-ICA,项目名称:me-ica,代码行数:42,代码来源:dwiparams.py

示例13: do

# 需要导入模块: from numpy import linalg [as 别名]
# 或者: from numpy.linalg import eig [as 别名]
def do(self, a, b, tags):
        ev = linalg.eigvals(a)
        evalues, evectors = linalg.eig(a)
        assert_almost_equal(ev, evalues) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:6,代码来源:test_linalg.py

示例14: test_types

# 需要导入模块: from numpy import linalg [as 别名]
# 或者: from numpy.linalg import eig [as 别名]
def test_types(self, dtype):
        x = np.array([[1, 0.5], [0.5, 1]], dtype=dtype)
        w, v = np.linalg.eig(x)
        assert_equal(w.dtype, dtype)
        assert_equal(v.dtype, dtype)

        x = np.array([[1, 0.5], [-1, 1]], dtype=dtype)
        w, v = np.linalg.eig(x)
        assert_equal(w.dtype, get_complex_dtype(dtype))
        assert_equal(v.dtype, get_complex_dtype(dtype)) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:12,代码来源:test_linalg.py

示例15: solve_spectral

# 需要导入模块: from numpy import linalg [as 别名]
# 或者: from numpy.linalg import eig [as 别名]
def solve_spectral(prob, *args, **kwargs):
    """Solve the spectral relaxation with lambda = 1.
    """

    # TODO: do this efficiently without SDP lifting

    # lifted variables and semidefinite constraint
    X = cvx.Semidef(prob.n + 1)

    W = prob.f0.homogeneous_form()
    rel_obj = cvx.Minimize(cvx.sum_entries(cvx.mul_elemwise(W, X)))

    W1 = sum([f.homogeneous_form() for f in prob.fs if f.relop == '<='])
    W2 = sum([f.homogeneous_form() for f in prob.fs if f.relop == '=='])

    rel_prob = cvx.Problem(
        rel_obj,
        [
            cvx.sum_entries(cvx.mul_elemwise(W1, X)) <= 0,
            cvx.sum_entries(cvx.mul_elemwise(W2, X)) == 0,
            X[-1, -1] == 1
        ]
    )
    rel_prob.solve(*args, **kwargs)

    if rel_prob.status not in [cvx.OPTIMAL, cvx.OPTIMAL_INACCURATE]:
        raise Exception("Relaxation problem status: %s" % rel_prob.status)

    (w, v) = LA.eig(X.value)
    return np.sqrt(np.max(w))*np.asarray(v[:-1, np.argmax(w)]).flatten(), rel_prob.value 
开发者ID:cvxgrp,项目名称:qcqp,代码行数:32,代码来源:qcqp.py


注:本文中的numpy.linalg.eig方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。