Closed GWeindel closed 1 year ago
The implementation of Solution 2 requires more rewriting than shown here, to try out the solution one can switch to the padding_implementation branch
Solution 2 sounds much less error-prone in the long run (and easier to interpret), so if that works it seems to preferred.
In several places you mention first and last stage, but only the first stage is exempted from this, right? For example
locations[-1] = 0
needs to be removed, I think.
I agree that solution 2 is preferred.
About the last stage, previous implementations did include a location/padding for that stage, but I think it is an error: The last stage ends with the RT, so there is no pattern expected. Hence, I think this last stage should be left without location as it might generate weirdness to account for this location while having the end of the time serie.
I might have fixed solution 1 with https://github.com/GWeindel/hsmm_mvpy/commit/1cc45bb99191e0c59852c90b2f48e8ef82b67d88.
I changed multiple things:
max_d
instead of mean_d
, removing a bias to earlier bumpsevent_width
, not event_width/2
However, many solution with random starting points do not converge.
For the location parameter, the padding in the cross-correlation justifies event_width/2
And it works (same simulation parameters as tutorial 2 but different seed):
init = hmp.models.hmp(hmp_dat, sfreq=epoch_data.sfreq, event_width=50, cpus=cpus, location=25)#Initialization of the model
estimates = init.fit()
hmp.visu.plot_topo_timecourse(epoch_data, estimates, info, init,
times_to_display = np.mean(np.cumsum(random_source_times,axis=1),axis=0), magnify=1)
vs.
init = hmp.models.hmp(hmp_dat, sfreq=epoch_data.sfreq, event_width=50, cpus=cpus, location=25)#Initialization of the model
estimates = init.fit()
hmp.visu.plot_topo_timecourse(epoch_data, estimates, info, init,
times_to_display = np.mean(np.cumsum(random_source_times,axis=1),axis=0), magnify=1)
The minimum duration might indeed be useful, I'll check that
Fixed by #102
Context
The cross-correlation used for the pattern analysis yields some padding in the signal
This forces us to add a penalty to the samples that immediately follow a detected event. Otherwise all n_events gets squashed into one (or a subset gets squashed), to reproduce use a location of 0 when fitting a model
To do this two solutions:
Solution 1: Add a location parameter
Problems:
params[1:-1,1] -= self.location
breaks working code and gives weird solutions on the existing datasetsSolution 2 : Censor first samples in the PDF of the time distribution
Instead of a location parameter, one can censor the samples that follow the event if it is a stage between two events. This has the advantage of modelling a time distribution without location and not require any additional step when computing the scale parameters from the average positions.
This is currently under investigation