def _format_for_gam2(count, time, pos): assert np.rank(count) == np.rank(time) == (np.rank(pos) - 1) assert count.shape[0] == time.shape[0] == pos.shape[0] assert (count.shape[1] + 1) == time.shape[1] == pos.shape[1] y = count.flatten()[:,None] npt = y.size tax, spax = 1, -1 # don't use real time as won't compare equivalent portions of trials # t = edge2cen(time, axis=tax) # (ntrial, nbin) # subtract offset to get all relative times #t = (t - t[:,:1]).flatten()[:,None] # instead use bin numbers ntrial, nbin = count.shape t = np.tile(np.arange(nbin, dtype=float)[None], (ntrial, 1)) t = t.flatten()[:,None] # also create trial numbers for pulling out appropriate later on # these don't correspond to original trial numbers because original trials # have been permuted before getting here tr = np.tile(np.arange(ntrial), (nbin, 1)).T.flatten() d = kin.get_dir(pos, tax=tax, spax=spax).reshape(npt, 3) p = edge2cen(pos, axis=tax).reshape(npt, 3) v = kin.get_vel(pos, time, tax=tax, spax=spax).reshape(npt, 3) sp = kin.get_speed(pos, time, tax=tax, spax=spax).flatten()[:,None] # q is a second direction set-of-columns for deviance calculation q = kin.get_dir(pos, tax=tax, spax=spax).reshape(npt, 3) return np.concatenate([y,t,d,p,v,sp,q], axis=1), tr
def _format_for_gam(count, time, pos): ''' Format data for gam_predict_cv, i.e. an (n, 12) array Parameters ---------- count : ndarray spike counts, shape (ntrial, nbin) time : ndarray bin_edges, shape (ntrial, nbin + 1) pos : ndarray positions at `bin_edges`, shape (ntrial, nbin + 1, 3) Returns ------- formatted_data : ndarray shape (ntrial * nbin, 12) dimension 1 is [count, t, dx, dy, dz, px, py, pz, vx, vy, vz, sp] ''' assert np.rank(count) == np.rank(time) == (np.rank(pos) - 1) assert count.shape[0] == time.shape[0] == pos.shape[0] assert (count.shape[1] + 1) == time.shape[1] == pos.shape[1] y = count.flatten()[:,None] npt = y.size tax, spax = 1, -1 # don't use real time as won't compare equivalent portions of trials # t = edge2cen(time, axis=tax) # (ntrial, nbin) # subtract offset to get all relative times #t = (t - t[:,:1]).flatten()[:,None] # instead use bin numbers ntrial, nbin = count.shape t = np.tile(np.arange(nbin, dtype=float)[None], (ntrial, 1)) t = t.flatten()[:,None] d = kin.get_dir(pos, tax=tax, spax=spax).reshape(npt, 3) p = edge2cen(pos, axis=tax).reshape(npt, 3) v = kin.get_vel(pos, time, tax=tax, spax=spax).reshape(npt, 3) sp = kin.get_speed(pos, time, tax=tax, spax=spax).flatten()[:,None] # q is a second direction set-of-columns for deviance calculation q = kin.get_dir(pos, tax=tax, spax=spax).reshape(npt, 3) return np.concatenate([y,t,d,p,v,sp,q], axis=1)