; $Id: join.pro,v 1.1 1993/04/02 18:54:39 idl Exp $ ; Copyright (c) 1991-1993, Research Systems Inc. All rights ; reserved. Unauthorized reproduction prohibited. Function EuclidRule, Case1, RCases ; Dist returns the vector of Euclidean Distances from Case ; to the other cases in the array RCase SC=Size(RCases) C=SC(1) if(SC(0) GT 1) THEN R=SC(2) ELSE R=1 M1= Case1#(Fltarr(R)+1) M2=Fltarr(C)+1 M1=M1-RCases if(R EQ 1) THEN Return,SQRT(Total(M1*M1)) $ else Return, transpose (SQRT(M2#(M1*M1))) END Function Distance1,Case1,RCases,N ; Determine appropriate rule for computing distances between ; cases and return the vector of distances between ; RCases and Case1. SC=Size(RCases) S=SC(1) if(SC(0) GE 2) THEN R=SC(2) else R=1 Case N of "%":BEGIN X=Case1#replicate(1.,R) - RCases A=where(X NE 0,count) if(count NE 0) THEN X(A)=1 if(SC(0) GT 1) THEN return, $ transpose(replicate(1.,S)#X*1/S) $ ELSE return,Total(X)*1/S END "COR":BEGIN V= [Correlate(Case1,RCases(*,0))] for i=1,R-1 DO V=[V,Correlate(Case1,RCases(*,i))] return,1-V END ELSE: return,EuclidRule(Case1,RCases) ENDCASE END Function Normal1, Data,R,C ;Normal returns Data normalized by columns Y= Data-Data#Replicate(1./R,R) #Replicate(1.,R) std =sqrt(Y^2 # Replicate(1./(R-1),R)) D1=Fltarr(c,c) for i=0,C-1 do $ if std(i) NE 0 then $ D1(i,i)=1./std(i) else d1(i,i)=0 return, D1#Y end Function FindRow,I,R ; D is a symmetric matrix stored linearly. FindRow ; reconstructs the ith row. R is the total number of rows. Common JBlock,D,INDEX case I of R-1:Begin ;RETURN,(R-1)*(R-2)/2:(R+1)*(R-2)/2) X=LINDGEN((R+1)*(R-2)/2 +1) Return,X((R-1)*(R-2)/2:(R+1)*(R-2)/2) END 0: BEGIN T=LIndgen(R-1) RETURN,(1+T)*T/2 END ELSE: BEGIN A1=I*(I-1)/2 A2=(I+1)*(I+2)/2 -1 T=LIndGen(R-I-1) T=(T+1)*T/2 RETURN,[A1+LIndgen(I),A2 + I*LIndgen(R-I-1 )+T] END ENDCASE END Pro MinDist,R,DMin,IMin,I ; MinDist computes the minimum distance from case I to any ; other case using the symmetric distance matrix D. This ; distance and the corresponding row number are returned ; in DMin and ; IMIN respectively. Common JBLock,D,INDEX DMin(I)=min(D(FindRow(INDEX(I),R))) if(!C LE INDEX(I)-1) THEN IMIN(I)=INDEX(!C) else $ IMIn(I)=INDEX(!C+1) RETURN END Pro SetVal,V,I,R Common JBlock,D,INDEX D(FindRow(INDEX(I),R))=v RETURN END FUNCTION AmalDist,I1,J1,R,pos,Am,cl,here ;AmalDist computes the distances from the cluster formed ; from I and J to the other cases and clusters as the ; minimum distance between members Common JBlock,D,INDEX I = INDEX(I1) J = INDEX(J1) X1=Fltarr(R) Y1=Fltarr(R) here = FindRow(I,R) X=D(here) case I of R-1:X1=[X,1.e30] 0: X1=[1.e30,X] ELSE:X1=[X(0:I-1),1.e30,X(I:R-2)] ENDCASE Y=D(FindRow(J,R)) case J of R-1:Y1=[Y,1.e30] 0: Y1=[1.e30,y] ELSE:Y1=[Y(0:J-1),1.e30,Y(J:R-2)] ENDCASE Ind=Where(Y1 EQ 1.e30) Y1(Where(X1 EQ 1.e30))= 1.e30 X1(Ind)=1.e30 INDEX(cl) = I INDEX(I) = cl case Am of "MAX" : V=X1>Y1 "MEAN": V=(pos(I)*X1+pos(J)*Y1)/(pos(I)+pos(J)) ELse : V=X1