Package net.myrrix.common.collection

Examples of net.myrrix.common.collection.FastByIDFloatMap$MapEntry


  private static FastByIDMap<float[]> buildBinarizedMatrix(FastByIDMap<FastByIDFloatMap> input, long[] idsInOrder) {
    int n = idsInOrder.length;
    FastByIDMap<float[]> result = new FastByIDMap<float[]>();
    for (FastByIDMap.MapEntry<FastByIDFloatMap> entry : input.entrySet()) {
      float[] rowOrCol = new float[n];
      FastByIDFloatMap inputValues = entry.getValue();
      for (int i = 0; i < n; i++) {
        if (inputValues.containsKey(idsInOrder[i])) {
          rowOrCol[i] = 1.0f;
        }
      }
      result.put(entry.getKey(), rowOrCol);
    }
View Full Code Here


    if (knownItemIDs == null) {
      throw new UnsupportedOperationException();
    }

    FastIDSet itemTagIDs = generation.getItemTagIDs();
    FastByIDFloatMap itemCounts = new FastByIDFloatMap();   
    Lock knownItemReadLock = generation.getKnownItemLock().readLock();
    knownItemReadLock.lock();
    try {
        // Don't count data from users that are really item tags
        Lock xReadLock = generation.getXLock().readLock();
        xReadLock.lock();
        try {
         
          for (FastByIDMap.MapEntry<FastIDSet> entry : generation.getKnownItemIDs().entrySet()) {
            long userID = entry.getKey();
            if (!itemTagIDs.contains(userID)) {
              FastIDSet itemIDs = entry.getValue();
              synchronized (itemIDs) {
                LongPrimitiveIterator it = itemIDs.iterator();
                while (it.hasNext()) {
                  long itemID = it.nextLong();
                  itemCounts.increment(itemID, 1.0f);
                }
              }
            }
          }
         
        } finally {
          xReadLock.unlock();
        }
    } finally {
      knownItemReadLock.unlock();
    }
   
    // Filter out 'items' that were really user tags
    FastIDSet userTagIDs = generation.getUserTagIDs();
    Lock yReadLock = generation.getYLock().readLock();
    yReadLock.lock();
    try {
      LongPrimitiveIterator it = itemCounts.keySetIterator();
      while (it.hasNext()) {
        if (userTagIDs.contains(it.nextLong())) {
          it.remove();
        }
      }
    } finally {
      yReadLock.unlock();
    }

    return TopN.selectTopN(new MostPopularItemsIterator(itemCounts.entrySet().iterator(), rescorer), howMany);
  }
View Full Code Here

  private static void addToByRow(long row,
                                 long column,
                                 float value,
                                 FastByIDMap<FastByIDFloatMap> RbyRow) {

    FastByIDFloatMap theRow = RbyRow.get(row);
    if (theRow == null) {
      theRow = new FastByIDFloatMap();
      RbyRow.put(row, theRow);
    }
    theRow.increment(column, value);
  }
View Full Code Here

   * @param row row to remove
   * @param column column to remove
   * @param RbyRow matrix R to update, keyed by row
   */
  private static void removeByRow(long row, long column, FastByIDMap<FastByIDFloatMap> RbyRow) {
    FastByIDFloatMap theRow = RbyRow.get(row);
    if (theRow != null) {
      theRow.remove(column);
      if (theRow.isEmpty()) {
        RbyRow.remove(row);
      }
    }
  }
View Full Code Here

    }
    result.append("\n\n");
    long[] rowKeys = keysInOrder(M);
    for (long rowKey : rowKeys) {
      appendWithPadOrTruncate(rowKey, result);
      FastByIDFloatMap row = M.get(rowKey);
      for (long colKey : colKeys) {
        result.append('\t');
        float value = row.get(colKey);
        if (Float.isNaN(value)) {
          appendWithPadOrTruncate("", result);
        } else {
          appendWithPadOrTruncate(value, result);
        }
View Full Code Here

      for (Pair<Long,FastByIDFloatMap> work : workUnit) {

        // Row (column) in original R matrix containing total association value. For simplicity we will
        // talk about users and rows only in the comments and variables. It's symmetric for columns / items.
        // This is Ru:
        FastByIDFloatMap ru = work.getSecond();

        // Start computing Wu = (YT*Cu*Y + lambda*I) = (YT*Y + YT*(Cu-I)*Y + lambda*I),
        // by first starting with a copy of YT * Y. Or, a variant on YT * Y, if LOSS_IGNORES_UNSPECIFIED is set
        RealMatrix Wu =
            LOSS_IGNORES_UNSPECIFIED ?
            partialTransposeTimesSelf(Y, YTY.getRowDimension(), ru.keySetIterator()) :
            YTY.copy();

        double[][] WuData = MatrixUtils.accessMatrixDataDirectly(Wu);
        double[] YTCupu = new double[features];

        for (FastByIDFloatMap.MapEntry entry : ru.entrySet()) {

          double xu = entry.getValue();

          float[] vector = Y.get(entry.getKey());
          if (vector == null) {
            log.warn("No vector for {}. This should not happen. Continuing...", entry.getKey());
            continue;
          }

          // Wu and YTCupu
          if (RECONSTRUCT_R_MATRIX) {
            for (int row = 0; row < features; row++) {
              YTCupu[row] += xu * vector[row];
            }
          } else {
            double cu = 1.0 + alpha * FastMath.abs(xu);           
            for (int row = 0; row < features; row++) {
              float vectorAtRow = vector[row];
              double rowValue = vectorAtRow * (cu - 1.0);
              double[] WuDataRow = WuData[row];             
              for (int col = 0; col < features; col++) {
                WuDataRow[col] += rowValue * vector[col];
                //Wu.addToEntry(row, col, rowValue * vector[col]);
              }
              if (xu > 0.0) {
                YTCupu[row] += vectorAtRow * cu;
              }
            }
          }

        }

        double lambdaTimesCount = lambda * ru.size();
        for (int x = 0; x < features; x++) {
          WuData[x][x] += lambdaTimesCount;         
          //Wu.addToEntry(x, x, lambdaTimesCount);
        }

View Full Code Here

TOP

Related Classes of net.myrrix.common.collection.FastByIDFloatMap$MapEntry

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.