Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to approximate a value from a formula

Tags:

python

math

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:

\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.

I found the value theta this way. Problem is, it took me about 60 seconds using Python, to find a theta of 0.456.

What is quicker approach to find this theta (since I would like to apply this for other data)?

like image 943
PascalVKooten Avatar asked Dec 07 '25 03:12

PascalVKooten


1 Answers

If you know a lower and an upper bound for θ, and the function is monotonic in the range between these, then you could employ a bisection algorithm to easily and quickly find the desired value.

like image 143
MvG Avatar answered Dec 08 '25 18:12

MvG



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!