Ejemplo n.º 1
0
    def encode(self, bnd):
        '''
        Return spike counts corresponding to given direction and encoding model.

        Parameters
        ----------
        bnd :BinnedData
          uses bnd.pos, bnd.bin_edges
        '''
        pos = bnd.pos
        time = bnd.bin_edges
        ntask, nrep, nedge, ndim = pos.shape
        model = self.model

        assert(ndim == 3)
        nbin = nedge - 1
        lshape = ntask, nrep, nbin
        rate = np.zeros(lshape, dtype=float)
        assert(model == 'kd') # only model currently implemented 
        
        rate += self.B['k']                           # baseline
        dr    = get_dir(pos)
        rate += np.dot(dr, self.B['D'])               # direction
        rate += np.dot(pos[...,:-1,:], self.B['P'])   # position
        speed = get_speed(pos, time, tax=2, spax=-1)
        rate += self.B['s'] * speed
        return np.exp(rate)
Ejemplo n.º 2
0
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
Ejemplo n.º 3
0
    def encode(self, bnd):
        '''
        Return spike counts corresponding to given direction and encoding model.

        Parameters
        ----------
        bnd :BinnedData
          uses bnd.pos, bnd.bin_edges
        '''
        pos = bnd.pos
        time = bnd.bin_edges
        ntask, nrep, nedge, ndim = pos.shape
        model = self.model

        assert (ndim == 3)
        nbin = nedge - 1
        lshape = ntask, nrep, nbin
        rate = np.zeros(lshape, dtype=float)
        assert (model == 'kd')  # only model currently implemented

        rate += self.B['k']  # baseline
        dr = get_dir(pos)
        rate += np.dot(dr, self.B['D'])  # direction
        rate += np.dot(pos[..., :-1, :], self.B['P'])  # position
        speed = get_speed(pos, time, tax=2, spax=-1)
        rate += self.B['s'] * speed
        return np.exp(rate)
Ejemplo n.º 4
0
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)