python类erf()的实例源码

statfn.py 文件源码 项目:necrobot 作者: incnone 项目源码 文件源码 阅读 28 收藏 0 点赞 0 评论 0
def get_winrates(user_id_1: int, user_id_2: int, ndchar: NDChar, amplified: bool) -> tuple or None:
    stats_1 = await get_character_stats(user_id_1, ndchar, amplified)
    stats_2 = await get_character_stats(user_id_2, ndchar, amplified)
    if not stats_1.has_wins or not stats_2.has_wins:
        return None

    m2_minus_m1 = stats_2.mean - stats_1.mean
    sum_var = stats_1.var + stats_2.var
    erf_arg = m2_minus_m1 / math.sqrt(2*sum_var)
    if m2_minus_m1 > 0:
        winrate_of_1_if_both_finish = (1.0 + math.erf(erf_arg))/2.0
    else:
        winrate_of_1_if_both_finish = (1.0 - math.erf(-erf_arg))/2.0

    both_finish_prob = stats_1.winrate * stats_2.winrate
    neither_finish_prob = (1-stats_1.winrate)*(1-stats_2.winrate)
    winrate_of_1 = winrate_of_1_if_both_finish*both_finish_prob + (stats_1.winrate - both_finish_prob)
    winrate_of_2 = (1.0-winrate_of_1_if_both_finish)*both_finish_prob + (stats_2.winrate - both_finish_prob)
    return winrate_of_1, winrate_of_2, neither_finish_prob
ibeval.py 文件源码 项目:neva 作者: marcobardoscia 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def blackcox_pd(equity, extasset, sigma):
    """Compute the probability of default for external assets following a 
    Geometric Brownian Motion and the Black and Cox model.

    Parameters:
        equity (float): equity
        extasset (float): external assets
        sigma (float): volatility of the Geometric Browninan Motion

    Returns:
        probability of default
    """
    if equity <= 0.0:
        return 1.0
    if equity >= extasset:
        return 0.0
    else:
        #return 1 + (- 1/2 * (1 + math.erf((-math.log(1 - equity/extasset) - sigma**2/2) / 
        #                                  (math.sqrt(2) * sigma)) )
        #            + (extasset/equity)/2 * (1 + math.erf((math.log(1 - equity/extasset) - sigma**2/2) / 
        #                                                  (math.sqrt(2) * sigma)) ) )
        return (1/2 * (1 + math.erf((math.log(1 - equity/extasset) + sigma**2/2) / 
                                    (math.sqrt(2) * sigma)) ) + 
                (extasset/(extasset - equity))/2 * (1 + math.erf((math.log(1 - equity/extasset) - sigma**2/2) / 
                                                                 (math.sqrt(2) * sigma)) ) )
bs_erf_numba_guvec_par.py 文件源码 项目:BlackScholes_bench 作者: IntelPython 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def black_scholes_numba_opt(price, strike, t, mr, sig_sig_two, vol, call, put):
        P = float( price [0] )
        S = strike [0]
        T = t [0]

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

        z = T * sig_sig_two[0]
        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

        res = P * d1 - Se * d2
        call [0] = res
        put [0] = res - P + Se
bs_erf_numba_vec.py 文件源码 项目:BlackScholes_bench 作者: IntelPython 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def black_scholes_numba_opt(price, strike, t, mr, sig_sig_two):
        P = price
        S = strike
        T = t

        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

        r  = P * d1 - Se * d2
        return complex(r, r - P + Se)
bs_erf_numba_vec_par.py 文件源码 项目:BlackScholes_bench 作者: IntelPython 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def black_scholes_numba_opt(price, strike, t, mr, sig_sig_two):
        P = price
        S = strike
        T = t

        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

        r  = P * d1 - Se * d2
        return complex(r, r - P + Se)
reco.py 文件源码 项目:caly-recommend-system 作者: CalyFactory 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def __get_snd_score(self, x):
        return (1.0 + math.erf(x / math.sqrt(2.0))) / 2.0
ibeval.py 文件源码 项目:neva 作者: marcobardoscia 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def lognormal_pd(equity, extasset, sigma):
    """Compute the probability of default for external assets following a 
    Geometric Brownian Motion.

    Such probability of default is the correct probability of default to use 
    for the NEVA interbank valuation function with external assets following a
    Geometric Brownian Motion, implemented in `exante_en_merton_gbm`. See 
    Eq. (16a) in [1].

    Parameters:
        equity (float): equity
        extasset (float): external assets
        sigma (float): volatility of the Geometric Browninan Motion

    Returns:
        probability of default

    References:
        [1] P. Barucca, M. Bardoscia, F. Caccioli, M. D'Errico, G. Visentin, 
            S. Battiston, G. Caldarelli. Network Valuation in Financial Systems, 
            https://arxiv.org/abs/1606.05164
    """
    if equity >= extasset:
        #print('wow1')
        return 0.0
    else:
        #print('wow2', (sigma**2 / 2 + math.log(1.0 - equity/extasset)) / (math.sqrt(2) * sigma))
        #print('wow2', sigma**2 / 2, math.log(1.0 - equity/extasset), (math.sqrt(2) * sigma))
        return 1/2 * (1 + math.erf((sigma**2 / 2 + math.log(1 - equity/extasset))
                                   / (math.sqrt(2) * sigma)))
