BayesicFitting

Model Fitting and Evidence Calculation

View project on GitHub



Module Tools Source

  module contains a mixed bag of "usefull" methods.

getItem( k )

Return the k-th item of the ilist
     or the last when not enough
     or the ilist itself when it is not a list

Parameters

  • ilist : an item or a list of items
         List to obtain an item from
  • k : int
         item to be returned

firstIndex( condition=lambda x: True )
Returns the index of first item in the `iterable` that satisfies the `condition`.

If the condition is not given, it returns 0

Parameters

  • iterable : iterable
         to find the first item in
  • condition : lambda function
         the condition

Raises

  StopIteration: if no item satysfing the condition is found.

Examples

firstIndex( (1,2,3), condition=lambda x: x % 2 == 0)
2
firstIndex( range( 3, 100 ) )
3
firstIndex( () )
Traceback (most recent call last)
...
StopIteration

getColumnData( kcol )
Return the kcol-th column from xdata

Parameters

xdata 2D array_like or Table
     the data array kcol int
     column index

isBetween( x, xe )
Return True when x falls between xs and xe or on xs or xe.
     where the order of xs, xe is unknown.

getKwargs( )
Return kwargs as dictionary

setAttribute( name, value, type=None, islist=False, isnone=False )
Set an attribute to an object.

Parameters

  • obj : object
         to set the attribute to
  • name : str
         of the attribute
  • value : any
         of the attribute
  • type : class
         check class of the object
  • islist : boolean
         check if it is a list of type
  • isnone : boolean
         value could be a None

Raises

TypeError : if any checks fails

setNoneAttributes( name, value, listNone )
Set attribute contained in dictionary dictList into the attr-list. A list is a native list or a numpy.ndarray. It also checks the type. if values is a singular item of the proper type it will be inserted as [value].

Parameters

  • obj : object
         to place the attribute in
  • name : str
         of the attribute
  • value : any
         of the attribute
  • listNone : list of names
         that could have a None value

Returns

  True on succesful insertion. False otherwise.

Raises

  TypeError if the type is not as in the dictionary

setListOfAttributes( name, value, dictList )

  """ Set attribute contained in dictionary dictList into the attr-list. A list is a native list or a numpy.ndarray. It also checks the type. if values is a singular item of the proper type it will be inserted as [value].

Parameters

  • obj : object
         to place the attribute in
  • name : str
         of the attribute
  • value : any
         of the attribute
  • dictList : dictionary
         of possible attributes {"name": type}

Returns

  True on succesful insertion. False otherwise.

Raises

  TypeError if the type is not as in the dictionary

setSingleAttributes( name, value, dictSingle )
Set a singular attribute contained in dictionary dictSingle into the attr-list. It also checks the type.

Parameters

  • obj : object
         to place the attribute in
  • name : str
         of the attribute
  • value : any
         of the attribute
  • dictSingle : dictionary
         of possible attributes {"name": type}

Returns

  True on succesful insertion. False otherwise.

Raises

  TypeError if the type is not as in the dictionary

makeNext( k )

  """ Return next item of x, and last item if x is exhausted. Or x itself if x is singular.

length( )
Return the length of any item. Singletons have length 1; None has length 0..

toArray( ndim=1, dtype=None )
Return a array of x when x is a number

Parameters

  • x : any number, list/array of numbers or []
         to be converted to numpy.ndarray
  • ndim : int
         minimum number of dimensions present
  • dtype : type
         conversion to type (None : as is)

isList( cls )
Return (True,False) if item is a instance of cls
        (True,True) if item is a (list|ndarray) of instances of cls
        (False,False) if not

isInstance( cls )
Returns true when one of the following is true 1. when cls is int : item is an int or item is a numpy.integer. 2. when cls is float : item is an float or item is an int. 3. when cls is cls : item is a cls.

ndprint( form='{0:.3f}' )
Print a ndarray, formatted.

decorate( des, copy=True )
Transfer attributes from src to des. If copy is True try to copy the attributes, otherwise link it.

Parameters

  • src : object
         source of the attributes
  • des : object
         destiny for the attributes
  • copy : bool
         if True: copy

subclassof( cls )
Determine if sub inherits from the class cls

Parameters

  • sub : class object
         supposed sub class
  • cls : class object
         supposed parent class

printclass( nitems=8, printId=False )
Print the attributes of a class.

printlist( nitems=8 )

shortName( )
Return a short version the string representation: upto first non-letter.

nicenumber( )
Return a nice number close to (but below) |x|.

fix2int( )
Return integer array with values as in x

Parameters

  • x : array_like
         array of integer floats

track( )

Parameters

  • statement : str
         statement to be traced

average( weights=None, circular=None )
Return (weighted) average and standard deviation of input array.

Parameters

  • xx : array_like
         input to be averaged
  • weights : array_like
         if present these are the weights
  • circular : list of 2 floats
         the input is a circular item between [low,high]