I am new to HTM - just completed the full set of HTM-school videos - which are great!
I have a problem with the hotgym/prediction/one-gym example. I am using Ubuntu 18.10
I have installed nupic and nupic-mysql as docker containers and successfully run the swarm to get a good model. I can then do “python ./run.py” to output predictions to file correctly. But I cannot get the --plot option to work. I have installed matplotlib using pip. At first this gave en error but I was able to fix this by changing “TKAgg” to “Agg” (in file nupic_output.py), i.e.:
from
import matplotlib
matplotlib.use('TKAgg')
to
import matplotlib
matplotlib.use('Agg')
But this then gives a new error:
File "./run.py", line 151, in <module>
runModel(GYM_NAME, plot=plot)
File "./run.py", line 141, in runModel
runIoThroughNupic(inputData, model, gymName, plot)
File "./run.py", line 127, in runIoThroughNupic
output.write([timestamp], [consumption], [prediction])
File "/usr/local/src/nupic/examples/opf/clients/hotgym/prediction/one_gym/nupic_output.py", line 171, in write
self.initializeLines(timestamps)
File "/usr/local/src/nupic/examples/opf/clients/hotgym/prediction/one_gym/nupic_output.py", line 151, in initializeLines
self.dates[index], self.actualValues[index]
File "/usr/local/lib/python2.7/dist-packages/matplotlib/__init__.py", line 1867, in inner
return func(ax, *args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/matplotlib/axes/_axes.py", line 1528, in plot
for line in self._get_lines(*args, **kwargs):
File "/usr/local/lib/python2.7/dist-packages/matplotlib/axes/_base.py", line 406, in _grab_next_args
for seg in self._plot_args(this, kwargs):
File "/usr/local/lib/python2.7/dist-packages/matplotlib/axes/_base.py", line 383, in _plot_args
x, y = self._xy_from_xy(x, y)
File "/usr/local/lib/python2.7/dist-packages/matplotlib/axes/_base.py", line 215, in _xy_from_xy
bx = self.axes.xaxis.update_units(x)
File "/usr/local/lib/python2.7/dist-packages/matplotlib/axis.py", line 1474, in update_units
self._update_axisinfo()
File "/usr/local/lib/python2.7/dist-packages/matplotlib/axis.py", line 1492, in _update_axisinfo
self.set_major_locator(info.majloc)
File "/usr/local/lib/python2.7/dist-packages/matplotlib/axis.py", line 1597, in set_major_locator
self.stale = True
File "/usr/local/lib/python2.7/dist-packages/matplotlib/artist.py", line 241, in stale
self.stale_callback(self, val)
File "/usr/local/lib/python2.7/dist-packages/matplotlib/artist.py", line 68, in _stale_axes_callback
self.axes.stale = val
File "/usr/local/lib/python2.7/dist-packages/matplotlib/artist.py", line 241, in stale
self.stale_callback(self, val)
File "/usr/local/lib/python2.7/dist-packages/matplotlib/figure.py", line 60, in _stale_figure_callback
self.figure.stale = val
File "/usr/local/lib/python2.7/dist-packages/matplotlib/artist.py", line 241, in stale
self.stale_callback(self, val)
File "/usr/local/lib/python2.7/dist-packages/matplotlib/pyplot.py", line 577, in _auto_draw_if_interactive
fig.canvas.draw_idle()
File "/usr/local/lib/python2.7/dist-packages/matplotlib/backend_bases.py", line 2055, in draw_idle
self.draw(*args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/matplotlib/backends/backend_agg.py", line 437, in draw
self.figure.draw(self.renderer)
File "/usr/local/lib/python2.7/dist-packages/matplotlib/artist.py", line 55, in draw_wrapper
return draw(artist, renderer, *args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/matplotlib/figure.py", line 1493, in draw
renderer, self, artists, self.suppressComposite)
File "/usr/local/lib/python2.7/dist-packages/matplotlib/image.py", line 141, in _draw_list_compositing_images
a.draw(renderer)
File "/usr/local/lib/python2.7/dist-packages/matplotlib/artist.py", line 55, in draw_wrapper
return draw(artist, renderer, *args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/matplotlib/axes/_base.py", line 2635, in draw
mimage._draw_list_compositing_images(renderer, self, artists)
File "/usr/local/lib/python2.7/dist-packages/matplotlib/image.py", line 141, in _draw_list_compositing_images
a.draw(renderer)
File "/usr/local/lib/python2.7/dist-packages/matplotlib/artist.py", line 55, in draw_wrapper
return draw(artist, renderer, *args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/matplotlib/axis.py", line 1190, in draw
ticks_to_draw = self._update_ticks(renderer)
File "/usr/local/lib/python2.7/dist-packages/matplotlib/axis.py", line 1028, in _update_ticks
tick_tups = list(self.iter_ticks()) # iter_ticks calls the locator
File "/usr/local/lib/python2.7/dist-packages/matplotlib/axis.py", line 971, in iter_ticks
majorLocs = self.major.locator()
File "/usr/local/lib/python2.7/dist-packages/matplotlib/dates.py", line 1249, in __call__
self.refresh()
File "/usr/local/lib/python2.7/dist-packages/matplotlib/dates.py", line 1269, in refresh
dmin, dmax = self.viewlim_to_dt()
File "/usr/local/lib/python2.7/dist-packages/matplotlib/dates.py", line 1026, in viewlim_to_dt
.format(vmin))
ValueError: view limit minimum 0.0 is less than 1 and is an invalid Matplotlib date value. This often happens if you pass a non-datetime value to an axis that has datetime units
I have examined the line in question in matplotlib.dates.py and what it seems to be complaining about is that there is a zero difference between the max and min values of the dates array. Which is not surprising since your code initially sets all 100 values to the same date:
def initializeLines(self, timestamps):
for index in range(len(self.names)):
print "initializing %s" % self.names[index]
# graph = self.graphs[index]
self.dates.append(deque([timestamps[index]] * WINDOW, maxlen=WINDOW))
self.convertedDates.append(deque(
[date2num(date) for date in self.dates[index]], maxlen=WINDOW
))
self.actualValues.append(deque([0.0] * WINDOW, maxlen=WINDOW))
self.predictedValues.append(deque([0.0] * WINDOW, maxlen=WINDOW))
print(self.dates[index])
actualPlot, = self.graphs[index].plot(
self.dates[index], self.actualValues[index] --- error here
)
I do not really understand what the above code is supposed to do (I am quite new to python also). Please can you help get this working for me (and others).
Simon