ibeval.py 文件源码 项目:neva 作者: marcobardoscia 项目源码 文件源码 阅读 30 收藏 0 点赞 0 评论 0
def lognormal_cav_aext(equity, extasset, ibliabtot, sigma):
    """Compute the conditional expected endogenous recovery for external 
    assets following a Geometric Brownian Motion.

    Such conditional expected endogenous recovery is the correct conditional 
    expected endogenous recovery to use for the NEVA interbank valuation 
    function with external assets following a Geometric Brownian Motion, 
    implemented in `end_lognormal_dr`. See Eq. (16b) in [1].

    Parameters:
        equity (float): equity
        extasset (float): external assets
        ibliabtot (float): total interbank liabilities        
        sigma (float): volatility of the Geometric Browninan Motion

    Returns:
        conditional expected endogenous recovery

    References:
        [1] P. Barucca, M. Bardoscia, F. Caccioli, M. D'Errico, G. Visentin, 
            S. Battiston, G. Caldarelli. Network Valuation in Financial Systems, 
            https://arxiv.org/abs/1606.05164
    """
    out = 0.0
    if extasset > equity:
        tmp_sigma_1 = sigma**2 / 2
        tmp_sigma_2 = math.sqrt(2) * sigma
        out += 1/2 * (1 + math.erf((math.log(1 - equity/extasset) - tmp_sigma_1) 
                                    / tmp_sigma_2))
        if extasset > equity + ibliabtot:
            out -= 1/2 * (1 + math.erf((math.log(1 - (equity + ibliabtot)/extasset) - 
                                                tmp_sigma_1) 
                                       / tmp_sigma_2))
    return extasset * out
flowgo_relative_viscosity_model_costa2.py 文件源码 项目:pyflowgo 作者: pyflowgo 项目源码 文件源码 阅读 29 收藏 0 点赞 0 评论 0
def compute_relative_viscosity(self, state):

        phi = state.get_crystal_fraction()
        if self._strain_rate == 1.0:
            # needle-like B particles from Cimarelli et al., 2011
            # self.phi_max_2 = 0.44
            delta_1 = 4.45
            gama_1 = 8.55
            phi_star_1 = 0.28
            epsilon_1 = 0.001

            f = (1. - epsilon_1) * math.erf(min(25., (
                (math.sqrt(math.pi) / (2. * (1. - epsilon_1))) * (phi / phi_star_1) * (
                    1. + (math.pow((phi / phi_star_1), gama_1))))))

            relative_viscosity = (1. + math.pow((phi / phi_star_1), delta_1)) / (
                math.pow((1. - f), (2.5 * phi_star_1)))
            return relative_viscosity

        if self._strain_rate == 0.0001:
            # needle-like, B particles from Cimarelli et al., 2011
            # self.phi_max = 0.36
            delta_1 = 7.5
            gama_1 = 5.5
            phi_star_1 = 0.26
            epsilon_1 = 0.0002

            f = (1. - epsilon_1) * math.erf(min(25., (
                (math.sqrt(math.pi) / (2. * (1. - epsilon_1))) * (phi / phi_star_1) * (
                    1. + (math.pow((phi / phi_star_1), gama_1))))))

            relative_viscosity = (1. + math.pow((phi / phi_star_1), delta_1)) / (
                math.pow((1. - f), (2.5 * phi_star_1)))
            return relative_viscosity
