Skip to content
DeepForgeby svx
All problems

LinUCB Selection

Problem

Compute the LinUCB score theta . x + alpha * sqrt(x^T A^{-1} x) for a two-dimensional arm.

A is the 2x2 covariance matrix and theta is the estimated coefficient vector. Return the score; the caller selects the arm with the largest score.

Hint

The exploration term is the Mahalanobis norm of the context under A inverse.

Test cases

case 1
in: [[1,2],[[1,0],[0,1]],[1,1],0.5]
expected: 3.7071067811865475
case 2
in: [[0,0],[[2,0],[0,2]],[1,1],1]
expected: 1
case 3
in: [[1,-1],[[1,0.5],[0.5,1]],[2,0],0]
expected: 2
case 4
in: [[0.5,0.5],[[4,2],[2,3]],[1,2],2]
expected: 3.845207879911715
Starter codePython
import math
def linucb_select(theta, A, x, alpha):
    # Your code here
    pass

4 test cases · run your code against them in the editor