net.librec.recommender.ext.AssociationRuleRecommender Maven / Gradle / Ivy
Show all versions of librec-core Show documentation
/**
* Copyright (C) 2016 LibRec
*
* This file is part of LibRec.
* LibRec is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* LibRec is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with LibRec. If not, see .
*/
package net.librec.recommender.ext;
import com.clearspring.analytics.util.Lists;
import com.google.common.collect.HashBasedTable;
import com.google.common.collect.Maps;
import com.google.common.collect.Table;
import net.librec.common.LibrecException;
import net.librec.math.structure.*;
import net.librec.recommender.AbstractRecommender;
import net.librec.recommender.MatrixRecommender;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* Choonho Kim and Juntae Kim, A Recommendation Algorithm Using Multi-Level Association Rules, WI 2003.
*
* Simple Association Rule Recommender: we do not consider the item categories (or multi levels) used in the original
* paper. Besides, we consider all association rules without ruling out weak ones (by setting high support and
* confidence threshold).
*
* @author guoguibing and wangkeqiang
*/
public class AssociationRuleRecommender extends MatrixRecommender {
/**
* confidence matrix of association rules
*/
private SequentialAccessSparseMatrix associations;
private DenseMatrix userItemRates;
// /**
// * user-vector cache, item-vector cache
// */
// protected LoadingCache userCache;
// /**
// * Guava cache configuration
// */
// protected static String cacheSpec;
/**
* setup
*
* @throws LibrecException if error occurs
*/
@Override
protected void setup() throws LibrecException {
super.setup();
// cacheSpec = conf.get("guava.cache.spec",
// "maximumSize=200,expireAfterAccess=2m");
userItemRates = new DenseMatrix(trainMatrix.rowSize(), trainMatrix.columnSize());
for (MatrixEntry entry : trainMatrix) {
userItemRates.set(entry.row(), entry.column(), entry.get());
}
// userCache = trainMatrix.rowCache(cacheSpec);
}
@Override
protected void trainModel() throws LibrecException {
// plus to adapt to 3.0
List