flowgo_relative_viscosity_model_costa1.py 文件源码 项目:pyflowgo 作者: pyflowgo 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def compute_relative_viscosity(self, state):

        phi = state.get_crystal_fraction()
        if self._strain_rate == 1.0:
            # for spheres, A particles from Cimarelli et al., 2011
            # self.phi_max = 0.61,
            delta_1 = 11.4
            gama_1 = 1.6
            phi_star_1 = 0.67
            epsilon_1 = 0.01

            f = (1. - epsilon_1) * math.erf(min(25., (
                (math.sqrt(math.pi) / (2. * (1. - epsilon_1))) * (phi / phi_star_1) * (
                    1. + (math.pow((phi / phi_star_1), gama_1))))))

            relative_viscosity = (1. + math.pow((phi / phi_star_1), delta_1)) / (
                math.pow((1. - f), (2.5 * phi_star_1)))
            return relative_viscosity

        if self._strain_rate == 0.0001:
            # spheres A particles from Cimarelli et al., 2011
            # self.phi_max_1 = 0.54,
            delta_1 = 11.48
            gama_1 = 1.52
            phi_star_1 = 0.62
            epsilon_1 = 0.005

            f = (1. - epsilon_1) * math.erf(min(25., (
                (math.sqrt(math.pi) / (2. * (1. - epsilon_1))) * (phi / phi_star_1) * (
                    1. + (math.pow((phi / phi_star_1), gama_1))))))

            relative_viscosity = (1. + math.pow((phi / phi_star_1), delta_1)) / (
                math.pow((1. - f), (2.5 * phi_star_1)))
            return relative_viscosity
probability.py 文件源码 项目:python_fun_excercise 作者: pongem 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def normal_cdf(x, mu=0,sigma=1):
    return (1 + math.erf((x - mu) / math.sqrt(2) / sigma)) / 2
predict_obs_cartpole.py 文件源码 项目:gym 作者: openai 项目源码 文件源码 阅读 27 收藏 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
stat_util.py 文件源码 项目:variantfishtest 作者: ianfab 项目源码 文件源码 阅读 28 收藏 0 点赞 0 评论 0
def erf(x):
  #Python 2.7 defines math.erf(), but we need to cater for older versions.
  a = 8*(math.pi-3)/(3*math.pi*(4-math.pi))
  x2 = x*x
  y = -x2 * (4/math.pi + a*x2) / (1 + a*x2)
  return math.copysign(math.sqrt(1 - math.exp(y)), x)
stat_util.py 文件源码 项目:variantfishtest 作者: ianfab 项目源码 文件源码 阅读 30 收藏 0 点赞 0 评论 0
def erf_inv(x):
  # Above erf formula inverted analytically
  a = 8*(math.pi-3)/(3*math.pi*(4-math.pi))
  y = math.log(1-x*x)
  z = 2/(math.pi*a) + y/2
  return math.copysign(math.sqrt(math.sqrt(z*z - y/a) - z), x)
stat_util.py 文件源码 项目:variantfishtest 作者: ianfab 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def phi(q):
  # Cumlative distribution function for the standard Gaussian law: quantile -> probability
  return 0.5*(1+erf(q/math.sqrt(2)))
util.py 文件源码 项目:shakecast 作者: usgs 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def lognorm_opt(med=0, spread=0, step=.01, just_norm=False, shaking=False):
    p_norm = (math.erf((shaking-med)/(math.sqrt(2) * spread)) + 1)/2
    return p_norm * 100
rating_stats.py 文件源码 项目:halite_ranking 作者: Janzert 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def phi(x):
    """Cumulative distribution function for the standard normal distribution
    Taken from python math module documentation"""
    return (1.0 + math.erf(x / math.sqrt(2.0))) / 2.0
test_dists.py 文件源码 项目:nengo_dl 作者: nengo 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def norm_cdf(x):
    return 0.5 * (1 + math.erf(x / np.sqrt(2)))
gaussmle.py 文件源码 项目:picasso 作者: jungmannlab 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def _erf(x):
    ''' Currently not needed, but might be useful for a CUDA implementation '''
    ax = _np.abs(x)
    if ax < 0.5:
        t = x*x
        top = ((((.771058495001320e-04*t-.133733772997339e-02)*t+.323076579225834e-01)*t+.479137145607681e-01)*t+.128379167095513e+00) + 1.0
        bot = ((.301048631703895e-02*t+.538971687740286e-01)*t+.375795757275549e+00)*t + 1.0
        return x * (top / bot)
    if ax < 4.0:
        top = ((((((-1.36864857382717e-07*ax+5.64195517478974e-01)*ax+7.21175825088309e+00)*ax+4.31622272220567e+01)*ax+1.52989285046940e+02)*ax+3.39320816734344e+02)*ax+4.51918953711873e+02)*ax + 3.00459261020162e+02
        bot = ((((((1.0*ax+1.27827273196294e+01)*ax+7.70001529352295e+01)*ax+2.77585444743988e+02)*ax+6.38980264465631e+02)*ax+9.31354094850610e+02)*ax+7.90950925327898e+02)*ax + 3.00459260956983e+02
        erf = 0.5 + (0.5 - _np.exp(-x * x) * top / bot)
        if x < 0.0:
            erf = -erf
        return erf
    if ax < 5.8:
        x2 = x*x
        t = 1.0 / x2
        top = (((2.10144126479064e+00*t+2.62370141675169e+01)*t+2.13688200555087e+01)*t+4.65807828718470e+00)*t + 2.82094791773523e-01
        bot = (((9.41537750555460e+01*t+1.87114811799590e+02)*t+9.90191814623914e+01)*t+1.80124575948747e+01)*t + 1.0
        erf = (.564189583547756e0 - top / (x2 * bot)) / ax
        erf = 0.5 + (0.5 - _np.exp(-x2) * erf)
        if x < 0.0:
            erf = -erf
        return erf
    return _np.sign(x)
