Package org.apache.mahout.math.list

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


    log.info("Number of unique items {}", attributeFrequency.size());

    OpenIntHashSet returnFeatures = new OpenIntHashSet();
    if (returnableFeatures == null || returnableFeatures.isEmpty()) {
      returnableFeatures = new IntArrayList();
      for (int j = 0; j < attributeFrequency.size(); j++) {
        returnableFeatures.add(j);
      }
    }
View Full Code Here


    // Constructing initial FPTree from the list of transactions
    int nodecount = 0;
    int i = 0;
    while (transactions.hasNext()) {
      Pair<IntArrayList,Long> transaction = transactions.next();
      IntArrayList iArr = transaction.getFirst();
      tree.accumulate(iArr, transaction.getSecond());
      i++;
      if (i % 10000 == 0) {
        log.info("FPTree Building: Read {} Transactions", i);
      }
View Full Code Here

  }

  public static final IntArrayList getGroupMembers(int groupId,
                                                   int maxPerGroup,
                                                   int numFeatures) {
    IntArrayList ret = new IntArrayList();
    int start = groupId * maxPerGroup;
    int end = start + maxPerGroup;
    if (end > numFeatures)
      end= numFeatures;
    for (int i = start; i < end; i++) {
      ret.add(i);
    }
    return ret;
  }
View Full Code Here

  @Override
  public void readFields(DataInput in) throws IOException {
    super.readFields(in);
    this.mass = in.readInt();
    int numpoints = in.readInt();
    this.boundPoints = new IntArrayList();
    for (int i = 0; i < numpoints; i++) {
      this.boundPoints.add(in.readInt());
    }
    this.mass = boundPoints.size();
  }
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

    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 cutOff = 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 / cutOff; // == 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 cutOff = 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 / cutOff; // == 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 / cutOff; // == 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.piv)));
    } catch (IllegalArgumentException exc) {
      buf.append(unknown).append(exc.getMessage());
    }

    buf.append("\n\nL = ");
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 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

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.