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

Fixed assertion of list with None in the logging agent #236

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

Conversation

drmargarido
Copy link

List comparisons with None to check if they are empty or contain stuff can be incorrect. So I initialized the lastobs to an empty list, and checked if the list has any element with any().

Resolves issue -> #234 LoggingAgent throws ValueError.

@drmargarido
Copy link
Author

drmargarido commented Mar 23, 2018

To reproduce the error you can run this project -> Gamesbeater

NOTE: You need to use the main pybrain repository, instead of my fork which is listed in the dependencies section.

@mlk621
Copy link

mlk621 commented Aug 8, 2018

I have a system environment version of pybrain with the latest pybrain version that runs fine and does not throw this error, however, when I created my own virtual environment and updated versions of various packages, etc. then I am getting this error as well. I am not sure why that is happening since my system version is still a recent version of python.

I suggest a correction to this fix, that instead assert self.lastobs != None in logging.py should be changed to assert self.lastobs is not None instead of initializing an empty list, as you suggest.

The reason for this is that an Environment object's getSensors() method is set to return a numpy array of doubles. It will throw an an error if this is not the case. If you track that what will be returned by getSenstors() from environment.py to getObservation() in task.py to experiment.py's _oneInteraction() method where it calls the agent's integrateObservation() function, this is where we see that self.lastobs is set from the current tasks getObservation() method. Therefore, when _oneInteraction() gets to the line sef.agent.giveReward(reward), then an error is produced by the line we are having the error with assert self.lastobs != None.

Now, numpy arrays have a .any() option as you are suggesting with the empty list, however, this is checking things element-wise to return True/False (see numpy documentation). What we want is to jsut check whether lastobs is not None, meaning it is a numpy array of doubles. I did some testing and assert self.lastobs is not None does what we want, so I suggest this be the fix for this error.

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

2 participants