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

Add example solving OpenAI Gym MountainCarContinuous env #149

Merged

Conversation

jakobj
Copy link
Member

@jakobj jakobj commented Jun 15, 2020

This example demonstrates how to solve an Open AI Gym environment with CGP. Fitness function is based on empirical observations to maximize solving speed. Found solution is almost always of the form c \dot x, sometimes c \dot x - x for that last bit of efficiency (try it!). The solution intuitively makes sense, doesn't it? ;) #interpretableRL

tagging our mountaincar expert @weidel-p

@jakobj jakobj added this to the #thefuture milestone Jun 15, 2020
@mschmidt87
Copy link
Member

This is pretty cool! However, a principle problem that I see is that this has an additional dependency, namely OpenAI Gym. I think there are two possible ways:

  • move this example in a new subfolder, that could be called additional_examples or something like this and then explain in the README.md that this has an additional dependency. Perhaps even put gym in a pip requirements file.
  • move this example in a new, separate repository with "advanced" examples or miniprojects/demonstrations.

For the example itself:

  • It would be really cool to add a visualization of the resulting behavior after the evoluation. Even cooler: Create visualizations with all "evolutionary steps" where the fitness makes a jump towards higher values.
  • Add some logging of the found solution.

@weidel-p
Copy link

Hey, thanks for tagging me here. It's the first time I look into CGP, it looks very cool and the installation was super easy, it just works. 🥇

Regarding this PR, I agree with @mschmidt87. A bit more information and visualization would be neat. I ran the script, it counted from 0 to 500 and in the end, something reached a fitness for 13.5. Is this a good or bad value? I would also like to see the found solution and if this solution is sufficient to solve the task according to the criteria by the Gym.
Also, as @mschmidt87 said, some visualization would be great. At least the best solution should be rendered.

@jakobj
Copy link
Member Author

jakobj commented Jun 21, 2020

Thanks for your comments! ✨

I don't like the idea of creating a separate advanced examples or similar directory. Instead I've added a comment to the docstring of the module that this example needs gym installed. Do you think that's enough?

I've added visualization of the solutions for every increase of the champion's fitness. Please check whether this works for you. 😬

I'm not sure what you mean by "logging the found solution" do you mean just print to the screen? ;)

@jakobj
Copy link
Member Author

jakobj commented Jun 21, 2020

"I would also like to see the found solution and if this solution is sufficient to solve the task according to the criteria by the Gym."

Actually I'm not sure what the criteria are for this environment. Do you know where to check this @weidel-p?

@jakobj jakobj force-pushed the enh/mountain-car-example branch 2 times, most recently from 1d47d5e to bb8a9cc Compare June 22, 2020 09:49
@weidel-p
Copy link

Yes, it works for me. Looks very good :) 👍

You can find the threshold for solving the task in the leaderboard here:
https://github.com/openai/gym/wiki/Leaderboard
or you can also find it in the python code of the environment: gym/envs/__init__.py

For this task, the threshold is at 90.

@mschmidt87
Copy link
Member

Looks good, in principle, but I think the amount of animations is too many at the end. Let's just animate the winning, final solution, and perhaps keep it as a switch to visualize all steps with fitness gain.

With logging the solution, yes, just print it to the screen.

@mschmidt87
Copy link
Member

Regarding the additional dependency: What about adding something like:

try:
    import gym
except ImportError:
    raise ImportError("Could not import OpenAI Gym package. Please install it via `pip install gym`.")

@jakobj
Copy link
Member Author

jakobj commented Jun 24, 2020

thanks for the reviews @weidel-p @mschmidt87 :)

i've implemeted your suggestions and am happy to report that the found solution passes the solving criteria for this environment. in order to achieve this i needed to adapt the fitness function a bit, putting more emphasis on the reward gathered rather than the number of episodes solved.

please have another look!

@jakobj jakobj modified the milestones: #thefuture, 0.2.0 Jun 24, 2020
@jakobj jakobj force-pushed the enh/mountain-car-example branch 2 times, most recently from 15832bb to 3cbe7e5 Compare June 24, 2020 20:48
@mschmidt87
Copy link
Member

Very nice, @jakobj , just a minor suggestion: Why not setting the min_fitness parameter to 90., since that is the official criterium for "passing the task"? 200.0 seems like an arbitrary choice? I think it would be quite impressive for the user to see that 90 is achieved after only ~100 generations.

@jakobj
Copy link
Member Author

jakobj commented Jun 29, 2020

yes, i agree this would be the optimal case. however, the requirement is defined as ">90 fitness averaged over 100 consecutive trials". unfortunately we can not use this as an objective during evolution since only high-performance solutions are able to achieve this large number of trials in a reasonable amount of time. hence i opted for this specific combination objective + min fitness.

@mschmidt87
Copy link
Member

Okay, understood. As a minor change, I would suggest to use dx/dt instead of \dot x.

@jakobj
Copy link
Member Author

jakobj commented Jun 29, 2020

fixed, pls have another look :)

Copy link
Member

@mschmidt87 mschmidt87 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@jakobj jakobj merged commit 2cdbb75 into Happy-Algorithms-League:master Jun 29, 2020
@jakobj jakobj deleted the enh/mountain-car-example branch June 29, 2020 12:54
@mschmidt87 mschmidt87 modified the milestones: 0.2.0, 0.1.1 Jun 30, 2020
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

3 participants