glyph package¶
Subpackages¶
Submodules¶
glyph.application module¶
Convenience classes and functions that allow you to quickly build gp apps.
-
class
AlgorithmFactory
[source]¶ Bases:
glyph.application.AFactory
Factory class for gp algorithms.
-
class
Application
(config, gp_runner, checkpoint_file=None, callbacks=(<function make_checkpoint>, <function log>))[source]¶ Bases:
object
An application based on
GPRunner
.Controls execution of the runner and adds checkpointing and logging functionality; also defines a set of available command line options and their default values.
To create a full console application one can use the factory function default_console_app().
Parameters: - config (dict or argparse.Namespace) – Container holding all configs
- gp_runner – Instance of
GPRunner
- checkpoint_file – Path to checkpoint_file
- callbacks –
-
assessment_runner
¶
-
logbook
¶
-
run
(break_condition=None)[source]¶ Run gp app.
Parameters: break_condition (callable(application)) – is called after every evolutionary step. Returns: number of iterations executed during run.
-
workdir
¶
-
class
ConstraintsFactory
[source]¶ Bases:
glyph.application.AFactory
-
class
CreateFactory
[source]¶ Bases:
glyph.application.AFactory
Factory class for creation
-
class
GPRunner
(IndividualClass, algorithm_factory, assessment_runner, callbacks=(<function update_pareto_front>, <function update_logbook_record>))[source]¶ Bases:
object
Runner for gp problem sets.
Takes care of propper initialization, execution, and accounting of a gp run (i.e. population creation, random state, generation count, hall of fame, and logbook). The method init() has to be called once before stepping through the evolution process with method step(); init() and step() invoke the assessment runner.
Parameters: - IndividualClass – Class inherited from gp.AExpressionTree.
- algorithm_factory – callable() -> gp algorithm, as defined in gp.algorithms.
- assessment_runner – callable(population) -> None, updates fitness values of each invalid individual in population.
-
class
MateFactory
[source]¶ Bases:
glyph.application.AFactory
Factory class for gp mating functions.
-
class
MutateFactory
[source]¶ Bases:
glyph.application.AFactory
Factory class for gp mutation functions.
-
class
ParallelizationFactory
[source]¶ Bases:
glyph.application.AFactory
Factory class for parallel execution schemes.
-
class
SelectFactory
[source]¶ Bases:
glyph.application.AFactory
Factory class for selection
-
default_console_app
(IndividualClass, AssessmentRunnerClass, parser=ArgumentParser(prog='sphinx-build', usage=None, description=None, formatter_class=<class 'argparse.HelpFormatter'>, conflict_handler='error', add_help=True), callbacks=(<function make_checkpoint>, <function log>))[source]¶ Factory function for a console application.
-
default_gprunner
(Individual, assessment_runner, callbacks=(<function update_pareto_front>, <function update_logbook_record>), **kwargs)[source]¶ Create a default GPRunner instance.
For config options see
MateFactory
,MutateFactory
,AlgorithmFactory
.
glyph.assessment module¶
Some usefull classes/functions for the fitness assessment part in gp problems.
-
class
AAssessmentRunner
(parallel_factory=<glyph.assessment.SingleProcessFactory object>)[source]¶ Bases:
object
Abstract runner for the (parallel) assessment of individuals in a population.
Child classes have to at least override the measure() method, which might be executed in a different process or even on a remote machine depending on the parallelization scheme. Child classes may override the setup() method, which is executed once on object instantiation. Child classes may override the assign_fitness() method, which is executed in the main process. This can be usefull if you want to locally post-process the results of measure(), when collected from remote processes.
Parameters: parallel_factory – callable() -> obj, obj has to implement some kind of (parallel) map() method. -
__call__
(population)[source]¶ Update the fitness of each individual in population that has an invalid fitness.
Parameters: population – a squence of individuals.
-
__getstate__
()[source]¶ Modify pickling behavior for the class.
All the attributes except ‘parallel’ can be pickled.
-
-
const_opt
(measure, individual, lsq=False, default_constants=<function default_constants>, f_kwargs=None, **kwargs)[source]¶ Apply constant optimization
Parameters: - measure – callable(individual, *f_args) -> scalar.
- individual – an individual tha is passed on to measure.
- bounds – bounds for the constant values (s.
scipy.optimize.minimize
). - method – Type of solver. Should either be ‘leastsq’, or one of scipy.optimize.minimize’s solvers.
Returns: (popt, measure_opt), popt: the optimal values for the constants; measure_opt: the measure evaluated at popt.
-
const_opt_leastsq
(measure, individual, default_constants=<function default_constants>, f_kwargs=None, **kwargs)[source]¶
-
default_constants
(ind)[source]¶ Return a one for each different constant in the primitive set.
Parameters: ind ( glyph.gp.individual.AExpressionTree
) –Returns: A value for each constant in the primitive set.
-
max_fitness_on_timeout
(max_fitness, timeout)[source]¶ Decorate a function. Associate max_fitness with long running individuals.
Parameters: - max_fitness – fitness of aborted individual calls.
- timeout – time until timeout
Returns: fitness or max_fitness
-
measure
(*funcs, pre=<function identity>, post=<function identity>)[source]¶ Combine several measurement functions into one.
Optionaly do pre- and/or post-processing.
Parameters: - funcs – a sequence of measure functions as returned by measure() (eg.
callable(*a, **kw) -> tuple
), and/or single valued functions (eg.callable(*a, **kw)
-> numerical value). - pre – some pre-processing function that is to be apllied on input once before passing the result to each function in funcs.
- post – some post-processing function that is to be apllied on the tuple of measure values as returned by the combined funcs.
Returns: callable(input) -> tuple of measure values, where input is usually a phenotype (eg. an expression tree).
- funcs – a sequence of measure functions as returned by measure() (eg.
glyph.observer module¶
-
class
ProgressObserver
[source]¶ Bases:
object
Animates the progress of the evolutionary optimization.
Note
Uses matplotlib’s interactive mode.
-
__call__
(app)[source]¶ Note
To be used as a callback in
glyph.application.Application
.Parameters: app (glyph.application.Application) –
-