function[loss,learning]= GeneralizationFit(x0,T,g,tt,data)
    noise =0;   
    [~,learning,~,~,~]= GeneralizationModel(T,x0,g,tt,noise);
    %changed to nansum for pp 9 one nan trial: pp moved backwards in a
    %changed to nansum for excluding angle +- 60 degrees
    l = nansum((data(logical(sum((T.trialtype == tt.fit),2)))'-learning.total(logical(sum((T.trialtype == tt.fit),2)))).^2);
    loss = l;
end
    