I have two values $a$ and $b$ where $a \ge 0$ and $b \ge 0$ and I have to calculate the formula below.
$$ \frac{1}{2}\int_0^1\text{abs}\left[\left( \frac{p_i^{(a - 1)} \times (1 - p_i)^{(b - 1)}}{\beta(a,b)} \right)- 1\right] dp_i $$ I have to calculate above value. I am facing below error while doing that.
...
My equation is implemented as
import scipy.special as sc
import scipy.integrate as spi
integrand_np = lambda p_i: abs(((p_i ** (a - 1)) * ((1 - p_i) ** (b - 1)) / (sc.beta(a,b)) - 1) / 2
result1, error = spi.quad(integrand_np, a, b)
:35: IntegrationWarning: The occurrence of roundoff error is detected, which prevents the requested tolerance from being achieved. The error may be underestimated. result1, error = spi.quad(integrand_np, a, b) ...
I am getting an error. I tried to use betaln by changing my equation. Still I am facing below issue
IntegrationWarning: The occurrence of roundoff error is detected, which prevents the requested tolerance from being achieved. The error may be underestimated.
Sample a values = [1400, 440, 799] Sample b values = [700,560, 1400]
To prevent error is there a way to use scipy.special.betaln. I changed above formula as below to use betaln
$$ \frac{1}{2}\int_0^1 ( \frac{p_i^{(a - 1)} \times (1 - p_i)^{(b - 1)})}{\beta(a,b)} ) dp_i - \frac{1}{2}\int_0^1 1 dp_i $$
$$ \frac{1}{2*beta(a,b)}\int_0^1 ( p_i^{(a - 1)} \times (1 - p_i)^{(b - 1)}) ) dp_i - \frac{1}{2}\int_0^1 1 dp_i $$
$$ integralvalue = \int_0^1 ( p_i^{(a - 1)} \times (1 - p_i)^{(b - 1)}) ) dp_i $$
Then I am applying log to use betaln function. But still it is not working. ...
import scipy.special as sc
import scipy.integrate as spi
import numpy as np
integrand = lambda p_i: abs(((p_i ** (p_count - 1)) * ((1 - p_i) ** (n_count - 1))))
integral_second_term = lambda p_i: 1/2
result1, error = spi.quad(integrand, a, b)
result2, error1 = spi.quad(integral_second_term, a, b)
final_log = np.log(result1) - sc.betaln(p_count, n_count) - np.log(2)
final_output = abs((np.exp(final_log)) - result2)
...
It is not giving correct values
gammastar
) introduced by Temme. For the magnitude of $a$, $b$ indicated in the question, this likewise underflows to zero. $\endgroup$scipy.special.btdtr(a, b, x)
(here with $x=1$)? $\endgroup$