-
Notifications
You must be signed in to change notification settings - Fork 333
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
[WIP] Add Jupyter Notebook to visualise topologies #234
Conversation
Added a Jupyter Notebook to visualise the topologies.
@ljvmiranda921 could you check if you get the same error as I did? I copied the necessary bits from the |
Works for me, what OS are you on? It would be helpful if you can write (or copy-paste) the whole traceback and some details on your machine so that we can find potential solutions like this: Logger
Traceback---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-5-98fc35d22b0a> in <module>()
3 topology = top.Star()
4
----> 5 plot_optimization(options, topology)
<ipython-input-4-ac035cf64f85> in plot_optimization(options, topology)
33
34 # Enables us to view it in a Jupyter notebook
---> 35 HTML(animation.to_html5_video())
36 HTML(animation3d.to_html5_video())
/usr/lib64/python3.6/site-packages/matplotlib/animation.py in to_html5_video(self, embed_limit)
1351 bitrate=rcParams['animation.bitrate'],
1352 fps=1000. / self._interval)
-> 1353 self.save(f.name, writer=writer)
1354
1355 # Now open and base64 encode
/usr/lib64/python3.6/site-packages/matplotlib/animation.py in save(self, filename, writer, fps, dpi, codec, bitrate, extra_args, metadata, extra_anim, savefig_kwargs)
1198 # TODO: See if turning off blit is really necessary
1199 anim._draw_next_frame(d, blit=False)
-> 1200 writer.grab_frame(**savefig_kwargs)
1201
1202 # Reconnect signal for first draw if necessary
/usr/lib64/python3.6/contextlib.py in __exit__(self, type, value, traceback)
97 value = type()
98 try:
---> 99 self.gen.throw(type, value, traceback)
100 except StopIteration as exc:
101 # Suppress StopIteration *unless* it's the same exception that
/usr/lib64/python3.6/site-packages/matplotlib/animation.py in saving(self, fig, outfile, dpi, *args, **kwargs)
239 yield self
240 finally:
--> 241 self.finish()
242
243
/usr/lib64/python3.6/site-packages/matplotlib/animation.py in finish(self)
365 def finish(self):
366 '''Finish any processing for writing the movie.'''
--> 367 self.cleanup()
368
369 def grab_frame(self, **savefig_kwargs):
/usr/lib64/python3.6/site-packages/matplotlib/animation.py in cleanup(self)
403 def cleanup(self):
404 '''Clean-up and collect the process used to write the movie file.'''
--> 405 out, err = self._proc.communicate()
406 self._frame_sink().close()
407 _log.debug('MovieWriter -- Command stdout:\n%s', out)
/usr/lib64/python3.6/subprocess.py in communicate(self, input, timeout)
841
842 try:
--> 843 stdout, stderr = self._communicate(input, endtime, timeout)
844 finally:
845 self._communication_started = True
/usr/lib64/python3.6/subprocess.py in _communicate(self, input, endtime, orig_timeout)
1503 selector.register(self.stdin, selectors.EVENT_WRITE)
1504 if self.stdout:
-> 1505 selector.register(self.stdout, selectors.EVENT_READ)
1506 if self.stderr:
1507 selector.register(self.stderr, selectors.EVENT_READ)
/usr/lib64/python3.6/selectors.py in register(self, fileobj, events, data)
349
350 def register(self, fileobj, events, data=None):
--> 351 key = super().register(fileobj, events, data)
352 poll_events = 0
353 if events & EVENT_READ:
/usr/lib64/python3.6/selectors.py in register(self, fileobj, events, data)
235 raise ValueError("Invalid events: {!r}".format(events))
236
--> 237 key = SelectorKey(fileobj, self._fileobj_lookup(fileobj), events, data)
238
239 if key.fd in self._fd_to_key:
/usr/lib64/python3.6/selectors.py in _fileobj_lookup(self, fileobj)
222 """
223 try:
--> 224 return _fileobj_to_fd(fileobj)
225 except ValueError:
226 # Do an exhaustive search.
/usr/lib64/python3.6/selectors.py in _fileobj_to_fd(fileobj)
37 except (AttributeError, TypeError, ValueError):
38 raise ValueError("Invalid file object: "
---> 39 "{!r}".format(fileobj)) from None
40 if fd < 0:
41 raise ValueError("Invalid file descriptor: {}".format(fd))
ValueError: Invalid file object: <_io.BufferedReader name=61> |
@whzup do you already have |
Also check if you have this declared before calling any animators in your notebook (check
I also recommend you work on the Also, it turns out that the |
Hmm, in the links you provided the people use CentOS I actually use OpenSUSE. I reinstalled ffmpeg and included it in the path using Here is my
Is maybe something missing? |
Have you tried the SO solution above? They're both linux so they should complement. I'm clueless after that. Try some workarounds:
Then set this: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you want, I can take this PR on. But if you have solved the matplotlib problem, then feel free 👍
I'm reinstalling |
It works now 👍 Thanks for the help! |
I found this very weird behaviour that the 4 particles on the right side don't even move for a huge part of the optimization process. Do you think this is related to the boundaries issue #150? If so we urgently need the PR from them! 😮 Also, I think the best function to see the different behaviours might be the sphere function. What do you think? |
HTML video works now
Could be, but the stopping condition is usually for high dimensional search (we only have 2 dimensions). Many reasons exist: high cognitive param, inertia settings, etc. I suggest you try different I’d follow up with them (@jolayfield and co.) at the end of this month.
Sphere is very easy tho, the particles might just move like in the Star topology. I suggest you try an objective function with many local optima and one or very few global optima. From there we can see how other topologies will shine. |
Hi @whzup, I think it's better to work with what we have first. Won't an |
@ljvmiranda921, sure! I'll go with the |
Finished the Star topology section
Problem with Code to reproduce: def plot_optimization(options, topology):
bounds = (np.array([-5, -5]), np.array([5, 5]))
optimizer = ps.single.GeneralOptimizerPSO(n_particles=50,
dimensions=2,
options=options,
topology=topology,
bounds=bounds)
optimizer.optimize(fx.ackley, iters=500)
m = Mesher(func=fx.ackley,
delta=0.01,
limits=[(-5, 5), (-5, 5)],
levels=np.arange(-20,20,1))
d = Designer(limits=[(-5, 5), (-5, 5), (-10, 0)],
label=['x-axis', 'y-axis', 'z-axis'])
animation = plot_contour(pos_history=optimizer.pos_history,
designer=d,
mesher=m,
mark=[0,0])
pos_history_3d = m.compute_history_3d(optimizer.pos_history)
animation3d = plot_surface(pos_history=pos_history_3d,
mesher=m,
designer=d,
mark=[0,0,0])
return (animation, animation3d), optimizer |
@whzup Don't panic. Can you help me investigate that? Things we can check:
|
I found that the
Yes, I'll go ahead and check those 👍 ! |
Gonna work on this after we got #238 . |
I'll close this one for now. This is just a notebook so I think we can rebranch this from the new development branch (my bad). cc: @whzup |
Description
This is a Jupyter notebook with animations of different topologies and some general information about the topologies themselves.
Related Issue
#156
Motivation and Context
The goal of this PR is to visualise the differences between the topologies that have been implemented so far. Additionally, it provides another resource where one might look up how to use the
pyswarms
library. A Jupyter notebook is added where animations of different topologies are shown so one can compare the different neighbourhood properties visually.How Has This Been Tested?
TBD
Screenshots (if appropriate):
TBD
Types of changes
Checklist:
TBD