It is necessary to calculate the expression:

N[Integrate[PDF[BetaDistribution[alpha1, beta1], x] CDF[BetaDistribution[alpha2, beta2], x], {x, 0, 1}]] 

The expression solves the problem of comparing two advertisements by Bayesian statistics and probabilistic inference. This formula is written in Mathematica terms.
N[expr] - numerically calculate the expression expr.
Integrate[f, {x, xmin, xmax}] is the integral of the function f over x in the interval from xmin to xmax.
PDF[dist, x] is the probability density function for the dist distribution at x.
CDF[dist,x] is the distribution function of the random variable for the dist distribution at the point x.
BetaDistribution[alpha, beta] - a continuous beta distribution with parameters alpha , beta .

In its usual form, it looks like this: Integral as usual

Found a library that computes PDF and CDF : https://github.com/jstat/jstat . But with the integral problem.

  • And what is the actual problem with the integral? - Alexander Muksimov
  • I could not find a library in which there is an integral calculation. and not quite sure about the calculation method - Natalya
  • You can always use the Euler method. ru.wikipedia.org/wiki/… - hedgehogues
  • Do you understand what this method is? - hedgehogues
  • @ Natalia Khenkina "... and not quite sure about the calculation method" - what are you not sure about? The function under the integral has infinite poles or is it not Leibniz integrable? What is the problem? Alas, I do not have time to explore it now. - Alexander Muksimov

1 answer 1

Here you can find a library of numerical methods: http://www.numericjs.com/ . There are a lot of similar libraries on request. Численные методы JavaScript .

If she does not like something, then it is quite possible to limit herself to calculating this integral by the Euler method: https://ru.wikipedia.org/wiki/Method_Eiler . This algorithm is extremely simple. You need to set the interval [a, b] = [0, 1] , select the integration step h = 0.01 , repeat the formula in the loop:

Formula for calculating

I brought several equalities. You need most likely the second. For this, it is necessary to keep the previous value in memory at each iteration. The last equality is not very good to calculate, since the calculation of the function f will occur twice, which will slow down the work of your script.

Thus, loop through all the values ​​from the segment [0; 1] [0; 1] and get the result of integration in y_n .

  • Thanks, I will try now! - Natalia