Comments (3)
Also tried it in Google Colab
IndexError Traceback (most recent call last)
in ()
4 problem = FireflyProblem(function=FUNCTIONS['michalewicz'], firefly_number=20)
5 best_firefly = problem.solve()
----> 6 problem.replay()
19 frames
/usr/local/lib/python3.7/dist-packages/swarmlib/util/problem_base.py in replay(self)
23 Start the problems visualization.
24 """
---> 25 self._visualizer.replay()
/usr/local/lib/python3.7/dist-packages/swarmlib/util/base_visualizer.py in replay(self, **kwargs)
84 # iteration_number+1 for initialization frame
85 _ = animation.FuncAnimation(self._fig, self._animate, frames=frames, interval=self.__frame_interval,
---> 86 blit=True, init_func=self._init, repeat=self.__continuous, fargs=[frames])
87
88 plt.show()
/usr/local/lib/python3.7/dist-packages/matplotlib/animation.py in init(self, fig, func, frames, init_func, fargs, save_count, cache_frame_data, **kwargs)
1632 self._save_seq = []
1633
-> 1634 super().init(fig, **kwargs)
1635
1636 # Need to reset the saved seq, since right now it will contain data
/usr/local/lib/python3.7/dist-packages/matplotlib/animation.py in init(self, fig, interval, repeat_delay, repeat, event_source, *args, **kwargs)
1394 if event_source is None:
1395 event_source = fig.canvas.new_timer(interval=self._interval)
-> 1396 super().init(fig, event_source=event_source, *args, **kwargs)
1397
1398 def _step(self, *args):
/usr/local/lib/python3.7/dist-packages/matplotlib/animation.py in init(self, fig, event_source, blit)
881 self._stop)
882 if self._blit:
--> 883 self._setup_blit()
884
885 def del(self):
/usr/local/lib/python3.7/dist-packages/matplotlib/animation.py in _setup_blit(self)
1195 self._resize_id = self._fig.canvas.mpl_connect('resize_event',
1196 self._on_resize)
-> 1197 self._post_draw(None, self._blit)
1198
1199 def _on_resize(self, event):
/usr/local/lib/python3.7/dist-packages/matplotlib/animation.py in _post_draw(self, framedata, blit)
1148 self._blit_draw(self._drawn_artists)
1149 else:
-> 1150 self._fig.canvas.draw_idle()
1151
1152 # The rest of the code in this class is to facilitate easy blitting
/usr/local/lib/python3.7/dist-packages/matplotlib/backend_bases.py in draw_idle(self, *args, **kwargs)
2058 if not self._is_idle_drawing:
2059 with self._idle_draw_cntx():
-> 2060 self.draw(*args, **kwargs)
2061
2062 @Property
/usr/local/lib/python3.7/dist-packages/matplotlib/backends/backend_agg.py in draw(self)
434 (self.toolbar._wait_cursor_for_draw_cm() if self.toolbar
435 else nullcontext()):
--> 436 self.figure.draw(self.renderer)
437 # A GUI class may be need to update a window using this draw, so
438 # don't forget to call the superclass.
/usr/local/lib/python3.7/dist-packages/matplotlib/artist.py in draw_wrapper(artist, renderer, *args, **kwargs)
71 @wraps(draw)
72 def draw_wrapper(artist, renderer, *args, **kwargs):
---> 73 result = draw(artist, renderer, *args, **kwargs)
74 if renderer._rasterizing:
75 renderer.stop_rasterizing()
/usr/local/lib/python3.7/dist-packages/matplotlib/artist.py in draw_wrapper(artist, renderer)
48 renderer.start_filter()
49
---> 50 return draw(artist, renderer)
51 finally:
52 if artist.get_agg_filter() is not None:
/usr/local/lib/python3.7/dist-packages/matplotlib/figure.py in draw(self, renderer)
2845 self.stale = False
2846
-> 2847 self.canvas.draw_event(renderer)
2848
2849 def draw_without_rendering(self):
/usr/local/lib/python3.7/dist-packages/matplotlib/backend_bases.py in draw_event(self, renderer)
1777 s = 'draw_event'
1778 event = DrawEvent(s, self, renderer)
-> 1779 self.callbacks.process(s, event)
1780
1781 def resize_event(self):
/usr/local/lib/python3.7/dist-packages/matplotlib/cbook/init.py in process(self, s, *args, **kwargs)
290 except Exception as exc:
291 if self.exception_handler is not None:
--> 292 self.exception_handler(exc)
293 else:
294 raise
/usr/local/lib/python3.7/dist-packages/matplotlib/cbook/init.py in _exception_printer(exc)
94 def _exception_printer(exc):
95 if _get_running_interactive_framework() in ["headless", None]:
---> 96 raise exc
97 else:
98 traceback.print_exc()
/usr/local/lib/python3.7/dist-packages/matplotlib/cbook/init.py in process(self, s, *args, **kwargs)
285 if func is not None:
286 try:
--> 287 func(*args, **kwargs)
288 # this does not capture KeyboardInterrupt, SystemExit,
289 # and GeneratorExit
/usr/local/lib/python3.7/dist-packages/matplotlib/animation.py in _start(self, *args)
905
906 # Now do any initial draw
--> 907 self._init_draw()
908
909 # Add our callback for stepping the animation and
/usr/local/lib/python3.7/dist-packages/matplotlib/animation.py in _init_draw(self)
1696 self._draw_frame(frame_data)
1697 else:
-> 1698 self._drawn_artists = self._init_func()
1699 if self._blit:
1700 if self._drawn_artists is None:
/usr/local/lib/python3.7/dist-packages/swarmlib/util/base_visualizer.py in _init(self)
92 Init function for animations. Only used for FuncAnimation
93 """
---> 94 self.__particles.set_offsets([[]])
95 self._marker_colors = np.full(len(self._positions[0][0]), self._marker_color) # Create array of correct size
96 self.__particle_vel.X = []
/usr/local/lib/python3.7/dist-packages/matplotlib/collections.py in set_offsets(self, offsets)
562 offsets = offsets[None, :]
563 self._offsets = np.column_stack(
--> 564 (np.asarray(self.convert_xunits(offsets[:, 0]), 'float'),
565 np.asarray(self.convert_yunits(offsets[:, 1]), 'float')))
566 self.stale = True
IndexError: index 0 is out of bounds for axis 1 with size 0
from swarmlib.
Also in Shell:
swarm fireflies 14
2022-06-27 12:54:28,458 [INFO ] Start firefly algorithm with parameters="{'dark': False, 'interval': 1000, 'continuous': False, 'seed': None, 'function': 'michalewicz', 'upper_boundary': 4.0, 'lower_boundary': 0.0, 'alpha': 0.25, 'beta': 1.0, 'gamma': 0.97, 'iteration_number': 10, 'firefly_number': 14}"
2022-06-27 12:54:29,272 [INFO ] Current best value: -0.6543338821854172, Overall best value: -0.6543338821854172
2022-06-27 12:54:29,281 [INFO ] Current best value: -1.046547634297289, Overall best value: -1.046547634297289
2022-06-27 12:54:29,291 [INFO ] Current best value: -1.7810052971375656, Overall best value: -1.7810052971375656
2022-06-27 12:54:29,299 [INFO ] Current best value: -1.7928715391071766, Overall best value: -1.7928715391071766
2022-06-27 12:54:29,308 [INFO ] Current best value: -1.7999274187707126, Overall best value: -1.7999274187707126
2022-06-27 12:54:29,317 [INFO ] Current best value: -1.800946593957634, Overall best value: -1.800946593957634
2022-06-27 12:54:29,327 [INFO ] Current best value: -1.8009744891690338, Overall best value: -1.8009744891690338
2022-06-27 12:54:29,334 [INFO ] Current best value: -1.8009726637321928, Overall best value: -1.8009744891690338
2022-06-27 12:54:29,342 [INFO ] Current best value: -1.800891240644705, Overall best value: -1.8009744891690338
2022-06-27 12:54:29,350 [INFO ] Current best value: -1.799779373119411, Overall best value: -1.8009744891690338
Traceback (most recent call last):
File "\envs\optimization\lib\site-packages\matplotlib\cbook_init_.py", line 287, in process
func(*args, **kwargs)
File "\envs\optimization\lib\site-packages\matplotlib\animation.py", line 907, in _start
self._init_draw()
File "\envs\optimization\lib\site-packages\matplotlib\animation.py", line 1698, in _init_draw
self._drawn_artists = self._init_func()
File \envs\optimization\lib\site-packages\swarmlib\util\base_visualizer.py", line 94, in _init
self._particles.set_offsets([[]])
File "\envs\optimization\lib\site-packages\matplotlib\collections.py", line 564, in set_offsets
(np.asarray(self.convert_xunits(offsets[:, 0]), 'float'),
IndexError: index 0 is out of bounds for axis 1 with size 0
Traceback (most recent call last):
File "\envs\optimization\lib\site-packages\matplotlib\cbook_init.py", line 287, in process
func(*args, **kwargs)
File "\envs\optimization\lib\site-packages\matplotlib\animation.py", line 1207, in _on_resize
self._init_draw()
File "\envs\optimization\lib\site-packages\matplotlib\animation.py", line 1698, in _init_draw
self._drawn_artists = self._init_func()
File "\envs\optimization\lib\site-packages\swarmlib\util\base_visualizer.py", line 94, in _init
self.__particles.set_offsets([[]])
File "\envs\optimization\lib\site-packages\matplotlib\collections.py", line 564, in set_offsets
(np.asarray(self.convert_xunits(offsets[:, 0]), 'float'),
IndexError: index 0 is out of bounds for axis 1 with size 0
from swarmlib.
Fixed the issue with downgrading matplotlib (3.5.2 -> 3.5.0)
Now it works.
from swarmlib.
Related Issues (20)
- Use color gradient for intermediate best solutions
- What if the input of the object function is not 2-dimensional? HOT 1
- Cannot import matplotlib HOT 9
- Support 3D Visualization
- Add Unit Tests
- Move CI/CD Pipeline to GitHub Actions
- Rename cuckoo search's --max-generations option to --iteration-number
- Set the log level at runtime
- Add the Bacterial Foraging Optimization Algorithm
- Add the Elephant Herding Optimization algorithm
- Read swarmlib's dependencies only from the requirements.txt file HOT 2
- Show help message when calling CLI without args.
- Add Sailfish Optimizer
- Add bird swarm algorithm
- Decouple the algorithms from the CLI and visualization
- Strange Error which might be caused by matplotlib
- Strange Error which might be caused by matplotlib HOT 3
- IndexError: index 0 is out of bounds for axis 1 with size 0 HOT 3
- Is it possible to use Particle Swarm Optimization with custom functions? HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from swarmlib.