# Path: pycast/common/pycastobject.py
# class PyCastObject(object):
# 
# 
#     """The base class for all pycast objects.
# 
#     This class is used to introduce a common interface for potential
#     C/C++/OpenCL optimization within pycast, as well as other common
#     tasks.
#     """
# 
#     # stores, if pycast should only create optimized instances.
#     # default = False
#     _globalOptimize = False
# 
#     def __init__(self):
#         """Initializes the PyCastObject."""
#         super(PyCastObject, self).__init__()
#         self.optimizationEnabled = False
# 
#         if PyCastObject._globalOptimize:
#             self._enable_instance_optimization()
# 
#     def _enable_instance_optimization(self):
#         """Enables the optimization for the PyCastObject instance.
# 
#         :warning:    Do not forget to implement the disable_instance_optimization()
#             as well.
#         """
#         self.optimizationEnabled = True
# 
#     def _disable_instance_optimization(self):
#         """Disables the optimization for the PyCastObject instance."""
#         self.optimizationEnabled = False
# 
#     @classmethod
#     def enable_global_optimization(cls):
#         """Enables the global optimization of pycast methods, if possible.
# 
#         By default, optimization is turned off.
# 
#         :note:    Only new created instances will be affected.
#         """
#         cls._globalOptimize = True
# 
#     @classmethod
#     def disable_global_optimization(cls):
#         """Disables the global optimization of pycast methods.
# 
#         :note:    Only new created instances will be affected.
#         """
#         cls._globalOptimize = False
# 
# Path: pycast/common/timeseries.py
# _STR_EPOCHS = "UNIX-epochs"
# class TimeSeries(PyCastObject):
# class MultiDimensionalTimeSeries(TimeSeries):
#     def __init__(self, isNormalized=False, isSorted=False):
#     def set_timeformat(self, tsformat=None):
#     def to_gnuplot_datafile(self, datafilepath):
#     def __copy__(self):
#     def to_twodim_list(self):
#     def from_twodim_list(cls, datalist, tsformat=None):
#     def initialize_from_sql_cursor(self, sqlcursor):
#     def __str__(self):
#     def __add__(self, otherTimeSeries):
#     def __len__(self):
#     def __eq__(self, otherTimeSeries):
#     def __ne__(self, otherTimeSeries):
#     def __iter__(self):
#     def __getitem__(self, index):
#     def __setitem__(self, index, value):
#     def convert_timestamp_to_epoch(cls, timestamp, tsformat):
#     def convert_epoch_to_timestamp(cls, timestamp, tsformat):
#     def add_entry(self, timestamp, data):
#     def sort_timeseries(self, ascending=True):
#     def sorted_timeseries(self, ascending=True):
#     def normalize(self, normalizationLevel="minute", fusionMethod="mean", interpolationMethod="linear"):
#     def is_normalized(self):
#     def _check_normalization(self):
#     def is_sorted(self):
#     def apply(self, method):
#     def sample(self, percentage):
#     def __init__(self, dimensions=1, isNormalized=False, isSorted=False):
#     def dimension_count(self):
#     def add_entry(self, timestamp, data):
#     def sorted_timeseries(self, ascending=True):
#     def to_twodim_list(self):
#     def from_twodim_list(cls, datalist, tsformat=None, dimensions=1):
#     def __add__(self, otherTimeSeries):
#     def __eq__(self, otherTimeSeries):
#     def __copy__(self):
#     def initialize_from_sql_cursor(self, sqlcursor):
#     def to_gnuplot_datafile(self, datafilepath):
#     def normalize(self, normalizationLevel="minute", fusionMethod="mean", interpolationMethod="linear"):
# 
# Path: pycast/errors/meansigneddifferenceerror.py
# MSD = MeanSignedDifferenceError


