image thumbnail
from Fit GLM with quadratic penalty by Patrick Mineault
Fits GLM with a quadratic penalty, determines hyperparams through cross-validation or evidence

evalMaxGlmLikelihood(y,family,familyextra,weights)
function [ll] = evalMaxGlmLikelihood(y,family,familyextra,weights)
    %Evaluate the negative of the maximum attainable likelihood for a given observation
    if nargin < 4
        weights = 1;
    end
    
    switch family
        case 'normid'
            ll = 0;
        case 'binomlogit'
            y = y/familyextra;
            ll = -familyextra*((weights.*y)'*log(y+eps) + (weights.*(1-y))'*log(1-y+eps));
        case 'poissexp'
            ll = -(weights.*y)'*log(y+eps) + sum(weights.*y);
    end
end

Contact us at files@mathworks.com