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


Python linalg.eigvalsh方法代码示例

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


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

示例1: test_UPLO

# 需要导入模块: from numpy import linalg [as 别名]
# 或者: from numpy.linalg import eigvalsh [as 别名]
def test_UPLO(self):
        Klo = np.array([[0, 0], [1, 0]], dtype=np.double)
        Kup = np.array([[0, 1], [0, 0]], dtype=np.double)
        tgt = np.array([-1, 1], dtype=np.double)
        rtol = get_rtol(np.double)

        # Check default is 'L'
        w = np.linalg.eigvalsh(Klo)
        assert_allclose(w, tgt, rtol=rtol)
        # Check 'L'
        w = np.linalg.eigvalsh(Klo, UPLO='L')
        assert_allclose(w, tgt, rtol=rtol)
        # Check 'l'
        w = np.linalg.eigvalsh(Klo, UPLO='l')
        assert_allclose(w, tgt, rtol=rtol)
        # Check 'U'
        w = np.linalg.eigvalsh(Kup, UPLO='U')
        assert_allclose(w, tgt, rtol=rtol)
        # Check 'u'
        w = np.linalg.eigvalsh(Kup, UPLO='u')
        assert_allclose(w, tgt, rtol=rtol) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:23,代码来源:test_linalg.py

示例2: test_0_size

# 需要导入模块: from numpy import linalg [as 别名]
# 或者: from numpy.linalg import eigvalsh [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 = linalg.eigvalsh(a)
        assert_(res.dtype.type is np.float64)
        assert_equal((0, 1), res.shape)
        # This is just for documentation, it might make sense to change:
        assert_(isinstance(res, np.ndarray))

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

示例3: test_UPLO

# 需要导入模块: from numpy import linalg [as 别名]
# 或者: from numpy.linalg import eigvalsh [as 别名]
def test_UPLO(self):
        Klo = np.array([[0, 0],[1, 0]], dtype=np.double)
        Kup = np.array([[0, 1],[0, 0]], dtype=np.double)
        tgt = np.array([-1, 1], dtype=np.double)
        rtol = get_rtol(np.double)

        # Check default is 'L'
        w = np.linalg.eigvalsh(Klo)
        assert_allclose(np.sort(w), tgt, rtol=rtol)
        # Check 'L'
        w = np.linalg.eigvalsh(Klo, UPLO='L')
        assert_allclose(np.sort(w), tgt, rtol=rtol)
        # Check 'l'
        w = np.linalg.eigvalsh(Klo, UPLO='l')
        assert_allclose(np.sort(w), tgt, rtol=rtol)
        # Check 'U'
        w = np.linalg.eigvalsh(Kup, UPLO='U')
        assert_allclose(np.sort(w), tgt, rtol=rtol)
        # Check 'u'
        w = np.linalg.eigvalsh(Kup, UPLO='u')
        assert_allclose(np.sort(w), tgt, rtol=rtol) 
开发者ID:ktraunmueller,项目名称:Computable,代码行数:23,代码来源:test_linalg.py

示例4: compute_score

# 需要导入模块: from numpy import linalg [as 别名]
# 或者: from numpy.linalg import eigvalsh [as 别名]
def compute_score(weights, model_num, scoreFunc, derivDaggerDerivList,
                  forceIndices, forceScore,
                  nGaugeParams, opPenalty, germLengths, l1Penalty=1e-2,
                  scoreDict=None):
    """Returns a germ set "score" in which smaller is better.  Also returns
    intentionally bad score (`forceScore`) if `weights` is zero on any of
    the "forced" germs (i.e. at any index in `forcedIndices`).
    This function is included for use by :func:`optimize_integer_germs_slack`,
    but is not convenient for just computing the score of a germ set. For that,
    use :func:`calculate_germset_score`.
    """
    if forceIndices is not None and _np.any(weights[forceIndices] <= 0):
        score = forceScore
    else:
        #combinedDDD = _np.einsum('i,ijk', weights,
        #                         derivDaggerDerivList[model_num])
        combinedDDD = _np.squeeze(
            _np.tensordot(_np.expand_dims(weights, 1),
                          derivDaggerDerivList[model_num], (0, 0)))
        assert len(combinedDDD.shape) == 2

        sortedEigenvals = _np.sort(_np.real(_nla.eigvalsh(combinedDDD)))
        observableEigenvals = sortedEigenvals[nGaugeParams:]
        score = (_scoring.list_score(observableEigenvals, scoreFunc)
                 + l1Penalty * _np.sum(weights)
                 + opPenalty * _np.dot(germLengths, weights))
    if scoreDict is not None:
        # Side effect: calling compute_score caches result in scoreDict
        scoreDict[model_num, tuple(weights)] = score
    return score 
