def print_distribution_statistics(original, models, steps, resolution): ret = "Model & Order & Interval & Distribution \\\\ \n" for fts in models: _crps1, _crps2, _t1, _t2 = Measures.get_distribution_statistics( original, fts, steps, resolution) ret += fts.shortname + " & " ret += str(fts.order) + " & " ret += str(_crps1) + " & " ret += str(_crps2) + " \\\\ \n" print(ret)
def print_distribution_statistics(original, models, steps, resolution): """ Run probabilistic benchmarks on given models and data and print the results :param data: test data :param models: a list of FTS models to benchmark :return: """ ret = "Model & Order & Interval & Distribution \\\\ \n" for fts in models: _crps1, _crps2, _t1, _t2 = Measures.get_distribution_statistics(original, fts, steps, resolution) ret += fts.shortname + " & " ret += str(fts.order) + " & " ret += str(_crps1) + " & " ret += str(_crps2) + " \\\\ \n" print(ret)
def run_probabilistic(mfts, partitioner, train_data, test_data, window_key=None, **kwargs): """ Probabilistic forecast benchmark function to be executed on cluster nodes :param mfts: FTS model :param partitioner: Universe of Discourse partitioner :param train_data: data used to train the model :param test_data: ata used to test the model :param steps: :param resolution: :param window_key: id of the sliding window :param transformation: data transformation :param indexer: seasonal indexer :return: a dictionary with the benchmark results """ import time import numpy as np from pyFTS.models import hofts, ifts, pwfts from pyFTS.models.ensemble import ensemble from pyFTS.partitioners import Grid, Entropy, FCM from pyFTS.benchmarks import Measures, arima, quantreg, knn from pyFTS.models.seasonal import SeasonalIndexer tmp = [ hofts.HighOrderFTS, ifts.IntervalFTS, pwfts.ProbabilisticWeightedFTS, arima.ARIMA, ensemble.AllMethodEnsembleFTS, knn.KNearestNeighbors ] tmp2 = [ Grid.GridPartitioner, Entropy.EntropyPartitioner, FCM.FCMPartitioner ] tmp3 = [ Measures.get_distribution_statistics, SeasonalIndexer.SeasonalIndexer, SeasonalIndexer.LinearSeasonalIndexer ] indexer = kwargs.get('indexer', None) steps_ahead = kwargs.get('steps_ahead', 1) method = kwargs.get('method', None) if mfts.benchmark_only: _key = mfts.shortname + str( mfts.order if mfts.order is not None else "") + str(mfts.alpha) else: pttr = str(partitioner.__module__).split('.')[-1] _key = mfts.shortname + " n = " + str( mfts.order) + " " + pttr + " q = " + str(partitioner.partitions) mfts.partitioner = partitioner mfts.append_transformation(partitioner.transformation) _key += str(steps_ahead) _key += str(method) if method is not None else "" if mfts.has_seasonality: mfts.indexer = indexer _start = time.time() mfts.fit(train_data, **kwargs) _end = time.time() times = _end - _start _crps1, _t1, _brier = Measures.get_distribution_statistics( test_data, mfts, **kwargs) _t1 += times ret = { 'key': _key, 'obj': mfts, 'CRPS': _crps1, 'time': _t1, 'brier': _brier, 'window': window_key, 'steps': steps_ahead, 'method': method } return ret