A General Theory of the Stochastic Linear Bandit and Its Applications