API reference¶
Primary entry point¶
ecabc.ABC is the supported workflow for application code. See
API stability policy for the frozen contract.
- class ecabc.ABC(num_employers, objective_fn, obj_fn_args={}, num_processes=1)[source]¶
Bases:
object- Parameters:
- add_param(min_val, max_val, restrict=True, name=None)[source]¶
ABC.add_param: adds a parameter to be processed by the user- supplied objective function
- property average_ret_val: int | float | None¶
Returns average objective_fn return value for bee population
- property best_ret_val: int | float | None¶
Returns objective_fn return value from best-performing bee
- initialize()[source]¶
ABC.initialize: creates num_employers employer bees and num_employers onlooker bees
- search()[source]¶
Perform one search cycle for all bees in the colony.
For each bee: if it has exhausted its current food source, an employer finds a new random food source and an onlooker travels near a well-performing bee; otherwise one parameter is mutated and the bee moves only if the neighbor food is better. The colony is then replaced with the updated bee states.
Exhaustion is the maximum number of search cycles a bee may stay at its current food source,
EX = NE * D, whereNEis the number of employers andDis the number of parameters.
Secondary exports¶
ecabc.Bee, ecabc.Parameter, and ecabc.utils remain part of
the frozen 3.x surface. Prefer the ABC workflow for new code; these
types are useful for tests, extensions, and advanced inspection.
- class ecabc.Bee(params, obj_fn_val, stay_limit, is_employer=False)[source]¶
Bases:
object- property abandon: bool¶
When called, increment how many times the bee has stayed at its current food source; if reached stay limit, return True else False
- static calc_fitness(obj_fn_val)[source]¶
Static method: Bee.calc_fitness: Calculates fitness score based on objective function value, using the equation:
fitness = 1 / (1 + ofv) if ofv >= 0 fitness = 1 + abs(ofv) if ofv < 0
Where ofv is the objective function value and fitness is the resulting fitness score
- class ecabc.Parameter(min_val, max_val, restrict=True, name=None)[source]¶
Bases:
object
Package version¶
- ecabc.__version__ = '3.0.2'¶
str(object=’’) -> str str(bytes_or_buffer[, encoding[, errors]]) -> str
Create a new string object from the given object. If encoding or errors is specified, then the object must expose a data buffer that will be decoded using the given encoding and error handler. Otherwise, returns the result of object.__str__() (if defined) or repr(object). encoding defaults to sys.getdefaultencoding(). errors defaults to ‘strict’.
Utilities¶
Import helpers as import ecabc.utils. Public functions:
apply_mutationcall_obj_fnchoose_beedetermine_best_bee
- ecabc.utils.apply_mutation(curr_params, all_params)[source]¶
apply_mutation: alters the value of one parameter in supplied list of values
- ecabc.utils.call_obj_fn(params, obj_fn, obj_fn_args)[source]¶
call_obj_fn: calls supplied objective function, evaluating using supplied parameters; callable in single- and multi-processed configurations
- Parameters:
- Returns:
(params, objective function return value)
- Return type:
- ecabc.utils.choose_bee(bees)[source]¶
choose_bee: choose a bee based on probabilities a given bee will be chosen; probabilities based on fitness score (higher fitness score == higher probability of being chosen)
- ecabc.utils.determine_best_bee(bees)[source]¶
determine_best_bee: return highest fitness score w/ corresponding objective function return value and parameters given a list of bees
- ecabc.utils.random() x in the interval [0, 1).¶