Package de.lmu.ifi.dbs.elki.math.linearalgebra

Examples of de.lmu.ifi.dbs.elki.math.linearalgebra.Matrix


    public SubspaceDistance distance(V o1, V o2, PCAFilteredResult pca1, PCAFilteredResult pca2) {
      if(pca1.getCorrelationDimension() != pca2.getCorrelationDimension()) {
        throw new IllegalStateException("pca1.getCorrelationDimension() != pca2.getCorrelationDimension()");
      }

      Matrix strong_ev1 = pca1.getStrongEigenvectors();
      Matrix weak_ev2 = pca2.getWeakEigenvectors();
      Matrix m1 = weak_ev2.getColumnDimensionality() == 0 ? strong_ev1.transpose() : strong_ev1.transposeTimes(weak_ev2);
      double d1 = m1.norm2();

      WeightedDistanceFunction df1 = new WeightedDistanceFunction(pca1.similarityMatrix());
      WeightedDistanceFunction df2 = new WeightedDistanceFunction(pca2.similarityMatrix());

      double affineDistance = Math.max(df1.distance(o1, o2).doubleValue(), df2.distance(o1, o2).doubleValue());
View Full Code Here


   * @return Weight matrix
   */
  public static Matrix computeWeightMatrix(int bpp) {
    final int dim = bpp * bpp * bpp;

    final Matrix m = new Matrix(dim, dim);
    // maximum occurring distance in manhattan between bins:
    final double max = 3. * (bpp - 1.);
    for(int x = 0; x < dim; x++) {
      final int rx = (x / bpp) / bpp;
      final int gx = (x / bpp) % bpp;
      final int bx = x % bpp;
      for(int y = 0; y < dim; y++) {
        final int ry = (y / bpp) / bpp;
        final int gy = (y / bpp) % bpp;
        final int by = y % bpp;

        final double dr = Math.abs(rx - ry);
        final double dg = Math.abs(gx - gy);
        final double db = Math.abs(bx - by);

        final double val = 1 - (dr + dg + db) / max;
        m.set(x, y, val);
      }
    }
    return m;
  }
View Full Code Here

    // sort neighbors
    for(Cluster<?> clus : split) {
      ArrayList<FCPair<Double, DBID>> cmem = new ArrayList<FCPair<Double, DBID>>(clus.size());
      Vector av = averages.get(clus).getColumnVector();
      Matrix covm = covmats.get(clus);

      for(DBID i1 : clus.getIDs()) {
        Double d = MathUtil.mahalanobisDistance(covm, av.minus(relation.get(i1).getColumnVector()));
        cmem.add(new FCPair<Double, DBID>(d, i1));
      }
View Full Code Here

     *         specified PCAs
     */
    public int correlationDistance(PCAFilteredResult pca1, PCAFilteredResult pca2, int dimensionality) {
      // TODO nur in eine Richtung?
      // pca of rv1
      Matrix v1 = pca1.getEigenvectors();
      Matrix v1_strong = pca1.adapatedStrongEigenvectors();
      Matrix e1_czech = pca1.selectionMatrixOfStrongEigenvectors();
      int lambda1 = pca1.getCorrelationDimension();

      // pca of rv2
      Matrix v2 = pca2.getEigenvectors();
      Matrix v2_strong = pca2.adapatedStrongEigenvectors();
      Matrix e2_czech = pca2.selectionMatrixOfStrongEigenvectors();
      int lambda2 = pca2.getCorrelationDimension();

      // for all strong eigenvectors of rv2
      Matrix m1_czech = pca1.dissimilarityMatrix();
      for(int i = 0; i < v2_strong.getColumnDimensionality(); i++) {
        Vector v2_i = v2_strong.getCol(i);
        // check, if distance of v2_i to the space of rv1 > delta
        // (i.e., if v2_i spans up a new dimension)
        double dist = Math.sqrt(v2_i.transposeTimes(v2_i) - v2_i.transposeTimesTimes(m1_czech, v2_i));

        // if so, insert v2_i into v1 and adjust v1
        // and compute m1_czech new, increase lambda1
        if(lambda1 < dimensionality && dist > delta) {
          adjust(v1, e1_czech, v2_i, lambda1++);
          m1_czech = v1.times(e1_czech).timesTranspose(v1);
        }
      }

      // for all strong eigenvectors of rv1
      Matrix m2_czech = pca2.dissimilarityMatrix();
      for(int i = 0; i < v1_strong.getColumnDimensionality(); i++) {
        Vector v1_i = v1_strong.getCol(i);
        // check, if distance of v1_i to the space of rv2 > delta
        // (i.e., if v1_i spans up a new dimension)
        double dist = Math.sqrt(v1_i.transposeTimes(v1_i) - v1_i.transposeTimes(m2_czech).times(v1_i).get(0));
View Full Code Here

   * @return Weight matrix
   */
  public static Matrix computeWeightMatrix(final int quanth, final int quants, final int quantb) {
    final int dim = quanth * quants * quantb;
    assert (dim > 0);
    final Matrix m = new Matrix(dim, dim);
    for(int x = 0; x < dim; x++) {
      final int hx = x / (quantb * quants);
      final int sx = (x / quantb) % quants;
      final int bx = x % quantb;
      for(int y = 0; y < dim; y++) {
        final int hy = y / (quantb * quants);
        final int sy = (y / quantb) % quants;
        final int by = y % quantb;

        final double cos = Math.cos((hx + .5) / quanth * MathUtil.TWOPI) * (sx + .5) / quants - Math.cos((hy + .5) / quanth * MathUtil.TWOPI) * (sy + .5) / quants;
        final double sin = Math.sin((hx + .5) / quanth * MathUtil.TWOPI) * (sx + .5) / quants - Math.sin((hy + .5) / quanth * MathUtil.TWOPI) * (sy + .5) / quants;
        final double db = (bx - by) / (double) quantb;
        final double val = 1. - Math.sqrt((db * db + sin * sin + cos * cos) / 5);
        m.set(x, y, val);
      }
    }
    return m;
  }
View Full Code Here

   * @param pca2 second PCA
   * @return true, if the strong eigenvectors of the two specified pcas span up
   *         the same space
   */
  private boolean approximatelyLinearDependent(PCAFilteredResult pca1, PCAFilteredResult pca2) {
    Matrix m1_czech = pca1.dissimilarityMatrix();
    Matrix v2_strong = pca2.adapatedStrongEigenvectors();
    for(int i = 0; i < v2_strong.getColumnDimensionality(); i++) {
      Vector v2_i = v2_strong.getCol(i);
      // check, if distance of v2_i to the space of pca_1 > delta
      // (i.e., if v2_i spans up a new dimension)
      double dist = Math.sqrt(v2_i.transposeTimes(v2_i) - v2_i.transposeTimesTimes(m1_czech, v2_i));

      // if so, return false
View Full Code Here

   * @param p a vector in the space underlying this solution
   * @return the data projections
   */
  public Matrix dataProjections(V p) {
    Vector centered = p.getColumnVector().minus(centroid);
    Matrix sum = new Matrix(p.getDimensionality(), strongEigenvectors.getColumnDimensionality());
    for(int i = 0; i < strongEigenvectors.getColumnDimensionality(); i++) {
      Vector v_i = strongEigenvectors.getCol(i);
      v_i.timesEquals(centered.transposeTimes(v_i));
      sum.setCol(i, v_i);
    }
    return sum;
  }
View Full Code Here

   * Wraps the matrixArray in a KernelMatrix
   *
   * @param matrixArray two dimensional double array
   */
  public KernelMatrix(final double[][] matrixArray) {
    kernel = new Matrix(matrixArray);
  }
View Full Code Here

   * @param database the database that holds the objects
   * @param ids the IDs of those objects for which the kernel matrix is computed
   */
  public <O extends FeatureVector<O, ?>> KernelMatrix(final PrimitiveSimilarityFunction<? super O, DoubleDistance> kernelFunction, final Relation<? extends O> database, final ArrayDBIDs ids) {
    LoggingUtil.logExpensive(Level.FINER, "Computing kernel matrix");
    kernel = new Matrix(ids.size(), ids.size());
    double value;
    for(int idx = 0; idx < ids.size(); idx++) {
      for(int idy = idx; idy < ids.size(); idy++) {
        value = kernelFunction.similarity(database.get(ids.get(idx)), database.get(ids.get(idy))).doubleValue();
        kernel.set(idx, idy, value);
View Full Code Here

   *
   * @param matrix the matrix to be centered
   * @return centered matrix (for convenience)
   */
  public static Matrix centerMatrix(final Matrix matrix) {
    final Matrix normalizingMatrix = new Matrix(matrix.getRowDimensionality(), matrix.getColumnDimensionality(), 1.0 / matrix.getColumnDimensionality());
    return matrix.minusEquals(normalizingMatrix.times(matrix)).minusEquals(matrix.times(normalizingMatrix)).plusEquals(normalizingMatrix.times(matrix).times(normalizingMatrix));
  }
View Full Code Here

TOP

Related Classes of de.lmu.ifi.dbs.elki.math.linearalgebra.Matrix

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.