Home > NoiseTools > nt_cluster1D.m

# nt_cluster1D

## PURPOSE

[C,A,score]=nt_cluster1D_b(x) - cluster 1D data into 2 clusters

## SYNOPSIS

function [C,A,score]=nt_cluster1D(x);

## DESCRIPTION

    [C,A,score]=nt_cluster1D_b(x) - cluster 1D data into 2 clusters

      x: column vector or matrix of data to cluster

      C: centroid pairs (one pair per column)
      A: ownership matrix (0, 1)
      score: energy/total energy, for each column

## CROSS-REFERENCE INFORMATION

This function calls:

- nt_split [idx,score_vector,score]=nt_split(x,depth,thresh,guard,minstep) - split time series into intervals

This function is called by:

- nt_cluster_jd [IDX,todss,SCORE,COVS]=nt_cluster_jd(x,dsr,smooth,flags,init,verbose) - cluster with joint diagonalization

## SOURCE CODE

    0001 function [C,A,score]=nt_cluster1D(x);
    0002 %[C,A,score]=nt_cluster1D_b(x) - cluster 1D data into 2 clusters
    0003 %
    0004 %  x: column vector or matrix of data to cluster
    0005 %
    0006 %  C: centroid pairs (one pair per column)
    0007 %  A: ownership matrix (0, 1)
    0008 %  score: energy/total energy, for each column
    0009
    0010 if nargin<1; error('!'); end
    0011 if size(x,1)<2; error('too small to cluster'); end
    0012
    0013 A=zeros(size(x));       % cluster ownership labels
    0014 C=zeros(2,size(x,2));   % centroids
    0015
    0016 for iCol=1:size(x,2)
    0017
    0018     xx=x(:,iCol);
    0019     [xx,iSort]=sort(xx);
    0020     [idx,score_vector,score0]=nt_split(xx);
    0021     score(:,iCol)=score0;
    0022     C(:,iCol)=[mean(xx(1:idx)),mean(xx(idx+1:end))];
    0023     t=1:size(xx,1);
    0024     A(t(iSort(idx+1:end)), iCol)=1; % 0: low values, 1: high values
    0025
    0026 %     figure(1); clf; subplot 211;
    0027 %     hold on; histogram(xx,-5:0.01:5, 'displaystyle','stairs' ); histogram(xx(1:idx),-5:0.01:5); plot(C(:,iCol),[500 500], '.r');
    0028 %     subplot 212; plot(x(:,iCol))
    0029 %     disp(score0)
    0030 %     pause
    0031 end
    0032
    0033