BoxCox Transformation

This commit is contained in:
Petrônio Cândido 2017-10-25 10:09:28 -02:00
parent e9b86d7025
commit 2b038968f7

View File

@ -8,10 +8,9 @@ class Transformation(object):
Data transformation used to pre and post processing of the FTS
"""
def __init__(self, parameters):
self.isInversible = True
self.parameters = parameters
self.minimalLength = 1
def __init__(self, **kwargs):
self.is_invertible = True
self.minimal_length = 1
def apply(self, data, param, **kwargs):
pass
@ -28,9 +27,9 @@ class Differential(Transformation):
Differentiation data transform
"""
def __init__(self, parameters):
super(Differential, self).__init__(parameters)
super(Differential, self).__init__()
self.lag = parameters
self.minimalLength = 2
self.minimal_length = 2
def apply(self, data, param=None, **kwargs):
if param is not None:
@ -75,7 +74,7 @@ class Differential(Transformation):
class Scale(Transformation):
def __init__(self, min=0, max=1):
super(Scale, self).__init__([min, max])
super(Scale, self).__init__()
self.data_max = None
self.data_min = None
self.transf_max = max
@ -130,12 +129,23 @@ class AdaptiveExpectation(Transformation):
return inc
def boxcox(original, plambda):
n = len(original)
if plambda != 0:
modified = [(original[t] ** plambda - 1) / plambda for t in np.arange(0, n)]
class BoxCox(Transformation):
def __init__(self, plambda):
super(BoxCox, self).__init__()
self.plambda = plambda
def apply(self, data, param=None, **kwargs):
if self.plambda != 0:
modified = [(dat ** self.plambda - 1) / self.plambda for dat in data]
else:
modified = [math.log(original[t]) for t in np.arange(0, n)]
modified = [np.log(dat) for dat in data]
return np.array(modified)
def inverse(self, data, param=None, **kwargs):
if self.plambda != 0:
modified = [np.exp(np.log(dat * self.plambda + 1) ) / self.plambda for dat in data]
else:
modified = [np.exp(dat) for dat in data]
return np.array(modified)