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 plotting module #130

Closed
ljvmiranda921 opened this issue Jun 12, 2018 · 0 comments
Closed

Add plotting module #130

ljvmiranda921 opened this issue Jun 12, 2018 · 0 comments
Labels
enhancement Feature requests

Comments

@ljvmiranda921
Copy link
Owner

I think it is better to decouple visualization from optimization.

Before, we have a PlotEnviroment class that takes an optimizer instance, runs
the optimization, and plots whatever the user requires (cost history, animations, etc.).

Some problems I see:

  • What if I want to experiment with my swarm first before visualization?
  • What if optimization takes a long time? Does it mean that the PlotEnvironment class
    will repeat this whole process again?
  • What if I really want to plot this particular history because of some interesting property
    I found in this rollout? PlotEnvironment will just ignore that because it has its own rollout.

It's better if we have the user do the optimization first, get the histories (via the properties
in the SwarmOptimizer class, e.g. my_optimizer.cost_history) and pass that to the plotting
function (doesn't need to be contained in a class)

Rough draft:

import pyswarms as ps
from pyswarms.utils.plotters import (plot_cost_history, plot_2d_trajectory)

# Setup PSO
optimizer = ps.single.GlobalBestPSO(n_particles=100, dimensions=2, options=my_options)
optimizer.optimize(f, iters=1000) # Run for 1k iterations

# Obtain history
swarm_cost_history = optimizer.cost_history  # Of shape (1000, )
swarm_pos_history = optimizer.pos_history # Of shape (1000, 100, 2)
swarm_velocity_history = optimizer.velocity_history # Of shape (1000, 100, 2)

# Plot!
# Plotters can still accept an Axis class from matplotlib

plot_cost_history(swarm_cost_history, title='My cost history')

# Plotting velocity is optional. Only plot if an arg is passed
# Still returns an animate class from matplotlib
# Contour can be turned on or off. Make a separate "backend" for this so that proper errors can
#   be passed.
plot_2d_trajectory(swarm_pos_history, swarm_velocity_history, contour=True)
@ljvmiranda921 ljvmiranda921 added the enhancement Feature requests label Jun 12, 2018
@ljvmiranda921 ljvmiranda921 added documentation Documentation improvements or fixes unit tests Test-related changes labels Jun 12, 2018
ljvmiranda921 pushed a commit that referenced this issue Jun 13, 2018
Reference: #130

This commit adds a plotters.py module to replace the environments
module. We hope that we can actually decouple the optimization and
visualization part, without having the environment to do another
rollout of your PSO.

Signed-off-by: Lester James V. Miranda <ljvmiranda@gmail.com>
ljvmiranda921 pushed a commit that referenced this issue Jun 13, 2018
Reference: #130

The problem before is that we tend to have many parameters in our
plotting functions. The formatters module changes that. We have
three types of formatters: Designer, Animator, and Mesher. There
are defaults present, but the user can change and pass them to the
ploting functions whenever needed.

Signed-off-by: Lester James V. Miranda <ljvmiranda@gmail.com>
ljvmiranda921 pushed a commit that referenced this issue Jun 13, 2018
Reference: #130

This commit adds a plotters.py module to replace the environments
module. We hope that we can actually decouple the optimization and
visualization part, without having the environment to do another
rollout of your PSO.

Signed-off-by: Lester James V. Miranda <ljvmiranda@gmail.com>
ljvmiranda921 pushed a commit that referenced this issue Jun 13, 2018
Reference: #130

The problem before is that we tend to have many parameters in our
plotting functions. The formatters module changes that. We have
three types of formatters: Designer, Animator, and Mesher. There
are defaults present, but the user can change and pass them to the
ploting functions whenever needed.

Signed-off-by: Lester James V. Miranda <ljvmiranda@gmail.com>
ljvmiranda921 pushed a commit that referenced this issue Jun 13, 2018
Reference: #130

This commit adds a plotters.py module to replace the environments
module. We hope that we can actually decouple the optimization and
visualization part, without having the environment to do another
rollout of your PSO.

Signed-off-by: Lester James V. Miranda <ljvmiranda@gmail.com>
ljvmiranda921 pushed a commit that referenced this issue Jun 13, 2018
Reference: #130

The problem before is that we tend to have many parameters in our
plotting functions. The formatters module changes that. We have
three types of formatters: Designer, Animator, and Mesher. There
are defaults present, but the user can change and pass them to the
ploting functions whenever needed.

Signed-off-by: Lester James V. Miranda <ljvmiranda@gmail.com>
ljvmiranda921 pushed a commit that referenced this issue Jun 14, 2018
Reference: #130

This commit adds a plotters.py module to replace the environments
module. We hope that we can actually decouple the optimization and
visualization part, without having the environment to do another
rollout of your PSO.

Signed-off-by: Lester James V. Miranda <ljvmiranda@gmail.com>
ljvmiranda921 pushed a commit that referenced this issue Jun 14, 2018
Reference: #130

The problem before is that we tend to have many parameters in our
plotting functions. The formatters module changes that. We have
three types of formatters: Designer, Animator, and Mesher. There
are defaults present, but the user can change and pass them to the
ploting functions whenever needed.

Signed-off-by: Lester James V. Miranda <ljvmiranda@gmail.com>
ljvmiranda921 pushed a commit that referenced this issue Jun 14, 2018
This commit adds the plotters module into ReadTheDocs index
and adds a deprecated information on plot_environment.py

Signed-off-by: Lester James V. Miranda <ljvmiranda@gmail.com>

[WIP-env] Add deprecated to env docs

[WIP] Add plotters DOCS
ljvmiranda921 pushed a commit that referenced this issue Jun 14, 2018
This commit updates the docstrings in formatters.py
and adds a legend attribute in plotters.py

Signed-off-by: Lester James V. Miranda <ljvmiranda@gmail.com>
ljvmiranda921 pushed a commit that referenced this issue Jun 14, 2018
Reference: #130

This commit adds a plotters.py module to replace the environments
module. We hope that we can actually decouple the optimization and
visualization part, without having the environment to do another
rollout of your PSO.

Signed-off-by: Lester James V. Miranda <ljvmiranda@gmail.com>
ljvmiranda921 pushed a commit that referenced this issue Jun 14, 2018
Reference: #130

The problem before is that we tend to have many parameters in our
plotting functions. The formatters module changes that. We have
three types of formatters: Designer, Animator, and Mesher. There
are defaults present, but the user can change and pass them to the
ploting functions whenever needed.

Signed-off-by: Lester James V. Miranda <ljvmiranda@gmail.com>
ljvmiranda921 pushed a commit that referenced this issue Jun 14, 2018
This commit adds the plotters module into ReadTheDocs index
and adds a deprecated information on plot_environment.py

Signed-off-by: Lester James V. Miranda <ljvmiranda@gmail.com>

[WIP-env] Add deprecated to env docs

[WIP] Add plotters DOCS
ljvmiranda921 pushed a commit that referenced this issue Jun 14, 2018
This commit updates the docstrings in formatters.py
and adds a legend attribute in plotters.py

Signed-off-by: Lester James V. Miranda <ljvmiranda@gmail.com>
ljvmiranda921 pushed a commit that referenced this issue Jun 14, 2018
Reference: #130

This commit adds a plotters.py module to replace the environments
module. We hope that we can actually decouple the optimization and
visualization part, without having the environment to do another
rollout of your PSO.

Signed-off-by: Lester James V. Miranda <ljvmiranda@gmail.com>
ljvmiranda921 pushed a commit that referenced this issue Jun 14, 2018
Reference: #130

The problem before is that we tend to have many parameters in our
plotting functions. The formatters module changes that. We have
three types of formatters: Designer, Animator, and Mesher. There
are defaults present, but the user can change and pass them to the
ploting functions whenever needed.

Signed-off-by: Lester James V. Miranda <ljvmiranda@gmail.com>
ljvmiranda921 pushed a commit that referenced this issue Jun 14, 2018
This commit adds the plotters module into ReadTheDocs index
and adds a deprecated information on plot_environment.py

Signed-off-by: Lester James V. Miranda <ljvmiranda@gmail.com>
ljvmiranda921 pushed a commit that referenced this issue Jun 14, 2018
This commit updates the docstrings in formatters.py
and adds a legend attribute in plotters.py

Signed-off-by: Lester James V. Miranda <ljvmiranda@gmail.com>
@ljvmiranda921 ljvmiranda921 added v0.3.0 and removed documentation Documentation improvements or fixes unit tests Test-related changes labels Jun 14, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Feature requests
Projects
No open projects
Development

No branches or pull requests

1 participant