Example usage for org.apache.mahout.cf.taste.impl.common RefreshHelper RefreshHelper

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

Introduction

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

Prototype

public RefreshHelper(Callable<?> refreshRunnable) 

Source Link

Usage

From source file:com.mashup.resys.neighborhood.AbstractUserNeighborhood.java

License:Apache License

AbstractUserNeighborhood(UserSimilarity userSimilarity, DataModel dataModel, double samplingRate) {
    if ((userSimilarity == null) || (dataModel == null)) {
        throw new IllegalArgumentException("userSimilarity or dataModel is null");
    }//w w  w  . j  a  v  a2  s .c o m
    if (Double.isNaN(samplingRate) || (samplingRate <= 0.0) || (samplingRate > 1.0)) {
        throw new IllegalArgumentException("samplingRate must be in (0,1]");
    }
    this.userSimilarity = userSimilarity;
    this.dataModel = dataModel;
    this.samplingRate = samplingRate;
    this.refreshHelper = new RefreshHelper(null);
    this.refreshHelper.addDependency(this.dataModel);
    this.refreshHelper.addDependency(this.userSimilarity);
}

From source file:com.recsys.factorizer.CustomAbstractFactorizer.java

License:Apache License

protected CustomAbstractFactorizer(DataModel dataModel) throws TasteException {
    this.dataModel = dataModel;
    buildMappings();//from ww  w  . ja v  a2 s .c o m
    refreshHelper = new RefreshHelper(new Callable<Object>() {
        @Override
        public Object call() throws TasteException {
            buildMappings();
            return null;
        }
    });
    refreshHelper.addDependency(dataModel);
}

From source file:com.recsys.svd.CustomSVDRecommender.java

License:Apache License

/**
 * Create an SVDRecommender using a persistent store to cache
 * factorizations. A factorization is loaded from the store if present,
 * otherwise a new factorization is computed and saved in the store.
 *
 * The {@link #refresh(java.util.Collection) refresh} method recomputes the
 * factorization and overwrites the store.
 *
 * @param dataModel//from  w  w  w . ja v  a 2 s.c  om
 * @param factorizer
 * @param candidateItemsStrategy
 * @param persistenceStrategy
 *
 * @throws TasteException
 */
public CustomSVDRecommender(DataModel dataModel, Factorizer factorizer,
        CandidateItemsStrategy candidateItemsStrategy, PersistenceStrategy persistenceStrategy)
        throws TasteException {
    super(dataModel, candidateItemsStrategy);
    this.factorizer = Preconditions.checkNotNull(factorizer);
    this.persistenceStrategy = Preconditions.checkNotNull(persistenceStrategy);
    try {
        factorization = persistenceStrategy.load();
    } catch (IOException e) {
        throw new TasteException("Error loading factorization", e);
    }

    if (factorization == null) {
        train();
    }

    refreshHelper = new RefreshHelper(new Callable<Object>() {
        @Override
        public Object call() throws TasteException {
            train();
            return null;
        }
    });
    refreshHelper.addDependency(getDataModel());
    refreshHelper.addDependency(factorizer);
}

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

License:Apache License

/**
 * @param dataModel//  ww  w  . j  a  va 2 s  .c  om
 *          {@link DataModel} which provdes users
 * @param clusterSimilarity
 *          {@link ClusterSimilarity} used to compute cluster similarity
 * @param numClusters
 *          desired number of clusters to create
 * @param samplingRate
 *          percentage of all cluster-cluster pairs to consider when finding next-most-similar clusters.
 *          Decreasing this value from 1.0 can increase performance at the cost of accuracy
 * @throws IllegalArgumentException
 *           if arguments are <code>null</code>, or <code>numClusters</code> is less than 2, or samplingRate
 *           is {@link Double#NaN} or nonpositive or greater than 1.0
 */
