Example usage for org.apache.mahout.cf.taste.impl.recommender.svd PersistenceStrategy load

List of usage examples for org.apache.mahout.cf.taste.impl.recommender.svd PersistenceStrategy load

Introduction

In this page you can find the example usage for org.apache.mahout.cf.taste.impl.recommender.svd PersistenceStrategy load.

Prototype

Factorization load() throws IOException;

Source Link

Document

Load a factorization from a persistent store.

Usage

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   www .  ja  v a2  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: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 {//from   w w  w .  ja  va  2s . c  o  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 w ww .  j  a v a 2s .  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);
}

From source file:recommender.MyRecommender.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   w  w  w. ja  va  2  s . c o m
 * @param factorizer
 * @param candidateItemsStrategy
 * @param persistenceStrategy
 *
 * @throws TasteException
 */
public MyRecommender(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);
}