ahwillia / affinewarp

An implementation of piecewise linear time warping for multi-dimensional time series alignment
MIT License
162 stars 36 forks source link

Transformed Units Have Drastically Reduced Fire Rates #16

Open mohrabi opened 3 years ago

mohrabi commented 3 years ago

Hi! So I have been trying to apply ShiftWarping on my dataset, but the transformed neurons have reduced spike count rate and in some of the trials, after a certain point of time, transformed units burst! I have no idea whether if this phenomenon is expected or it is due to my code.

The raster plot for one of my neurons is attached, before and after time warping.

130361430-c98d5ec8-f895-473c-b713-9445d158f870

ahwillia commented 3 years ago

The results look very strange. The bursting artifacts are edge effects. Can you provide a short code snippet which shows what you are doing?

mohrabi commented 3 years ago

Oops sorry! I meant LinearWarping

Anyway, here is my code:

twModelLinear = PiecewiseWarping(n_knots=0, warp_reg_scale=1e-6, 
                           smoothness_reg_scale=20.0) 
twModelLinear.fit(np.einsum('ijk->ikj', data.su), iterations=20)
linearTwSu = np.einsum('ijk->ikj', twModelLinear.transform(np.einsum('ijk->ikj', data.su)))

twModel = twModelShift
twSu       = shiftedTwSu

fig, axes = plt.subplots(2, data.nUnit, figsize=(32,8))
for iUnit in range(data.nUnit):
    spikeInds = [np.where(data.su[i, iUnit, :] == 1)[0] for i in range(data.nTrial)]
    axes[0, iUnit].eventplot(np.array(spikeInds, dtype=object))

    spikeInds = [np.where(twSu[i, iUnit, :] == 1)[0] for i in range(data.nTrial)]
    axes[1, iUnit].eventplot(np.array(spikeInds, dtype=object))

and about that edge artifact, is there a clean way to identify (and probably remove) the corrupted trials? For example a simple method by which we can extract the valid time samples based on the warp functions.