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

Fixes type mismatch issue: https://github.com/rll/rllab/issues/224 #228

Open
wants to merge 1 commit into
base: py2
Choose a base branch
from

Conversation

riturajkaushik
Copy link

It used to throw the following error on line 146 of optimizers/conjugate_gradient_optimizer.py of rllab:py2 branch while trying to run trpo_cartpole.py in that branch.

Traceback (most recent call last):
  File "trpo_cartpole.py", line 27, in <module>
    algo.train()
  File "/home/rkaushik/projects/cloned_libs/rllab/rllab/algos/batch_polopt.py", line 253, in train
    self.optimize_policy(itr, samples_data)
  File "/home/rkaushik/projects/cloned_libs/rllab/rllab/algos/npo.py", line 109, in optimize_policy
    self.optimizer.optimize(all_input_values)
  File "/home/rkaushik/projects/cloned_libs/rllab/rllab/optimizers/conjugate_gradient_optimizer.py", line 146, in optimize
    n_samples, (n_samples * self._subsample_factor), replace=False)
  File "mtrand.pyx", line 1176, in mtrand.RandomState.choice (numpy/random/mtrand/mtrand.c:18822)
TypeError: 'float' object cannot be interpreted as an index 

This resolves this issue by typecasting (to int) the 2nd parameter of np.random.choice(...) call like this.

inds = np.random.choice(
                n_samples, int(n_samples * self._subsample_factor), replace=False)

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

Successfully merging this pull request may close these issues.

None yet

1 participant