dataset.py 文件源码

python
阅读 23 收藏 0 点赞 0 评论 0

项目:kafe 作者: dsavoiu 项目源码 文件源码
def make_from_matrix(self, cov_mat, check_singular=False):
        """
        Sets the covariance matrix manually.

        Parameters
        ----------

        **cov_mat** : numpy.matrix
            A *square*, *symmetric* (and usually *regular*) matrix.

        Keyword Arguments
        -----------------

        check_singular : boolean, optional
            Whether to force singularity check. Defaults to ``False``.
        """

        # Check matrix suitability
        _mat = np.asmatrix(cov_mat)  # cast to matrix
        _shp = _mat.shape
        if not _shp[0] == _shp[1]:   # check square shape
            raise ValueError("Failed to make ErrorSource: matrix must be "
                               "square, got shape %r" % (_shp,))
        if (_mat == _mat.T).all():  # check if symmetric
            if check_singular:
                try:
                    _mat.I  # try to invert matrix
                except LinAlgError:
                    raise ValueError("Failed to make ErrorSource: singular "
                                       "matrix!")
        else:
            raise ValueError("Failed to make ErrorSource: covariance "
                               "matrix not symmetric")

        self.error_type = 'matrix'
        self.error_value = _mat
        self.size = _shp[0]
        self.has_correlations = (np.diag(np.diag(_mat)) == _mat).all()
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号