示例#1
0
  /** Asserts that the two HLLs are register-wise equal. */
  private static void assertElementsEqual(final HLL hllA, final HLL hllB) {
    final BitVector bitVectorA = hllA.probabilisticStorage;
    final BitVector bitVectorB = hllB.probabilisticStorage;

    final LongIterator iterA = bitVectorA.registerIterator();
    final LongIterator iterB = bitVectorB.registerIterator();

    for (; iterA.hasNext() && iterB.hasNext(); ) {
      assertEquals(iterA.next(), iterB.next());
    }
    assertFalse(iterA.hasNext());
    assertFalse(iterB.hasNext());
  }
 /** Constructs and returns a {@link HIRModel}. */
 @Override
 public HIRModel get() {
   LongSet items = buildContext.getItems();
   LongIterator outer = items.iterator();
   while (outer.hasNext()) {
     final long item1 = outer.nextLong();
     final SparseVector vec1 = buildContext.itemVector(item1);
     LongIterator inner = items.iterator();
     while (inner.hasNext()) {
       final long item2 = inner.nextLong();
       SparseVector vec2 = buildContext.itemVector(item2);
       DAMatrix.putItemPair(item1, vec1, item2, vec2);
     }
   }
   return new HIRModel(
       DAMatrix.buildMatrix(), RSMatrix.RowStochastic(), TFMatrix.ColumnStochastic());
 }
  /**
   * Creates a matrix to process genre data and generate the first factor of the proximity matrix
   * needed for a {@code HIRItemScorer}.
   *
   * @param dao The DataAccessObject interfacing with the item data for the model
   * @param gDao The genreDataAccessObject interfacing with the genre data for the model
   */
  public RowStochasticFactorOfProximity(ItemDAO dao, ItemGenreDAO gDao) {
    LongSet items = dao.getItemIds();
    int genreSize = gDao.getGenreSize();
    itemSize = items.size();
    double[][] data = new double[itemSize][genreSize];

    rowStochastic = MatrixUtils.createRealMatrix(data);

    int i = 0;
    LongIterator iter = items.iterator();
    while (iter.hasNext()) {
      long item = iter.nextLong();
      rowStochastic.setRowVector(i, gDao.getItemGenre(item));
      i++;
    }
  }
示例#4
0
 /**
  * Creates a new tree set using elements provided by a type-specific iterator.
  *
  * @param i a type-specific iterator whose elements will fill the set.
  */
 public LongAVLTreeSet(final LongIterator i) {
   while (i.hasNext()) add(i.nextLong());
 }