Example usage for org.apache.mahout.cf.taste.impl.model.jdbc ReloadFromJDBCDataModel ReloadFromJDBCDataModel

List of usage examples for org.apache.mahout.cf.taste.impl.model.jdbc ReloadFromJDBCDataModel ReloadFromJDBCDataModel

Introduction

In this page you can find the example usage for org.apache.mahout.cf.taste.impl.model.jdbc ReloadFromJDBCDataModel ReloadFromJDBCDataModel.

Prototype

public ReloadFromJDBCDataModel(JDBCDataModel delegate) throws TasteException 

Source Link

Usage

From source file:DatabaseConnection.java

License:Apache License

/**
 * Sets the dataModel for this connection
 *//*from  ww  w  .  j  a  va 2  s.c om*/
public void setDataModel() {
    JDBCDataModel dataModel = new MySQLJDBCDataModel(dataSource, viewName, "userId", "numericalId",
            "preferenceValue", "time_stamp");

    try {
        reloadModel = new ReloadFromJDBCDataModel(dataModel);
    } catch (TasteException e) {
        e.printStackTrace();
    }
    if (reloadModel != null) {
        model = reloadModel.getDelegateInMemory();

    } else
        model = dataModel;

}

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

License:Apache License

private void createDataModel() throws TasteException {
    this.dataModel = new ReloadFromJDBCDataModel(
            new PostgreSQLBooleanPrefJDBCDataModel(dataSource.getDataSource()));
}

From source file:com.github.gurelkaynak.recommendationengine.jdbi.DataModelFactory.java

public ReloadFromJDBCDataModel build(PGPoolingDataSource dataSource) throws TasteException {
    return new ReloadFromJDBCDataModel(new PostgreSQLJDBCDataModel(dataSource, this.table, this.userField,
            this.itemField, this.ratingField, null));
}

From source file:com.rssrecommender.services.MahoutService.java

