function [find,vaf,outperm,addcon,coord] = ms_uniscalac(prox,inperm,kblock)
% UNISCALAC finds and fits a linear unidimensional scale using iterative
% projection to a symmetric proximity matrix in the $L_{2}$-norm based on a
% permutation identified through the use of iterative quadratic assignment.
%
% syntax: [find,vaf,outperm,addcon,coord] = ...
% ms_uniscalac(prox,inperm,kblock)
%
% PROX is the input proximity matrix ($n \times n$ with a zero main
% diagonal and a dissimilarity interpretation); INPERM is a given starting
% permutation of the first $n$ integers; FIND is the least-squares optimal
% matrix (with variance-accounted-for of VAF) to PROX having a linear
% unidimensional form for the object ordering given by the ending
% permutation OUTPERM. The spacings among the objects are given by the
% entries in FIND. KBLOCK defines the block size in the use of the
% iterative quadratic assignment routine. The additive constant for the
% model is given by ADDCON, and the $n$ ordered coordinates in COORD.
n = size(prox,1);
dumone = zeros(1,1);
targlinear = targlin(n);
[outperm,rawindex,index] = ms_order(prox,targlinear,inperm,kblock);
[fit,vaf,coord,addcon] = ms_linfitac(prox,outperm,dumone);
if (any(outperm - inperm) ~= 0)
inperm = outperm;
[outperm,rawindex,index] = ms_order(prox,fit,inperm,kblock);
[fit,vaf,coord,addcon] = ms_linfitac(prox,outperm,dumone);
end
find = fit;