python类seterr()的实例源码

testutil.py 文件源码 项目:treecat 作者: posterior 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def numpy_seterr():
    np.seterr(divide='raise', invalid='raise')
blending.py 文件源码 项目:uchroma 作者: cyanogen 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def _compose_alpha(img_in, img_layer, opacity: float=1.0):
    """
    Calculate alpha composition ratio between two images.
    """
    comp_alpha = np.minimum(img_in[:, :, 3], img_layer[:, :, 3]) * opacity
    new_alpha = img_in[:, :, 3] + (1.0 - img_in[:, :, 3]) * comp_alpha
    np.seterr(divide='ignore', invalid='ignore')
    ratio = comp_alpha / new_alpha
    ratio[ratio == np.NAN] = 0.0
    return ratio
mixedvine.py 文件源码 项目:mixedvines 作者: asnelt 项目源码 文件源码 阅读 36 收藏 0 点赞 0 评论 0
def _marginal_densities(self, samples):
            '''
            Evaluate marginal densities and cumulative distribution functions.

            Parameters
            ----------
            samples : array_like
                n-by-d matrix of samples where n is the number of samples and d
                is the number of marginals.

            Returns
            -------
            dout : dictionary
                The densities and cumulative distribution functions.  Keys:
                `logpdf`: Equal to first element of `logp`.
                'logp': Log of the probability density function.
                'cdfp': Upper cumulative distribution functions.
                'cdfm': Lower cumulative distribution functions.
                'is_continuous': List of booleans where element i is `True` if
                output element i is continuous.
            '''
            logp = np.zeros(samples.shape)
            cdfp = np.zeros(samples.shape)
            cdfm = np.zeros(samples.shape)
            is_continuous = np.zeros(len(self.marginals), dtype=bool)
            for k, marginal in enumerate(self.marginals):
                is_continuous[k] = marginal.is_continuous
                cdfp[:, k] = marginal.cdf(samples[:, k])
                if marginal.is_continuous:
                    logp[:, k] = marginal.logpdf(samples[:, k])
                else:
                    cdfm[:, k] = marginal.cdf(samples[:, k] - 1)
                    old_settings = np.seterr(divide='ignore')
                    logp[:, k] = np.log(np.maximum(0, cdfp[:, k] - cdfm[:, k]))
                    np.seterr(**old_settings)
            logpdf = logp[:, self.output_layer.input_indices[0][0]]
            dout = {'logpdf': logpdf, 'logp': logp, 'cdfp': cdfp, 'cdfm': cdfm,
                    'is_continuous': is_continuous}
            return dout
copula.py 文件源码 项目:mixedvines 作者: asnelt 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def logcdf(self, samples):
        '''
        Calculates the log of the cumulative distribution function.

        Parameters
        ----------
        samples : array_like
            n-by-2 matrix of samples where n is the number of samples.

        Returns
        -------
        vals : ndarray
            Log of the cumulative distribution function evaluated at `samples`.
        '''
        samples = np.copy(np.asarray(samples))
        samples = self.__crop_input(samples)
        samples = self.__rotate_input(samples)
        vals = self._logcdf(samples)
        # Transform according to rotation, but take `__rotate_input` into
        # account.
        if self.rotation == '90°':
            old_settings = np.seterr(divide='ignore')
            vals = np.log(np.maximum(0, samples[:, 0] - np.exp(vals)))
            np.seterr(**old_settings)
        elif self.rotation == '180°':
            old_settings = np.seterr(divide='ignore')
            vals = np.log(np.maximum(0,
                                     (1 - samples[:, 0]) + (1 - samples[:, 1])
                                     - 1.0 + np.exp(vals)))
            np.seterr(**old_settings)
        elif self.rotation == '270°':
            old_settings = np.seterr(divide='ignore')
            vals = np.log(np.maximum(0, samples[:, 1] - np.exp(vals)))
            np.seterr(**old_settings)
        return vals
copula.py 文件源码 项目:mixedvines 作者: asnelt 项目源码 文件源码 阅读 52 收藏 0 点赞 0 评论 0
def _logcdf(self, samples):
        old_settings = np.seterr(divide='ignore')
        vals = np.sum(np.log(samples), axis=1)
        np.seterr(**old_settings)
        return vals
copula.py 文件源码 项目:mixedvines 作者: asnelt 项目源码 文件源码 阅读 36 收藏 0 点赞 0 评论 0
def _logcdf(self, samples):
        if self.theta == 0:
            vals = np.sum(np.log(samples), axis=1)
        else:
            old_settings = np.seterr(divide='ignore')
            vals = (-1 / self.theta) \
                * np.log(np.maximum(samples[:, 0]**(-self.theta)
                                    + samples[:, 1]**(-self.theta) - 1, 0))
            np.seterr(**old_settings)
        return vals
Decoder.py 文件源码 项目:Poccala 作者: Byshx 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def viterbi(self, data, data_time, unit_train_time=unit_time):
        """
        viterbi???
        :param data: ????(??)
        :param data_time: ????????
        :param unit_train_time: ????????
        :return: 
        """

        def info(p):
            """???????"""
            point_ = p.max()
            mark_ = np.where(p == point_)
            mark_state = mark_[0][0]
            return point_, mark_state

        self.__cal_data(data, data_time, unit_train_time)
        complex_states, complex_observation, complex_A, complex_B, complex_? = self.__embedded_list
        '''????'''
        np.seterr(divide='ignore')
        if self.__p_list is None:
            self.__p_list = np.log(complex_?) + complex_B[:, 0]
            point, mark = info(self.__p_list)
            self.score += point
            self.mark = mark
            if mark == len(complex_states) - 1:
                return True
        else:
            p_ = np.zeros_like(self.__p_list)
            for j in range(len(complex_states)):
                tmp = self.__p_list + np.log(complex_A[:, j])
                max_p = tmp.max()
                p_[j] = max_p
            self.__p_list = p_ + complex_B[:, 0]
            point, mark = info(self.__p_list)
            self.score += point
            self.mark = mark
            if len(complex_states) - mark <= 1:
                return True
