glyph.utils package¶
Submodules¶
glyph.utils.argparse module¶
Collection of helper functions for arparse.
glyph.utils.break_condition module¶
-
class
SoftTimeOut
(ttl)[source]¶ Bases:
object
Break condition based on a soft time out.
Start a new generation as long as there is some time left.
Parameters: ttl – time to live in seconds -
alive
¶
-
now
¶
-
-
break_condition
(target=0, error_index=0, ttl=0, max_iter=inf)[source]¶ Combined breaking condition based on time to live, minimum target and maximum number of iterations.
Parameters: - target – value of desired error metric
- error_index – index in fitness tuple
- ttl – time to live in seconds
- max_iter – maximum number of iterations
glyph.utils.logging module¶
-
load_config
(config_file, placeholders=None, level=20)[source]¶ Load logging configuration from .yaml file.
glyph.utils.numeric module¶
-
class
SlowConversionTerminator
(method, step_size=10, min_stat=10, threshold=25)[source]¶ Bases:
object
Decorate a minimize method used in
scipy.optimize.minimize
to cancel non promising constant optimizations.The stopping criteria is based on the improvement rate :math:`rac{Delta f}[Delta fev}`.
If the improvement rate is below the quantile for a given number of function evaluations, optimization is stopped. :params method: seescipy.optimize.minimize
method :params step_size: number of function evaluations betweem iterations :params min_stat: minimum sample size before stopping :params threshold: quantile
-
hill_climb
(fun, x0, args, precision=5, maxfev=100, directions=5, target=0, rng=<module 'numpy.random' from '/home/docs/checkouts/readthedocs.org/user_builds/glyph/envs/stable/lib/python3.6/site-packages/numpy/random/__init__.py'>, **kwargs)[source]¶ Stochastic hill climber for constant optimization. Try self.directions different solutions per iteration to select a new best individual.
Parameters: - fun – function to optimize
- x0 – initial guess
- args – additional arguments to pass to fun
- precision – maximum precision of x0
- maxfev – maximum number of function calls before stopping
- directions – number of directions to explore before doing a hill climb step
- target – stop if fun(x) <= target
- rng – (seeded) random number generator
Returns:
Module contents¶
-
class
Memoize
(fn)[source]¶ Bases:
object
Memoize(fn) - an instance which acts like fn but memoizes its arguments
Will only work on functions with non-mutable arguments http://code.activestate.com/recipes/52201/
-
partition
(pred, iterable)[source]¶ Use a predicate to partition entries into false entries and true entries.
>>> is_odd = lambda x: x % 2 >>> odd, even = partition(is_odd, range(10)) >>> list(odd) [0, 2, 4, 6, 8]
-
random_state
(obj, rng=<module 'random' from '/home/docs/checkouts/readthedocs.org/user_builds/glyph/envs/stable/lib/python3.6/random.py'>)[source]¶ Do work inside this contextmanager with a random state defined by obj.
Looks for _prev_state to seed the rng. On exit, it will write the current state of the rng as _tmp_state to the obj.
Params obj: Any object. Params rng: Instance of a random number generator.