2016-12-23 14:18:33 +04:00
|
|
|
|
import numpy as np
|
|
|
|
|
import math
|
|
|
|
|
import random as rnd
|
2016-12-26 17:21:28 +04:00
|
|
|
|
import functools, operator
|
|
|
|
|
from pyFTS.common import FuzzySet, Membership, Transformations
|
2016-12-23 14:18:33 +04:00
|
|
|
|
|
|
|
|
|
|
2016-12-26 17:21:28 +04:00
|
|
|
|
# K. H. Huarng, “Effective lengths of intervals to improve forecasting in fuzzy time series,”
|
|
|
|
|
# Fuzzy Sets Syst., vol. 123, no. 3, pp. 387–394, Nov. 2001.
|
2017-02-24 20:29:55 +04:00
|
|
|
|
from pyFTS.partitioners import partitioner
|
2016-12-26 17:21:28 +04:00
|
|
|
|
|
2017-02-24 20:29:55 +04:00
|
|
|
|
|
|
|
|
|
class HuarngPartitioner(partitioner.Partitioner):
|
2017-05-05 22:33:27 +04:00
|
|
|
|
"""Huarng Empirical Partitioner"""
|
2017-07-04 23:30:53 +04:00
|
|
|
|
def __init__(self, data,npart,func = Membership.trimf, transformation=None, indexer=None):
|
|
|
|
|
super(HuarngPartitioner, self).__init__("Huarng", data, npart, func=func, transformation=transformation, indexer=indexer)
|
2017-02-24 20:29:55 +04:00
|
|
|
|
|
|
|
|
|
def build(self, data):
|
2017-02-27 22:53:29 +04:00
|
|
|
|
diff = Transformations.Differential(1)
|
|
|
|
|
data2 = diff.apply(data)
|
2017-02-24 20:29:55 +04:00
|
|
|
|
davg = np.abs( np.mean(data2) / 2 )
|
|
|
|
|
|
|
|
|
|
if davg <= 1.0:
|
|
|
|
|
base = 0.1
|
|
|
|
|
elif 1 < davg <= 10:
|
|
|
|
|
base = 1.0
|
|
|
|
|
elif 10 < davg <= 100:
|
|
|
|
|
base = 10
|
|
|
|
|
else:
|
|
|
|
|
base = 100
|
|
|
|
|
|
|
|
|
|
sets = []
|
2017-02-27 22:53:29 +04:00
|
|
|
|
|
|
|
|
|
dlen = self.max - self.min
|
2017-02-24 20:29:55 +04:00
|
|
|
|
npart = math.ceil(dlen / base)
|
2017-02-27 22:53:29 +04:00
|
|
|
|
partition = math.ceil(self.min)
|
2017-02-24 20:29:55 +04:00
|
|
|
|
for c in range(npart):
|
2017-05-02 03:56:47 +04:00
|
|
|
|
if self.membership_function == Membership.trimf:
|
|
|
|
|
sets.append( FuzzySet.FuzzySet(self.prefix + str(c), Membership.trimf,
|
|
|
|
|
[partition - base, partition, partition + base], partition))
|
|
|
|
|
elif self.membership_function == Membership.gaussmf:
|
|
|
|
|
sets.append(FuzzySet.FuzzySet(self.prefix + str(c), Membership.gaussmf,
|
|
|
|
|
[partition, base/2], partition))
|
|
|
|
|
elif self.membership_function == Membership.trapmf:
|
|
|
|
|
sets.append(FuzzySet.FuzzySet(self.prefix + str(c), Membership.trapmf,
|
|
|
|
|
[partition - base, partition - (base/2),
|
|
|
|
|
partition + (base / 2), partition + base], partition))
|
|
|
|
|
|
2017-02-24 20:29:55 +04:00
|
|
|
|
partition += base
|
|
|
|
|
|
|
|
|
|
return sets
|