开发者ID:pyGSTio,项目名称:pyGSTi,代码行数:32,代码来源:germselection.py

示例5: sq_sing_vals_from_deriv

# 需要导入模块: from numpy import linalg [as 别名]
# 或者: from numpy.linalg import eigvalsh [as 别名]
def sq_sing_vals_from_deriv(deriv, weights=None):
    """Calculate the squared singulare values of the Jacobian of the germ set.
    Parameters
    ----------
    deriv : numpy.array
        Array of shape ``(nGerms, flattened_op_dim, vec_model_dim)``. Each
        sub-array corresponding to an individual germ is the Jacobian of the
        vectorized gate representation of that germ raised to some power with
        respect to the model parameters, normalized by dividing by the length
        of each germ after repetition.
    weights : numpy.array
        Array of length ``nGerms``, giving the relative contributions of each
        individual germ's Jacobian to the combined Jacobian (which is calculated
        as a convex combination of the individual Jacobians).
    Returns
    -------
    numpy.array
        The sorted squared singular values of the combined Jacobian of the germ
        set.
    """
    # shape (nGerms, vec_model_dim, vec_model_dim)
    derivDaggerDeriv = _np.einsum('ijk,ijl->ikl', _np.conjugate(deriv), deriv)
    # awkward to convert to tensordot, so leave as einsum

    # Take the average of the D^dagger*D/L^2 matrices associated with each germ
    # with optional weights.
    combinedDDD = _np.average(derivDaggerDeriv, weights=weights, axis=0)
    sortedEigenvals = _np.sort(_np.real(_nla.eigvalsh(combinedDDD)))

    return sortedEigenvals 
开发者ID:pyGSTio,项目名称:pyGSTi,代码行数:32,代码来源:germselection.py

示例6: do

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

        ev2 = linalg.eigvalsh(a, 'U')
        assert_allclose(ev2, evalues, rtol=get_rtol(ev.dtype)) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:12,代码来源:test_linalg.py

示例7: test_types

# 需要导入模块: from numpy import linalg [as 别名]
# 或者: from numpy.linalg import eigvalsh [as 别名]
def test_types(self, dtype):
        x = np.array([[1, 0.5], [0.5, 1]], dtype=dtype)
        w = np.linalg.eigvalsh(x)
        assert_equal(w.dtype, get_real_dtype(dtype)) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:6,代码来源:test_linalg.py

示例8: test_invalid

# 需要导入模块: from numpy import linalg [as 别名]
# 或者: from numpy.linalg import eigvalsh [as 别名]
def test_invalid(self):
        x = np.array([[1, 0.5], [0.5, 1]], dtype=np.float32)
        assert_raises(ValueError, np.linalg.eigvalsh, x, UPLO="lrong")
        assert_raises(ValueError, np.linalg.eigvalsh, x, "lower")
        assert_raises(ValueError, np.linalg.eigvalsh, x, "upper") 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:7,代码来源:test_linalg.py

示例9: do

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

        ev2 = linalg.eigvalsh(a, 'U')
        assert_allclose(ev2, evalues, rtol=get_rtol(ev.dtype)) 
开发者ID:ryfeus,项目名称:lambda-packs,代码行数:12,代码来源:test_linalg.py

示例10: test_types

# 需要导入模块: from numpy import linalg [as 别名]
# 或者: from numpy.linalg import eigvalsh [as 别名]
def test_types(self):
        def check(dtype):
            x = np.array([[1, 0.5], [0.5, 1]], dtype=dtype)
            w = np.linalg.eigvalsh(x)
            assert_equal(w.dtype, get_real_dtype(dtype))
        for dtype in [single, double, csingle, cdouble]:
            yield check, dtype 
开发者ID:ryfeus,项目名称:lambda-packs,代码行数:9,代码来源:test_linalg.py


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