python类erf()的实例源码

Util.py 文件源码 项目:qfrm 作者: pjgranahan 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
def norm_cdf(x, mu=0, sigma=1):
        """

        Parameters
        ----------
        x :
        mu : float
            distribution's mean
        sigma : float
            distribution's standard deviation

        Returns
        -------
        float
            pdf or cdf value, depending on input flag ``f``

        Notes
        -----
        http://stackoverflow.com/questions/809362/how-to-calculate-cumulative-normal-distribution-in-python

        Examples
        --------
        Compares total absolute error for 100 values

        >>> from scipy.stats import norm
        >>> sum( [abs(Util.norm_cdf(x) - norm.cdf(x)) for x in range(100)])
        3.3306690738754696e-16
        """

        y = 0.5 * (1 - math.erf(-(x - mu)/(sigma * math.sqrt(2.0))))
        if y > 1: y = 1
        return y
Probability.py 文件源码 项目:Data-Science 作者: titu1994 项目源码 文件源码 阅读 32 收藏 0 点赞 0 评论 0
def normalCDF(x, mu = 0, sigma = 1.0):
    return (1 + math.erf((x - mu) / math.sqrt(2) / sigma)) / 2
predict_obs_cartpole.py 文件源码 项目:gym-adv 作者: lerrel 项目源码 文件源码 阅读 35 收藏 0 点赞 0 评论 0
def _step(self, action):
        # the first element of action is the actual current action
        current_action = action[0]

        observation, reward, done, info = self.cartpole._step(current_action)

        if not done:
            # We add the newly predicted observations to the list before checking predictions
            # in order to give the agent a chance to predict the observations that they
            # are going to get _this_ round.
            self.predicted_observations.append(action[1:])

            if self.iteration > TIME_BEFORE_BONUS_ALLOWED:
                for i in xrange(min(NUM_PREDICTED_OBSERVATIONS, len(self.predicted_observations))):
                    l2dist = np.sqrt(np.sum(np.square(np.subtract(
                        self.predicted_observations[-(i + 1)][i],
                        observation
                    ))))

                    bonus = CORRECT_PREDICTION_BONUS * (1 - math.erf(l2dist))

                    reward += bonus

            self.iteration += 1

        return observation, reward, done, info
bs_erf_naive.py 文件源码 项目:BlackScholes_bench 作者: IntelPython 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
def black_scholes ( nopt, price, strike, t, rate, vol, call, put ):
    mr = -rate
    sig_sig_two = vol * vol * 2

    for i in range(nopt):
        P = float( price [i] )
        S = strike [i]
        T = t [i]

        a = log(P / S)
        b = T * mr

        z = T * sig_sig_two
        c = 0.25 * z
        y = invsqrt(z)

        w1 = (a - b + c) * y
        w2 = (a - b - c) * y

        d1 = 0.5 + 0.5 * erf(w1)
        d2 = 0.5 + 0.5 * erf(w2)

        Se = exp(b) * S

        call [i] = P * d1 - Se * d2
        put [i] = call [i] - P + Se
bs_erf_numba_jit.py 文件源码 项目:BlackScholes_bench 作者: IntelPython 项目源码 文件源码 阅读 18 收藏 0 点赞 0 评论 0
def black_scholes( nopt, price, strike, t, rate, vol, call, put):
    mr = -rate
    sig_sig_two = vol * vol * 2

    for i in range(nopt):
        P = float( price[i] )
        S = strike [i]
        T = t [i]

        a = log(P / S)
        b = T * mr

        z = T * sig_sig_two
        c = 0.25 * z
        y = 1./sqrt(z)

        w1 = (a - b + c) * y 
        w2 = (a - b - c) * y

        d1 = 0.5 + 0.5 * erf(w1)
        d2 = 0.5 + 0.5 * erf(w2)

        Se = exp(b) * S

        call [i] = P * d1 - Se * d2
        put [i] = call [i] - P + Se
day5_normal1.py 文件源码 项目:HackerRank_Python 作者: csixteen 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
def F(x, u, std_dev):
    return (1.0 + erf((x-u) / (std_dev * sqrt(2.0)))) / 2.0
day5_normal2.py 文件源码 项目:HackerRank_Python 作者: csixteen 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def F(x, u, std_dev):
    return (1.0 + erf((x-u) / (std_dev * sqrt(2.0)))) / 2.0
day6_central_limit_theorem3.py 文件源码 项目:HackerRank_Python 作者: csixteen 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def F(x, u, std_dev):
    return 0.5*(1 + erf((x-u)/(std_dev*(2**0.5))))
Ptw.py 文件源码 项目:F_UNCLE 作者: fraserphysics 项目源码 文件源码 阅读 16 收藏 0 点赞 0 评论 0
def __call__(self, temp, strain_rate, material, **overrides):
        """Solves for the yield stress and flow stress at the given condition

        Args:
           temp(float): Temperature, in degrees Kelvin
       strain_rate(float): Strain rate, in sec**-1
       material(str): Key for material type
        Keyword Args:
           **overrides(dict): Passed as a chain of keyword arguments. These
                              arguments override any material property

        Return:
           flow_stress(float): Flow stress in ??Pa??
           yield_stress(float): Yield stress in ??Pa??

        """

        g_modu, t_norm, psi_norm = self.__pre__(temp, strain_rate, material,
                                                **overrides)

        s_o = self.get_option('s_o')
        s_inf = self.get_option('s_inf')
        kappa = self.get_option('kappa')
        beta = self.get_option('beta')
        y_o = self.get_option('y_o')
        y_inf = self.get_option('y_inf')
        y_1 = self.get_option('y_1')
        y_2 = self.get_option('y_2')

        if psi_norm == 0.0:
            erf_psi_norm = 0.0
        else:
            erf_psi_norm = erf(kappa * t_norm * log(psi_norm**(-1)))
        # end

        glide_flow_stress = s_o - (s_o - s_inf) * erf_psi_norm

        shock_flow_stress = s_o * psi_norm**beta
        glide_yield_stress = y_o - (y_o - y_inf) * erf_psi_norm

        shock_yield_stress = y_1 * psi_norm**y_2

        flow_stress = max((glide_flow_stress, shock_flow_stress))
        yield_stress = max((glide_yield_stress,
                            min((shock_yield_stress, shock_flow_stress))))

        flow_stress *= g_modu
        yield_stress *= g_modu

        return flow_stress, yield_stress


问题


面经


文章

微信
公众号

扫码关注公众号