~ubuntu-branches/ubuntu/vivid/elki/vivid

« back to all changes in this revision

Viewing changes to src/de/lmu/ifi/dbs/elki/database/relation/RelationUtil.java

  • Committer: Package Import Robot
  • Author(s): Erich Schubert
  • Date: 2014-01-22 16:23:20 UTC
  • mfrom: (1.1.8)
  • Revision ID: package-import@ubuntu.com-20140122162320-dtqtgcdiki8t9unc
Tags: 0.6.0-1
* New upstream final.
* 3DPC extension is not included, but may be uploaded as a separate
  package when there is actual need (it is a demo software, not meant
  for use outside of research, so just get the source code!)
* Upgrade to policy 3.9.5.0 (no changes)

Show diffs side-by-side

added added

removed removed

Lines of Context:
26
26
import de.lmu.ifi.dbs.elki.data.FeatureVector;
27
27
import de.lmu.ifi.dbs.elki.data.NumberVector;
28
28
import de.lmu.ifi.dbs.elki.data.type.VectorFieldTypeInformation;
 
29
import de.lmu.ifi.dbs.elki.database.ids.ArrayDBIDs;
 
30
import de.lmu.ifi.dbs.elki.database.ids.DBIDArrayIter;
29
31
 
30
32
/**
31
33
 * Utility functions for handling database relation.
87
89
  }
88
90
 
89
91
  /**
 
92
   * <em>Copy</em> a relation into a double matrix.
 
93
   * 
 
94
   * This is <em>not recommended</em> unless you need to modify the data
 
95
   * temporarily.
 
96
   * 
 
97
   * @param relation Relation
 
98
   * @param ids IDs, with well-defined order (i.e. array)
 
99
   * @return Data matrix
 
100
   */
 
101
  public static double[][] relationAsMatrix(final Relation<? extends NumberVector<?>> relation, ArrayDBIDs ids) {
 
102
    final int rowdim = ids.size();
 
103
    final int coldim = dimensionality(relation);
 
104
    double[][] mat = new double[rowdim][coldim];
 
105
    int r = 0;
 
106
    for (DBIDArrayIter iter = ids.iter(); iter.valid(); iter.advance(), r++) {
 
107
      NumberVector<?> vec = relation.get(iter);
 
108
      double[] row = mat[r];
 
109
      for (int c = 0; c < coldim; c++) {
 
110
        row[c] = vec.doubleValue(c);
 
111
      }
 
112
    }
 
113
    assert (r == rowdim);
 
114
    return mat;
 
115
  }
 
116
 
 
117
  /**
90
118
   * Get the column name or produce a generic label "Column XY".
91
119
   * 
92
120
   * @param rel Relation