Examples of IntArrayList


Examples of org.apache.mahout.math.list.IntArrayList

    DoubleMatrix1D[] LUrows = new DoubleMatrix1D[m];
    for (int i = 0; i < m; i++) {
      LUrows[i] = LU.viewRow(i);
    }

    IntArrayList nonZeroIndexes =
        new IntArrayList(); // sparsity
    DoubleMatrix1D LUcolj = LU.viewColumn(0).like()// blocked column j
    Mult multFunction = Mult.mult(0);

    // Outer loop.
    int CUT_OFF = 10;
    for (int j = 0; j < n; j++) {
      // blocking (make copy of j-th column to localize references)
      LUcolj.assign(LU.viewColumn(j));

      // sparsity detection
      int maxCardinality = m / CUT_OFF; // == heuristic depending on speedup
      LUcolj.getNonZeros(nonZeroIndexes, null, maxCardinality);
      int cardinality = nonZeroIndexes.size();
      boolean sparse = (cardinality < maxCardinality);

      // Apply previous transformations.
      for (int i = 0; i < m; i++) {
        int kmax = Math.min(i, j);
        double s;
        if (sparse) {
          s = LUrows[i].zDotProduct(LUcolj, 0, kmax, nonZeroIndexes);
        } else {
          s = LUrows[i].zDotProduct(LUcolj, 0, kmax);
        }
        double before = LUcolj.getQuick(i);
        double after = before - s;
        LUcolj.setQuick(i, after); // LUcolj is a copy
        LU.setQuick(i, j, after);   // this is the original
        if (sparse) {
          if (before == 0 && after != 0) { // nasty bug fixed!
            int pos = nonZeroIndexes.binarySearch(i);
            pos = -pos - 1;
            nonZeroIndexes.beforeInsert(pos, i);
          }
          if (before != 0 && after == 0) {
            nonZeroIndexes.remove(nonZeroIndexes.binarySearch(i));
          }
        }
      }

      // Find pivot and exchange if necessary.
View Full Code Here

Examples of org.apache.mahout.math.list.IntArrayList

    // transformations
    Mult div = Mult.div(0);
    PlusMult minusMult = PlusMult.minusMult(0);

    IntArrayList nonZeroIndexes =
        new IntArrayList(); // sparsity
    DoubleMatrix1D Browk = org.apache.mahout.math.matrix.DoubleFactory1D.dense.make(nx); // blocked row k

    // Solve L*Y = B(piv,:)
    int CUT_OFF = 10;
    for (int k = 0; k < n; k++) {
      // blocking (make copy of k-th row to localize references)
      Browk.assign(Brows[k]);

      // sparsity detection
      int maxCardinality = nx / CUT_OFF; // == heuristic depending on speedup
      Browk.getNonZeros(nonZeroIndexes, null, maxCardinality);
      int cardinality = nonZeroIndexes.size();
      boolean sparse = (cardinality < maxCardinality);

      for (int i = k + 1; i < n; i++) {
        //for (int j = 0; j < nx; j++) B[i][j] -= B[k][j]*LU[i][k];
        //for (int j = 0; j < nx; j++) B.set(i,j, B.get(i,j) - B.get(k,j)*LU.get(i,k));

        minusMult.setMultiplicator(-LU.getQuick(i, k));
        if (minusMult.getMultiplicator() != 0) {
          if (sparse) {
            Brows[i].assign(Browk, minusMult, nonZeroIndexes);
          } else {
            Brows[i].assign(Browk, minusMult);
          }
        }
      }
    }

    // Solve U*B = Y;
    for (int k = n - 1; k >= 0; k--) {
      // for (int j = 0; j < nx; j++) B[k][j] /= LU[k][k];
      // for (int j = 0; j < nx; j++) B.set(k,j, B.get(k,j) / LU.get(k,k));
      div.setMultiplicator(1 / LU.getQuick(k, k));
      Brows[k].assign(div);

      // blocking
      if (Browk == null) {
        Browk = org.apache.mahout.math.matrix.DoubleFactory1D.dense.make(B.columns());
      }
      Browk.assign(Brows[k]);

      // sparsity detection
      int maxCardinality = nx / CUT_OFF; // == heuristic depending on speedup
      Browk.getNonZeros(nonZeroIndexes, null, maxCardinality);
      int cardinality = nonZeroIndexes.size();
      boolean sparse = (cardinality < maxCardinality);

      //Browk.getNonZeros(nonZeroIndexes,null);
      //boolean sparse = nonZeroIndexes.size() < nx/10;

View Full Code Here

Examples of org.apache.mahout.math.list.IntArrayList

      buf.append(unknown).append(exc.getMessage());
    }

    buf.append("\npivot = ");
    try {
      buf.append(String.valueOf(new IntArrayList(this.getPivot())));
    }
    catch (IllegalArgumentException exc) {
      buf.append(unknown).append(exc.getMessage());
    }
View Full Code Here

Examples of org.apache.mahout.math.list.IntArrayList

   *
   * @param condition The condition to be matched.
   * @return the new view.
   */
  public DoubleMatrix2D viewSelection(DoubleMatrix1DProcedure condition) {
    IntArrayList matches = new IntArrayList();
    for (int i = 0; i < rows; i++) {
      if (condition.apply(viewRow(i))) {
        matches.add(i);
      }
    }

    matches.trimToSize();
    return viewSelection(matches.elements(), null); // take all columns
  }
View Full Code Here

Examples of org.apache.mahout.math.list.IntArrayList

    catch (IllegalArgumentException exc) { // we can hold rows*columns>Integer.MAX_VALUE cells !
      if (!"matrix too large".equals(exc.getMessage())) {
        throw exc;
      }
    }
    indexes = new IntArrayList();
    values = new DoubleArrayList();
    starts = new int[rows + 1];
  }
