1

I want to generate the following artificial dataset to test a contextual bandit algorithm. What is the easiest way to get it done in python may be? Can anyone point me to a link which demonstrates a code for it?

The unit vectors θ1 , ..., θK for K actions are drawn uniformly from Rd . in each iteration t of T complete iterations, a context xt is first sampled from an uniform distribution within ∥x| ≤ 1.

Martin Thoma
  • 124,992
  • 159
  • 614
  • 958
user77005
  • 1,769
  • 4
  • 18
  • 26

1 Answers1

0

If I understand your question right, you want to generate:

  1. context xt from uniform distribution
  2. a unit vector of K elements indicating which arm to choose with only a single value being set to one, again from a uniform distribution

Both tasks can be easily achieved with the numpy package:

  1. Use numpy.random.uniform to generate values from uniform distribution within any range.
  2. Use numpy.random.randint to generate integers from uniform distribution and then use the generated values to set certain list element to 1.
Andrzej Pronobis
  • 33,828
  • 17
  • 76
  • 92
  • would this kind of sampling ensure that the l2-norm of the context vector x is less than or equal to 1? – user77005 Jan 15 '16 at 07:29