In simulated data at least, generating events can lead to situations where events are missed.
#Simulation parameters (see tutorial 2 for complete cell)
# Randomly specify the transition events
n_events = 5
name_sources = np.random.choice(all_source_names,n_events+1, replace=False)#randomly pick source without replacement
# Generated sources = array(['middletemporal-lh', 'caudalmiddlefrontal-rh',
#'caudalanteriorcingulate-rh', 'lateraloccipital-lh',
# 'parstriangularis-lh', 'temporalpole-rh'], dtype='<U27')
times = np.random.uniform(25,300,n_events+1)/shape#randomly pick average times in millisecond between the events
#Generated : array([18.25129272, 18.15805496, 9.26716797, 16.61963181, 15.8271108 , 30.23900551])
When using the fit_single() function with the number of events generated, the correct solution is found without difficulties
selected = init.fit_single(number_of_sources-1)#function to fit an instance of a 10 events model
hmp.visu.plot_topo_timecourse(eeg_dat, selected, positions, init, magnify=1, sensors=False,
times_to_display = np.mean(np.cumsum(random_source_times,axis=1),axis=0))
But running the fit function fails to find the correct number of events despite relatively high signal to noise ratio
estimates, traces = init.fit(threshold=1, verbose=True, trace=True)
hmp.visu.plot_topo_timecourse(eeg_dat, estimates, positions, init,
times_to_display = np.mean(np.cumsum(random_source_times,axis=1),axis=0))
Analyzing the trace of the fit() algorithm shows that all the samples between first and last bump is modelled as an event similar to the first one
hmp.visu.plot_iterations(traces, eeg_dat, init, positions, ['magnitudes_proposed','parameters_proposed'])
...
Looking at the event_sliding() function when given the true channel contribution shows that the third event is likely missed because the likelihood is too low compared to the others (to fix), but why the second one is missed is yet unknown.
init = hmp.models.hmp(hmp_dat, sfreq=eeg_dat.sfreq, event_width=50, cpus=cpus, em_method='max')#Initialization of the model
default_colors = ['cornflowerblue','indianred','orange','darkblue','darkgreen','gold', 'brown']
_, ax = plt.subplots(figsize=(12,3), dpi=300)
init.sliding_event(show=False, ax=ax)
for event in range(n_events):
times = [int(x) for x in init.starts+np.sum(random_source_times[:,:event+1], axis=1)+1]
true_mags = np.median(init.events[times], axis=0)
init.sliding_event(magnitudes=true_mags, color=default_colors[event], ax=ax)
plt.vlines(np.mean(np.cumsum(random_source_times,axis=1),axis=0), -250,600, colors=default_colors[:n_events])
plt.ylim(-250,800)