# Path: sciquence/representation/sax.py
# def sax(sequence, window, alphabet_size=5, adjust=True):
#     '''
# 
#     Symbolic Aggregate Approximation.
# 
#     Transform time series into a string.
# 
#     Parameters
#     ----------
#     sequence: numpy.ndarray
#         One-dimensional numpy array of arbitrary length
#     window: int
#         Length of sliding window
#     alphabet_size: int
#         Number of Gaussian breakpoints
#     adjust: bool, default True
#         Compute only for equal-size chunks
# 
#     Returns
#     -------
#     sax_representation: str
#         A SAX representation
# 
#     Examples
#     --------
#     >>> import numpy as np
#     >>> from sciquence.representation import sax
#     >>> np.random.seed(42)
#     >>> random_time_series = np.random.rand(50)
#     >>> print sax(random_time_series, 10, alphabet_size=5)
#     dcccc
# 
#     References
#     ----------
#     .. [1] Lin, J., Keogh, E., Lonardi, S., & Chiu, B. (2003).
#            A Symbolic Representation of Time Series,
#            with Implications for Streaming Algorithms.
#            In proceedings of the 8th ACM SIGMOD Workshop
#            on Research Issues in Data Mining and Knowledge Discovery.
# 
#            http://www.cs.ucr.edu/~eamonn/SAX.pdf
# 
#     .. [2] http://www.cs.ucr.edu/~eamonn/SAX.htm
#     .. [3] https://jmotif.github.io/sax-vsm_site/morea/algorithm/SAX.html
# 
#     '''
# 
#     # TODO: check dimensionality, size, aphabet size etc.
#     # Pre-step: checking if all arguments have proper values
# 
# 
#     # First step: Standardization ( aka normalization, z-normalization or standard score)
#     scaled = scale(sequence)
# 
#     # Second step: PAA
#     paa_repr = paa(scaled, window=window, adjust=adjust)
# 
#     # Last step:
#     breakpoints = gauss_breakpoints(alphabet_size)
#     letters = _alphabet(alphabet_size)
# 
#     breakpoints= np.array(breakpoints)
#     symbols = np.array(letters)
#     return reduce(add, symbols[np.digitize(paa_repr, breakpoints)])


import numpy as np
import scipy.stats
from sklearn.preprocessing import scale, StandardScaler
from sklearn.feature_extraction.text import TfidfVectorizer
from operator import add
from sciquence.sliding_window import wingen, raw_wingen
from sciquence.representation import sax
from scipy.spatial.distance import cosine
from sklearn.base import BaseEstimator
        rows = []
        for row in X:
            rows.append(self._transform(row))

        # TF-IDF transformation
        # TODO: implement own TF-IDF transformer. Here, some kind of hack is used
        hacky_list = [reduce(add, [word + " " for word in ts]) for ts in rows]

        self.timeseries =  self.tfidf.fit_transform(hacky_list)

        return self


    def predict(self, X):
        predictions = []
        # Transform and compute cosine similarity
        for row in X:
            pred = get_most_similar(self._transform(row), self.timeseries)
            predictions.append(pred)
        return np.array(predictions)


    def _transform(self, row):
        row_sax = []

        # TODO: check this option
        wgen = wingen if self.adjust else raw_wingen

        for window in wgen(row, self.window):
            row_sax.append(

# Path: sciquence/representation/sax.py
# def sax(sequence, window, alphabet_size=5, adjust=True):
#     '''
# 
#     Symbolic Aggregate Approximation.
# 
#     Transform time series into a string.
# 
#     Parameters
#     ----------
#     sequence: numpy.ndarray
#         One-dimensional numpy array of arbitrary length
#     window: int
#         Length of sliding window
#     alphabet_size: int
#         Number of Gaussian breakpoints
#     adjust: bool, default True
#         Compute only for equal-size chunks
# 
#     Returns
#     -------
#     sax_representation: str
#         A SAX representation
# 
#     Examples
#     --------
#     >>> import numpy as np
#     >>> from sciquence.representation import sax
#     >>> np.random.seed(42)
#     >>> random_time_series = np.random.rand(50)
#     >>> print sax(random_time_series, 10, alphabet_size=5)
#     dcccc
# 
#     References
#     ----------
#     .. [1] Lin, J., Keogh, E., Lonardi, S., & Chiu, B. (2003).
#            A Symbolic Representation of Time Series,
#            with Implications for Streaming Algorithms.
#            In proceedings of the 8th ACM SIGMOD Workshop
#            on Research Issues in Data Mining and Knowledge Discovery.
# 
#            http://www.cs.ucr.edu/~eamonn/SAX.pdf
# 
#     .. [2] http://www.cs.ucr.edu/~eamonn/SAX.htm
#     .. [3] https://jmotif.github.io/sax-vsm_site/morea/algorithm/SAX.html
# 
#     '''
# 
#     # TODO: check dimensionality, size, aphabet size etc.
#     # Pre-step: checking if all arguments have proper values
# 
# 
#     # First step: Standardization ( aka normalization, z-normalization or standard score)
#     scaled = scale(sequence)
# 
#     # Second step: PAA
#     paa_repr = paa(scaled, window=window, adjust=adjust)
# 
#     # Last step:
#     breakpoints = gauss_breakpoints(alphabet_size)
#     letters = _alphabet(alphabet_size)
# 
#     breakpoints= np.array(breakpoints)
#     symbols = np.array(letters)
#     return reduce(add, symbols[np.digitize(paa_repr, breakpoints)])


# Path: sciquence/sax_vsm.py
import numpy as np
import scipy.stats
from sklearn.preprocessing import scale, StandardScaler
from sklearn.feature_extraction.text import TfidfVectorizer
from operator import add
from sciquence.sliding_window import wingen, raw_wingen
from sciquence.representation import sax
from scipy.spatial.distance import cosine
from sklearn.base import BaseEstimator

        rows = []
        for row in X:
            rows.append(self._transform(row))

        # TF-IDF transformation
        # TODO: implement own TF-IDF transformer. Here, some kind of hack is used
        hacky_list = [reduce(add, [word + " " for word in ts]) for ts in rows]

        self.timeseries =  self.tfidf.fit_transform(hacky_list)

        return self


    def predict(self, X):
        predictions = []
        # Transform and compute cosine similarity
        for row in X:
            pred = get_most_similar(self._transform(row), self.timeseries)
            predictions.append(pred)
        return np.array(predictions)


    def _transform(self, row):
        row_sax = []

        # TODO: check this option
        wgen = wingen if self.adjust else raw_wingen

        for window in wgen(row, self.window):
            row_sax.append(

                sax(window, window=self.word_length, alphabet_size=self.alphabet_size)