Experiment
This module contains the main experiments performed using the current framework.
Created on Mon Sep 30 13:42:15 2019
@author: Jorge Mario Cruz-Duarte (jcrvz.github.io), e-mail: j.m.cruzduarte@ieee.org
The Experiment class orchestrates batch hyper-heuristic runs across multiple
benchmark functions and dimensionalities.
Configuration can be provided via a JSON file in exconf/ or as Python
dictionaries.
Quick usage:
from customhys.experiment import Experiment
# From a JSON configuration file
exp = Experiment(config_file="demo.json")
exp.run()
# Or programmatically
exp = Experiment(
exp_config={
"experiment_name": "quick",
"experiment_type": "default",
"heuristic_collection_file": "default.txt",
},
hh_config={"cardinality": 3, "num_replicas": 30},
prob_config={"dimensions": [2, 5], "functions": ["Sphere"]},
)
exp.run()
- class customhys.experiment.Experiment(config_file=None, exp_config=None, hh_config=None, prob_config=None)[source]
Bases:
objectCreate an experiment using certain configurations.
- __init__(config_file=None, exp_config=None, hh_config=None, prob_config=None)[source]
Initialise the experiment object.
- Parameters:
config_file (str) – Name of the configuration JSON file with the configuration dictionaries: exp_config, hh_config, and prob_config. If only the filename is provided, it is assumed that such a file is in the directory ‘./exconf/’. Otherwise, the full path must be entered. The default value is None.
exp_config (dict) –
Configuration dictionary related to the experiment. Keys and default values are listed as follows:
’experiment_name’: ‘test’, # Name of the experiment ‘experiment_type’: ‘default’, # Type: ‘default’, ‘brute_force’, ‘basic_metaheuristics’ ‘heuristic_collection_file’: ‘default.txt’, # Heuristic space located in /collections/ ‘weights_dataset_file’: None, # Weights or probability distribution of heuristic space ‘use_parallel’: True, # Run the experiment using a pool of processors ‘parallel_pool_size’: None, # Number of processors available, None = Default ‘auto_collection_num_vals’: 5 # Number of values for creating an automatic collection
NOTE 1: ‘experiment_type’: ‘default’ or another name mean hyper-heuristic. NOTE 2: If the collection does not exist, and it is not a reserved one (‘default.txt’, ‘automatic.txt’, ‘basicmetaheuristics.txt’, ‘test_collection’), then an automatic heuristic space is generated with
op.build_operatorswith ‘auto_collection_num_vals’ asnum_valsand ‘heuristic_collection_file’ asfilename. NOTE 3: # ‘weights_dataset_file’ must be determined in a pre-processing step. For the ‘default’ heuristic space, it is provided ‘operators_weights.json’.hh_config (dict) –
Configuration dictionary related to the hyper-heuristic procedure. Keys and default values are listed as follows:
’cardinality’: 3, # Maximum cardinality used for building metaheuristics ‘num_agents’: 30, # Population size employed by the metaheuristic ‘num_iterations’: 100, # Maximum number of iterations used by the metaheuristic ‘num_replicas’: 50, # Number of replicas for each metaheuristic implemented ‘num_steps’: 100, # * Number of steps that the hyper-heuristic performs ‘max_temperature’: 200, # * Initial temperature for HH-Simulated Annealing ‘stagnation_percentage’: 0.3, # * Percentage of stagnation used by the hyper-heuristic ‘cooling_rate’: 0.05 # * Cooling rate for HH-Simulated Annealing
NOTE 4: Keys with * correspond to those that are only used when
exp_config['experiment_type']is neither ‘brute_force’ nor ‘basic_metaheuristic’.prob_config (dict) –
Configuration dictionary related to the problems to solve. Keys and default values are listed as follows:
’dimensions’: [2, 5, 10, 20, 30, 40, 50], # List of dimensions for the problem domains ‘functions’: bf.__all__, # List of function names of the optimisation problems ‘is_constrained’: True # True if the problem domain is hard constrained
- Returns:
None.
- exception customhys.experiment.ExperimentError[source]
Bases:
ExceptionSimple ExperimentError to manage exceptions.
- customhys.experiment.read_config_file(config_file=None, exp_config=None, hh_config=None, prob_config=None)[source]
Return the experimental (exp_config), hyper-heuristic (hh_config), problem (prob_config) configuration variables from config_file, if it is supplied. Otherwise, use the exp_config, hh_config, and prob_config inputs. If there is no input, then assume the default values for these three configuration variables. Further information about these variables can be found in the Experiment class’s __doc__.
- customhys.experiment.create_task_list(function_list, dimension_list)[source]
Return a list of combinations (in tuple form) for problems from functions and dimensions. :param list function_list:
List of functions from the benchmark_func module.
- Parameters:
dimension_list (list) – List of dimensions considered for each one of these functions.
- Returns:
list of tuples