from pycast.common.pycastobject import PyCastObject
from pycast.common.timeseries import TimeSeries, FusionMethods
from pycast.errors.meansigneddifferenceerror import MSD
            that has been calculated during regression

        :return TimeSeries timeseries_y: the predicted values for the
            dependent TimeSeries. Its length and first dimension will
            equal to timeseriesX.
        """
        new_entries = []
        for entry in timeseriesX:
            predicted_value = m * entry[1] + n
            new_entries.append([entry[0], predicted_value])
        return TimeSeries.from_twodim_list(new_entries)

    def match_time_series(self, timeseries1, timeseries2):
        """Return two lists of the two input time series with matching dates

        :param TimeSeries timeseries1: The first timeseries
        :param TimeSeries timeseries2: The second timeseries
        :return:    Two two dimensional lists containing the matched values,
        :rtype:     two List
        """
        time1 = map(lambda item: item[0], timeseries1.to_twodim_list())
        time2 = map(lambda item: item[0], timeseries2.to_twodim_list())

        matches = filter(lambda x: (x in time1), time2)
        listX  = filter(lambda x: (x[0] in matches), timeseries1.to_twodim_list())
        listY  = filter(lambda x: (x[0] in matches), timeseries2.to_twodim_list())

        return listX, listY



# Path: pycast/common/pycastobject.py
# class PyCastObject(object):
# 
# 
#     """The base class for all pycast objects.
# 
#     This class is used to introduce a common interface for potential
#     C/C++/OpenCL optimization within pycast, as well as other common
#     tasks.
#     """
# 
#     # stores, if pycast should only create optimized instances.
#     # default = False
#     _globalOptimize = False
# 
#     def __init__(self):
#         """Initializes the PyCastObject."""
#         super(PyCastObject, self).__init__()
#         self.optimizationEnabled = False
# 
#         if PyCastObject._globalOptimize:
#             self._enable_instance_optimization()
# 
#     def _enable_instance_optimization(self):
#         """Enables the optimization for the PyCastObject instance.
# 
#         :warning:    Do not forget to implement the disable_instance_optimization()
#             as well.
#         """
#         self.optimizationEnabled = True
# 
#     def _disable_instance_optimization(self):
#         """Disables the optimization for the PyCastObject instance."""
#         self.optimizationEnabled = False
# 
#     @classmethod
#     def enable_global_optimization(cls):
#         """Enables the global optimization of pycast methods, if possible.
# 
#         By default, optimization is turned off.
# 
#         :note:    Only new created instances will be affected.
#         """
#         cls._globalOptimize = True
# 
#     @classmethod
#     def disable_global_optimization(cls):
#         """Disables the global optimization of pycast methods.
# 
#         :note:    Only new created instances will be affected.
#         """
#         cls._globalOptimize = False
# 
# Path: pycast/common/timeseries.py
# _STR_EPOCHS = "UNIX-epochs"
# class TimeSeries(PyCastObject):
# class MultiDimensionalTimeSeries(TimeSeries):
#     def __init__(self, isNormalized=False, isSorted=False):
#     def set_timeformat(self, tsformat=None):
#     def to_gnuplot_datafile(self, datafilepath):
#     def __copy__(self):
#     def to_twodim_list(self):
#     def from_twodim_list(cls, datalist, tsformat=None):
#     def initialize_from_sql_cursor(self, sqlcursor):
#     def __str__(self):
#     def __add__(self, otherTimeSeries):
#     def __len__(self):
#     def __eq__(self, otherTimeSeries):
#     def __ne__(self, otherTimeSeries):
#     def __iter__(self):
#     def __getitem__(self, index):
#     def __setitem__(self, index, value):
#     def convert_timestamp_to_epoch(cls, timestamp, tsformat):
#     def convert_epoch_to_timestamp(cls, timestamp, tsformat):
#     def add_entry(self, timestamp, data):
#     def sort_timeseries(self, ascending=True):
#     def sorted_timeseries(self, ascending=True):
#     def normalize(self, normalizationLevel="minute", fusionMethod="mean", interpolationMethod="linear"):
#     def is_normalized(self):
#     def _check_normalization(self):
#     def is_sorted(self):
#     def apply(self, method):
#     def sample(self, percentage):
#     def __init__(self, dimensions=1, isNormalized=False, isSorted=False):
#     def dimension_count(self):
#     def add_entry(self, timestamp, data):
#     def sorted_timeseries(self, ascending=True):
#     def to_twodim_list(self):
#     def from_twodim_list(cls, datalist, tsformat=None, dimensions=1):
#     def __add__(self, otherTimeSeries):
#     def __eq__(self, otherTimeSeries):
#     def __copy__(self):
#     def initialize_from_sql_cursor(self, sqlcursor):
#     def to_gnuplot_datafile(self, datafilepath):
#     def normalize(self, normalizationLevel="minute", fusionMethod="mean", interpolationMethod="linear"):
# 
# Path: pycast/errors/meansigneddifferenceerror.py
# MSD = MeanSignedDifferenceError


# Path: pycast/methods/regression.py
from pycast.common.pycastobject import PyCastObject
from pycast.common.timeseries import TimeSeries, FusionMethods
from pycast.errors.meansigneddifferenceerror import MSD

            that has been calculated during regression

        :return TimeSeries timeseries_y: the predicted values for the
            dependent TimeSeries. Its length and first dimension will
            equal to timeseriesX.
        """
        new_entries = []
        for entry in timeseriesX:
            predicted_value = m * entry[1] + n
            new_entries.append([entry[0], predicted_value])
        return TimeSeries.from_twodim_list(new_entries)

    def match_time_series(self, timeseries1, timeseries2):
        """Return two lists of the two input time series with matching dates

        :param TimeSeries timeseries1: The first timeseries
        :param TimeSeries timeseries2: The second timeseries
        :return:    Two two dimensional lists containing the matched values,
        :rtype:     two List
        """
        time1 = map(lambda item: item[0], timeseries1.to_twodim_list())
        time2 = map(lambda item: item[0], timeseries2.to_twodim_list())

        matches = filter(lambda x: (x in time1), time2)
        listX  = filter(lambda x: (x[0] in matches), timeseries1.to_twodim_list())
        listY  = filter(lambda x: (x[0] in matches), timeseries2.to_twodim_list())

        return listX, listY



class LinearRegression(PyCastObject):