mev-4.0.01/source/org/tigr/microarray/mev/cluster/algorithm/impl/terrain/MergeJoinBag.java

Code
Comments
Other
Rev Date Author Line
2 26 Feb 07 jari 1 /*
2 26 Feb 07 jari 2 Copyright @ 1999-2003, The Institute for Genomic Research (TIGR).
2 26 Feb 07 jari 3 All rights reserved.
2 26 Feb 07 jari 4 */
2 26 Feb 07 jari 5 /*
2 26 Feb 07 jari 6  * $RCSfile: MergeJoinBag.java,v $
2 26 Feb 07 jari 7  * $Revision: 1.3 $
2 26 Feb 07 jari 8  * $Date: 2005/03/10 15:45:30 $
2 26 Feb 07 jari 9  * $Author: braistedj $
2 26 Feb 07 jari 10  * $State: Exp $
2 26 Feb 07 jari 11  */
2 26 Feb 07 jari 12 package org.tigr.microarray.mev.cluster.algorithm.impl.terrain; 
2 26 Feb 07 jari 13
2 26 Feb 07 jari 14 import java.util.Arrays;
2 26 Feb 07 jari 15
2 26 Feb 07 jari 16 public class MergeJoinBag {
2 26 Feb 07 jari 17     private int[][]   m_pVectToInd;  // indeces matrix (packed by rows)  | all syncronous
2 26 Feb 07 jari 18     private float[][] m_pDistToVal;  // distances matrix (packed by rows)| all syncronous  
2 26 Feb 07 jari 19
2 26 Feb 07 jari 20     // statistics
2 26 Feb 07 jari 21     private float m_fltMin;
2 26 Feb 07 jari 22     private float m_fltMax;
2 26 Feb 07 jari 23
2 26 Feb 07 jari 24     // helpers
2 26 Feb 07 jari 25     public int[] getIndVector(int row) {
2 26 Feb 07 jari 26         return this.m_pVectToInd[row];
2 26 Feb 07 jari 27     }
2 26 Feb 07 jari 28
2 26 Feb 07 jari 29     public float[] getValVector(int row) {
2 26 Feb 07 jari 30         return this.m_pDistToVal[row];
2 26 Feb 07 jari 31     }
2 26 Feb 07 jari 32
2 26 Feb 07 jari 33     public MergeJoinBag(int iRowCount, int iColumnCount) {
2 26 Feb 07 jari 34         this(iRowCount, iColumnCount, false);
2 26 Feb 07 jari 35     }
2 26 Feb 07 jari 36
2 26 Feb 07 jari 37     public MergeJoinBag(int iRowCount, int iColumnCount, boolean bNoIndMatr) {
2 26 Feb 07 jari 38         if (bNoIndMatr)
2 26 Feb 07 jari 39             m_pVectToInd = null;
2 26 Feb 07 jari 40         else {
2 26 Feb 07 jari 41             m_pVectToInd = new int[iRowCount][iColumnCount];
2 26 Feb 07 jari 42             for (int i=0; i<m_pVectToInd.length; i++)
2 26 Feb 07 jari 43                 Arrays.fill(m_pVectToInd[i], -1); 
2 26 Feb 07 jari 44         }
2 26 Feb 07 jari 45         m_pDistToVal = new float[iRowCount][iColumnCount];
2 26 Feb 07 jari 46         for (int i=0; i<m_pDistToVal.length; i++)
2 26 Feb 07 jari 47             Arrays.fill(m_pDistToVal[i], Float.MAX_VALUE); 
2 26 Feb 07 jari 48         m_fltMin =  Float.MAX_VALUE;
2 26 Feb 07 jari 49         m_fltMax = -Float.MAX_VALUE;
2 26 Feb 07 jari 50     }
2 26 Feb 07 jari 51
2 26 Feb 07 jari 52     public int getRowCount() {
2 26 Feb 07 jari 53         return m_pDistToVal.length;
2 26 Feb 07 jari 54     }
2 26 Feb 07 jari 55
2 26 Feb 07 jari 56     public int getColumnCount() {
2 26 Feb 07 jari 57         if (m_pDistToVal.length <= 0 || m_pDistToVal[0] == null)
2 26 Feb 07 jari 58             return 0;
2 26 Feb 07 jari 59         return m_pDistToVal[0].length;
2 26 Feb 07 jari 60     }
2 26 Feb 07 jari 61
2 26 Feb 07 jari 62     public void Clear() {
2 26 Feb 07 jari 63         m_pVectToInd = null;
2 26 Feb 07 jari 64         m_pDistToVal = null;
2 26 Feb 07 jari 65     }
2 26 Feb 07 jari 66
2 26 Feb 07 jari 67     public void AppendTo(int iIndFrom, int iIndTo, float fltDist) {
2 26 Feb 07 jari 68         // Append the pair iIndTo and fltDist
2 26 Feb 07 jari 69         int[] pFirstInt = getIndVector(iIndFrom);
2 26 Feb 07 jari 70         float[] pFirstDist = getValVector(iIndFrom);
2 26 Feb 07 jari 71
2 26 Feb 07 jari 72         // find the index to insert to..
2 26 Feb 07 jari 73         // TODO: Change the following code to binary_search-like procedure//
2 26 Feb 07 jari 74         int iIndToInsert=0;                                               //
2 26 Feb 07 jari 75         for (; iIndToInsert<pFirstDist.length; iIndToInsert++)            //
2 26 Feb 07 jari 76             if (fltDist <= pFirstDist[iIndToInsert])                      //
2 26 Feb 07 jari 77                 break;                                                    //
2 26 Feb 07 jari 78         ////////////////////////////////////////////////////////////////////
2 26 Feb 07 jari 79
2 26 Feb 07 jari 80         if (iIndToInsert<pFirstDist.length) { // if found
2 26 Feb 07 jari 81             // then shift the tail (RtlMoveMemory(Destination,Source,Length))
2 26 Feb 07 jari 82             if (pFirstDist.length-iIndToInsert-1 > 0) {
2 26 Feb 07 jari 83                 System.arraycopy(pFirstDist, iIndToInsert, pFirstDist, iIndToInsert+1, pFirstDist.length-iIndToInsert-1);
2 26 Feb 07 jari 84                 System.arraycopy(pFirstInt, iIndToInsert, pFirstInt, iIndToInsert+1, pFirstInt.length-iIndToInsert-1);
2 26 Feb 07 jari 85             }
2 26 Feb 07 jari 86             pFirstInt[iIndToInsert]  = iIndTo;
2 26 Feb 07 jari 87             pFirstDist[iIndToInsert] = fltDist;
2 26 Feb 07 jari 88         }
2 26 Feb 07 jari 89     }
2 26 Feb 07 jari 90
2 26 Feb 07 jari 91     public void Assert(int iIndFrom, int iIndTo, float fltDist) {
2 26 Feb 07 jari 92         m_fltMin = Math.min(m_fltMin, fltDist);
2 26 Feb 07 jari 93         m_fltMax = Math.max(m_fltMax, fltDist);
2 26 Feb 07 jari 94         AppendTo(iIndFrom, iIndTo, fltDist);
2 26 Feb 07 jari 95         AppendTo(iIndTo, iIndFrom, fltDist);
2 26 Feb 07 jari 96     }
2 26 Feb 07 jari 97
2 26 Feb 07 jari 98     public void Normalize(float fltLow) {
2 26 Feb 07 jari 99         float delta=(m_fltMax-m_fltMin);
2 26 Feb 07 jari 100
2 26 Feb 07 jari 101         for (int i=0; i<m_pDistToVal.length; i++)
2 26 Feb 07 jari 102             for (int j=0; j<m_pDistToVal[i].length; j++)
2 26 Feb 07 jari 103             m_pDistToVal[i][j] = (1f-(m_pDistToVal[i][j]-m_fltMin)/delta)*(1f-fltLow)+fltLow;
2 26 Feb 07 jari 104     }
2 26 Feb 07 jari 105 }