code: def sample(self, N=1):
          
          if not self.filt:
              self.forward()
          paths = np.empty((len(self.filt), N), np.int)
          paths[-1, :] = rs.multinomial(self.filt[-1], M=N)
          log_trans = np.log(self.hmm.trans_mat)
          for t, f in reversed(list(enumerate(self.filt[:-1]))):
              for n in range(N):
                  probs = rs.exp_and_normalise(log_trans[:, paths[t + 1, n]] + np.log(f))
                  paths[t, n] = rs.multinomial_once(probs)
          return paths
docs: Sample N trajectories from the posterior. 
          
          Note
          ----
          Performs the forward step in case it has not been performed.