0
我嘗試實現Tensorflow輪盤賭選擇於是我開始用這樣的:Tensorflow:「」輪盤賭」的選擇
x = tf.random_uniform([tf.shape(probabilities)[0]])
cumsum = tf.cumsum(probabilities, axis=1) # cumulative sum
b = tf.greater_equal(x, cumsum) # Boolean values now
...
indices = tf.where(b) # this given indices for all the True values, I need only the first one per row
indices = indices[:,1] # we only need column index
此有任何建議或更好的方法做輪盤賭選擇?
所以一個小例子,使之更加清楚
probabilities = [[0.2 0.3 0.5],
[0.1 0.6 0.3],
[0.5 0.4 0.1]]
x = [0.27, 0.86, 0.73] # drawn randomly
然後我想輸出爲[1,2,1]