# 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
        used to calculate the bounds of the interval.

        further reading: http://en.wikipedia.org/wiki/Confidence_interval

        :param Timeseries independentTs: The Timeseries used for the
            independent variable (x-axis). The Timeseries must have
            at least 2 datapoints with different dates and values
        :param Timeseries dependentTs: The Timeseries used as the
            dependent variable (y-axis). The Timeseries must have
            at least 2 datapoints, which dates match with independentTs
        :param float confidenceLevel: The percentage of entries in the sample that should
            have an prediction error closer or equal to 0 than the bounds of the confidence interval.
        :param float samplePercentage: How much of the dependentTs should be used for sampling

        :return:    A tuple containing the y-axis intercept and the slope
                    used to execute the regression and the (underestimation, overestimation)
                    for the given confidenceLevel
        :rtype:     tuple
        :raise: Raises an :py:exc:`ValueError` if
                - independentTs and dependentTs have not at least two matching dates
                - independentTs has only one distinct value
                - The dates in one or both Timeseries are not distinct.
        """
        #First split the time series into sample and training data
        sampleY, trainingY = dependentTs.sample(samplePercentage)

        sampleX_list = self.match_time_series(sampleY, independentTs)[1]
        trainingX_list = self.match_time_series(trainingY, independentTs)[1]

        sampleX = TimeSeries.from_twodim_list(sampleX_list)

# 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

        used to calculate the bounds of the interval.

        further reading: http://en.wikipedia.org/wiki/Confidence_interval

        :param Timeseries independentTs: The Timeseries used for the
            independent variable (x-axis). The Timeseries must have
            at least 2 datapoints with different dates and values
        :param Timeseries dependentTs: The Timeseries used as the
            dependent variable (y-axis). The Timeseries must have
            at least 2 datapoints, which dates match with independentTs
        :param float confidenceLevel: The percentage of entries in the sample that should
            have an prediction error closer or equal to 0 than the bounds of the confidence interval.
        :param float samplePercentage: How much of the dependentTs should be used for sampling

        :return:    A tuple containing the y-axis intercept and the slope
                    used to execute the regression and the (underestimation, overestimation)
                    for the given confidenceLevel
        :rtype:     tuple
        :raise: Raises an :py:exc:`ValueError` if
                - independentTs and dependentTs have not at least two matching dates
                - independentTs has only one distinct value
                - The dates in one or both Timeseries are not distinct.
        """
        #First split the time series into sample and training data
        sampleY, trainingY = dependentTs.sample(samplePercentage)

        sampleX_list = self.match_time_series(sampleY, independentTs)[1]
        trainingX_list = self.match_time_series(trainingY, independentTs)[1]

        sampleX = TimeSeries.from_twodim_list(sampleX_list)

        trainingX = TimeSeries.from_twodim_list(trainingX_list)