From be119604a92d2242644ecf9afac0ab4eddb102f6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=C3=B4nio=20C=C3=A2ndido?= Date: Tue, 28 Jan 2020 15:13:11 -0300 Subject: [PATCH] Improvements of FCM_FTS --- pyFTS/fcm/GA.py | 10 +++++++--- pyFTS/fcm/fts.py | 6 +++++- pyFTS/hyperparam/Evolutionary.py | 4 ++-- pyFTS/hyperparam/GridSearch.py | 4 +++- 4 files changed, 17 insertions(+), 7 deletions(-) diff --git a/pyFTS/fcm/GA.py b/pyFTS/fcm/GA.py index a199e16..e463b46 100644 --- a/pyFTS/fcm/GA.py +++ b/pyFTS/fcm/GA.py @@ -4,7 +4,6 @@ import math import time from functools import reduce from operator import itemgetter -import dispy import random from pyFTS.common import Util @@ -13,7 +12,6 @@ from pyFTS.partitioners import Grid, Entropy # , Huarng from pyFTS.models import hofts from pyFTS.common import Membership from pyFTS.hyperparam import Util as hUtil -from pyFTS.distributed import dispy as dUtil from pyFTS.fcm import common, fts @@ -267,6 +265,8 @@ def GeneticAlgorithm(dataset, **kwargs): ret = evaluate(dataset, individual, **kwargs) individual['rmse'] = ret['rmse'] elif distributed=='dispy': + import dispy + from pyFTS.distributed import dispy as dUtil jobs = [] for ct, individual in enumerate(population): job = cluster.submit(dataset, individual, **kwargs) @@ -396,13 +396,17 @@ def log_result(conn, datasetname, result): def execute(datasetname, dataset, **kwargs): - conn = hUtil.open_hyperparam_db('hyperparam.db') + file = kwargs.get('file', 'hyperparam.db') + + conn = hUtil.open_hyperparam_db(file) experiments = kwargs.get('experiments', 30) distributed = kwargs.get('distributed', False) if distributed == 'dispy': + import dispy + from pyFTS.distributed import dispy as dUtil nodes = kwargs.get('nodes', ['127.0.0.1']) cluster, http_server = dUtil.start_dispy_cluster(evaluate, nodes=nodes) kwargs['cluster'] = cluster diff --git a/pyFTS/fcm/fts.py b/pyFTS/fcm/fts.py index 4d31995..cbeeff7 100644 --- a/pyFTS/fcm/fts.py +++ b/pyFTS/fcm/fts.py @@ -1,6 +1,6 @@ from pyFTS.common import fts from pyFTS.models import hofts -from pyFTS.fcm import common +from pyFTS.fcm import common, GA, Activations import numpy as np @@ -10,6 +10,10 @@ class FCM_FTS(hofts.HighOrderFTS): super(FCM_FTS, self).__init__(**kwargs) self.fcm = common.FuzzyCognitiveMap(**kwargs) + def train(self, data, **kwargs): + ret = GA.execute(data, **kwargs) + self.fcm.weights = ret['weights'] + def forecast(self, ndata, **kwargs): ret = [] diff --git a/pyFTS/hyperparam/Evolutionary.py b/pyFTS/hyperparam/Evolutionary.py index 3f046de..d3c5154 100644 --- a/pyFTS/hyperparam/Evolutionary.py +++ b/pyFTS/hyperparam/Evolutionary.py @@ -562,7 +562,7 @@ def execute(datasetname, dataset, **kwargs): :param datasetname: :param dataset: The time series to optimize the FTS - :keyword database_file: + :keyword file: :keyword experiments: :keyword distributed: :keyword ngen: An integer value with the maximum number of generations, default value: 30 @@ -591,7 +591,7 @@ def execute(datasetname, dataset, **kwargs): :return: the best genotype """ - file = kwargs.get('database_file', 'hyperparam.db') + file = kwargs.get('file', 'hyperparam.db') conn = hUtil.open_hyperparam_db(file) diff --git a/pyFTS/hyperparam/GridSearch.py b/pyFTS/hyperparam/GridSearch.py index b59a093..b99d54c 100644 --- a/pyFTS/hyperparam/GridSearch.py +++ b/pyFTS/hyperparam/GridSearch.py @@ -127,7 +127,9 @@ def execute(hyperparams, datasetname, dataset, **kwargs): print("Evaluation values: \n {}".format(hp_values)) cluster, http_server = dUtil.start_dispy_cluster(cluster_method, nodes=nodes) - conn = hUtil.open_hyperparam_db('hyperparam.db') + file = kwargs.get('file', 'hyperparam.db') + + conn = hUtil.open_hyperparam_db(file) for instance in product(*hp_values): partitions = instance[index['partitions']]