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.
|
|
|
|
|
|
|
|
|
|
def GridPartitionerTrimf(data, prefix="A"):
|
2016-12-23 14:18:33 +04:00
|
|
|
|
data2 = Transformations.differential(data)
|
2016-12-26 17:21:28 +04:00
|
|
|
|
davg = np.abs( np.mean(data2) / 2 )
|
|
|
|
|
|
2016-12-23 14:18:33 +04:00
|
|
|
|
if davg <= 1.0:
|
|
|
|
|
base = 0.1
|
2016-12-26 17:21:28 +04:00
|
|
|
|
elif 1 < davg <= 10:
|
2016-12-23 14:18:33 +04:00
|
|
|
|
base = 1.0
|
2016-12-26 17:21:28 +04:00
|
|
|
|
elif 10 < davg <= 100:
|
2016-12-23 14:18:33 +04:00
|
|
|
|
base = 10
|
|
|
|
|
else:
|
|
|
|
|
base = 100
|
|
|
|
|
|
|
|
|
|
sets = []
|
|
|
|
|
dmax = max(data)
|
2016-12-26 17:21:28 +04:00
|
|
|
|
dmax += dmax * 0.10
|
2016-12-23 14:18:33 +04:00
|
|
|
|
dmin = min(data)
|
2016-12-26 17:21:28 +04:00
|
|
|
|
dmin -= dmin * 0.10
|
2016-12-23 14:18:33 +04:00
|
|
|
|
dlen = dmax - dmin
|
2016-12-26 17:21:28 +04:00
|
|
|
|
npart = math.ceil(dlen / base)
|
2016-12-23 14:18:33 +04:00
|
|
|
|
partition = math.ceil(dmin)
|
|
|
|
|
for c in range(npart):
|
2016-12-26 17:21:28 +04:00
|
|
|
|
sets.append(
|
|
|
|
|
FuzzySet.FuzzySet(prefix + str(c), Membership.trimf, [partition - base, partition, partition + base], partition))
|
|
|
|
|
partition += base
|
2016-12-23 14:18:33 +04:00
|
|
|
|
|
|
|
|
|
return sets
|