Distributed Evolutionary Hyperparameter Optimization (DEHO) for MVFTS

This commit is contained in:
Petrônio Cândido 2019-07-18 12:02:27 -03:00
parent 0b03fbfa57
commit 9f41a49ad9
2 changed files with 69 additions and 5 deletions

View File

@ -1,3 +1,7 @@
"""
Distributed Evolutionary Hyperparameter Optimization (DEHO) for MVFTS
"""
import numpy as np import numpy as np
import pandas as pd import pandas as pd
import math import math
@ -37,7 +41,7 @@ def genotype(mf, npart, partitioner, order, alpha, lags, f1, f2):
return ind return ind
def random_genotype(): def random_genotype(**kwargs):
""" """
Create random genotype Create random genotype
@ -58,7 +62,7 @@ def random_genotype():
# #
def initial_population(n): def initial_population(n, **kwargs):
""" """
Create a random population of size n Create a random population of size n
@ -67,7 +71,7 @@ def initial_population(n):
""" """
pop = [] pop = []
for i in range(n): for i in range(n):
pop.append(random_genotype()) pop.append(random_genotype(**kwargs))
return pop return pop
@ -340,7 +344,7 @@ def elitism(population, new_population, **kwargs):
def GeneticAlgorithm(dataset, **kwargs): def GeneticAlgorithm(dataset, **kwargs):
""" """
Genetic algoritm for hyperparameter optimization Genetic algoritm for Distributed Evolutionary Hyperparameter Optimization (DEHO)
:param dataset: The time series to optimize the FTS :param dataset: The time series to optimize the FTS
:keyword ngen: An integer value with the maximum number of generations, default value: 30 :keyword ngen: An integer value with the maximum number of generations, default value: 30
@ -397,7 +401,7 @@ def GeneticAlgorithm(dataset, **kwargs):
new_population = [] new_population = []
population = initial_operator(npop) population = initial_operator(npop, **kwargs)
last_best = population[0] last_best = population[0]
best = population[1] best = population[1]
@ -516,6 +520,16 @@ def GeneticAlgorithm(dataset, **kwargs):
def process_experiment(fts_method, result, datasetname, conn): def process_experiment(fts_method, result, datasetname, conn):
"""
Persist the results of an DEHO execution in sqlite database (best hyperparameters) and json file (generation statistics)
:param fts_method:
:param result:
:param datasetname:
:param conn:
:return:
"""
log_result(conn, datasetname, fts_method, result['individual']) log_result(conn, datasetname, fts_method, result['individual'])
persist_statistics(datasetname, result['statistics']) persist_statistics(datasetname, result['statistics'])
return result['individual'] return result['individual']
@ -541,6 +555,7 @@ def log_result(conn, datasetname, fts_method, result):
def execute(datasetname, dataset, **kwargs): def execute(datasetname, dataset, **kwargs):
""" """
Batch execution of Distributed Evolutionary Hyperparameter Optimization (DEHO) for monovariate methods
:param datasetname: :param datasetname:
:param dataset: The time series to optimize the FTS :param dataset: The time series to optimize the FTS

49
pyFTS/hyperparam/mvfts.py Normal file
View File

@ -0,0 +1,49 @@
"""
Distributed Evolutionary Hyperparameter Optimization (DEHO) for MVFTS
"""
import numpy as np
import pandas as pd
import math
import random
from pyFTS.hyperparam import Evolutionary
def genotype(vars, params, f1, f2):
"""
Create the individual genotype
:param vars: dictionary with variable names, types, and other parameters
:param params: dictionary with variable hyperparameters var: {mf, npart, partitioner, alpha}
:param f1: accuracy fitness value
:param f2: parsimony fitness value
:return: the genotype, a dictionary with all hyperparameters
"""
ind = dict(vars=vars, params=params, f1=f1, f2=f2)
return ind
def random_genotype(**kwargs):
"""
Create random genotype
:return: the genotype, a dictionary with all hyperparameters
"""
order = random.randint(1, 3)
lags = [k for k in np.arange(1, order+1)]
return genotype(
random.randint(1, 4),
random.randint(10, 100),
random.randint(1, 2),
order,
random.uniform(0, .5),
lags,
None,
None
)
def phenotype(individual, train, fts_method, parameters={}):
pass