From e5235873dda4a72fc97e64a635e3ee94a9ab9594 Mon Sep 17 00:00:00 2001 From: Nelson Brochado Date: Wed, 30 Dec 2020 18:54:23 +0100 Subject: [PATCH] some typos in comments and 1 variable fixed --- src/agent/agent.py | 8 ++++---- src/algorithm/distributed_algorithm/search_loop.py | 4 ++-- src/algorithm/hill_climbing.py | 2 +- src/algorithm/mapper.py | 2 +- src/algorithm/parameters.py | 8 ++++---- src/algorithm/search_loop.py | 4 ++-- src/fitness/base_ff_classes/moo_ff.py | 2 +- src/fitness/multi_objective/singlefit_multiobj.py | 4 ++-- src/fitness/progsys.py | 2 +- src/fitness/regex/RegexEval.py | 2 +- src/fitness/sequence_match.py | 2 +- src/operators/subtree_parse.py | 4 ++-- src/representation/individual.py | 2 +- src/scripts/GE_LR_parser.py | 10 +++++----- src/utilities/algorithm/NSGA2.py | 10 +++++----- src/utilities/algorithm/command_line_parser.py | 12 ++++++------ src/utilities/algorithm/initialise_run.py | 6 +++--- src/utilities/fitness/error_metric.py | 4 ++-- src/utilities/fitness/math_functions.py | 2 +- src/utilities/representation/check_methods.py | 2 +- 20 files changed, 46 insertions(+), 46 deletions(-) diff --git a/src/agent/agent.py b/src/agent/agent.py index f1059fa7..87167b18 100644 --- a/src/agent/agent.py +++ b/src/agent/agent.py @@ -18,13 +18,13 @@ def __init__(self, ip): # Interaction probability received in constructor self.interaction_probability = ip - # Only initialize singel individual. Single agent can only have single genetic information + # Only initialize single individual. Single agent can only have single genetic information self.individual = initialisation(1) # Evaluate the fitness for the the individual self.individual = evaluate_fitness(self.individual) - # Flag which store the boolean value for other nebouring agents found or not + # Flag which store the boolean value for other neighbouring agents found or not self.agents_found = False @@ -83,12 +83,12 @@ def act(self): # Sort the individuals list individuals.sort(reverse=True) - # Get the higest performing individual from the sorted population + # Get the highest performing individual from the sorted population self.new_individual = individuals[0] def update(self): #Update the information if the agent has sense nearby agents if self.agents_found: - # Repalce the individual with the higest performing individual obtained from act method + # Replace the individual with the highest performing individual obtained from act method self.individual = [self.new_individual] \ No newline at end of file diff --git a/src/algorithm/distributed_algorithm/search_loop.py b/src/algorithm/distributed_algorithm/search_loop.py index 2e757d10..eeda9fd9 100644 --- a/src/algorithm/distributed_algorithm/search_loop.py +++ b/src/algorithm/distributed_algorithm/search_loop.py @@ -15,9 +15,9 @@ def create_agents(n,p): def search_loop(): """ - This loop is used when the multiagent parameter is passed + This loop is used when the multi-agent parameter is passed """ - # Create a list of agents based on the paramater passed + # Create a list of agents based on the parameter passed agents = create_agents(params['AGENT_SIZE'],params['INTERACTION_PROBABILITY']) ##Multi-Agent based GE diff --git a/src/algorithm/hill_climbing.py b/src/algorithm/hill_climbing.py index 65156d06..70f262f5 100644 --- a/src/algorithm/hill_climbing.py +++ b/src/algorithm/hill_climbing.py @@ -4,7 +4,7 @@ from utilities.stats import trackers -"""Hill-climbing is just about the simplest metaheuristic there +"""Hill-climbing is just about the simplest meta-heuristic there is. It's of interest in GP/GE because of the lingering suspicion among many researchers that crossover just doesn't work. This goes back to 90s work by Chellapilla and by O'Reilly. Today, many papers are diff --git a/src/algorithm/mapper.py b/src/algorithm/mapper.py index 97630410..8e26b7b4 100644 --- a/src/algorithm/mapper.py +++ b/src/algorithm/mapper.py @@ -82,7 +82,7 @@ def map_ind_from_genome(genome): The number of used codons. """ - # Create local variables to avoide multiple dictionary lookups + # Create local variables to avoid multiple dictionary lookups max_tree_depth, max_wraps = params['MAX_TREE_DEPTH'], params['MAX_WRAPS'] bnf_grammar = params['BNF_GRAMMAR'] diff --git a/src/algorithm/parameters.py b/src/algorithm/parameters.py index eebbb692..37e62a92 100644 --- a/src/algorithm/parameters.py +++ b/src/algorithm/parameters.py @@ -176,12 +176,12 @@ # encourage diversity in the population. 'MUTATE_DUPLICATES': False, - # MULTIAGENT Parameters - # True or False for Multiagent + # MULTI-AGENT Parameters + # True or False for multi-agent 'MULTIAGENT': False, # Agent Size. Number of agents having their own copy of genetic material 'AGENT_SIZE': 100, - # Interaction Probablity. How frequently the agents can interaction with each other + # Interaction Probability. How frequently the agents can interaction with each other 'INTERACTION_PROBABILITY': 0.5, # OTHER @@ -201,7 +201,7 @@ def load_params(file_name): try: open(file_name, "r") except FileNotFoundError: - s = "algorithm.paremeters.load_params\n" \ + s = "algorithm.parameters.load_params\n" \ "Error: Parameters file not found.\n" \ " Ensure file extension is specified, e.g. 'regression.txt'." raise Exception(s) diff --git a/src/algorithm/search_loop.py b/src/algorithm/search_loop.py index 63520e3f..75c785fa 100755 --- a/src/algorithm/search_loop.py +++ b/src/algorithm/search_loop.py @@ -16,7 +16,7 @@ def search_loop(): """ if params['MULTICORE']: - # initialize pool once, if mutlicore is enabled + # initialize pool once, if multi-core is enabled params['POOL'] = Pool(processes=params['CORES'], initializer=pool_init, initargs=(params,)) # , maxtasksperchild=1) @@ -55,7 +55,7 @@ def search_loop_from_state(): individuals = trackers.state_individuals if params['MULTICORE']: - # initialize pool once, if mutlicore is enabled + # initialize pool once, if multi-core is enabled params['POOL'] = Pool(processes=params['CORES'], initializer=pool_init, initargs=(params,)) # , maxtasksperchild=1) diff --git a/src/fitness/base_ff_classes/moo_ff.py b/src/fitness/base_ff_classes/moo_ff.py index 01d45259..aab361bd 100644 --- a/src/fitness/base_ff_classes/moo_ff.py +++ b/src/fitness/base_ff_classes/moo_ff.py @@ -66,7 +66,7 @@ def value(fitness_vector, objective_index): :param fitness_vector: A vector/list of fitnesses. :param objective_index: The index of the desired fitness. - :return: The fitness at the objective index of the fitness vecror. + :return: The fitness at the objective index of the fitness vector. """ if not isinstance(fitness_vector, list): diff --git a/src/fitness/multi_objective/singlefit_multiobj.py b/src/fitness/multi_objective/singlefit_multiobj.py index 8b3b74d5..50965b82 100644 --- a/src/fitness/multi_objective/singlefit_multiobj.py +++ b/src/fitness/multi_objective/singlefit_multiobj.py @@ -11,7 +11,7 @@ class singlefit_multiobj(base_ff): """ An example of a single fitness class that generates - two fitness values for multiobjective optimisation + two fitness values for multi-objective optimisation """ maximise = True @@ -57,7 +57,7 @@ def value(fitness_vector, objective_index): :param fitness_vector: A vector/list of fitnesses. :param objective_index: The index of the desired fitness. - :return: The fitness at the objective index of the fitness vecror. + :return: The fitness at the objective index of the fitness vector. """ if not isinstance(fitness_vector, list): diff --git a/src/fitness/progsys.py b/src/fitness/progsys.py index 1526c90d..a8860fac 100644 --- a/src/fitness/progsys.py +++ b/src/fitness/progsys.py @@ -33,7 +33,7 @@ def __init__(self): params['GRAMMAR_FILE']) self.eval = self.create_eval_process() if params['MULTICORE']: - print("Warming: Multicore is not supported with progsys " + print("Warming: multi-core is not supported with progsys " "as fitness function.\n" "Fitness function only allows sequential evaluation.") diff --git a/src/fitness/regex/RegexEval.py b/src/fitness/regex/RegexEval.py index ce7e5f1f..493d8054 100644 --- a/src/fitness/regex/RegexEval.py +++ b/src/fitness/regex/RegexEval.py @@ -32,7 +32,7 @@ def __init__(self): if params['MULTICORE']: s = "fitness.regex.RegexEval.RegexEval\n" \ - "Error: Multicore evaluation cannot be used with RegexEval " \ + "Error: multi-core evaluation cannot be used with RegexEval " \ "fitness function, as this fitness function already manages " \ "processes using the multiprocessing library." raise Exception(s) diff --git a/src/fitness/sequence_match.py b/src/fitness/sequence_match.py index c8bd75ad..02d1d63d 100644 --- a/src/fitness/sequence_match.py +++ b/src/fitness/sequence_match.py @@ -124,7 +124,7 @@ def compress(s): def compressibility(s): """ - Compressability is in [0, 1]. It's high when the compressed string + Compressibility is in [0, 1]. It's high when the compressed string is much shorter than the original. :param s: diff --git a/src/operators/subtree_parse.py b/src/operators/subtree_parse.py index d0f6aeb7..25e157f2 100644 --- a/src/operators/subtree_parse.py +++ b/src/operators/subtree_parse.py @@ -30,7 +30,7 @@ def combine_snippets(): # Get new snippets list. updated_snippets = sorted(trackers.snippets.keys()) - # Initialise counter for reduction interations. + # Initialise counter for reduction iterations. no_passes = 1 while updated_snippets != original_snippets: @@ -454,7 +454,7 @@ def check_reductions(alt_cs, pre, aft, idx, children): children) elif all([i != [] for i in children]): - # We have compiled a full set of potneital + # We have compiled a full set of potential # children to reduce_trees. Generate a key and check # if it exists. generate_key_and_check(pre, aft, reduce, diff --git a/src/representation/individual.py b/src/representation/individual.py index 3f0532b3..3bcdc60e 100755 --- a/src/representation/individual.py +++ b/src/representation/individual.py @@ -114,7 +114,7 @@ def evaluate(self): evaluation on either training or test distributions. Sets fitness value. - :return: Nothing unless multicore evaluation is being used. In that + :return: Nothing unless multi-core evaluation is being used. In that case, returns self. """ diff --git a/src/scripts/GE_LR_parser.py b/src/scripts/GE_LR_parser.py index e9db8ab2..290e0793 100644 --- a/src/scripts/GE_LR_parser.py +++ b/src/scripts/GE_LR_parser.py @@ -43,18 +43,18 @@ def parse_terminals(target): for T in sorted(terms.keys()): # Iterate over all Terminals. - # Find all occurances of this terminal in the target string. - occurrances = [] + # Find all occurrences of this terminal in the target string. + occurrences = [] index = 0 while index < len(target): index = target.find(T, index) - if index not in occurrances and index != -1: - occurrances.append(index) + if index not in occurrences and index != -1: + occurrences.append(index) index += len(T) else: break - for idx in occurrances: + for idx in occurrences: # Check each occurrence of this terminal in the target string. for NT in terms[T]: diff --git a/src/utilities/algorithm/NSGA2.py b/src/utilities/algorithm/NSGA2.py index bf60a2e7..2dbb9143 100644 --- a/src/utilities/algorithm/NSGA2.py +++ b/src/utilities/algorithm/NSGA2.py @@ -23,7 +23,7 @@ def compute_pareto_metrics(population): def sort_non_dominated(population): - """Sort the first *k* *population* into different nondomination levels + """Sort the first *k* *population* into different non-domination levels using the "Fast Nondominated Sorting Approach" proposed by Deb et al., see [Deb2002]_. This algorithm has a time complexity of :math:`O(MN^2)`, where :math:`M` is the number of objectives and :math:`N` the number of @@ -32,7 +32,7 @@ def sort_non_dominated(population): :param population: A list of individuals to select from. :returns: A list of Pareto fronts (lists), the first list includes - nondominated individuals. + non-dominated individuals. .. [Deb2002] Deb, Pratab, Agarwal, and Meyarivan, "A fast elitist non-dominated sorting genetic algorithm for multi-objective @@ -100,13 +100,13 @@ def sort_non_dominated(population): def dominates(individual1, individual2): """ - Returns whether or not *indvidual1* dominates *indvidual2*. An individual + Returns whether or not *individual1* dominates *individual2*. An individual dominates another if all fitness values are at least as good on all objectives, and strictly better than on at least one objective. :param individual1: The individual that would be dominated. :param individual2: The individual dominant. - :returns: :obj:`True` if indvidual_1 dominates indvidual_2, + :returns: :obj:`True` if *individual1* dominates *individual2*, :obj:`False` otherwise. """ @@ -235,7 +235,7 @@ def crowded_comparison_operator(self, other, pareto): :return: True if *self* is better than *other* and False otherwise. """ - # Between two solutions with differing nondomination ranks, we prefer the + # Between two solutions with differing non-domination ranks, we prefer the # solution with the lower (better) rank. Otherwise, if both solutions # belong to the same front, then we prefer the solution that is located in # a lesser crowded region, i.e., with the larger crowding distance. diff --git a/src/utilities/algorithm/command_line_parser.py b/src/utilities/algorithm/command_line_parser.py index 50d3f9e0..a8e5ad42 100644 --- a/src/utilities/algorithm/command_line_parser.py +++ b/src/utilities/algorithm/command_line_parser.py @@ -172,14 +172,14 @@ def __call__(self, parser, namespace, value, option_string=None): parser.add_argument('--codon_size', dest='CODON_SIZE', type=int, - help='Sets the range from 0 to condon_size to be used ' + help='Sets the range from 0 to codon_size to be used ' 'in genome, requires int value') parser.add_argument('--max_genome_length', dest='MAX_GENOME_LENGTH', type=int, help='Sets the maximum chromosome length for the ' 'algorithm, requires int value. The default max ' - 'genome length is set to None, i.e. gemomes can ' + 'genome length is set to None, i.e. genomes can ' 'grow indefinitely. This can also be set by ' 'specifying the max genome length to be 0.') parser.add_argument('--max_wraps', @@ -234,7 +234,7 @@ def __call__(self, parser, namespace, value, option_string=None): parser.add_argument('--tournament_size', dest='TOURNAMENT_SIZE', type=int, - help='Sets the number of indivs to contest tournament,' + help='Sets the number of individuals to contest tournament,' ' requires int.') parser.add_argument('--selection_proportion', dest='SELECTION_PROPORTION', @@ -348,12 +348,12 @@ def __call__(self, parser, namespace, value, option_string=None): dest='MULTICORE', action='store_true', default=None, - help='Turns on multicore evaluation.') + help='Turns on multi-core evaluation.') parser.add_argument('--cores', dest='CORES', type=int, help='Specify the number of cores to be used for ' - 'multicore evaluation. Requires int.') + 'multi-core evaluation. Requires int.') # REPLACEMENT parser.add_argument('--replacement', @@ -473,7 +473,7 @@ def __call__(self, parser, namespace, value, option_string=None): dest='MULTIAGENT', action='store_true', default=None, - help='This enable the multiagent mode. If this mode is' + help='This enable the multi-agent mode. If this mode is' ' enabled the search_loop and step parameter are' ' overridden with search_multiagent and step_multiagent' ' respectively') diff --git a/src/utilities/algorithm/initialise_run.py b/src/utilities/algorithm/initialise_run.py index db3410a0..65713dca 100644 --- a/src/utilities/algorithm/initialise_run.py +++ b/src/utilities/algorithm/initialise_run.py @@ -149,15 +149,15 @@ class name matches the file name. else: # Just module name specified. Use default location. - # If multiagent is specified need to change + # If multi-agent is specified need to change # how search and step module is called - # Loop and step functions for multiagent is contained + # Loop and step functions for multi-agent is contained # inside algorithm search_loop_distributed and # step_distributed respectively if params['MULTIAGENT'] and \ ( op == 'SEARCH_LOOP' or op == 'STEP' ) : - # Define the directory structure for the multiagent search + # Define the directory structure for the multi-agent search # loop and step multiagent_ops = {'search_loop':'distributed_algorithm.search_loop' \ ,'step':'distributed_algorithm.step'} diff --git a/src/utilities/fitness/error_metric.py b/src/utilities/fitness/error_metric.py index 41117753..8c99c831 100755 --- a/src/utilities/fitness/error_metric.py +++ b/src/utilities/fitness/error_metric.py @@ -66,7 +66,7 @@ def hinge(y, yhat): if 0 in y_vals: y[y == 0] = -1 - # Our definition of hinge loss cannot be used for multiclass + # Our definition of hinge loss cannot be used for multi-class assert len(y_vals) == 2 # NB not np.max. maximum does element-wise max. Also we use the @@ -104,7 +104,7 @@ def f1_score(y, yhat): if -1 in y_vals: y[y == -1] = 0 - # We binarize with a threshold, so this cannot be used for multiclass + # We binarize with a threshold, so this cannot be used for multi-class assert len(y_vals) == 2 # convert real values to boolean {0, 1} with a zero threshold diff --git a/src/utilities/fitness/math_functions.py b/src/utilities/fitness/math_functions.py index e0be7e3e..82a3613e 100644 --- a/src/utilities/fitness/math_functions.py +++ b/src/utilities/fitness/math_functions.py @@ -177,7 +177,7 @@ def percentile(sorted_list, p): in a sorted list :param sorted_list: The sorted list - :param p: The percetile + :param p: The percentile :return: The element corresponding to the percentile """ diff --git a/src/utilities/representation/check_methods.py b/src/utilities/representation/check_methods.py index eccf1f60..cb8d47cf 100644 --- a/src/utilities/representation/check_methods.py +++ b/src/utilities/representation/check_methods.py @@ -87,7 +87,7 @@ def check_ind_from_parser(ind, target): Checks the mapping of an individual generated by the GE parser against the specified target string to ensure the GE individual is correct. - :param ind: An instance of the representation.individaul.Individual class. + :param ind: An instance of the representation.individual.Individual class. :param target: A target string against which to match the phenotype of the individual. :return: Nothing.