diff --git a/pyFTS/hyperparam/mvfts.py b/pyFTS/hyperparam/mvfts.py index 27bbaf3..418e46d 100644 --- a/pyFTS/hyperparam/mvfts.py +++ b/pyFTS/hyperparam/mvfts.py @@ -75,9 +75,14 @@ def random_genotype(**kwargs): explanatory_params = [] for v in explanatory_variables: + var = vars[v] + if var['type'] == 'common': + npart = random.randint(7, 50) + else: + npart = var['npart'] param = { 'mf': random.randint(1, 4), - 'npart': random.randint(10, 50), + 'npart': npart, 'partitioner': 1, #random.randint(1, 2), 'alpha': random.uniform(0, .5) } @@ -85,7 +90,7 @@ def random_genotype(**kwargs): target_params = { 'mf': random.randint(1, 4), - 'npart': random.randint(10, 50), + 'npart': random.randint(7, 50), 'partitioner': 1, #random.randint(1, 2), 'alpha': random.uniform(0, .5) } @@ -133,6 +138,8 @@ def phenotype(individual, train, fts_method, parameters={}, **kwargs): partitioner_specific={'mf': mf}, npart=tparams['npart'], alpha_cut=tparams['alpha'], data=train) + explanatory_vars.append(target_var) + model = fts_method(explanatory_variables=explanatory_vars, target_variable=target_var, **parameters) model.fit(train, **parameters) @@ -171,6 +178,7 @@ def evaluate(dataset, individual, **kwargs): :param parameters: dict with model specific arguments for fit method. :return: a tuple (len_lags, rmse) with the parsimony fitness value and the accuracy fitness value """ + import logging from pyFTS.models import hofts, ifts, pwfts from pyFTS.common import Util from pyFTS.benchmarks import Measures diff --git a/pyFTS/partitioners/partitioner.py b/pyFTS/partitioners/partitioner.py index 5bd991f..2a6d32c 100644 --- a/pyFTS/partitioners/partitioner.py +++ b/pyFTS/partitioners/partitioner.py @@ -2,7 +2,7 @@ from pyFTS.common import FuzzySet, Membership import numpy as np from scipy.spatial import KDTree import matplotlib.pylab as plt - +import logging class Partitioner(object): """ @@ -154,7 +154,6 @@ class Partitioner(object): method = kwargs.get('method', 'fuzzy') nearest = self.search(data, type='index') - mv = np.zeros(self.partitions) for ix in nearest: @@ -317,16 +316,20 @@ class Partitioner(object): it represents the fuzzy set name. :return: the fuzzy set """ - if isinstance(item, (int, np.int, np.int8, np.int16, np.int32, np.int64)): - if item < 0 or item >= self.partitions: - raise ValueError("The fuzzy set index must be between 0 and {}.".format(self.partitions)) - return self.sets[self.ordered_sets[item]] - elif isinstance(item, str): - if item not in self.sets: - raise ValueError("The fuzzy set with name {} does not exist.".format(item)) - return self.sets[item] - else: - raise ValueError("The parameter 'item' must be an integer or a string and the value informed was {} of type {}!".format(item, type(item))) + try: + if isinstance(item, (int, np.int, np.int8, np.int16, np.int32, np.int64)): + if item < 0 or item >= self.partitions: + raise ValueError("The fuzzy set index must be between 0 and {}.".format(self.partitions)) + return self.sets[self.ordered_sets[item]] + elif isinstance(item, str): + if item not in self.sets: + raise ValueError("The fuzzy set with name {} does not exist.".format(item)) + return self.sets[item] + else: + raise ValueError("The parameter 'item' must be an integer or a string and the value informed was {} of type {}!".format(item, type(item))) + except Exception as ex: + logging.exception("Error") + def __iter__(self): """ diff --git a/pyFTS/tests/hyperparam.py b/pyFTS/tests/hyperparam.py index 5a7ef69..b6a4a4a 100644 --- a/pyFTS/tests/hyperparam.py +++ b/pyFTS/tests/hyperparam.py @@ -17,7 +17,7 @@ def get_dataset(): data['time'] = pd.to_datetime(data["time"], format='%m/%d/%y %I:%M %p') #return 'SONDA.ws_10m', data - return 'Malaysia', data.iloc[:5000] #train, test + return 'Malaysia', data.iloc[:2000] #train, test #return 'Malaysia.temperature', data # train, test ''' @@ -47,7 +47,6 @@ datsetname, dataset = get_dataset() # window_size=10000, train_rate=.9, increment_rate=1,) explanatory_variables =[ - {'name': 'Load', 'data_label': 'load', 'type': 'common'}, {'name': 'Temperature', 'data_label': 'temperature', 'type': 'common'}, {'name': 'Daily', 'data_label': 'time', 'type': 'seasonal', 'seasonality': DateTime.minute_of_day, 'npart': 24 }, {'name': 'Weekly', 'data_label': 'time', 'type': 'seasonal', 'seasonality': DateTime.day_of_week, 'npart': 7 }, @@ -59,13 +58,13 @@ target_variable = {'name': 'Load', 'data_label': 'load', 'type': 'common'} nodes=['192.168.28.38'] deho_mv.execute(datsetname, dataset, ngen=10, npop=10,psel=0.6, pcross=.5, pmut=.3, - window_size=5000, train_rate=.9, increment_rate=1, + window_size=2000, train_rate=.9, increment_rate=1, experiments=1, fts_method=wmvfts.WeightedMVFTS, variables=explanatory_variables, target_variable=target_variable, - distributed='dispy', nodes=nodes, - #parameters=dict(num_batches=5) + #distributed='dispy', nodes=nodes, + parameters=dict(num_batches=5) #parameters=dict(distributed='dispy', nodes=nodes, num_batches=5) ) diff --git a/pyFTS/tests/multivariate.py b/pyFTS/tests/multivariate.py index e8510ec..b7925bd 100644 --- a/pyFTS/tests/multivariate.py +++ b/pyFTS/tests/multivariate.py @@ -23,8 +23,8 @@ from pyFTS.data import Malaysia, Enrollments df = Malaysia.get_dataframe() df['time'] = pd.to_datetime(df["time"], format='%m/%d/%y %I:%M %p') -train_mv = df.iloc[:4500] -test_mv = df.iloc[4500:5000] +train_mv = df.iloc[:1800] +test_mv = df.iloc[1800:2000] del(df)