test_numeric.py 文件源码 项目:radar 作者: amoose136 项目源码 文件源码 阅读 29 收藏 0 点赞 0 评论 0
def test_set(self):
        with np.errstate():
            err = np.seterr()
            old = np.seterr(divide='print')
            self.assertTrue(err == old)
            new = np.seterr()
            self.assertTrue(new['divide'] == 'print')
            np.seterr(over='raise')
            self.assertTrue(np.geterr()['over'] == 'raise')
            self.assertTrue(new['divide'] == 'print')
            np.seterr(**old)
            self.assertTrue(np.geterr() == old)
test_numeric.py 文件源码 项目:radar 作者: amoose136 项目源码 文件源码 阅读 45 收藏 0 点赞 0 评论 0
def test_divide_err(self):
        with np.errstate(divide='raise'):
            try:
                np.array([1.]) / np.array([0.])
            except FloatingPointError:
                pass
            else:
                self.fail()
            np.seterr(divide='ignore')
            np.array([1.]) / np.array([0.])
test_numeric.py 文件源码 项目:radar 作者: amoose136 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def setUp(self):
        self.olderr = np.seterr(invalid='ignore')
test_numeric.py 文件源码 项目:radar 作者: amoose136 项目源码 文件源码 阅读 35 收藏 0 点赞 0 评论 0
def tearDown(self):
        np.seterr(**self.olderr)
test_umath.py 文件源码 项目:radar 作者: amoose136 项目源码 文件源码 阅读 37 收藏 0 点赞 0 评论 0
def setUp(self):
        self.olderr = np.seterr(invalid='ignore')
test_umath_complex.py 文件源码 项目:radar 作者: amoose136 项目源码 文件源码 阅读 30 收藏 0 点赞 0 评论 0
def setUp(self):
        self.olderr = np.seterr(invalid='ignore')
test_umath_complex.py 文件源码 项目:radar 作者: amoose136 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def tearDown(self):
        np.seterr(**self.olderr)
test_umath_complex.py 文件源码 项目:radar 作者: amoose136 项目源码 文件源码 阅读 36 收藏 0 点赞 0 评论 0
def setUp(self):
        self.olderr = np.seterr(invalid='ignore')
test_umath_complex.py 文件源码 项目:radar 作者: amoose136 项目源码 文件源码 阅读 37 收藏 0 点赞 0 评论 0
def tearDown(self):
        np.seterr(**self.olderr)
test_core.py 文件源码 项目:radar 作者: amoose136 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def setUp(self):
        # Base data definition.
        self.d = (array([1.0, 0, -1, pi / 2] * 2, mask=[0, 1] + [0] * 6),
                  array([1.0, 0, -1, pi / 2] * 2, mask=[1, 0] + [0] * 6),)
        self.err_status = np.geterr()
        np.seterr(divide='ignore', invalid='ignore')
test_core.py 文件源码 项目:radar 作者: amoose136 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def tearDown(self):
        np.seterr(**self.err_status)
test_old_ma.py 文件源码 项目:radar 作者: amoose136 项目源码 文件源码 阅读 34 收藏 0 点赞 0 评论 0
def test_testUfuncRegression(self):
        f_invalid_ignore = [
            'sqrt', 'arctanh', 'arcsin', 'arccos',
            'arccosh', 'arctanh', 'log', 'log10', 'divide',
            'true_divide', 'floor_divide', 'remainder', 'fmod']
        for f in ['sqrt', 'log', 'log10', 'exp', 'conjugate',
                  'sin', 'cos', 'tan',
                  'arcsin', 'arccos', 'arctan',
                  'sinh', 'cosh', 'tanh',
                  'arcsinh',
                  'arccosh',
                  'arctanh',
                  'absolute', 'fabs', 'negative',
                  'floor', 'ceil',
                  'logical_not',
                  'add', 'subtract', 'multiply',
                  'divide', 'true_divide', 'floor_divide',
                  'remainder', 'fmod', 'hypot', 'arctan2',
                  'equal', 'not_equal', 'less_equal', 'greater_equal',
                  'less', 'greater',
                  'logical_and', 'logical_or', 'logical_xor']:
            try:
                uf = getattr(umath, f)
            except AttributeError:
                uf = getattr(fromnumeric, f)
            mf = getattr(np.ma, f)
            args = self.d[:uf.nin]
            with np.errstate():
                if f in f_invalid_ignore:
                    np.seterr(invalid='ignore')
                if f in ['arctanh', 'log', 'log10']:
                    np.seterr(divide='ignore')
                ur = uf(*args)
                mr = mf(*args)
            self.assertTrue(eq(ur.filled(0), mr.filled(0), f))
            self.assertTrue(eqmask(ur.mask, mr.mask))
astrom_common.py 文件源码 项目:astromalign 作者: dstndstn 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def set_fp_err():
    #np.seterr(all='raise')
    np.seterr(all='warn')


问题


面经


文章

微信
公众号

扫码关注公众号