Bottom-Up algorithm - pcaseg.m

[segment,tc] = pcaseg(data,num_segments,q,flag)

 data Matrix Sample matrix 
 (samples in the rows, variables in the columns)
 num_segments Scalar integer Desired number of segments
 q Scalar integer Number of principal components
 flag Scalar integer 0: Hotelling T2
 1: Q model error
 segment Structure Result of the segmentation
 tc Column vector Total cost of the segments in every iteration

This function execute the Bottom-Up segmentation of the data until only num_segments segments remain.

The result of the segmentation can be found in the structure segment. It contains the following:
segment.lx : the left bound of the segments;
segment.rx : the right bound of the segments; : merging cost of the segments with their right neighbors;
segment.c : cost of the segments;
segment.pc : principal components of the PCA model of the segments;
segment.avg : mean of the data in the particular segments;
segment.latent : eigenvalues of the covariance matrices.

This function uses the pcaresid.m and princomp.m functions.


flag=[0 1];    % 0:T2, 1:Q  for Bottom-Up algorithm
for i=1:length(flag)
    segment=[]; tc=[]; index=[];
    [segment,tc] = pcaseg(x,inicBU,q,flag(i));