def calculatePathIntegrationError(self, time, dt=None, trajectory=None,
                                    envelope=False, inputNoise=None):
    """
    Calculate the error of our path integration, relative to an ideal module.
    To do this, we track the movement of an individual bump

    Note that the network must be trained before this is done.
    :param time: How long to simulate for in seconds.  We recommend using a
            small value, e.g. ~10s.
    :param trajectory: An optional trajectory that specifies how the network moves.
    :param inputNoise: Whether or not to apply noise, and how much.
    :return: A tuple of the true trajectory and the inferred trajectory.
    """
    # Set up plotting
    if self.plotting:
      self.fig = plt.figure()
      self.ax1 = self.fig.add_subplot(411)
      self.ax2 = self.fig.add_subplot(412)
      self.ax3 = self.fig.add_subplot(413)
      self.ax4 = self.fig.add_subplot(414)
      plt.tight_layout()
      plt.ion()
      self.fig.show()
      self.fig.canvas.draw()
      mouse = plt.imread(os.path.dirname(os.path.realpath(__file__))
                         + "/mouse_graphic.png")

      self.ax1.set_xlabel("Excitatory population activity")
      self.ax2.set_xlabel("Inhibitory population activity")
      self.ax3.set_xlabel("Movement in cells")
      self.ax3.set_ylabel("Cost")
      self.ax4.set_xlabel("Location")

      plt.tight_layout()


    if dt is None:
      oldDt = self.dt
    else:
      oldDt = self.dt
      self.dt = dt

    # Simulate for a second to get nice starting activation bumps.
    # Turn plotting off so as not to confuse the viewer
    oldPlotting = self.plotting
    self.plotting = False
    self.simulate(1, 1, 1, 0, envelope=envelope, inputNoise=None)
    self.plotting = oldPlotting


    estimatedVelocities = []
    trueVelocities = []

    times = np.arange(0, time, self.dt)
    if trajectory is None:
      # Sum together two different sinusoidals for a more interesting path.
      trajectory = (np.sin((-times*np.pi/10 - np.pi/2.))+1)*2.5
      trajectory += (np.cos((-times*np.pi/3 - np.pi/2.))+1)*.75
      velocities = np.diff(trajectory)/self.dt

    oldActivations = copy.copy(self.activationsI)
    oldX = trajectory[0]
    for i, t in enumerate(times[:-1]):
      v = velocities[i]
      x = trajectory[i]

      feedforwardInputI = np.ones(self.activationsI.shape)
      feedforwardInputE = np.ones(self.activationsEL.shape)

      if inputNoise is not None:
        noisesI = np.random.random_sample(feedforwardInputI.shape)*inputNoise
        noisesE = np.random.random_sample(feedforwardInputE.shape)*inputNoise
      else:
        noisesE = 1.
        noisesI = 1.

      self.update(feedforwardInputI*noisesI, feedforwardInputE*noisesE,
                  v, True, envelope=envelope)

      estimationTime = np.abs(np.mod(t, ESTIMATION_INTERVAL))
      if estimationTime <= 0.00001 or \
          np.abs(estimationTime - ESTIMATION_INTERVAL) <= 0.00001:

          rotations = [np.sum(np.abs(np.roll(oldActivations, i) -
                                     self.activationsI))
                       for i in range(-10, 11, 1)]

          shift = np.argmin(rotations) - 10

          trueVelocities.append(x - oldX)
          oldX = x
          oldActivations = copy.copy(self.activationsI)
          estimatedVelocities.append(shift)

      if self.plotting:
        plotTime = np.abs(np.mod(t, PLOT_INTERVAL))
        if plotTime <= 0.00001 or np.abs(plotTime - PLOT_INTERVAL) <= 0.00001:
          self.ax3.clear()
          self.ax3.plot(np.arange(-len(rotations)/2 + 1, len(rotations)/2 + 1, 1),
                                  rotations,
                                  color="g",
                                  label="Shift")
          self.ax3.legend(loc="best")
          self.ax3.set_xlabel("Movement in cells")
          self.ax3.set_ylabel("Cost")
          self.ax3.axvline(x=shift)

          self.ax4.clear()
          self.ax4.set_xlim(np.amin(trajectory), np.amax(trajectory))
          self.ax4.set_ylim(0, 1)
          mouse_bound = (x - 0.25*np.sign(v), x + 0.25*np.sign(v), .05, .55)
          self.ax4.imshow(mouse,
                          aspect='auto',
                          extent=mouse_bound,
                          zorder=-1)
          self.ax4.set_xlabel("Location")
          self.ax4.axes.get_yaxis().set_visible(False)

          self.fig.canvas.draw()

          self.plotActivation(time=t, velocity=v, boosting=False)

    self.dt = oldDt
    return(np.asarray(trueVelocities), np.asarray(estimatedVelocities))
Calculate the error of our path integration, relative to an ideal module.
    To do this, we track the movement of an individual bump

    Note that the network must be trained before this is done.
    :param time: How long to simulate for in seconds.  We recommend using a
            small value, e.g. ~10s.
    :param trajectory: An optional trajectory that specifies how the network moves.
    :param inputNoise: Whether or not to apply noise, and how much.
    :return: A tuple of the true trajectory and the inferred trajectory.