# pyFTS.hyperparam package

## Module contents

## Submodules

## pyFTS.hyperparam.Util module

Common facilities for hyperparameter optimization

`pyFTS.hyperparam.Util.``create_hyperparam_tables`(conn)

  Create a sqlite3 table designed to store benchmark results.

  Parameters

    conn – a sqlite3 database connection

`pyFTS.hyperparam.Util.``insert_hyperparam`(data, conn)

  Insert benchmark data on database

  Parameters

    data – a tuple with the benchmark data with format:

  Dataset: Identify on which dataset the dataset was performed Tag: a user defined word that indentify a benchmark set Model: FTS model Transformation: The name of data transformation, if one was used mf: membership function Order: the order of the FTS method Partitioner: UoD partitioning scheme Partitions: Number of partitions alpha: alpha cut lags: lags Measure: accuracy measure Value: the measure value

  Parameters

    conn – a sqlite3 database connection

  Returns

`pyFTS.hyperparam.Util.``open_hyperparam_db`(name)

  Open a connection with a Sqlite database designed to store benchmark results.

  Parameters

    name – database filenem

  Returns

    a sqlite3 database connection

## pyFTS.hyperparam.GridSearch module

`pyFTS.hyperparam.GridSearch.``cluster_method`(individual, dataset, **kwargs)

`pyFTS.hyperparam.GridSearch.``dict_individual`(mf, partitioner, partitions, order, lags, alpha_cut)

`pyFTS.hyperparam.GridSearch.``execute`(hyperparams, datasetname, dataset, **kwargs)

`pyFTS.hyperparam.GridSearch.``process_jobs`(jobs, datasetname, conn)

## pyFTS.hyperparam.Evolutionary module

Distributed Evolutionary Hyperparameter Optimization (DEHO) for MVFTS

`pyFTS.hyperparam.Evolutionary.``GeneticAlgorithm`(dataset, **kwargs)

  Genetic algoritm for Distributed Evolutionary Hyperparameter Optimization (DEHO)

  Parameters

    - dataset – The time series to optimize the FTS

    - ngen – An integer value with the maximum number of generations, default value: 30

    - mgen – An integer value with the maximum number of generations without improvement to stop, default value 7

    - npop – An integer value with the population size, default value: 20

    - pcross – A float value between 0 and 1 with the probability of crossover, default: .5

    - psel – A float value between 0 and 1 with the probability of selection, default: .5

    - pmut – A float value between 0 and 1 with the probability of mutation, default: .3

    - fts_method – The FTS method to optimize

    - parameters – dict with model specific arguments for fts_method

    - elitism – A boolean value indicating if the best individual must always survive to next population

    - initial_operator – a function that receives npop and return a random population with size npop

    - evalutation_operator – a function that receives a dataset and an individual and return its fitness

    - selection_operator – a function that receives the whole population and return a selected individual

    - crossover_operator – a function that receives the whole population and return a descendent individual

    - mutation_operator – a function that receives one individual and return a changed individual

    - window_size – An integer value with the the length of scrolling window for train/test on dataset

    - train_rate – A float value between 0 and 1 with the train/test split ([0,1])

    - increment_rate – A float value between 0 and 1 with the the increment of the scrolling window, relative to the window_size ([0,1])

    - collect_statistics – A boolean value indicating to collect statistics for each generation

    - distributed – A value indicating it the execution will be local and sequential (distributed=False), or parallel and distributed (distributed=’dispy’ or distributed=’spark’)

    - cluster – If distributed=’dispy’ the list of cluster nodes, else if distributed=’spark’ it is the master node

  Returns

    the best genotype

`pyFTS.hyperparam.Evolutionary.``crossover`(population, **kwargs)

  Crossover operation between two parents

  Parameters

    population – the original population

  Returns

    a genotype

`pyFTS.hyperparam.Evolutionary.``double_tournament`(population, **kwargs)

  Double tournament selection strategy.

  Parameters

    population –

  Returns

`pyFTS.hyperparam.Evolutionary.``elitism`(population, new_population, **kwargs)

  Elitism operation, always select the best individual of the population and discard the worst

  Parameters

    - population –

    - new_population –

  Returns

`pyFTS.hyperparam.Evolutionary.``evaluate`(dataset, individual, **kwargs)

  Evaluate an individual using a sliding window cross validation over the dataset.

  Parameters

    - dataset – Evaluation dataset

    - individual – genotype to be tested

    - window_size – The length of scrolling window for train/test on dataset

    - train_rate – The train/test split ([0,1])

    - increment_rate – The increment of the scrolling window, relative to the window_size ([0,1])

    - parameters – dict with model specific arguments for fit method.

  Returns

    a tuple (len_lags, rmse) with the parsimony fitness value and the accuracy fitness value

