diff --git a/pyFTS/common/FuzzySet.py b/pyFTS/common/FuzzySet.py index 7913469..d25ccd0 100644 --- a/pyFTS/common/FuzzySet.py +++ b/pyFTS/common/FuzzySet.py @@ -126,7 +126,7 @@ def fuzzyfy(data, partitioner, **kwargs): :keyword mode: the fuzzyfication mode (sets: return the fuzzy sets names, vector: return a vector with the membership values for all fuzzy sets, both: return a list with tuples (fuzzy set, membership value) ) :returns a list with the fuzzyfied values, depending on the mode - + """ alpha_cut = kwargs.get('alpha_cut', 0.) mode = kwargs.get('mode', 'sets') diff --git a/pyFTS/models/multivariate/common.py b/pyFTS/models/multivariate/common.py index 45ca204..e2bc388 100644 --- a/pyFTS/models/multivariate/common.py +++ b/pyFTS/models/multivariate/common.py @@ -43,7 +43,7 @@ class MultivariateFuzzySet(Composite.FuzzySet): def fuzzyfy_instance(data_point, var, tuples=True): - fsets = var.partitioner(data_point, mode='sets', method='fuzzy', alpha_cut=var.alpha_cut) + fsets = var.partitioner.fuzzyfy(data_point, mode='sets', method='fuzzy', alpha_cut=var.alpha_cut) if tuples: return [(var.name, fs) for fs in fsets] else: diff --git a/pyFTS/tests/general.py b/pyFTS/tests/general.py index 2bb39c6..c27baa1 100644 --- a/pyFTS/tests/general.py +++ b/pyFTS/tests/general.py @@ -14,17 +14,73 @@ from pyFTS.benchmarks import benchmarks as bchmk, Measures from pyFTS.models import chen, yu, cheng, ismailefendi, hofts, pwfts, tsaur, song, sadaei from pyFTS.common import Transformations, Membership -from pyFTS.data import TAIEX +dataset = pd.read_csv('https://query.data.world/s/2bgegjggydd3venttp3zlosh3wpjqj', sep=';') -data = TAIEX.get_data() +dataset['data'] = pd.to_datetime(dataset["data"], format='%Y-%m-%d %H:%M:%S') -fs = Grid.GridPartitioner(data=data, npart=23) +train_mv = dataset.iloc[:24505] +test_mv = dataset.iloc[24505:] + +from itertools import product + +levels = ['VL', 'L', 'M', 'H', 'VH'] +sublevels = [str(k) for k in np.arange(0, 7)] +names = [] +for combination in product(*[levels, sublevels]): + names.append(combination[0] + combination[1]) + +print(names) + +from pyFTS.models.multivariate import common, variable, mvfts +from pyFTS.models.seasonal import partitioner as seasonal +from pyFTS.models.seasonal.common import DateTime + + + +sp = {'seasonality': DateTime.day_of_year , 'names': ['Jan','Feb','Mar','Apr','May', + 'Jun','Jul', 'Aug','Sep','Oct', + 'Nov','Dec']} + +vmonth = variable.Variable("Month", data_label="data", partitioner=seasonal.TimeGridPartitioner, npart=12, + data=train_mv, partitioner_specific=sp) + + + +sp = {'seasonality': DateTime.minute_of_day, 'names': [str(k)+'hs' for k in range(0,24)]} + +vhour = variable.Variable("Hour", data_label="data", partitioner=seasonal.TimeGridPartitioner, npart=24, + data=train_mv, partitioner_specific=sp) + + +vavg = variable.Variable("Radiation", data_label="glo_avg", alias='rad', + partitioner=Grid.GridPartitioner, npart=35, partitioner_specific={'names': names}, + data=train_mv) + +from pyFTS.models.multivariate import mvfts, wmvfts, cmvfts, grid + +parameters = [ + {}, {}, + {'order': 2, 'knn': 1}, + {'order': 2, 'knn': 2}, + {'order': 2, 'knn': 3}, +] + +for ct, method in enumerate([mvfts.MVFTS, wmvfts.WeightedMVFTS, + cmvfts.ClusteredMVFTS, cmvfts.ClusteredMVFTS, cmvfts.ClusteredMVFTS]): + + if method != cmvfts.ClusteredMVFTS: + model = method(explanatory_variables=[vmonth, vhour, vavg], target_variable=vavg, **parameters[ct]) + else: + fs = grid.GridCluster(explanatory_variables=[vmonth, vhour, vavg], target_variable=vavg) + model = method(explanatory_variables=[vmonth, vhour, vavg], target_variable=vavg, partitioner=fs, + **parameters[ct]) + + model.shortname += str(ct) + model.fit(train_mv) + + forecasts = model.predict(test_mv.iloc[:100]) + + print(model.shortname, forecasts) -test = [2000, 5000, 5500, 12000] -for method in [yu.WeightedFTS, tsaur.MarkovWeightedFTS, song.ConventionalFTS, sadaei.ExponentialyWeightedFTS, ismailefendi.ImprovedWeightedFTS, - chen.ConventionalFTS, cheng.TrendWeightedFTS, hofts.HighOrderFTS, pwfts.ProbabilisticWeightedFTS]: - model = method(partitioner=fs) - model.fit(data) - print(model.forecast(test))