def _run_dba(self, tseries, initial_value):
        nseries = len(tseries)

        self.average = initial_value

        # first iteration: get initial within-group sum of squares
        if self.verbose:
            print 'Doing iteration'
            print ' ', '0', '...'
        wgss = self._dba_iteration(tseries)

        # main DBA loop
        for i in range(1, self.max_iter):
            if self.verbose:
                print ' ', i, '...', 'WGSS:', wgss
            wgss_old = wgss
            # WGSS is actually from previous iteration, but don't compute again because it is expensive
            wgss = self._dba_iteration(tseries)
            if wgss > wgss_old:
                # sum of squares should be non-increasing
                print 'Warning! Within-group sum of squares increased at iteration', i, 'terminating algorithm.'
                break
            elif np.abs(wgss - wgss_old) / wgss_old < self.tol:
                # convergence
                break

        # compute final within-group sum of squares
        wgss = 0.0
        for k in range(nseries):
            wgss += dynamic_time_warping(tseries[k], self.average)[0]
        self.wgss = wgss
Perform the DBA algorithm.
dataset/ETHPy150Open brandonckelly/bck_stats/bck_stats/dba.py/DBA._run_dba