Example usage for org.apache.mahout.cf.taste.impl.common FastIDSet addAll

List of usage examples for org.apache.mahout.cf.taste.impl.common FastIDSet addAll

Introduction

In this page you can find the example usage for org.apache.mahout.cf.taste.impl.common FastIDSet addAll.

Prototype

public boolean addAll(FastIDSet c) 

Source Link

Usage

From source file:com.buddycloud.channeldirectory.search.handler.common.mahout.ChannelRecommender.java

License:Apache License

private int getPreferenceCount(long theUserId) throws TasteException {
    FastIDSet possibleItemIDs = new FastIDSet();
    long[] theNeighborhood = userNeighborhood.getUserNeighborhood(theUserId);
    DataModel dataModel = recommenderDataModel.getDataModel();

    for (long userID : theNeighborhood) {
        possibleItemIDs.addAll(dataModel.getItemIDsFromUser(userID));
    }/*ww w  .j  a v a2  s . c o m*/
    possibleItemIDs.removeAll(dataModel.getItemIDsFromUser(theUserId));

    return possibleItemIDs.size();
}

From source file:com.webir.popcornsaver.cluster.TreeClusteringRecommender.java

License:Apache License

private void findClusters(List<FastIDSet> newClusters) throws TasteException {
    if (clusteringByThreshold) {
        Pair<FastIDSet, FastIDSet> nearestPair = findNearestClusters(newClusters);
        if (nearestPair != null) {
            FastIDSet cluster1 = nearestPair.getFirst();
            FastIDSet cluster2 = nearestPair.getSecond();
            while (clusterSimilarity.getSimilarity(cluster1, cluster2) >= clusteringThreshold) {
                newClusters.remove(cluster1);
                newClusters.remove(cluster2);
                FastIDSet merged = new FastIDSet(cluster1.size() + cluster2.size());
                merged.addAll(cluster1);
                merged.addAll(cluster2);
                newClusters.add(merged);
                nearestPair = findNearestClusters(newClusters);
                if (nearestPair == null) {
                    break;
                }//from   w  w w .  j a v a  2  s  .  co m
                cluster1 = nearestPair.getFirst();
                cluster2 = nearestPair.getSecond();
            }
        }
    } else {
        while (newClusters.size() > numClusters) {
            Pair<FastIDSet, FastIDSet> nearestPair = findNearestClusters(newClusters);
            if (nearestPair == null) {
                break;
            }
            FastIDSet cluster1 = nearestPair.getFirst();
            FastIDSet cluster2 = nearestPair.getSecond();
            newClusters.remove(cluster1);
            newClusters.remove(cluster2);
            FastIDSet merged = new FastIDSet(cluster1.size() + cluster2.size());
            merged.addAll(cluster1);
            merged.addAll(cluster2);
            newClusters.add(merged);
        }
    }
}

From source file:com.webir.popcornsaver.cluster.TreeClusteringRecommender.java

License:Apache License

private List<RecommendedItem> computeTopRecsForCluster(FastIDSet cluster) throws TasteException {
    DataModel dataModel = getDataModel();
    FastIDSet possibleItemIDs = new FastIDSet();
    LongPrimitiveIterator it = cluster.iterator();
    while (it.hasNext()) {
        possibleItemIDs.addAll(dataModel.getItemIDsFromUser(it.next()));
    }/*from  w  w w .  j a  v a 2 s .c  o m*/

    TopItems.Estimator<Long> estimator = new Estimator(cluster);

    List<RecommendedItem> topItems = TopItems.getTopItems(possibleItemIDs.size(), possibleItemIDs.iterator(),
            null, estimator);

    log.debug("Recommendations are: {}", topItems);
    return Collections.unmodifiableList(topItems);
}

From source file:de.unima.dws.webmining.rs.recommender.AvgUserPrefAdaptedUserBasedRecommender.java

License:Apache License

protected FastIDSet getAllOtherItems(long[] theNeighborhood, long theUserID) throws TasteException {
    DataModel dataModel = getDataModel();
    FastIDSet possibleItemIDs = new FastIDSet();
    for (long userID : theNeighborhood) {
        possibleItemIDs.addAll(dataModel.getItemIDsFromUser(userID));
    }/*from   w  ww . j a va2s .c o  m*/
    possibleItemIDs.removeAll(dataModel.getItemIDsFromUser(theUserID));
    return possibleItemIDs;
}

From source file:io.prediction.engines.base.mahout.AllValidItemsCandidateItemsStrategy.java

License:Apache License

protected FastIDSet doGetCandidateItemsInternal(long[] validItemIDs, long[] seenItemIDs) throws TasteException {
    FastIDSet possibleItemsIDs = new FastIDSet();
    possibleItemsIDs.addAll(this.validItemIDs);

    if (seenItemIDs != null)
        possibleItemsIDs.removeAll(seenItemIDs);

    return possibleItemsIDs;
}