View Full Code Here

Examples of org.apache.mahout.math.list.IntArrayList

   * #forEachKey(IntProcedure)}. <p> This method can be used to iterate over the keys of the receiver.
   *
   * @return the keys.
   */
  public IntArrayList keys() {
    IntArrayList list = new IntArrayList(size());
    keys(list);
    return list;
  }
View Full Code Here

Examples of org.apache.mahout.math.list.IntArrayList

  /**
   * Returns a string representation of the receiver, containing the String representation of each key-value pair,
   * sorted ascending by key.
   */
  public String toString() {
    IntArrayList theKeys = keys();
    //theKeys.sort();

    StringBuilder buf = new StringBuilder();
    buf.append('[');
    int maxIndex = theKeys.size() - 1;
    for (int i = 0; i <= maxIndex; i++) {
      int key = theKeys.get(i);
      buf.append(String.valueOf(key));
      buf.append("->");
      buf.append(String.valueOf(get(key)));
      if (i < maxIndex) {
        buf.append(", ");
View Full Code Here

Examples of org.apache.mahout.math.list.IntArrayList

  /**
   * Returns a string representation of the receiver, containing the String representation of each key-value pair,
   * sorted ascending by value.
   */
  public String toStringByValue() {
    IntArrayList theKeys = new IntArrayList();
    keysSortedByValue(theKeys);

    StringBuilder buf = new StringBuilder();
    buf.append('[');
    int maxIndex = theKeys.size() - 1;
    for (int i = 0; i <= maxIndex; i++) {
      int key = theKeys.get(i);
      buf.append(String.valueOf(key));
      buf.append("->");
      buf.append(String.valueOf(get(key)));
      if (i < maxIndex) {
        buf.append(", ");
View Full Code Here

Examples of org.apache.mahout.math.list.IntArrayList

   * #forEachKey(IntProcedure)}. <p> This method can be used to iterate over the keys of the receiver.
   *
   * @return the keys.
   */
  public IntArrayList keys() {
    IntArrayList list = new IntArrayList(size());
    keys(list);
    return list;
  }
View Full Code Here

Examples of org.apache.mahout.math.list.IntArrayList

  /**
   * Returns a string representation of the receiver, containing the String representation of each key-value pair,
   * sorted ascending by key.
   */
  public String toString() {
    IntArrayList theKeys = keys();
    //theKeys.sort();

    StringBuilder buf = new StringBuilder();
    buf.append('[');
    int maxIndex = theKeys.size() - 1;
    for (int i = 0; i <= maxIndex; i++) {
      int key = theKeys.get(i);
      buf.append(String.valueOf(key));
      buf.append("->");
      buf.append(String.valueOf(get(key)));
      if (i < maxIndex) {
        buf.append(", ");
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.