@PostConstruct
public void init() {
    try {//  w  ww .  j  a  v a 2 s.  c om
        dataSource = new MysqlConnectionPoolDataSource();

        dataSource.setServerName("localhost");
        dataSource.setUser("root");
        dataSource.setPassword("1234");
        dataSource.setDatabaseName("rss_rec");
        dataSource.setCachePreparedStatements(true);
        dataSource.setCachePrepStmts(true);
        dataSource.setCacheResultSetMetadata(true);
        dataSource.setAlwaysSendSetIsolation(true);
        dataSource.setElideSetAutoCommits(true);

        model = new MySQLJDBCDataModel(dataSource, "user_likes_article", "user_id", "article_id", "rating",
                null);
        m = new ReloadFromJDBCDataModel(model);
        is = new PearsonCorrelationSimilarity(m);

        //            ItemSimilarity is = new EuclideanDistanceSimilarity(model, Weighting.WEIGHTED);
        //            cis = new CachingItemSimilarity(is, 150);
        r = new GenericItemBasedRecommender(m, is);
        rsr = new IDRescorer() {

            @Override
            public double rescore(long id, double originalScore) {
                Article a = af.find((int) id);
                long diff = Calendar.getInstance().getTimeInMillis() - a.getDate().getTime() + 1;
                double time = 1.0d / (diff / (1000 * 360 * 12)); // half day period since feeds are update regularly
                return originalScore * time;
            }

            @Override
            public boolean isFiltered(long id) {
                //always rescore
                return false;
            }
        };
        //            Optimizer optimizer = new ConjugateGradientOptimizer();
        //            r = new KnnItemBasedRecommender(m, is, optimizer, 5);
        //          
    } catch (TasteException ex) {
        Logger.getLogger(MahoutService.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:recommender.MyRecommender.java

public void init() {
    if (svdRecommender == null) {
        try {//  w ww. j av  a2 s .c o  m
            // load properties file, includes database settings (url, username, password) and connection pool maximum number of connections (used by ConnectionPool)
            prop = new Properties();
            prop.load(Recommender.class.getResourceAsStream("settings.properties"));

            // load settings from MySQL database
            loadSettings();

            // load macro classes and sub classes into bidirectional map
            loadCategories();

            // load users profiles
            loadUsersProfiles();

            // load groups with their priorities
            loadGroups();

            // load groups with their translations
            loadGroupsLangs();

            // JDBC data model
            mysql_datasource = new MysqlDataSource();

            mysql_datasource.setServerName(prop.getProperty("db_hostname"));
            mysql_datasource.setUser(prop.getProperty("db_username"));
            mysql_datasource.setPassword(prop.getProperty("db_password"));
            mysql_datasource.setDatabaseName("recommender");

            /*dm = new MySQLJDBCDataModel(
             mysql_datasource, "preferences", "user_id",
             "item_id", "preference", "timestamp");*/
            dm = new MySQLJDBCDataModel(mysql_datasource, "preferences", "user_id", "item_id", "preference",
                    "timestamp");

            // Switching to MEMORY mode. Load all data from database into memory first
            // there is no need of a ConnectionPool because this technique uses a memory-based ReloadFromJDBCDataModel wrapper,
            // decreasing the number of connections to 1
            rdm = new ReloadFromJDBCDataModel((JDBCDataModel) dm);

            // Factorize matrix
            // factorizes the rating matrix using "Alternating-Least-Squares with Weighted--Regularization" as described in the paper
            // "Large-scale Collaborative Filtering for the Netflix Prize" http://machinelearning202.pbworks.com/w/file/fetch/60922097/netflix_aaim08%28submitted%29.pdf
            factorizer = new ALSWRFactorizer(rdm, 2, 0.025, 3);

            // Configure SVD algorithm
            svdRecommender = new SVDRecommender(rdm, factorizer);
        } catch (IOException | TasteException ex) {
            java.util.logging.Logger.getLogger(Recommender.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
}

From source file:smartcityrecommender.Recommender.java

License:Open Source License

public static void init() {
    if (svdRecommender == null) {
        try {/*  www . j a va2 s.co  m*/
            // load properties file, includes database settings (url, username, password) and connection pool maximum number of connections (used by ConnectionPool)
            prop = new Properties();
            prop.load(Recommender.class.getResourceAsStream("settings.properties"));

            // load settings from MySQL database
            loadSettings();

            //start logging this recommender stats to db every n seconds, read from settings (recommenderLoggingPeriod)
            scheduledThreadPool = Executors.newScheduledThreadPool(1);
            RecommenderLoggerStatus logger = new RecommenderLoggerStatus();

            scheduledThreadPool.scheduleAtFixedRate(logger, 1, 86400, TimeUnit.SECONDS); // the logging period is 1 day

            // load macro classes and sub classes into bidirectional map
            loadCategories();

            // load users profiles
            loadUsersProfiles();

            // load groups with their priorities
            loadGroups();

            // load groups with their translations
            loadGroupsLangs();

            // JDBC data model
            mysql_datasource = new MysqlDataSource();

            mysql_datasource.setServerName(prop.getProperty("db_hostname"));
            mysql_datasource.setUser(prop.getProperty("db_username"));
            mysql_datasource.setPassword(prop.getProperty("db_password"));
            mysql_datasource.setDatabaseName("recommender");

            dm = new MySQLJDBCDataModel(mysql_datasource, "preferences", "user_id", "item_id", "preference",
                    "timestamp");

            // Switching to MEMORY mode. Load all data from database into memory first
            // there is no need of a ConnectionPool because this technique uses a memory-based ReloadFromJDBCDataModel wrapper,
            // decreasing the number of connections to 1
            rdm = new ReloadFromJDBCDataModel((JDBCDataModel) dm);

            // Factorize matrix
            // factorizes the rating matrix using "Alternating-Least-Squares with Weighted--Regularization" as described in the paper
            // "Large-scale Collaborative Filtering for the Netflix Prize" http://machinelearning202.pbworks.com/w/file/fetch/60922097/netflix_aaim08%28submitted%29.pdf
            factorizer = new ALSWRFactorizer(rdm, 2, 0.025, 3);

            // Configure SVD algorithm
            svdRecommender = new SVDRecommender(rdm, factorizer);
        } catch (IOException | TasteException ex) {
            Logger.getLogger(Recommender.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
}