''' /******************************************************************************* * Copyright (C) 2018 Francois Petitjean * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, version 3 of the License. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . ******************************************************************************/ ''' from __future__ import division import numpy as np import matplotlib.pyplot as plt from functools import reduce __author__ ="Francois Petitjean" def performDBA(series, n_iterations=10): n_series = len(series) max_length = reduce(max, map(len, series)) cost_mat = np.zeros((max_length, max_length)) delta_mat = np.zeros((max_length, max_length)) path_mat = np.zeros((max_length, max_length), dtype=np.int8) medoid_ind = approximate_medoid_index(series,cost_mat,delta_mat) center = series[medoid_ind] for i in range(0,n_iterations): center = DBA_update(center, series, cost_mat, path_mat, delta_mat) return center def approximate_medoid_index(series,cost_mat,delta_mat): if len(series)<=50: indices = range(0,len(series)) else: indices = np.random.choice(range(0,len(series)),50,replace=False) medoid_ind = -1 best_ss = 1e20 for index_candidate in indices: candidate = series[index_candidate] ss = sum_of_squares(candidate,series,cost_mat,delta_mat) if(medoid_ind==-1 or ss35) psth1 = np.delete(psth_tot[0, :, :, 20], rows, axis=0) series1 = list() for ii in range(psth1.shape[0]): series1.append(psth1[ii]) series1 = np.array(series1) dba = performDBA(series1) plt.figure() plt.clf() plt.plot(psth1.T, 'C0', alpha=0.5) plt.plot(dba, 'k') plt.draw()