Package mystic :: Module tools

Module tools

source code

Various python tools

Main functions exported are:

   - flatten: flatten a sequence
   - flatten_array: flatten an array 
   - Null: a Null object pattern
   - getch: provides "press any key to quit"
   - Sow: A class whose instances are callable (to be used as monitors)
   - VerboseSow: A verbose version of the basic Sow
   - LoggingSow: A version of the basic Sow that logs to a file
   - CustomSow: A customizable 'n-variable' version of the basic Sow
   - random_seed: sets the seed for calls to 'random()'
   - wrap_function: bind an EvaluationMonitor and an evaluation counter
       to a function object
   - wrap_bounds: impose bounds on a funciton object
   - unpair: convert a 1D array of N pairs to two 1D arrays of N values

Other tools of interest are in:

   `mystic.mystic.filters` and `mystic.models.poly`
Classes
  Null
A Null object
  Sow
Instances of objects that can be passed as monitors.
  VerboseSow
A verbose version of the basic Sow.
  LoggingSow
A version of the basic Sow that writes to a file at specified intervals.
Functions
 
list_or_tuple(x)
True if x is a list or a tuple
source code
 
list_or_tuple_or_ndarray(x)
True if x is a list, tuple, or a ndarray
source code
 
flatten_array(sequence, maxlev=999, lev=0)
flatten a sequence; returns a ndarray
source code
 
flatten(sequence, maxlev=999, to_expand=list_or_tuple, lev=0)
flatten a sequence; returns original sequence type
source code
 
getch(str="Press any key to continue")
configurable pause of execution
source code
 
CustomSow(*args, **kwds)
generate a custom Sow
source code
 
random_seed(s)
sets the seed for calls to 'random()'
source code
 
wrap_function(function, args, EvaluationMonitor)
bind an EvaluationMonitor and an evaluation counter to a function object
source code
 
wrap_bounds(function, min=None, max=None)
impose bounds on a funciton object
source code
 
wrap_cf(CF, REG=None, cfmult=1.0, regmult=0.0)
wrap a cost function...
source code
 
unpair(pairs)
convert a 1D array of N pairs to two 1D arrays of N values
source code
Function Details

flatten(sequence, maxlev=999, to_expand=list_or_tuple, lev=0)

source code 

flatten a sequence; returns original sequence type

example usage...

>>> A = [1,2,3,[4,5,6],7,[8,[9]]]
>>> 
>>> # Flatten.
>>> flatten(A)
[1, 2, 3, 4, 5, 6, 7, 8, 9]
>>> 
>>> # Flatten only one level deep.
>>> flatten(A,1)
[1, 2, 3, 4, 5, 6, 7, 8, [9]]
>>> 
>>> # Flatten twice. 
>>> flatten(A,2)
[1, 2, 3, 4, 5, 6, 7, 8, 9]
>>> 
>>> # Flatten zero levels deep (i.e. don't flatten).
>>> flatten(A,0)
[1, 2, 3, [4, 5, 6], 7, [8, [9]]]

CustomSow(*args, **kwds)

source code 

generate a custom Sow

takes *args & **kwds, where args will be required inputs for the Sow:

   - args: property name strings (i.e. 'x')
   - kwds: must be in the form: property="doc" (i.e. x='Params')

example usage...

>>> sow = CustomSow('x','y',x="Params",y="Costs",e="Error",d="Deriv")
>>> sow(1,1)
>>> sow(2,4,e=0)
>>> sow.x
[1,2]
>>> sow.y
[1,4]
>>> sow.e
[0]
>>> sow.d
[]

unpair(pairs)

source code 

convert a 1D array of N pairs to two 1D arrays of N values

example usage...

>>> unpair([(a0,b0),(a1,b1),(a2,b2)])
[a0,a1,a2],[b0,b1,b2]