# restreigen

restreigen computes eigenvalues restriction (without Dykstra algorithm)

## Syntax

• out=restreigen(eigenvalues, niini, restr)example
• out=restreigen(eigenvalues, niini, restr, tol)example
• out=restreigen(eigenvalues, niini, restr, tol, userepmat)example

## Description

restreigen restricts the eigenvalues according to the constraint specified in scalar restr. This function is called in every concentration step of function tclust and can also be used inside function MixSim to generate groups with a prespecified level of overlapping

 out =restreigen(eigenvalues, niini, restr) Example using all default options.

 out =restreigen(eigenvalues, niini, restr, tol) Second example of eigenvalue restriction.

 out =restreigen(eigenvalues, niini, restr, tol, userepmat) Compare speed.

## Examples

expand all

### Example using all default options.

Suppose v=3 and k=4 so the matrix containing the eigenvalues is 3-by-4 First column of matrix eigenvalues contains the eigenvalues of the first group Second column of matrix eigenvalues contains the eigenvalues of the second group Thrid column of matrix eigenvalues contains the eigenvalues of the third group Fourth column of matrix eigenvalues contains the eigenvalues of the fourth group

rng(10,'twister')
eigenvalues=abs(10*randn(3,4));
% niini is the vector containing the sizes of the 4 groups
niini=[30;40;20;10];
out=restreigen(eigenvalues,niini,1.1)
disp('Input matrix of unrestricted eigenvalues')
disp(eigenvalues)
disp('Output matrix of restricted eigenvalues')
disp(out)
disp('Ratio between largest and smallest unrestricted eigenvalues')
disp(max(max(eigenvalues))/min(min(eigenvalues)))
disp('Ratio between largest and smallest restricted eigenvalues')
disp(max(max(out))/min(min(out)))

### Second example of eigenvalue restriction.

eigenvalues=abs(randn(3,4));
eigenvalues(:,3)=0;
niini=[30;40;20;10];
restreigen(eigenvalues,niini,1.1)
eigenvalues(:,3)=1;
restreigen(eigenvalues,niini,1.1)

### Compare speed.

We compare the speed of restreigneasy with that of restreigen. We use userepmat=2 if the current MATLAB version if >=R2017a or userepmat =1 if MATLAB version is >=R2013a but <R2017a else we use userepmat =0

v=10;
k=8;
tol=1e-8;
if verLessThanFS(9.2)== false
% If MATLAB version is at least 2017a
userepmat=2;
elseif verLessThanFS(8.1) == false
% if MATLAB version is at least R2013b
userepmat=1;
else
userepmat=0;
end
oldroutinetime=0;
newroutinetime=0;
rng(1)
for j=1:10000
eigenvalues=100*abs(randn(v,k));
% niini is the vector containing the sizes of the 4 groups
niini=randi(100,[k,1]);
tic;
outold=restreigeneasy(eigenvalues,niini,1.1);
% Uncomment the line below if you want
% outold=restreigen(eigenvalues,niini,1.1,tol,1);
oldroutinetime=oldroutinetime+toc;
tic;
outnew=restreigen(eigenvalues,niini,1.1,tol,userepmat);
newroutinetime=newroutinetime+toc;
if max(max(abs(outold-outnew)))>1e-5
error('The two routines are different')
end
end
disp(['Computing time of restreigeneasy: ' num2str(oldroutinetime)])
disp(['Computing time of restreigen: ' num2str(newroutinetime)])

## Input Arguments

### eigenvalues — Eigenvalues. Matrix.

v x k matrix containing the eigenvalues of the covariance matrices of the k groups.

v is the number of variables of the dataset which has to be clustered.

Data Types: single| double

### niini — Cluster size. Vector.

k x 1 vector containing the size of the k clusters

Data Types: single| double

### restr — Restriction factor. Scalar.

Scalar containing the restr parameter in tclust program.

More in detail, parameter restr defines the cluster's shape restrictions, which are applied on all clusters during each iteration.

Setting restr to 1, yields the strongest restriction, forcing all eigenvalues/determinants to be equal and so the method looks for similarly scattered (respectively spherical) clusters.

Data Types: single| double

### tol — tolerance. Scalar defining the tolerance of the procedure.

The default value is 1e-8

Example: 'tol',[1e-18] 

Data Types: double

### userepmat — use repmat, bsxfun or implicit expansion. Scalar.

If userepmat is equal to 1, function repmat is used instead of bsxfun inside the procedure. Remark: repmat is built in from MATLAB 2013b so it is faster to use repmat if the current version of MATLAB is >2013a.

If userepmat is 2, implicit expansion is used instead of bsxfun. Note that implicit expansion has been introduced only in 2017a therefore it will not work with previous releases.

Example: 'userepmat',1 

Data Types: double

## Output Arguments

### out —Restricted eigenvalues.  Matrix

v-by-k matrix containing restricted eigenvalues.

The ratio between two possible elements in matrix out is not greater than restr

Fritz H., Garcia-Escudero, L.A. and Mayo-Iscar, A. (2013), A fast algorithm for robust constrained clustering, "Computational Satistics and Data Analysis", Vol. 61, pp. 124-136.