1.6. Gene Random functions

Simple functions for performing gene randomisation.

1.6.1. Gene Randomisation

1.6.1.1. Integer functions

natural_selection.genetic_algorithms.utils.random_functions.random_int(gene)

Random integer from range.

Parameters

gene (Gene) – A gene with a set gene_min and gene_max.

Returns

Random number.

Return type

int

natural_selection.genetic_algorithms.utils.random_functions.random_int_step(gene)

Random integer step from a range. Stepping can be solely to the right (increment), left (decrement), or in both. This depends on step_lower_bound and step_upper_bound values of the gene. For left steps only, both need to be negative. For right only, both should be positive values.

stepped_value = value + random(int, int)

Stepped values are still bound to the gene_min and gene_max constraints and will continue setting until condition is matched.

Parameters

gene (Gene) – A gene with a set step_lower_bound and step_upper_bound.

Returns

Stepped value.

Return type

int

1.6.1.2. Float functions

natural_selection.genetic_algorithms.utils.random_functions.random_gaussian(gene)

Random float from gaussian dist.

Parameters

gene (Gene) – A gene with a set mu and sig.

Returns

Random number.

Return type

float

natural_selection.genetic_algorithms.utils.random_functions.random_uniform(gene)

Random float from uniform dist.

Parameters

gene (Gene) – A gene with a set gene_min and gene_max.

Returns

Random number.

Return type

float

natural_selection.genetic_algorithms.utils.random_functions.random_gaussian_step(gene)

Random gaussian step. Stepping can be solely to the right (increment), left (decrement), or in both. This depends on mu and sig values of the gene. For left steps only, both need to be negative. For right only, both should be positive values. These need to be considered in advance.

stepped_value = value + gaussian(mu, sig)

Stepped values are still bound to the gene_min and gene_max constraints and will continue setting until condition is matched.

Parameters

gene (Gene) – A gene with a set mu and sig.

Returns

Stepped value.

Return type

float

natural_selection.genetic_algorithms.utils.random_functions.random_uniform_step(gene)

Random uniform step from a range. Stepping can be solely to the right (increment), left (decrement), or in both. This depends on step_lower_bound and step_upper_bound values of the gene. For left steps only, both need to be negative. For right only, both should be positive values.

stepped_value = value + uniform(l, u)

Stepped values are still bound to the gene_min and gene_max constraints and will continue setting until condition is matched.

Parameters

gene (Gene) – A gene with a set step_lower_bound and step_upper_bound.

Returns

Stepped value.

Return type

float

1.6.1.3. List choice functions

natural_selection.genetic_algorithms.utils.random_functions.random_choice(gene)

Randomly select a object, such as strings, from a list. Gene must have defined choices list.

Parameters

gene (Gene) – A gene with a set choices list.

Returns

Selected choice.

Return type

object