ase_ga.population#

Members#

ase_ga.population.Population

Population class which maintains the current population and proposes which candidates to pair together.

ase_ga.population.RandomPopulation

ase_ga.population.RankFitnessPopulation

Ranks the fitness relative to set variable to flatten the surface in a certain direction such that mating across variable is equally likely irrespective of raw_score.

ase_ga.population.FitnessSharingPopulation

Fitness sharing population that penalizes structures if they are too similar.

ase_ga.population.MultiObjectivePopulation

Allows for assignment of fitness based on a set of two variables

Documentation#

Implementation of a population for maintaining a GA population and proposing structures to pair.

ase_ga.population.count_looks_like(a, all_cand, comp)[source]#

Utility method for counting occurrences.

class ase_ga.population.Population(data_connection, population_size, comparator=None, logfile=None, use_extinct=False, rng=np.random)[source]#

Population class which maintains the current population and proposes which candidates to pair together.

Parameters:

data_connection: DataConnection object

Bla bla bla.

population_size: int

The number of candidates in the population.

comparator: Comparator object

this will tell if two configurations are equal. Default compare atoms objects directly.

logfile: str

Text file that contains information about the population The format is:

timestamp: generation(if available): id1,id2,id3...

Using this file greatly speeds up convergence checks. Default None meaning that no file is written.

use_extinct: boolean

Set this to True if mass extinction and the extinct key are going to be used. Default is False.

rng: Random number generator

By default numpy.random.

update(new_cand=None)[source]#

New candidates can be added to the database after the population object has been created. This method extracts these new candidates from the database and includes them in the population.

get_current_population()[source]#

Returns a copy of the current population.

get_population_after_generation(gen)[source]#

Returns a copy of the population as it where after generation gen

get_two_candidates(with_history=True)[source]#

Returns two candidates for pairing employing the fitness criteria from L.B. Vilhelmsen et al., JACS, 2012, 134 (30), pp 12807-12816 and the roulete wheel selection scheme described in R.L. Johnston Dalton Transactions, Vol. 22, No. 22. (2003), pp. 4193-4207

get_one_candidate(with_history=True)[source]#

Returns one candidate for mutation employing the fitness criteria from L.B. Vilhelmsen et al., JACS, 2012, 134 (30), pp 12807-12816 and the roulete wheel selection scheme described in R.L. Johnston Dalton Transactions, Vol. 22, No. 22. (2003), pp. 4193-4207

is_uniform(func, min_std, pop=None)[source]#

Tests whether the current population is uniform or diverse. Returns True if uniform, False otherwise.

Parameters:

func: function

that takes one argument an atoms object and returns a value that will be used for testing against the rest of the population.

min_std: int or float

The minimum standard deviation, if the population has a lower std dev it is uniform.

pop: list, optional

use this list of Atoms objects instead of the current population.

mass_extinction(ids)[source]#

Kills every candidate in the database with gaid in the supplied list of ids. Typically used on the main part of the current population if the diversity is to small.

Parameters:

ids: list

list of ids of candidates to be killed.

class ase_ga.population.RandomPopulation(data_connection, population_size, comparator=None, logfile=None, exclude_used_pairs=False, bad_candidates=0, use_extinct=False)[source]#
update()[source]#

The update method in Population will add to the end of the population, that can’t be used here since we might have bad candidates that need to stay in the population, therefore just recalc the population every time.

get_one_candidate()[source]#

Returns one candidates at random.

get_two_candidates()[source]#

Returns two candidates at random.

class ase_ga.population.FitnessSharingPopulation(data_connection, population_size, comp_key, threshold, alpha_sh=1., comparator=None, logfile=None, use_extinct=False)[source]#

Fitness sharing population that penalizes structures if they are too similar. This is determined by a distance measure

Parameters:

comp_key: string

Key where the distance measure can be found in the atoms.info[‘key_value_pairs’] dictionary.

threshold: float or int

Value above which no penalization of the fitness takes place

alpha_sh: float or int

Determines the shape of the sharing function. Default is 1, which gives a linear sharing function.

update()[source]#

The update method in Population will add to the end of the population, that can’t be used here since the shared fitness will change for all candidates when new are added, therefore just recalc the population every time.

get_two_candidates()[source]#

Returns two candidates for pairing employing the fitness criteria from L.B. Vilhelmsen et al., JACS, 2012, 134 (30), pp 12807-12816 and the roulete wheel selection scheme described in R.L. Johnston Dalton Transactions, Vol. 22, No. 22. (2003), pp. 4193-4207

class ase_ga.population.RankFitnessPopulation(data_connection, population_size, variable_function, comparator=None, logfile=None, use_extinct=False, exp_function=True, exp_prefactor=0.5)[source]#

Ranks the fitness relative to set variable to flatten the surface in a certain direction such that mating across variable is equally likely irrespective of raw_score.

Parameters:

variable_function: function

A function that takes as input an Atoms object and returns the variable that differentiates the ranks.

exp_function: boolean

If True use an exponential function for ranking the fitness. If False use the same as in Population. Default True.

exp_prefactor: float

The prefactor used in the exponential fitness scaling function. Default 0.5

update()[source]#

The update method in Population will add to the end of the population, that can’t be used here since the fitness will potentially change for all candidates when new are added, therefore just recalc the population every time.

get_two_candidates()[source]#

Returns two candidates for pairing employing the roulete wheel selection scheme described in R.L. Johnston Dalton Transactions, Vol. 22, No. 22. (2003), pp. 4193-4207

class ase_ga.population.MultiObjectivePopulation(data_connection, population_size, variable_function=None, comparator=None, logfile=None, use_extinct=False, abs_data=None, rank_data=None, exp_function=True, exp_prefactor=0.5)[source]#
Allows for assignment of fitness based on a set of two variables

such that fitness is ranked according to a Pareto-front of non-dominated candidates.

Parameters:
  • abs_data (list) – Set of key_value_pairs in atoms object for which fitness should be assigned based on absolute value.

  • rank_data (list) – Set of key_value_pairs in atoms object for which data should be ranked in order to ascribe fitness.

  • variable_function (function) – A function that takes as input an Atoms object and returns the variable that differentiates the ranks. Only use if data is ranked.

  • exp_function (boolean) – If True use an exponential function for ranking the fitness. If False use the same as in Population. Default True.

  • exp_prefactor (float) – The prefactor used in the exponential fitness scaling function. Default 0.5

get_nonrank(nrcand, key=None)[source]#

“Returns a list of fitness values.