From 6a1ee719b75c24109460c8f5c309bd4f1620ceab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=C3=B4nio=20C=C3=A2ndido?= Date: Mon, 27 Jan 2020 14:54:38 -0300 Subject: [PATCH] Removing direct dispy import from hyperparam modules --- pyFTS/hyperparam/Evolutionary.py | 6 ++++-- pyFTS/hyperparam/GridSearch.py | 7 +++++-- pyFTS/hyperparam/mvfts.py | 4 +++- 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/pyFTS/hyperparam/Evolutionary.py b/pyFTS/hyperparam/Evolutionary.py index 3bc968b..3f046de 100644 --- a/pyFTS/hyperparam/Evolutionary.py +++ b/pyFTS/hyperparam/Evolutionary.py @@ -8,7 +8,6 @@ import math import time from functools import reduce from operator import itemgetter -import dispy import random from pyFTS.common import Util @@ -17,7 +16,7 @@ from pyFTS.partitioners import Grid, Entropy # , Huarng from pyFTS.common import Membership from pyFTS.models import hofts, ifts, pwfts from pyFTS.hyperparam import Util as hUtil -from pyFTS.distributed import dispy as dUtil + __measures = ['f1', 'f2', 'rmse', 'size'] @@ -415,6 +414,8 @@ def GeneticAlgorithm(dataset, **kwargs): for key in __measures: individual[key] = ret[key] elif distributed=='dispy': + from pyFTS.distributed import dispy as dUtil + import dispy jobs = [] for ct, individual in enumerate(population): job = cluster.submit(dataset, individual, **kwargs) @@ -602,6 +603,7 @@ def execute(datasetname, dataset, **kwargs): shortname = str(fts_method.__module__).split('.')[-1] if distributed == '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/hyperparam/GridSearch.py b/pyFTS/hyperparam/GridSearch.py index 4b26880..b59a093 100644 --- a/pyFTS/hyperparam/GridSearch.py +++ b/pyFTS/hyperparam/GridSearch.py @@ -4,8 +4,7 @@ from pyFTS.models import hofts from pyFTS.partitioners import Grid, Entropy from pyFTS.benchmarks import Measures from pyFTS.hyperparam import Util as hUtil -from pyFTS.distributed import dispy as dUtil -import dispy + import numpy as np from itertools import product @@ -73,6 +72,8 @@ def cluster_method(individual, dataset, **kwargs): def process_jobs(jobs, datasetname, conn): + from pyFTS.distributed import dispy as dUtil + import dispy for ct, job in enumerate(jobs): print("Processing job {}".format(ct)) result = job() @@ -98,6 +99,8 @@ def process_jobs(jobs, datasetname, conn): def execute(hyperparams, datasetname, dataset, **kwargs): + from pyFTS.distributed import dispy as dUtil + import dispy nodes = kwargs.get('nodes',['127.0.0.1']) diff --git a/pyFTS/hyperparam/mvfts.py b/pyFTS/hyperparam/mvfts.py index 0777d4f..2d7c4db 100644 --- a/pyFTS/hyperparam/mvfts.py +++ b/pyFTS/hyperparam/mvfts.py @@ -28,7 +28,7 @@ from pyFTS.partitioners import Grid, Entropy # , Huarng from pyFTS.common import Membership from pyFTS.models import hofts, ifts, pwfts from pyFTS.hyperparam import Util as hUtil -from pyFTS.distributed import dispy as dUtil + from pyFTS.hyperparam import Evolutionary, random_search as RS from pyFTS.models.multivariate import mvfts, wmvfts, variable from pyFTS.models.seasonal import partitioner as seasonal @@ -458,6 +458,8 @@ def execute(datasetname, dataset, **kwargs): kwargs['random_individual'] = random_genotype if distributed == 'dispy': + from pyFTS.distributed import dispy as dUtil + import dispy nodes = kwargs.get('nodes', ['127.0.0.1']) cluster, http_server = dUtil.start_dispy_cluster(evaluate, nodes=nodes) kwargs['cluster'] = cluster