def fit(self): ''' First finds the wavelet in types that fits the data the best => The smallest Euclidean distance between the approximation signal and under-sampled signal After finding the best Wavelet, uses it to decompose data into levels detail signals and builds a AR(p) model per approximation signal and detail signals using order as p for each corresponding ''' self.bestType = 'db1' bestDist = np.inf for t in self.types: approx_levels = pywt.wavedec(self.data, wavelet=t, level=self.levels) idx = np.int_(np.linspace(0, self.data.shape[0]-1, num=len(approx_levels[0]))) samples = self.data[idx] dist = np.linalg.norm(approx_levels[0]-samples) if dist < bestDist: bestDist = dist self.bestType = t self.coefs = pywt.wavedec(self.data, wavelet=self.bestType, level=self.levels) for i in range(len(self.order)): # model = AR_model(approx_levels[i], order=self.order[i]) model = Markov_model(approx_levels[i], maximum=np.max(approx_levels[i])) model.fit() self.models.append(model)
def __init__(self, data, maximum, corr_tresh=0.85, mean_ratio=0.1, match_rate=1.0, filter_window=21): ''' Create a Signature Pattern recognizer Markov based on PRESS's signature-driven method Params ------ @param data: Training data @type data: Array-like @param corr_tresh: Patterns should have a Pearson-Correlation above corr_tresh @type corr_tresh: float @param mean_ratio: ''' self.history = data[:] self.data = data[:] self.corr_thres = corr_tresh self.mr = mean_ratio self.window = filter_window self.match = match_rate self.N = data.shape[0] self.contain_pat = False self.warp = False self.markov = Markov_model(data=data, maximum=maximum)