Пример #1
0
  /**
   * The scale of the trifocal tensor is arbitrary. However there are situations when comparing
   * results that using a consistent scale is useful. This function normalizes the sensor such that
   * its Euclidean length (the f-norm) is equal to one.
   */
  public void normalizeScale() {
    double sum = 0;

    sum += SpecializedOps.elementSumSq(T1);
    sum += SpecializedOps.elementSumSq(T2);
    sum += SpecializedOps.elementSumSq(T3);

    double n = Math.sqrt(sum);

    CommonOps.scale(1.0 / n, T1);
    CommonOps.scale(1.0 / n, T2);
    CommonOps.scale(1.0 / n, T3);
  }
Пример #2
0
  /**
   * Extracts a row or column from this matrix. The returned vector will either be a row or column
   * vector depending on the input type.
   *
   * @param extractRow If true a row will be extracted.
   * @param element The row or column the vector is contained in.
   * @return Extracted vector.
   */
  public T extractVector(boolean extractRow, int element) {
    int length = extractRow ? mat.numCols : mat.numRows;

    T ret = extractRow ? createMatrix(1, length) : createMatrix(length, 1);

    if (extractRow) {
      SpecializedOps.subvector(mat, element, 0, length, true, 0, ret.getMatrix());
    } else {
      SpecializedOps.subvector(mat, 0, element, length, false, 0, ret.getMatrix());
    }

    return ret;
  }
Пример #3
0
  /**
   * Computes the most dominant eigen vector of A using an inverted shifted matrix. The inverted
   * shifted matrix is defined as <b>B = (A - &alpha;I)<sup>-1</sup></b> and can converge faster if
   * &alpha; is chosen wisely.
   *
   * @param A An invertible square matrix matrix.
   * @param alpha Shifting factor.
   * @return If it converged or not.
   */
  public boolean computeShiftInvert(DenseMatrix64F A, double alpha) {
    initPower(A);

    LinearSolver solver = LinearSolverFactory.linear(A.numCols);

    SpecializedOps.addIdentity(A, B, -alpha);
    solver.setA(B);

    boolean converged = false;

    for (int i = 0; i < maxIterations && !converged; i++) {
      solver.solve(q0, q1);
      double s = NormOps.normPInf(q1);
      CommonOps.divide(q1, s, q2);

      converged = checkConverged(A);
    }

    return converged;
  }
Пример #4
0
  /**
   * Computes the most dominant eigen vector of A using a shifted matrix. The shifted matrix is
   * defined as <b>B = A - &alpha;I</b> and can converge faster if &alpha; is chosen wisely. In
   * general it is easier to choose a value for &alpha; that will converge faster with the
   * shift-invert strategy than this one.
   *
   * @param A The matrix.
   * @param alpha Shifting factor.
   * @return If it converged or not.
   */
  public boolean computeShiftDirect(DenseMatrix64F A, double alpha) {
    SpecializedOps.addIdentity(A, B, -alpha);

    return computeDirect(B);
  }