gaussmle.py 文件源码 项目:picasso 作者: jungmannlab 项目源码 文件源码 阅读 28 收藏 0 点赞 0 评论 0
def _gaussian_integral(x, mu, sigma):
    sq_norm = 0.70710678118654757 / sigma       # sq_norm = sqrt(0.5/sigma**2)
    d = x - mu
    return 0.5 * (_math.erf((d + 0.5) * sq_norm) - _math.erf((d - 0.5) * sq_norm))
EPAIRED.py 文件源码 项目:ESPSS 作者: rcalinjageman 项目源码 文件源码 阅读 30 收藏 0 点赞 0 评论 0
def stdnormdist(x):
  #Cumulative standard normal distribution function
  #Lifted from https://docs.python.org/3.2/library/math.html
  return (1.0 + math.erf(x / math.sqrt(2.0))) / 2.0
predict_obs_cartpole.py 文件源码 项目:AI-Fight-the-Landlord 作者: YoungGer 项目源码 文件源码 阅读 30 收藏 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
wspr.py 文件源码 项目:weakmon 作者: rtmrtmrtmrtm 项目源码 文件源码 阅读 117 收藏 0 点赞 0 评论 0
def normal(x):
    y = 0.5 + 0.5*math.erf(x / 1.414213)
    return y

# how much of the distribution is < x?
ft8.py 文件源码 项目:weakmon 作者: rtmrtmrtmrtm 项目源码 文件源码 阅读 30 收藏 0 点赞 0 评论 0
def real_normal(x):
    y = 0.5 + 0.5*math.erf(x / 1.414213)
    return y
ch11_r03.py 文件源码 项目:Modern-Python-Cookbook 作者: PacktPublishing 项目源码 文件源码 阅读 33 收藏 0 点赞 0 评论 0
def phi(n):
    """
    Computes the cumulative distribution function of the standard,
    normal distribution for values <= n.

    >>> round(phi(0), 3)
    0.5
    >>> round(phi(-1), 3)
    0.159
    >>> round(phi(+1), 3)
    0.841

    """
    return (1+erf(n/sqrt(2)))/2
undertone.py 文件源码 项目:Undertone 作者: kgugle 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def percentage_of_area_under_std_normal_curve_from_zcore(z_score):
    return .5 * (math.erf(z_score / 2 ** .5) + 1)
thinkstats2.py 文件源码 项目:iota 作者: amaneureka 项目源码 文件源码 阅读 29 收藏 0 点赞 0 评论 0
def StandardNormalCdf(x):
    """Evaluates the CDF of the standard Normal distribution.

    See http://en.wikipedia.org/wiki/Normal_distribution
    #Cumulative_distribution_function

    Args:
        x: float

    Returns:
        float
    """
    return (math.erf(x / ROOT2) + 1) / 2
ratingutil.py 文件源码 项目:necrobot 作者: incnone 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def get_winrate(rating_1: Rating, rating_2: Rating):
    delta_mu = rating_1.mu - rating_2.mu
    if delta_mu >= 0:
        beta = trueskill.global_env().beta
        denom = sqrt(2 * (2 * beta * beta + rating_1.sigma * rating_1.sigma + rating_2.sigma * rating_2.sigma))
        return (erf(delta_mu/denom) + 1.0)/2.0
    else:
        return 1.0 - get_winrate(rating_2, rating_1)
thinkstats2.py 文件源码 项目:ThinkX 作者: AllenDowney 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def StandardNormalCdf(x):
    """Evaluates the CDF of the standard Normal distribution.

    See http://en.wikipedia.org/wiki/Normal_distribution
    #Cumulative_distribution_function

    Args:
        x: float

    Returns:
        float
    """
    return (math.erf(x / ROOT2) + 1) / 2
thinkbayes2.py 文件源码 项目:ThinkX 作者: AllenDowney 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def StandardNormalCdf(x):
    """Evaluates the CDF of the standard Normal distribution.

    See http://en.wikipedia.org/wiki/Normal_distribution
    #Cumulative_distribution_function

    Args:
        x: float

    Returns:
        float
    """
    return (math.erf(x / ROOT2) + 1) / 2


问题


面经


文章

微信
公众号

扫码关注公众号