Esempio n. 1
0
def ConvCnstrMODMaskDcplOptions(opt=None, method='cns'):
    """A wrapper function that dynamically defines a class derived from
    the Options class associated with one of the implementations of
    the Convolutional Constrained MOD with Mask Decoupling  problem,
    and returns an object instantiated with the provided parameters.
    The wrapper is designed to allow the appropriate object to be
    created by calling this function using the same syntax as would be
    used if it were a class. The specific implementation is selected
    by use of an additional keyword argument 'method'. Valid values are
    as specified in the documentation for :func:`ConvCnstrMODMaskDcpl`.
    """

    # Assign base class depending on method selection argument
    if method == 'ism':
        base = ConvCnstrMODMaskDcpl_IterSM.Options
    elif method == 'cg':
        base = ConvCnstrMODMaskDcpl_CG.Options
    elif method == 'cns':
        base = ConvCnstrMODMaskDcpl_Consensus.Options
    else:
        raise ValueError('Unknown ConvCnstrMODMaskDcpl solver method %s' %
                         method)

    # Nested class with dynamically determined inheritance
    class ConvCnstrMODMaskDcplOptions(base):
        def __init__(self, opt):
            super(ConvCnstrMODMaskDcplOptions, self).__init__(opt)

    # Allow pickling of objects of type ConvCnstrMODMaskDcplOptions
    _fix_dynamic_class_lookup(ConvCnstrMODMaskDcplOptions, method)

    # Return object of the nested class type
    return ConvCnstrMODMaskDcplOptions(opt)
Esempio n. 2
0
def ConvCnstrMODMaskDcpl(*args, **kwargs):
    """A wrapper function that dynamically defines a class derived from
    one of the implementations of the Convolutional Constrained MOD
    with Mask Decoupling problems, and returns an object instantiated
    with the provided. parameters. The wrapper is designed to allow the
    appropriate object to be created by calling this function using the
    same syntax as would be used if it were a class. The specific
    implementation is selected by use of an additional keyword
    argument 'method'. Valid values are:

    - ``'ism'`` :
      Use the implementation defined in :class:`.ConvCnstrMODMaskDcpl_IterSM`.
      This method works well for a small number of training images, but is
      very slow for larger training sets.
    - ``'cg'`` :
      Use the implementation defined in :class:`.ConvCnstrMODMaskDcpl_CG`.
      This method is slower than ``'ism'`` for small training sets, but has
      better run time scaling as the training set grows.
    - ``'cns'`` :
      Use the implementation defined in
      :class:`.ConvCnstrMODMaskDcpl_Consensus`. This method is the best choice
      for large training sets.

    The default value is ``'cns'``.
    """

    # Extract method selection argument or set default
    if 'method' in kwargs:
        method = kwargs['method']
        del kwargs['method']
    else:
        method = 'cns'

    # Assign base class depending on method selection argument
    if method == 'ism':
        base = ConvCnstrMODMaskDcpl_IterSM
    elif method == 'cg':
        base = ConvCnstrMODMaskDcpl_CG
    elif method == 'cns':
        base = ConvCnstrMODMaskDcpl_Consensus
    else:
        raise ValueError('Unknown ConvCnstrMODMaskDcpl solver method %s' %
                         method)

    # Nested class with dynamically determined inheritance
    class ConvCnstrMODMaskDcpl(base):
        def __init__(self, *args, **kwargs):
            super(ConvCnstrMODMaskDcpl, self).__init__(*args, **kwargs)

    # Allow pickling of objects of type ConvCnstrMODMaskDcpl
    _fix_dynamic_class_lookup(ConvCnstrMODMaskDcpl, method)

    # Return object of the nested class type
    return ConvCnstrMODMaskDcpl(*args, **kwargs)