Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Solution: ValueError: object too deep for desired array #5

Open
Yizheng-Sun opened this issue Nov 24, 2022 · 0 comments
Open

Solution: ValueError: object too deep for desired array #5

Yizheng-Sun opened this issue Nov 24, 2022 · 0 comments

Comments

@Yizheng-Sun
Copy link

function softmax_sample shoule be changed to:

def softmax_sample(distribution, temperature: float):
  if temperature == 0:
    temperature = 1
  distribution = numpy.array(distribution)**(1/temperature)
  p_sum = distribution[:,0].sum()
  sample_temp = distribution[:,0]/p_sum
  action = distribution[int(numpy.argmax(numpy.random.multinomial(1, sample_temp, 1)))][1]
  return 0, int(action)

because distribution is a 2d array, every element in it has 2 values. like this
[[ 0. 0.]
[ 4. 1.]
[ 1. 2.]
[ 0. 3.]
[ 0. 4.]
[ 0. 5.]
[ 0. 6.]
[ 0. 7.]
[ 0. 8.]
[ 0. 9.]
[ 0. 10.]
[ 0. 11.]........
The first value is the visit times and the second value is an action index.
p_sum should be calculated based on the first value so we use distribution[:,0].
when choose action index we should return the second value so we use
distribution[int(numpy.argmax(numpy.random.multinomial(1, sample_temp, 1)))][1]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant