Home > src > computeForce.m

computeForce

PURPOSE ^

% Visual Clustering of Parallel Coordinates

SYNOPSIS ^

function [ fM, iM ] = computeForce(M, subM, nl, q_alpha, q_d)

DESCRIPTION ^

% Visual Clustering of Parallel Coordinates
 @author Mazurek/Bartalsky
% computeForce.m parameters
 * *Description:*
 * Computed the gravitational Force of the parallel coordinates.
 * The computation of the force on a point computed, additionally
 * the direction of the force is determined.
 * *Input:*  
 * _M_ ... parallel coordinates of a dataset, rows are
 dimensions, collumns are observations
 * _subM_ ... subcoordinates of the matrix M
 * _nl_ ... number of neighboring lines considered for the computation
 * _q_alpha_ ... exponent of the angle, strengthens the influence of
 angles on the force
 * _q_d_ ... exponent of the distance, strengthens the influence of
 distance on the force
 * *Ouput:*
 * _fM_ ... direction of the subcoordinates, gravitational force
 * _iM_ ... gravitational force of the subcoordinates

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 %% Visual Clustering of Parallel Coordinates
0002 % @author Mazurek/Bartalsky
0003 %% computeForce.m parameters
0004 % * *Description:*
0005 % * Computed the gravitational Force of the parallel coordinates.
0006 % * The computation of the force on a point computed, additionally
0007 % * the direction of the force is determined.
0008 % * *Input:*
0009 % * _M_ ... parallel coordinates of a dataset, rows are
0010 % dimensions, collumns are observations
0011 % * _subM_ ... subcoordinates of the matrix M
0012 % * _nl_ ... number of neighboring lines considered for the computation
0013 % * _q_alpha_ ... exponent of the angle, strengthens the influence of
0014 % angles on the force
0015 % * _q_d_ ... exponent of the distance, strengthens the influence of
0016 % distance on the force
0017 % * *Ouput:*
0018 % * _fM_ ... direction of the subcoordinates, gravitational force
0019 % * _iM_ ... gravitational force of the subcoordinates
0020 function [ fM, iM ] = computeForce(M, subM, nl, q_alpha, q_d)
0021 
0022 
0023 subs=subM(1).subs;
0024 sub=size(subs,2);
0025 fM=zeros(size(M,1),size(M,2)+(size(M,2)-1)*sub);
0026 iM=zeros(size(M,1),size(M,2)+(size(M,2)-1)*sub);
0027 
0028 %% computation of the gravitational force between two coordinates
0029 for a=1 : size(M,2)-1
0030     M2dim=cat(2,M(:,a),subM(a).subs,M(:,a+1));
0031     [fij2dM, initf2dM]= computeForce2dim(M2dim,nl,q_alpha, q_d);
0032     fM(:,1+(a-1)*(sub+1):1+(a)*(sub+1))=fij2dM;
0033     iM(:,1+(a-1)*(sub+1):1+(a)*(sub+1))=initf2dM;
0034 end
0035 
0036 end
0037 
0038 %% computeAngle parameters
0039 % * *Description:*
0040 % * The angle between two lines is computed by the dot product of the
0041 % * lines. In the further computations the cosine of the angle is used
0042 % * because the possible results lie between 0 and 1.
0043 % * *Input:*
0044 % * _li_ ... line at the position that is computed
0045 % * _lk_ ... line of a neighbor
0046 % * *Ouput:*
0047 % * _angle_ ... angle between both lines
0048 function[ angle ]= computeAngle(li,lk)
0049 
0050 cos=dot(li,lk);
0051 angle=cos;
0052 %angle=acosd(cos);
0053 if(angle<0.0001)
0054     angle=1;
0055 end
0056 end
0057 
0058 %% computeDistance parameters
0059 % * *Description:*
0060 % * The distance between two points is the absolute difference of the two.
0061 % * Additionally the direction of the force is determined, when the point is
0062 % * pulled downwards the result is -1, otherwise it is 1.
0063 % * *Input:*
0064 % * _pij_ ... subcoordinate of the computed position
0065 % * _pkj_ ... subcoordinate of a neighbor
0066 % * *Ouput:*
0067 % * _absl_ ... absolute distance between pij, pkj
0068 % * _direction_ ... direction of the force, depends on where the neighbor
0069 % is positioned
0070 function[ absl, direction ]= computeDistance(pij,pkj)
0071 
0072 absl=abs(pij-pkj);
0073 if(absl ==0)
0074     absl=1;
0075 end
0076 
0077 direction=pkj-pij;
0078 if (direction==0)
0079     direction=1;
0080 end
0081 
0082 end
0083 
0084 %% computeForce2dim parameters
0085 % * *Description:*
0086 % * The force is computed between two dimensions, for the computation
0087 % * a defined number of neighbors are considered, as well as all lines
0088 % * that intersect with the computed line. For the angular part of the
0089 % force the cosine of the angle is used. The distance part is detemined by
0090 % the absolute difference between two lines and the direction of the force.
0091 % * *Input:*
0092 % * _M_ ... two dimensions of the parallel coordinates, rows are
0093 % dimensions, collumns are observations, subcoordinates are between the
0094 % dimensions
0095 % * _nl_ ... number of neighboring lines considered for the computation
0096 % * _q_alpha_ ... exponent of the angle, strengthens the influence of
0097 % angles on the force
0098 % * _q_d_ ... exponent of the distance, strengthens the influence of
0099 % distance on the force
0100 % * *Ouput:*
0101 % * _fijmatrix_ ... direction of the subcoordinates, gravitational force
0102 % * _initfmatrix_ ... gravitational force of the subcoordinates
0103 function[ fijmatrix, initfmatrix ]= computeForce2dim(M, nl, q_alpha, q_d)
0104 
0105 %sort rows descending to get indizes of all neighbors
0106 numbers=linspace(1,size(M,1),size(M,1))';
0107 sortedM1=cat(2,numbers,M);
0108 sortedM1= sortrows(sortedM1,-2);
0109 col1=sortedM1(:,1);
0110 sortedM2=cat(2,numbers,M);
0111 sortedM2= sortrows(sortedM2,-size(sortedM2,2));
0112 col2=sortedM2(:,1);
0113 
0114 %define all lines as linesegments for intersectioncontrol
0115 XY1=[zeros(size(M,1),1), M(:,1), ones(size(M,1),1), M(:,end)];
0116 out=lineSegmentIntersect(XY1,XY1);
0117 imatrix=out.intAdjacencyMatrix;
0118 
0119 fijmatrix=zeros(size(M,1),size(M,2));
0120 initfmatrix=zeros(size(M,1),size(M,2));
0121 % compute Fij
0122 for i=1:size(M,1) 
0123     
0124     index1=find(col1==i);
0125     index2=find(col2==i);
0126     
0127     %% computation of neighboring edges
0128     neighbors=zeros(nl*4,1);
0129     count=1;
0130     for b=1:nl
0131         if index1-b>0 && count<=nl*4
0132             if all(sortedM1(index1-b,1)~=neighbors)
0133                 %all neighoring lines above computed line
0134                 neighbors(count)=sortedM1(index1-b,1);
0135                 count=count+1;
0136             end
0137         end
0138         if index1+b<=size(M,1) && count<=nl*4
0139             if all(sortedM1(index1+b,1)~=neighbors)
0140                 %all neighoring lines below computed line
0141                 neighbors(count)=sortedM1(index1+b,1);
0142                 count=count+1;
0143             end
0144         end
0145         if index2-b>0 && count<=nl*4
0146             if all(sortedM2(index2-b,1)~=neighbors)
0147                 %all neighoring lines above computed line
0148                 neighbors(count)=sortedM2(index2-b,1);
0149                 count=count+1;
0150             end
0151         end
0152         if index2+b<=size(M,1) && count<=nl*4
0153             if all(sortedM2(index2+b,1)~=neighbors)
0154                 %all neighoring lines below computed line
0155                 neighbors(count)=sortedM2(index2+b,1);
0156                 count=count+1;
0157             end
0158         end 
0159     end
0160     neighbors(neighbors==0)=[];
0161     
0162     %% computation of intersecting lines
0163     intersections=zeros(size(M,1),1);
0164     count=1;
0165     for c=1:size(M,1)
0166         if any(c==neighbors) || c==i
0167         elseif imatrix(i,c)==1
0168         intersections(count)=c;
0169         count=count+1;
0170         end
0171     end
0172     intersections(intersections==0)=[];
0173 
0174     nedges=cat(1,neighbors,intersections);
0175     
0176     %% computation: all Fij of a certain line
0177     
0178     li=[1,M(i,end)]-[0,M(i,1)]; 
0179     for j=2:size(M,2)-1 
0180         sumFij=0;
0181         sumFij2=0;
0182         for k=1:size(nedges,1)
0183         
0184             %% computation of angle
0185             lk=[1,M(nedges(k),end)]-[0,M(nedges(k),1)];
0186             nli=li/norm(li);
0187             nlk=lk/norm(lk);
0188             angle=computeAngle(nli,nlk);
0189             
0190             %% computation of distance
0191             pij=M(i,j);
0192             pkj=M(nedges(k),j);
0193             [absl, direction]=computeDistance(pij,pkj);
0194             
0195             if(direction>=1)
0196                 flilk=(1/(angle^q_alpha))*(1/(direction^q_d));
0197             else
0198                 flilk=(1/(angle^q_alpha))*(1/(direction^q_d));
0199             end
0200             
0201             %% summ the components up for Fij
0202             sumFij=sumFij+flilk;
0203             flilk2=(1/(angle^q_alpha))*(1/(absl^q_d));
0204             %% summ the components up for Fij
0205             sumFij2=sumFij2+flilk2;
0206         end
0207         %% determine direction
0208         if sumFij==0
0209             fijmatrix(i,j)=0; 
0210         elseif sumFij<1
0211             fijmatrix(i,j)=1;
0212         else
0213             fijmatrix(i,j)=-1;
0214         end
0215         
0216         initfmatrix(i,j)=sumFij2;
0217     end    
0218 end
0219 
0220 end

Generated on Tue 31-May-2016 19:24:56 by m2html © 2005