From 21519fd0dd2eeda6e6a0990afb45fed44993f30c Mon Sep 17 00:00:00 2001 From: Felipe Vianna Date: Fri, 12 Feb 2021 15:48:32 +0100 Subject: [PATCH 1/2] - fixing exponential moving average - adding MaxPooling and AveragePooling transformations --- pyFTS/common/transformations/smoothing.py | 57 +++++++++++++++++++++-- 1 file changed, 54 insertions(+), 3 deletions(-) diff --git a/pyFTS/common/transformations/smoothing.py b/pyFTS/common/transformations/smoothing.py index 1f6a052..821ea82 100644 --- a/pyFTS/common/transformations/smoothing.py +++ b/pyFTS/common/transformations/smoothing.py @@ -1,10 +1,11 @@ from pyFTS.common.transformations.transformation import Transformation import numpy as np +from math import ceil class MovingAverage(Transformation): def __init__(self, **kwargs): - super(MovingAverage, self).__init__() + super(MovingAverage, self).__init__(**kwargs) self.name = 'Moving Average Smoothing' self.steps = kwargs.get('steps',2) @@ -20,8 +21,8 @@ class MovingAverage(Transformation): class ExponentialSmoothing(Transformation): def __init__(self, **kwargs): - super(MovingAverage, self).__init__() - self.name = 'Moving Average Smoothing' + super(ExponentialSmoothing,self).__init__(**kwargs) + self.name = 'Exponential Moving Average Smoothing' self.steps = kwargs.get('steps',2) self.beta = kwargs.get('beta',.5) @@ -39,3 +40,53 @@ class ExponentialSmoothing(Transformation): def inverse(self, data, param=None, **kwargs): return data + + +class AveragePooling(Transformation): + def __init__(self, **kwargs): + super(AveragePooling,self).__init__(**kwargs) + self.name = 'Exponential Average Smoothing' + self.kernel = kwargs.get('kernel',5) + self.stride = kwargs.get('stride',1) + self.padding = kwargs.get('padding','same') + + def apply(self, data): + result = [] + if self.padding == 'same': + for i in range(int(self.kernel/2), len(data)+int(self.kernel/2), self.stride): + result.append(np.mean(data[np.max([0,i-self.kernel]):np.min([i, len(data)])])) + + elif self.padding == 'valid': + for i in range(self.kernel, len(data), self.stride): + result.append(np.mean(data[i-self.kernel:i])) + else: + raise ValueError('Invalid padding schema') + return result + + def inverse(self, data, param=None, **kwargs): + return data + + +class MaxPooling(Transformation): + def __init__(self, **kwargs): + super(MaxPooling,self).__init__(**kwargs) + self.name = 'Exponential Average Smoothing' + self.kernel = kwargs.get('kernel',5) + self.stride = kwargs.get('stride',1) + self.padding = kwargs.get('padding','same') + + def apply(self, data): + result = [] + if self.padding == 'same': + for i in range(int(self.kernel/2), len(data)+int(self.kernel/2), self.stride): + result.append(np.max(data[np.max([0,i-self.kernel]):np.min([i, len(data)])])) + + elif self.padding == 'valid': + for i in range(self.kernel - 1, len(data), self.stride): + result.append(np.max(data[i-self.kernel:i])) + else: + raise ValueError('Invalid padding schema') + return result + + def inverse(self, data, param=None, **kwargs): + return data \ No newline at end of file From f8838651323dd073a1faaebdc54744ab7bbfcf82 Mon Sep 17 00:00:00 2001 From: Felipe Vianna Date: Fri, 12 Feb 2021 15:49:25 +0100 Subject: [PATCH 2/2] adding requirements to setup file. avoiding max pooling error when installing from source. --- pyFTS/common/transformations/smoothing.py | 2 -- setup.py | 6 +++++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/pyFTS/common/transformations/smoothing.py b/pyFTS/common/transformations/smoothing.py index 821ea82..92b7b5f 100644 --- a/pyFTS/common/transformations/smoothing.py +++ b/pyFTS/common/transformations/smoothing.py @@ -1,7 +1,5 @@ from pyFTS.common.transformations.transformation import Transformation import numpy as np -from math import ceil - class MovingAverage(Transformation): def __init__(self, **kwargs): diff --git a/setup.py b/setup.py index c896473..7361a74 100644 --- a/setup.py +++ b/setup.py @@ -5,6 +5,10 @@ import setuptools setuptools.setup( name='pyFTS', + install_requires=[ + 'matplotlib', + 'numpy', + 'pandas'], packages=['pyFTS', 'pyFTS.benchmarks', 'pyFTS.common', 'pyFTS.common.transformations', 'pyFTS.data', 'pyFTS.models.ensemble', 'pyFTS.models', 'pyFTS.models.seasonal', 'pyFTS.partitioners', 'pyFTS.probabilistic', 'pyFTS.tests', 'pyFTS.models.nonstationary', 'pyFTS.models.multivariate', @@ -28,6 +32,6 @@ setuptools.setup( 'Intended Audience :: Education', 'Topic :: Scientific/Engineering', 'Development Status :: 5 - Production/Stable' - + ] )