简体   繁体   English

如何近似公式中的值

[英]How to approximate a value from a formula

So I have one vector of alpha, one vector of beta, and I am trying to find a theta for when the sum of all the estimates (for alpha's 1 to N and beta's 1 to N ) equals 60: 所以我有一个alpha矢量,一个beta矢量,我试图找到一个theta,当所有估计的总和(对于alpha的1 to N和beta的1 to N )等于60:

\\ sum_ {i = 1} ^ N \\ frac {e ^ {\\ alpha_i(\\ theta- \\ beta_i)}} {1 + e ^ {\\ alpha_i(\\ theta- \\ beta_i)}} = 60

def CalcTheta(grensscore, alpha, beta):
    theta = 0.0001
    estimate = [grensscore-1]
    while(sum(estimate) < grensscore):
        theta += 0.00001
        for x in range(len(beta)):
            if x == 0:
                estimate = []
            estimate.append(math.exp(alpha[x] * (theta - beta[x])) /
                            (1 + math.exp(alpha[x] * (theta - beta[x]))))
    return(theta)

Basically what I did is start from theta = 0.0001 , and iterate through, calculating all these sums, and when it is lower than 60, continue by adding 0.0001 each time, while above 60 means we found the theta. 基本上我所做的是从theta = 0.0001开始,并迭代计算所有这些总和,当它低于60时,继续每次加0.0001,而高于60意味着我们找到了theta。

I found the value theta this way. 我找到的值theta这种方式。 Problem is, it took me about 60 seconds using Python, to find a theta of 0.456. 问题是,使用Python花了大约60秒来找到0.456的θ。

What is quicker approach to find this theta (since I would like to apply this for other data)? 什么是更快找到这个theta的方法(因为我想将其应用于其他数据)?

如果你知道θ的下限和上限,并且函数在它们之间的范围内是单调的,那么你可以使用二分算法来轻松快速地找到所需的值。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM