pyFTS/partitioners/Huarng.py
Petrônio Cândido de Lima e Silva 84e6e1abbf - Sliding Window benchmark
- Refactoring of partitioners for OO design
2017-02-24 13:29:55 -03:00

44 lines
1.3 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import numpy as np
import math
import random as rnd
import functools, operator
from pyFTS.common import FuzzySet, Membership, Transformations
# K. H. Huarng, “Effective lengths of intervals to improve forecasting in fuzzy time series,”
# Fuzzy Sets Syst., vol. 123, no. 3, pp. 387394, Nov. 2001.
from pyFTS.partitioners import partitioner
class HuarngPartitioner(partitioner.Partitioner):
def __init__(self, npart,data,func = Membership.trimf):
super(HuarngPartitioner, self).__init__("Huarng",data,npart,func)
def build(self, data):
data2 = Transformations.differential(data)
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 = []
dmax = max(data)
dmax += dmax * 0.10
dmin = min(data)
dmin -= dmin * 0.10
dlen = dmax - dmin
npart = math.ceil(dlen / base)
partition = math.ceil(dmin)
for c in range(npart):
sets.append(
FuzzySet.FuzzySet(self.prefix + str(c), Membership.trimf, [partition - base, partition, partition + base], partition))
partition += base
return sets