Database Reference
In-Depth Information
the fact that the users have purchased something using the following class.
The exposure is incremented using the expose method, and the purchase is
tracked using the success method as shown here:
public class BernoulliThompson {
double [] n;
double [] x;
public BernoulliThompson( int classes) {
n = new double [classes];
x = new double [classes];
}
public void expose( int k) {
if (k < n.length)
n[k] += 1.0;
}
public void success( int k) {
if (k < x.length) x[k] += 1.0;
}
Recall the discussion of the beta distribution in Chapter 9 as a model for the
probability of a Bernoulli trial. When the experiment begins, it is unknown
what the conversion rates will be, so perhaps it is best to assign the rates
for the different classes a uniform distribution, which can be modeled with
a Beta(1,1) distribution. After some visits have been observed, the Beta
distribution for each class can be updated to be a Beta(1+x,1+n-x)
distribution. This is known as a posterior distribution and is used to select
the design for a new visitor. Next a conversion rate is drawn from the
posterior distribution of each design. The design with the largest conversion
rate is then assigned to this visitor as follows:
Distribution d = new Distribution();
public int choose() {
int max = -1;
double mu = Double. NEGATIVE_INFINITY ;
for ( int i=0;i<x.length;i++) {
double alpha = 1.0 + x[i];
double beta = 1.0 + (n[i] - x[i]);
double x = d.nextBeta(alpha,beta);
if (x > mu) {
Search WWH ::




Custom Search