public TreeClusteringRecommender(DataModel dataModel, ClusterSimilarity clusterSimilarity, int numClusters,
        double samplingRate) throws TasteException {
    super(dataModel);
    Preconditions.checkArgument(clusterSimilarity != null, "clusterSimilarity is null");
    Preconditions.checkArgument(numClusters >= 2, "numClusters must be at least 2");
    Preconditions.checkArgument(samplingRate > 0.0 && samplingRate <= 1.0, "samplingRate is invalid: %f",
            samplingRate);
    this.clusterSimilarity = clusterSimilarity;
    this.numClusters = numClusters;
    this.clusteringThreshold = Double.NaN;
    this.clusteringByThreshold = false;
    this.samplingRate = samplingRate;
    this.refreshHelper = new RefreshHelper(new Callable<Object>() {
        @Override
        public Object call() throws TasteException {
            buildClusters();
            return null;
        }
    });
    refreshHelper.addDependency(dataModel);
    refreshHelper.addDependency(clusterSimilarity);
    buildClusters();
}

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

License:Apache License

/**
 * @param dataModel//from ww  w  . j  av a2  s.c  o  m
 *          {@link DataModel} which provides users
 * @param clusterSimilarity
 *          {@link ClusterSimilarity} used to compute cluster similarity
 * @param clusteringThreshold
 *          clustering similarity threshold; clusters will be aggregated into larger clusters until the next
 *          two nearest clusters' similarity drops below this threshold
 * @param samplingRate
 *          percentage of all cluster-cluster pairs to consider when finding next-most-similar clusters.
 *          Decreasing this value from 1.0 can increase performance at the cost of accuracy
 * @throws IllegalArgumentException
 *           if arguments are <code>null</code>, or <code>clusteringThreshold</code> is {@link Double#NaN},
 *           or samplingRate is {@link Double#NaN} or nonpositive or greater than 1.0
 */
public TreeClusteringRecommender(DataModel dataModel, ClusterSimilarity clusterSimilarity,
        double clusteringThreshold, double samplingRate) throws TasteException {
    super(dataModel);
    Preconditions.checkArgument(clusterSimilarity != null, "clusterSimilarity is null");
    Preconditions.checkArgument(!Double.isNaN(clusteringThreshold), "clusteringThreshold must not be NaN");
    Preconditions.checkArgument(samplingRate > 0.0 && samplingRate <= 1.0, "samplingRate is invalid: %f",
            samplingRate);
    this.clusterSimilarity = clusterSimilarity;
    this.numClusters = Integer.MIN_VALUE;
    this.clusteringThreshold = clusteringThreshold;
    this.clusteringByThreshold = true;
    this.samplingRate = samplingRate;
    this.refreshHelper = new RefreshHelper(new Callable<Object>() {
        @Override
        public Object call() throws TasteException {
            buildClusters();
            return null;
        }
    });
    refreshHelper.addDependency(dataModel);
    refreshHelper.addDependency(clusterSimilarity);
    buildClusters();
}

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

License:Apache License

public AvgUserPrefAdaptedUserBasedRecommender(DataModel dataModel, UserNeighborhood neighborhood,
        UserSimilarity similarity) {/*  w ww . j a  va  2 s. c  om*/
    super(dataModel);
    this.neighborhood = neighborhood;
    this.similarity = similarity;
    this.refreshHelper = new RefreshHelper(new Callable<Void>() {

        public Void call() {
            capper = buildCapper();
            return null;
        }
    });
    refreshHelper.addDependency(dataModel);
    refreshHelper.addDependency(similarity);
    refreshHelper.addDependency(neighborhood);
    capper = buildCapper();
}

From source file:lib.similarity.AbstractUnboundedSimilarity.java

License:Apache License

/**
 * <p>/*from w w w . j  a  va  2  s. com*/
 * Creates an AbstractUnboundedSimilarity.
 * </p>
 */
