image thumbnail

Ancestral polytree

by

 

01 Feb 2013 (Updated )

The code here provides the algorithm of learning ancestral polytree.

DimensionRangeValue( OriginalData,Vec )
function [ Dim,DimLength ] = DimensionRangeValue( OriginalData,Vec ) 
%  Input: OrigninalData
%  Output: the matric stored the value range of each dimension F and C
%  For example: OriginalData = [0 1 2 3;3 4 2 1;6 7 8 4];
%               Dim = [3 0 3 6;3 1 4 7;2 2 8;3 3 1 4];
% The first element of each row represents the number of how many different
% value of each column

if isempty( OriginalData ) == 1 || isempty( Vec ) == 1
   Dim = [];  DimLength = [];
   return
end

CountNumber = 0;
D = length( Vec ); DimLength = zeros( 1,D );
% CountNumber stores the maximun value of the column of the Dim matric, keep in mind that it may increase
t = 0;
 for q = 1 : D
     TempVector = unique( OriginalData(:,Vec(q))' );    
     if TempVector(1) == -1 ,TempVector(1)=[]; end
     RangeNumber = size(TempVector,2);
     DimLength( q ) = RangeNumber;
     t = t + 1;
     if CountNumber == 0
         CountNumber = RangeNumber;
         Dim = zeros( D ,CountNumber );
         Dim(t,:) = TempVector ;
       elseif CountNumber >= RangeNumber
         Dim(t,:) = [TempVector, zeros(1,CountNumber - RangeNumber)];
       elseif CountNumber < RangeNumber
         Dim = [Dim, zeros( D,RangeNumber - CountNumber )];  %#ok<AGROW>
         CountNumber = RangeNumber;
         Dim(t,:) = TempVector;
     end    
 end
 
end

Contact us