`pyFTS.hyperparam.Evolutionary.``execute`(datasetname, dataset, **kwargs)

  Batch execution of Distributed Evolutionary Hyperparameter Optimization (DEHO) for monovariate methods

  Parameters

    - datasetname –

    - dataset – The time series to optimize the FTS

    - file –

    - experiments –

    - distributed –

    - ngen – An integer value with the maximum number of generations, default value: 30

    - mgen – An integer value with the maximum number of generations without improvement to stop, default value 7

    - npop – An integer value with the population size, default value: 20

    - pcross – A float value between 0 and 1 with the probability of crossover, default: .5

    - psel – A float value between 0 and 1 with the probability of selection, default: .5

    - pmut – A float value between 0 and 1 with the probability of mutation, default: .3

    - fts_method – The FTS method to optimize

    - parameters – dict with model specific arguments for fts_method

    - elitism – A boolean value indicating if the best individual must always survive to next population

    - initial_operator – a function that receives npop and return a random population with size npop

    - random_individual – create an random genotype

    - evalutation_operator – a function that receives a dataset and an individual and return its fitness

    - selection_operator – a function that receives the whole population and return a selected individual

    - crossover_operator – a function that receives the whole population and return a descendent individual

    - mutation_operator – a function that receives one individual and return a changed individual

    - window_size – An integer value with the the length of scrolling window for train/test on dataset

    - train_rate – A float value between 0 and 1 with the train/test split ([0,1])

    - increment_rate – A float value between 0 and 1 with the the increment of the scrolling window, relative to the window_size ([0,1])

    - collect_statistics – A boolean value indicating to collect statistics for each generation

    - distributed – A value indicating it the execution will be local and sequential (distributed=False), or parallel and distributed (distributed=’dispy’ or distributed=’spark’)

    - cluster – If distributed=’dispy’ the list of cluster nodes, else if distributed=’spark’ it is the master node

  Returns

    the best genotype

`pyFTS.hyperparam.Evolutionary.``genotype`(mf, npart, partitioner, order, alpha, lags, f1, f2)

  Create the individual genotype

  Parameters

    - mf – membership function

    - npart – number of partitions

    - partitioner – partitioner method

    - order – model order

    - alpha – alpha-cut

    - lags – array with lag indexes

    - f1 – accuracy fitness value

    - f2 – parsimony fitness value

  Returns

    the genotype, a dictionary with all hyperparameters

`pyFTS.hyperparam.Evolutionary.``initial_population`(n, **kwargs)

  Create a random population of size n

  Parameters

    n – the size of the population

  Returns

    a list with n random individuals

`pyFTS.hyperparam.Evolutionary.``lag_crossover2`(best, worst)

  Cross over two lag genes

  Parameters

    - best – best genotype

    - worst – worst genotype

  Returns

    a tuple (order, lags)

`pyFTS.hyperparam.Evolutionary.``log_result`(conn, datasetname, fts_method, result)

`pyFTS.hyperparam.Evolutionary.``mutation`(individual, **kwargs)

  Mutation operator

  Parameters

    - individual – an individual genotype

    - pmut – individual probability o

  Returns

`pyFTS.hyperparam.Evolutionary.``mutation_lags`(lags, order)

  Mutation operation for lags gene

  Parameters

    - lags –

    - order –

  Returns

`pyFTS.hyperparam.Evolutionary.``persist_statistics`(datasetname, statistics)

`pyFTS.hyperparam.Evolutionary.``phenotype`(individual, train, fts_method, parameters={}, **kwargs)

  Instantiate the genotype, creating a fitted model with the genotype hyperparameters

  Parameters

    - individual – a genotype

    - train – the training dataset

    - fts_method – the FTS method

    - parameters – dict with model specific arguments for fit method.

  Returns

    a fitted FTS model

`pyFTS.hyperparam.Evolutionary.``process_experiment`(fts_method, result, datasetname, conn)

  Persist the results of an DEHO execution in sqlite database (best hyperparameters) and json file (generation statistics)

  Parameters

    - fts_method –

    - result –

    - datasetname –

    - conn –

  Returns

`pyFTS.hyperparam.Evolutionary.``random_genotype`(**kwargs)

  Create random genotype

  Returns

    the genotype, a dictionary with all hyperparameters

`pyFTS.hyperparam.Evolutionary.``tournament`(population, objective, **kwargs)

  Simple tournament selection strategy.

  Parameters

    - population – the population

    - objective – the objective to be considered on tournament

  Returns