/** 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++; } }
/** * 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()); }