Package qubx :: Module modeling_utils :: Class Optimizer
[hide private]
[frames] | no frames]

Class Optimizer

source code

     object --+    
              |    
util_types.Anon --+
                  |
                 Optimizer

Presents a consistent interface on one model/data-based optimization routine, e.g. MIL, MSL, MacRates. Created by QubX.Modeling.Utils.add_optimizer, listed in QubX.Modeling.Utils.optimizers, assignable as QubX.Modeling.Utils.optimizer. Used by sub-panels of QubX.Modeling.Utils.

Instance Methods [hide private]
 
__init__(self, name, get_model_prep, get_data_prep, get_ll, optimize, OnLL, OnIteration, OnOptimized)
@param name: string to identify the algorithm @param get_model_prep: func(model=None, modeltree=None) -> model_prep model: qubx.model.QubModel modeltree: qubx.tree.Node containing QMF (only if no model provided) model_prep: object derived from model, ready for computation, with fields: .source: the input QubModel, if provided .model: a private QubModel copy .modeltree: QMF tree, even if not provided since rates change so much more often, my algorithms re-use the rest of the prep when possible, by defining these fields: .K0, .K1, .K2: numpy.matrix of rate constants .set_rates(K0, K1): updates .K0, .K1, and .model .set_rates2(K0, K1, K2): preferred newer form for pressure sensitivity @param get_data_prep: func(segs, model_prep, wait=True, receiver=lambda dp: None) -> data_prep segs: list of qubx.data_types.SourceSeg model_prep: result of get_model_prep, since signal layout may depend on model stimuli wait: False to return immediately receiver: if wait, this function is called with data_prep when it's ready (on gobject thread) data_prep: object with prepared data, ready for computation, with fields: .segs: input the list of SourceSeg .model_prep: input prepared model and whatever else the algorithm needs, e.g.
source code
 
__onLL(self, LL) source code
 
__onIteration(self, iterations, LL, grads) source code
 
__onOptimized(self, iterations, LL, grads, hessian) source code

Inherited from util_types.Anon: __getattr__, __repr__, __str__, clone

Inherited from util_types.Anon (private): _find_arg_dicts, _str_indent

Inherited from object: __delattr__, __format__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __setattr__, __sizeof__, __subclasshook__

Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

__init__(self, name, get_model_prep, get_data_prep, get_ll, optimize, OnLL, OnIteration, OnOptimized)
(Constructor)

source code 


@param name: string to identify the algorithm
@param get_model_prep: func(model=None, modeltree=None) -> model_prep
    model: qubx.model.QubModel
    modeltree: qubx.tree.Node containing QMF (only if no model provided)
    model_prep: object derived from model, ready for computation, with fields:
        .source: the input QubModel, if provided
        .model: a private QubModel copy
        .modeltree: QMF tree, even if not provided
    since rates change so much more often, my algorithms re-use the rest of the prep when possible, by defining these fields:
        .K0, .K1, .K2: numpy.matrix of rate constants
        .set_rates(K0, K1): updates .K0, .K1, and .model
        .set_rates2(K0, K1, K2): preferred newer form for pressure sensitivity
@param get_data_prep: func(segs, model_prep, wait=True, receiver=lambda dp: None) -> data_prep
    segs: list of qubx.data_types.SourceSeg
    model_prep: result of get_model_prep, since signal layout may depend on model stimuli
    wait: False to return immediately
    receiver: if wait, this function is called with data_prep when it's ready (on gobject thread)
    data_prep: object with prepared data, ready for computation, with fields:
        .segs: input the list of SourceSeg
        .model_prep: input prepared model
        and whatever else the algorithm needs, e.g. sampled or idealized data
@param get_ll: func(model_prep=None, data_prep=None, wait=True, receiver=lambda LL: None, on_trial, **kw) -> LL
    evaluates the score for given model and data; fills them in from onscreen sources if not provided.
    wait: False to return immediately
    receiver: if wait == False: func(LL) called when computation is done
    on_trial: func(model_tree, row_dict) with completed trial info
    **kw: other keywords to apply to properties before running; e.g. use_Peq=True
@param optimize: func(model_prep=None, data_prep=None, wait=True, receiver=lambda LL: None, ext_return=False, on_trial, **kw) -> LL
    iterates, adjusting parameters to improve LL for given model and data; fills them in from onscreen sources if not provided.
    wait: False to return immediately
    receiver: if wait == False: func(result--see ext_return) called when computation is done
    ext_return: True to return the tuple (LL, iterations, grads, hessian); False to return LL
    on_trial: func(model_tree, row_dict) with completed trial info
    **kw: other keywords to apply to properties before running; e.g. use_Peq=True
@param OnLL: L{WeakEvent}(LL) when get_ll completes
@param OnIteration: L{WeakEvent}(iterations, LL, grads) each iteration during opt
@param OnOptimized: L{WeakEvent}(iterations, LL, grads, hessian) when optimize completes

Overrides: object.__init__