dacbench.envs.theory
Module Contents
Classes
An abstract class for an individual in binary representation |
|
An individual for LeadingOne problem |
|
Environment for RLS with step size |
|
RLS environment where the choices of r is discretised |
- class dacbench.envs.theory.BinaryProblem(n, rng=np.random.default_rng())
An abstract class for an individual in binary representation
- initialise_with_fixed_number_of_bits(self, k, rng=np.random.default_rng())
- is_optimal(self)
- get_optimal(self)
- eval(self)
- abstract get_fitness_after_flipping(self, locs)
Calculate the change in fitness after flipping the bits at positions locs
- Parameters
locs (1d-array) – positions where bits are flipped
objective after flipping
- abstract get_fitness_after_crossover(self, xprime, locs_x, locs_xprime)
Calculate fitness of the child aftering being crossovered with xprime
- Parameters
xprime (1d boolean array) – the individual to crossover with
locs_x (1d boolean/integer array) – positions where we keep current bits of self
locs_xprime (: 1d boolean/integer array) – positions where we change to xprime’s bits
- flip(self, locs)
flip the bits at position indicated by locs
- Parameters
locs (1d-array) – positions where bits are flipped
Returns: the new individual after the flip
- combine(self, xprime, locs_xprime)
combine (crossover) self and xprime by taking xprime’s bits at locs_xprime and self’s bits at other positions
- Parameters
xprime (1d boolean array) – the individual to crossover with
locs_x (1d boolean/integer array) – positions where we keep current bits of self
locs_xprime (: 1d boolean/integer array) – positions where we change to xprime’s bits
Returns: the new individual after the crossover
- mutate(self, p, n_childs, rng=np.random.default_rng())
Draw l ~ binomial(n, p), l>0 Generate n_childs children by flipping exactly l bits Return: the best child (maximum fitness), its fitness and number of evaluations used
- mutate_rls(self, l, rng=np.random.default_rng())
generate a child by flipping exactly l bits Return: child, its fitness
- crossover(self, xprime, p, n_childs, include_xprime=True, count_different_inds_only=True, rng=np.random.default_rng())
- Crossover operator:
for each bit, taking value from x with probability p and from self with probability 1-p
- Arguments:
x: the individual to crossover with p (float): in [0,1]
- class dacbench.envs.theory.LeadingOne(n, rng=np.random.default_rng(), initObj=None)
Bases:
dacbench.envs.theory.BinaryProblemAn individual for LeadingOne problem The aim is to maximise the number of leading (and consecutive) 1 bits in the string
- eval(self)
- is_optimal(self)
- get_optimal(self)
- get_fitness_after_flipping(self, locs)
Calculate the change in fitness after flipping the bits at positions locs
- Parameters
locs (1d-array) – positions where bits are flipped
objective after flipping
- get_fitness_after_crossover(self, xprime, locs_x, locs_xprime)
Calculate fitness of the child aftering being crossovered with xprime
- Parameters
xprime (1d boolean array) – the individual to crossover with
locs_x (1d boolean/integer array) – positions where we keep current bits of self
locs_xprime (: 1d boolean/integer array) – positions where we change to xprime’s bits
- dacbench.envs.theory.MAX_INT = 100000000.0
- dacbench.envs.theory.HISTORY_LENGTH = 5
- class dacbench.envs.theory.RLSEnv(config, test_env=False)
Bases:
dacbench.AbstractEnvEnvironment for RLS with step size Current assumption: we only consider (1+1)-RLS, so there’s only one parameter to tune (r)
- get_obs_domain_from_name(var_name)
Get default lower and upperbound of a observation variable based on its name. The observation space will then be created Return:
Two int values, e.g., 1, np.inf
- reset(self)
Resets env
- Returns
Environment state
- Return type
numpy.array
- get_state(self)
- step(self, action)
Execute environment step
- Parameters
action (Box) – action to execute
- Returns
state, reward, done, info
np.array, float, bool, dict
- close(self) bool
Close Env
No additional cleanup necessary
- Returns
Closing confirmation
- Return type
bool
- class dacbench.envs.theory.RLSEnvDiscrete(config, test_env=False)
Bases:
dacbench.envs.theory.RLSEnvRLS environment where the choices of r is discretised
- step(self, action)
Execute environment step
- Parameters
action (Box) – action to execute
- Returns
state, reward, done, info
np.array, float, bool, dict