Package org.apache.mahout.math.list

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


    }
   
    Map<String,Long> gList = PFPGrowth.deserializeMap(params, "gList", context.getConfiguration());
   
    for (Entry<String,Long> entry : gList.entrySet()) {
      IntArrayList groupList = groupFeatures.get(entry.getValue());
      Integer itemInteger = fMap.get(entry.getKey());
      if (groupList != null) {
        groupList.add(itemInteger);
      } else {
        groupList = new IntArrayList();
        groupList.add(itemInteger);
        groupFeatures.put(entry.getValue(), groupList);
      }
     
    }
    maxHeapSize = Integer.valueOf(params.get("maxHeapSize", "50"));
View Full Code Here


  public void setQuick(int row, int column, double value) {
    int i = row;
    int j = column;

    int k = -1;
    IntArrayList indexList = indexes[i];
    if (indexList != null) {
      k = indexList.binarySearch(j);
    }

    if (k >= 0) { // found
      if (value == 0) {
        DoubleArrayList valueList = values[i];
        indexList.remove(k);
        valueList.remove(k);
        int s = indexList.size();
        if (s > 2 && s * 3 < indexList.elements().length) {
          indexList.setSize(s * 3 / 2);
          indexList.trimToSize();
          indexList.setSize(s);

          valueList.setSize(s * 3 / 2);
          valueList.trimToSize();
          valueList.setSize(s);
        }
      } else {
        values[i].setQuick(k, value);
      }
    } else { // not found
      if (value == 0) {
        return;
      }

      k = -k - 1;

      if (indexList == null) {
        indexes[i] = new IntArrayList(3);
        values[i] = new DoubleArrayList(3);
      }
      indexes[i].beforeInsert(k, j);
      values[i].beforeInsert(k, value);
    }
View Full Code Here

  /** Not yet commented. */
  public static void test(int weight, int size) {
    WeightedRandomSampler sampler = new WeightedRandomSampler();
    sampler.setWeight(weight);

    IntArrayList sample = new IntArrayList();
    for (int i = 0; i < size; i++) {
      if (sampler.sampleNextElement()) {
        sample.add(i);
      }
    }
  }
View Full Code Here

   *
   * @param condition The condition to be matched.
   * @return the new view.
   */
  public DoubleMatrix1D viewSelection(DoubleProcedure condition) {
    IntArrayList matches = new IntArrayList();
    for (int i = 0; i < size; i++) {
      if (condition.apply(getQuick(i))) {
        matches.add(i);
      }
    }
    matches.trimToSize();
    return viewSelection(matches.elements());
  }
View Full Code Here

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

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

    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

    // 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

      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

   *
   * @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

    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

TOP

Related Classes of org.apache.mahout.math.list.IntArrayList

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.