diff --git a/benchmarks/Measures.py b/benchmarks/Measures.py index aa623da..590460a 100644 --- a/benchmarks/Measures.py +++ b/benchmarks/Measures.py @@ -200,6 +200,7 @@ def crps(targets, densities): def get_point_statistics(data, model, indexer=None): + """Condensate all measures for point forecasters""" if indexer is not None: ndata = np.array(indexer.get_data(data[model.order:])) else: @@ -232,6 +233,7 @@ def get_point_statistics(data, model, indexer=None): def get_interval_statistics(original, model): + """Condensate all measures for interval forecasters""" ret = list() forecasts = model.forecastInterval(original) ret.append(round(sharpness(forecasts), 2)) diff --git a/benchmarks/benchmarks.py b/benchmarks/benchmarks.py index 3be5e72..bd821b0 100644 --- a/benchmarks/benchmarks.py +++ b/benchmarks/benchmarks.py @@ -1,6 +1,9 @@ #!/usr/bin/python # -*- coding: utf8 -*- +"""Benchmarks to FTS methods""" + + import numpy as np import pandas as pd import time @@ -12,7 +15,7 @@ import matplotlib.pyplot as plt from mpl_toolkits.mplot3d import Axes3D # from sklearn.cross_validation import KFold from pyFTS.partitioners import partitioner, Grid, Huarng, Entropy, FCM -from pyFTS.benchmarks import Measures, naive, arima, ResidualAnalysis, ProbabilityDistribution, Util +from pyFTS.benchmarks import Measures, naive, arima, ResidualAnalysis, ProbabilityDistribution, Util, quantreg from pyFTS.common import Membership, FuzzySet, FLR, Transformations, Util from pyFTS import fts, chen, yu, ismailefendi, sadaei, hofts, hwang, pwfts, ifts from copy import deepcopy @@ -27,17 +30,38 @@ styles = ['-','--','-.',':','.'] nsty = len(styles) def get_benchmark_point_methods(): + """Return all non FTS methods for point forecast""" return [naive.Naive, arima.ARIMA] def get_point_methods(): + """Return all FTS methods for point forecast""" return [chen.ConventionalFTS, yu.WeightedFTS, ismailefendi.ImprovedWeightedFTS, sadaei.ExponentialyWeightedFTS, hofts.HighOrderFTS, pwfts.ProbabilisticWeightedFTS] +def get_benchmark_interval_methods(): + """Return all non FTS methods for interval forecast""" + return [quantreg.QuantileRegression] + def get_interval_methods(): + """Return all FTS methods for interval forecast""" return [ifts.IntervalFTS, pwfts.ProbabilisticWeightedFTS] -def external_point_sliding_window(models, parameters, data, windowsize,train=0.8, dump=False, save=False, file=None, sintetic=True): +def external_point_sliding_window(models, parameters, data, windowsize,train=0.8, dump=False, + save=False, file=None, sintetic=True): + """ + Sliding window benchmarks for non FTS point forecasters + :param models: non FTS point forecasters + :param parameters: parameters for each model + :param data: data set + :param windowsize: size of sliding window + :param train: percentual of sliding window data used to train the models + :param dump: + :param save: save results + :param file: file path to save the results + :param sintetic: if true only the average and standard deviation of the results + :return: DataFrame with the results + """ objs = {} lcolors = {} rmse = {} @@ -91,6 +115,23 @@ def external_point_sliding_window(models, parameters, data, windowsize,train=0.8 def point_sliding_window(data, windowsize, train=0.8,models=None,partitioners=[Grid.GridPartitioner], partitions=[10], max_order=3,transformation=None,indexer=None,dump=False, save=False, file=None, sintetic=True): + """ + Sliding window benchmarks for FTS point forecasters + :param data: + :param windowsize: size of sliding window + :param train: percentual of sliding window data used to train the models + :param models: FTS point forecasters + :param partitioners: Universe of Discourse partitioner + :param partitions: the max number of partitions on the Universe of Discourse + :param max_order: the max order of the models (for high order models) + :param transformation: data transformation + :param indexer: seasonal indexer + :param dump: + :param save: save results + :param file: file path to save the results + :param sintetic: if true only the average and standard deviation of the results + :return: DataFrame with the results + """ _process_start = time.time() @@ -210,7 +251,23 @@ def point_sliding_window(data, windowsize, train=0.8,models=None,partitioners=[G def all_point_forecasters(data_train, data_test, partitions, max_order=3, statistics=True, residuals=True, series=True, save=False, file=None, tam=[20, 5], models=None, transformation=None, distributions=False): - + """ + Fixed data benchmark for FTS point forecasters + :param data_train: data used to train the models + :param data_test: data used to test the models + :param partitions: the max number of partitions on the Universe of Discourse + :param max_order: the max order of the models (for high order models) + :param statistics: print statistics + :param residuals: print and plot residuals + :param series: plot time series + :param save: save results + :param file: file path to save the results + :param tam: figure dimensions to plot the graphs + :param models: list of models to benchmark + :param transformation: data transformation + :param distributions: plot distributions + :return: + """ if models is None: models = get_point_methods() diff --git a/benchmarks/distributed_benchmarks.py b/benchmarks/distributed_benchmarks.py index 57ea128..c7ec333 100644 --- a/benchmarks/distributed_benchmarks.py +++ b/benchmarks/distributed_benchmarks.py @@ -1,3 +1,11 @@ +""" +dispy Distributed Benchmarks to FTS methods + +To enable a dispy cluster node: + +python3 /usr/local/bin/dispynode.py -i [local IP] -d +""" + import random import dispy import dispy.httpd diff --git a/benchmarks/parallel_benchmarks.py b/benchmarks/parallel_benchmarks.py index 185b59a..a88044f 100644 --- a/benchmarks/parallel_benchmarks.py +++ b/benchmarks/parallel_benchmarks.py @@ -1,3 +1,7 @@ +""" +joblib Parallelized Benchmarks to FTS methods +""" + from copy import deepcopy from joblib import Parallel, delayed import multiprocessing @@ -64,9 +68,9 @@ def point_sliding_window(data, windowsize, train=0.8, models=None, partitioners= for model in benchmarks.get_point_methods(): mfts = model("") - if mfts.isHighOrder: + if mfts.is_high_order: for order in np.arange(1, max_order + 1): - if order >= mfts.minOrder: + if order >= mfts.min_order: mfts = model("") mfts.order = order pool.append(mfts) @@ -162,9 +166,9 @@ def interval_sliding_window(data, windowsize, train=0.8, models=None, partitione for model in benchmarks.get_interval_methods(): mfts = model("") - if mfts.isHighOrder: + if mfts.is_high_order: for order in np.arange(1, max_order + 1): - if order >= mfts.minOrder: + if order >= mfts.min_order: mfts = model("") mfts.order = order pool.append(mfts) @@ -261,9 +265,9 @@ def ahead_sliding_window(data, windowsize, train, steps,resolution, models=None, for model in benchmarks.get_interval_methods(): mfts = model("") - if mfts.isHighOrder: + if mfts.is_high_order: for order in np.arange(1, max_order + 1): - if order >= mfts.minOrder: + if order >= mfts.min_order: mfts = model("") mfts.order = order pool.append(mfts) diff --git a/tests/general.py b/tests/general.py index 46ab93c..8113025 100644 --- a/tests/general.py +++ b/tests/general.py @@ -55,7 +55,7 @@ from pyFTS.benchmarks import distributed_benchmarks as bchmk bchmk.point_sliding_window(taiex,2000,train=0.8, #models=[yu.WeightedFTS], # # partitioners=[Grid.GridPartitioner], #Entropy.EntropyPartitioner], # FCM.FCMPartitioner, ], partitions= np.arange(10,200,step=5), #transformation=diff, - dump=False, save=False, file="experiments/nasdaq_point_distributed.csv", + dump=True, save=False, file="experiments/nasdaq_point_distributed.csv", nodes=['192.168.1.42']) #, depends=[hofts, ifts]) #bchmk.testa(taiex,[10,20],partitioners=[Grid.GridPartitioner], nodes=['192.168.0.109', '192.168.0.101']) diff --git a/yu.py b/yu.py index cc5369b..ccc9699 100644 --- a/yu.py +++ b/yu.py @@ -3,8 +3,8 @@ from pyFTS.common import FuzzySet,FLR from pyFTS import fts -class WeightedFLRG(fts.FTS): - def __init__(self, order, LHS, **kwargs): +class WeightedFLRG(object): + def __init__(self, LHS, **kwargs): self.LHS = LHS self.RHS = [] self.count = 1.0