function [fit, vaf, coord, addcon] = linfitac_altcomp(prox,inperm)

%  LINFITAC_ALTCOMP does a confirmatory fitting of a given unidimensional order
%  using the Dykstra--Kaczmarz iterative projection 
%  least-squares method, but differing from linfit.m in 
%  including the estimation of an additive constant.
%
%  syntax: [fit, vaf, coord, addcon] = linfitac_altcomp(prox,inperm)
%
%  INPERM is the given order;
%  FIT is an $n \times n$ matrix that is fitted to 
%  PROX(INPERM,INPERM) with variance-accounted-for VAF;
%  COORD gives the ordered coordinates whose absolute differences
%  could be used to reconstruct FIT; ADDCON is the estimated
%  additive constant that can be interpreted as being added to PROX. Note
%  that in comparison with linfitac.m, ADDCON here has the opposite sign.

n = size(prox,1);


[member] = linear_order_member(inperm);

[fit,vaf,weights,addcon,end_condition] = partitionfit_addcon(prox,member);

addcon = -addcon;

for i = 1:n
    for j = 1:n
        if(i ~= j)
            fit(i,j) = fit(i,j) + addcon;
        end
    end
end


coord = zeros(n,1);

for i = 1:(n-1)
    
    coord(i+1) = coord(i) + weights(i);
end

meancoord = sum(coord)/n;

for i = 1:n
    
    coord(i) = coord(i) - meancoord;
    
end
