Пример #1
0
def LNKS_fobj(theta, stim, y, options):
    '''
    LNKS Objective function
    -----------------------
    This is an objective function for the LNK, LNKS, and LNKS_MP models.
    Calls LNKS_fobj_helper function, and numel_gradient function(objectivetools),
    if is_grad option is True. The numel_gradient function uses multiprocessing
    , a built-in python module, to make the gradient computing process parallel.

    Returns objective value(J) and gradient(grad).
    If is_grad option is False, only returns objective value.

    Inputs
    ------
        theta: model parameters
        stim: input data
        y: output data (fr)
        options (dictionary):
            model (string): models are ('LNK', 'LNKS', 'LNKS_MP')
            pathway (int): LNK pathway (1 or 2)
            is_grad (bool): bool (gradient on(True) or off(False))

    Outputs
    -------
        J: objective value
        grad: gradient of objective
    '''

    basis = LinearFilterBasis_8param()
    nzstim = stim - _np.mean(stim) # nzstim: mean subtracted stimulus
    options['basis'] = basis

    J0 = LNKS_fobj_helper(LNKS, theta, nzstim, y, options) # evaluate function value at original point

    if options['is_grad']:
        grad = _obj.numel_gradient(LNKS_fobj_helper, LNKS, theta, nzstim, y, J0, options)
        return J0, grad

    else:
        return J0