My database contains signals for which I calculate an "average signal" using Soft-DTW barycenter (https://github.com/mblondel/soft-dtw) in order to produce a representative signal of the database. I would like to calculate the standard deviation for all data points of the new representative signal. The thing is, I'm not sure how to define the population of data for which I calculate the standard deviation, given that the alignment using soft dtw involves the sum of several possible alignment paths. soft-dtw is defined(if gamma>0):
where:
When I tried to calculate the standard deviation for DBA following this https://github.com/fpetitjean/DBA which is also based on dynamic time warping, the calculation was more straightforward because the data population only includes the best alignment path, so I updated each iteration like this:
def _petitjean_assignment(X, barycenter, metric_params=None):
if metric_params is None:
metric_params = {}
n = X.shape[0]
barycenter_size = barycenter.shape[0]
assign = ([[] for _ in range(barycenter_size)],
[[] for _ in range(barycenter_size)])
for i in range(n):
path, _ = dtw_path(X[i], barycenter, **metric_params)
for pair in path:
assign[0][pair[1]].append(i)
assign[1][pair[1]].append(pair[0])
return assign
def _petitjean_update_barycenter(X, assign, barycenter_size, weights):
barycenter = numpy.zeros((barycenter_size, X.shape[-1]))
std_dev = numpy.zeros((barycenter_size, X.shape[-1]))
for t in range(barycenter_size):
barycenter[t] = numpy.average(X[assign[0][t], assign[1][t]], axis=0,
weights=weights[assign[0][t]])
std_dev[t] = numpy.std(X[assign[0][t], assign[1][t]], axis=0,
ddof=0)
return barycenter , std_dev
Is this the direction I should be heading or should I also consider the calculation with Soft-DTW? Is it even possible?
In the end, I want to get a plot that looks something like this:


