def compute_average(self, tseries, nstarts=1, initial_value=None, dba_length=None):
        if initial_value is not None:
            nstarts = 1

        if initial_value is None:
            # initialize the average as a random draw from the set of inputs
            start_idx = np.random.permutation(len(tseries))[:nstarts]

        best_wgss = 1e300
        if self.verbose:
            print 'Doing initialization iteration:'
        for i in range(nstarts):
            print i, '...'
            if initial_value is None:
                iseries = tseries[start_idx[i]]
            else:
                iseries = initial_value
            if dba_length is not None:
                # linearly interpolate initial average value to the requested length
                iseries0 = np.atleast_2d(iseries)
                if iseries0.shape[0] == 1:
                    iseries0 = iseries0.T  # vector, so transpose to shape (ntime, 1)
                nfeatures = iseries0.shape[1]
                iseries = np.zeros((dba_length, nfeatures))
                for k in range(nfeatures):
                    lininterp = interp1d(np.arange(iseries0.shape[0]), iseries0[:, k])
                    iseries[:, k] = lininterp(np.linspace(0.0, iseries0.shape[0]-1.01, num=dba_length))

            self._run_dba(tseries, iseries)

            if self.wgss < best_wgss:
                # found better average, save it
                if self.verbose:
                    print 'New best estimate found for random start', i
                best_wgss = self.wgss
                best_average = self.average

        self.wgss = best_wgss
        self.average = best_average

        return best_average
Perform the DBA algorithm to compute the average for a set of time series. The algorithm is a local optimization
dataset/ETHPy150Open brandonckelly/bck_stats/bck_stats/dba.py/DBA.compute_average