AbstractUnboundedSimilarity(final DataModel dataModel) throws TasteException {
    super(dataModel);

    this.cachedNumItems = dataModel.getNumItems();
    this.cachedNumUsers = dataModel.getNumUsers();
    this.refreshHelper = new RefreshHelper(new Callable<Object>() {
        @Override
        public Object call() throws TasteException {
            cachedNumItems = dataModel.getNumItems();
            cachedNumUsers = dataModel.getNumUsers();
            return null;
        }
    });
}

From source file:net.ufida.info.mahout.common.CachingRecommender.java

License:Apache License

public CachingRecommender(Recommender recommender) throws TasteException {
    Preconditions.checkArgument(recommender != null, "recommender is null");
    this.recommender = recommender;
    maxHowMany = new int[] { 1 };
    // Use "num users" as an upper limit on cache size. Rough guess.
    int numUsers = recommender.getDataModel().getNumUsers();
    recommendationsRetriever = new RecommendationRetriever();
    recommendationCache = new Cache<Long, Recommendations>(recommendationsRetriever, numUsers);
    estimatedPrefCache = new Cache<LongPair, Float>(new EstimatedPrefRetriever(), numUsers);
    refreshHelper = new RefreshHelper(new Callable<Object>() {
        @Override//from w  w  w .jav a2s  .com
        public Object call() {
            clear();
            return null;
        }
    });
    refreshHelper.addDependency(recommender);
}

From source file:org.plista.kornakapi.core.recommender.FoldingFactorizationBasedRecommender.java

License:Apache License

public FoldingFactorizationBasedRecommender(DataModel dataModel, CandidateItemsStrategy candidateItemsStrategy,
        PersistenceStrategy persistenceStrategy, int numEstimationThreads) throws TasteException {
    super(dataModel, candidateItemsStrategy);

    this.persistenceStrategy = Preconditions.checkNotNull(persistenceStrategy);
    try {/*w  w w.j  a va2  s .co  m*/
        Factorization factorization = persistenceStrategy.load();
        Preconditions.checkNotNull(factorization, "PersistenceStrategy must provide an initial factorization");
        foldingFactorization = new FoldingFactorization(factorization);
    } catch (IOException e) {
        throw new TasteException("Error loading factorization", e);
    }
    this.numEstimationThreads = numEstimationThreads;

    refreshHelper = new RefreshHelper(new Callable<Object>() {
        @Override
        public Object call() throws TasteException {
            reloadFactorization();
            return null;
        }
    });
    refreshHelper.addDependency(getDataModel());
    refreshHelper.addDependency(candidateItemsStrategy);
}

From source file:recommender.CustomRecommender.java

/**
 * Create a custom SVDRecommender using a persistent store to cache
 * factorizations. A factorization is loaded from the store if present,
 * otherwise a new factorization is computed and saved in the store.
 *
 * The {@link #refresh(java.util.Collection) refresh} method recomputes the
 * factorization and overwrites the store.
 *
 * @param dataModel/*from   ww w .  j  a  va2 s.c o  m*/
 * @param factorizer
 * @param candidateItemsStrategy
 * @param persistenceStrategy
 *
 * @throws TasteException
 */
public CustomRecommender(DataModel dataModel, Factorizer factorizer,
        CandidateItemsStrategy candidateItemsStrategy, PersistenceStrategy persistenceStrategy)
        throws TasteException {
    super(dataModel, candidateItemsStrategy);
    this.factorizer = Preconditions.checkNotNull(factorizer);
    this.persistenceStrategy = Preconditions.checkNotNull(persistenceStrategy);
    try {
        factorization = persistenceStrategy.load();
    } catch (IOException e) {
        throw new TasteException("Error loading factorization", e);
    }

    if (factorization == null) {
        train();
    }

    refreshHelper = new RefreshHelper(new Callable<Object>() {
        @Override
        public Object call() throws TasteException {
            train();
            return null;
        }
    });
    refreshHelper.addDependency(getDataModel());
    refreshHelper.addDependency(factorizer);
    refreshHelper.addDependency(candidateItemsStrategy);
}