How to use the pyts.quantization.SFA function in pyts

To help you get started, we’ve selected a few pyts examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github johannfaouzi / pyts / pyts / transformation / transformation.py View on Github external
for i in range(n_windows)])
            X_window = X_window.reshape(n_samples * n_windows, -1, order='F')
        else:
            n_windows = n_features // self.window_size
            remainder = n_features % self.window_size
            if remainder == 0:
                window_idx = np.array_split(np.arange(0, n_features),
                                            n_windows)
            else:
                split_idx = np.arange(self.window_size,
                                      n_windows * (self.window_size + 1),
                                      self.window_size)
                window_idx = np.split(np.arange(0, n_features), split_idx)[:-1]
            X_window = X[:, window_idx].reshape(n_samples * n_windows, -1)

        sfa = SFA(self.n_coefs, False, self.norm_mean,
                  self.norm_std, self.n_bins, self.quantiles,
                  self.variance_selection, self.variance_threshold)
        count = CountVectorizer(ngram_range=(1, 1))

        X_sfa = sfa.fit_transform(X_window)
        X_sfa = np.apply_along_axis(lambda x: ''.join(x),
                                    1,
                                    X_sfa).reshape(n_samples, -1)
        word_size = len(X_sfa[0, 0])
        if word_size == 1:
            count.set_params(tokenizer=self._tok)
        if self.numerosity_reduction:
            X_sfa = np.apply_along_axis(numerosity_reduction, 1, X_sfa)
        else:
            X_sfa = np.apply_along_axis(lambda x: ' '.join(x), 1, X_sfa)
        count.fit(X_sfa)
github johannfaouzi / pyts / pyts / transformation / transformation.py View on Github external
order='F')
            else:
                n_windows = n_features // window_size
                remainder = n_features % window_size
                if remainder == 0:
                    window_idx = np.array_split(np.arange(0, n_features),
                                                n_windows)
                else:
                    split_idx = np.arange(window_size,
                                          (n_windows + 1) * window_size,
                                          window_size)
                    window_idx = np.split(np.arange(0, n_features),
                                          split_idx)[:-1]
                X_window = X[:, window_idx].reshape(n_samples * n_windows, -1)

            sfa = SFA(self.n_coefs, True, self.norm_mean,
                      self.norm_std, self.n_bins, 'entropy',
                      self.variance_selection, self.variance_threshold)
            count = CountVectorizer(ngram_range=(1, 2))

            y_window = np.repeat(y_ind, n_windows)
            X_sfa = sfa.fit_transform(X_window, y_window)
            X_sfa = np.apply_along_axis(lambda x: ''.join(x),
                                        1,
                                        X_sfa).reshape(n_samples, -1)
            word_size = len(X_sfa[0, 0])
            if word_size == 1:
                count.set_params(tokenizer=self._tok)
            X_sfa = np.apply_along_axis(lambda x: ' '.join(x), 1, X_sfa)

            tf = count.fit_transform(X_sfa)
            _, pval = chi2(tf, y_ind)
github johannfaouzi / pyts / pyts / transformation / transformation.py View on Github external
for i in range(n_windows)])
            X_window = X_window.reshape(n_samples * n_windows, -1, order='F')
        else:
            n_windows = n_features // self.window_size
            remainder = n_features % self.window_size
            if remainder == 0:
                window_idx = np.array_split(np.arange(0, n_features),
                                            n_windows)
            else:
                split_idx = np.arange(self.window_size,
                                      n_windows * (self.window_size + 1),
                                      self.window_size)
                window_idx = np.split(np.arange(0, n_features), split_idx)[:-1]
            X_window = X[:, window_idx].reshape(n_samples * n_windows, -1)

        sfa = SFA(self.n_coefs, False, self.norm_mean,
                  self.norm_std, self.n_bins, self.quantiles,
                  self.variance_selection, self.variance_threshold)
        count = CountVectorizer(ngram_range=(1, 1))

        X_sfa = sfa.fit_transform(X_window)
        X_sfa = np.apply_along_axis(lambda x: ''.join(x),
                                    1,
                                    X_sfa).reshape(n_samples, -1)
        word_size = len(X_sfa[0, 0])
        if word_size == 1:
            count.set_params(tokenizer=self._tok)
        if self.numerosity_reduction:
            X_sfa = np.apply_along_axis(numerosity_reduction, 1, X_sfa)
        else:
            X_sfa = np.apply_along_axis(lambda x: ' '.join(x), 1, X_sfa)
        tf = count.fit_transform(X_sfa)
github johannfaouzi / pyts / pyts / classification / classification.py View on Github external
for i in range(n_windows)])
            X_window = X_window.reshape(n_samples * n_windows, -1, order='F')
        else:
            n_windows = n_features // self.window_size
            remainder = n_features % self. window_size
            if remainder == 0:
                window_idx = np.array_split(np.arange(0, n_features),
                                            n_windows)
            else:
                split_idx = np.arange(self.window_size,
                                      n_windows * (self.window_size + 1),
                                      self.window_size)
                window_idx = np.split(np.arange(0, n_features), split_idx)[:-1]
            X_window = X[:, window_idx].reshape(n_samples * n_windows, -1)

        sfa = SFA(self.n_coefs, False, self.norm_mean,
                  self.norm_std, self.n_bins, self.quantiles,
                  self.variance_selection, self.variance_threshold)
        tfidf = TfidfVectorizer(ngram_range=(1, 1), smooth_idf=self.smooth_idf,
                                sublinear_tf=self.sublinear_tf)

        X_sfa = sfa.fit_transform(X_window)
        X_sfa = np.apply_along_axis(lambda x: ''.join(x),
                                    1,
                                    X_sfa).reshape(n_samples, -1)
        word_size = len(X_sfa[0, 0])
        if word_size == 1:
            tfidf.set_params(tokenizer=self._tok)
        if self.numerosity_reduction:
            X_sfa = np.apply_along_axis(numerosity_reduction, 1, X_sfa)
        else:
            X_sfa = np.apply_along_axis(lambda x: ' '.join(x), 1, X_sfa)