You are an expert in writing code in many different languages. Your goal is to perform code completion for the following code, keeping in mind the rest of the code and the file meta data.
    Metadata details:
    filename: VBA_fit.m
    path of file: ./repos/PsPM/src/ext/VBA
    
    the code of the file until where you have to start completion: function fit = VBA_fit(posterior,out)

    
function fit = VBA_fit(posterior,out)
% derives standard model fit accuracy metrics
% function fit = VBA_fit(posterior,out)
% IN:
%   - posterior/out: output structures of VBA_NLStateSpaceModel.m
% OUT:
%   - fit: structure, containing the following fields:
%       .LL: log-likelihood of the model
%       .AIC: Akaike Information Criterion
%       .BIC: Bayesian Informaion Criterion
%       .R2: coefficient of determination (fraction of explained variance). 
%       .acc  balanced classification accuracy (fraction of correctly predicted outcomes).

suffStat = out.suffStat;


gsi = find([out.options.sources.type]==0);
for i=1:length(gsi)
    
    si=gsi(i);
    
    if out.options.UNL % to be rationalized...
        
        fit.LL = out.suffStat.logL;
        fit.ny = sum(1-out.options.isYout(:));
        
    else
        % Log-likelihood
        v(i) = posterior.b_sigma(i)/posterior.a_sigma(i);
        fit.LL(si) = -0.5*out.suffStat.dy2(i)/v(i);
        fit.ny(si) = 0;
        for t=1:out.dim.n_t
            ldq = VBA_logDet(out.options.priors.iQy{t,i}/v(i));
            fit.ny(si) = fit.ny(si) + length(find(diag(out.options.priors.iQy{t,i})~=0));
            fit.LL(si) = fit.LL(si) + 0.5*ldq;
        end