public abstract class TensorRecommender extends java.lang.Object implements Recommender
Modifier and Type | Field and Description |
---|---|
java.util.ArrayList<com.google.common.collect.BiMap<java.lang.String,java.lang.Integer>> |
allFeaturesMappingData |
protected Configuration |
conf
conf
|
protected RecommenderContext |
context
RecommenderContext
|
protected float |
decay
decay of learning rate
|
protected int[] |
dimensions
dimensions indices
|
protected boolean |
earlyStop
early-stop criteria
|
protected double |
globalMean
global mean of ratings
|
protected boolean |
isBoldDriver
whether to adjust learning rate automatically
|
protected boolean |
isRanking
is ranking or rating
|
protected int |
itemDimension
user and item index of tensor
|
com.google.common.collect.BiMap<java.lang.String,java.lang.Integer> |
itemMappingData
item Mapping Data
|
protected double |
lastLoss
objective loss
|
protected float |
learnRate
learn rate, maximum learning rate
|
protected org.apache.commons.logging.Log |
LOG
LOG
|
protected double |
loss
objective loss
|
protected float |
maxLearnRate
learn rate, maximum learning rate
|
protected double |
maxRate
Maximum rate of rating scale
|
protected double |
minRate
Minimum rate of rating scale
|
protected int |
numDimensions
dimensions
|
protected int |
numFactors
number of factors
|
protected int |
numItems
the number of items
|
protected int |
numIterations
the number of iterations
|
protected int |
numUsers
the number of users
|
protected RecommendedList |
recommendedList
Recommended Item List
|
protected float |
reg
regularization of user, item and all context
|
protected SparseTensor |
testTensor
testTensor
|
protected int |
topN
topN
|
protected SparseTensor |
trainTensor
train Tensor
|
protected int |
userDimension
user and item index of tensor
|
com.google.common.collect.BiMap<java.lang.String,java.lang.Integer> |
userMappingData
user Mapping Data
|
protected SparseTensor |
validTensor
validTensor
|
protected boolean |
verbose
verbose
|
Constructor and Description |
---|
TensorRecommender() |
Modifier and Type | Method and Description |
---|---|
protected void |
cleanup()
cleanup
|
double |
evaluate(RecommenderEvaluator evaluator)
evaluate
|
java.util.Map<Measure.MeasureValue,java.lang.Double> |
evaluateMap()
evaluate Map
|
DataModel |
getDataModel()
get DataModel
|
java.util.List<RecommendedItem> |
getRecommendedList()
get Recommended List
|
protected boolean |
isConverged(int iter)
Post each iteration, we do things:
print debug information
check if converged
if not, adjust learning rate
|
void |
loadModel(java.lang.String filePath)
load Model
|
protected abstract double |
predict(int[] keys)
predict a specific rating for user userIdx on item itemIdx with some other contexts indices, note that the
prediction is not bounded.
|
protected double |
predict(int[] keys,
boolean bound)
predict a specific rating for user userIdx on item itemIdx with some other contexts indices.
|
protected RecommendedList |
recommend()
recommend
* predict the ranking scores or ratings in the test data
|
void |
recommend(RecommenderContext context)
recommend
|
protected RecommendedList |
recommendRank()
recommend
* predict the ranking scores in the test data
|
protected RecommendedList |
recommendRating()
recommend
* predict the ratings in the test data
|
void |
saveModel(java.lang.String filePath)
save Model
|
void |
setContext(RecommenderContext context)
set Context
|
protected void |
setup()
setup
|
protected abstract void |
trainModel()
train Model
|
protected void |
updateLRate(int iter)
Update current learning rate after each epoch
bold driver: Gemulla et al., Large-scale matrix factorization with distributed stochastic gradient descent, KDD 2011. constant decay: Niu et al, Hogwild!: A lock-free approach to parallelizing stochastic gradient descent, NIPS 2011. Leon Bottou, Stochastic Gradient Descent Tricks more ways to adapt learning rate can refer to: http://www.willamette.edu/~gorr/classes/cs449/momrate.html |
protected final org.apache.commons.logging.Log LOG
protected boolean isRanking
protected int topN
protected Configuration conf
protected RecommenderContext context
protected SparseTensor trainTensor
protected SparseTensor testTensor
protected SparseTensor validTensor
protected RecommendedList recommendedList
public com.google.common.collect.BiMap<java.lang.String,java.lang.Integer> userMappingData
public com.google.common.collect.BiMap<java.lang.String,java.lang.Integer> itemMappingData
public java.util.ArrayList<com.google.common.collect.BiMap<java.lang.String,java.lang.Integer>> allFeaturesMappingData
protected boolean earlyStop
protected int numDimensions
protected int[] dimensions
protected int numFactors
protected double loss
protected double lastLoss
protected boolean isBoldDriver
protected float decay
protected boolean verbose
protected float learnRate
protected float maxLearnRate
protected int numIterations
protected int userDimension
protected int itemDimension
protected float reg
protected int numUsers
protected int numItems
protected double maxRate
protected double minRate
protected double globalMean
protected void setup() throws LibrecException
LibrecException
- if error occurs during setting uppublic void recommend(RecommenderContext context) throws LibrecException
recommend
in interface Recommender
context
- recommender contextLibrecException
- if error occurs during recommendingprotected abstract void trainModel() throws LibrecException
LibrecException
- if error occurs during trainingprotected RecommendedList recommend() throws LibrecException
LibrecException
- if error occurs during recommendingprotected RecommendedList recommendRank() throws LibrecException
LibrecException
- if error occurs during recommendingprotected RecommendedList recommendRating() throws LibrecException
LibrecException
- if error occurs during recommendingprotected abstract double predict(int[] keys) throws LibrecException
keys
- user index, item index and context indicesLibrecException
- if error occurs during predictingprotected double predict(int[] keys, boolean bound) throws LibrecException
keys
- user index, item index and context indicesbound
- whether there is a boundLibrecException
- if error occurs during predictingprotected boolean isConverged(int iter) throws LibrecException
iter
- current iterationLibrecException
- if error occursprotected void updateLRate(int iter)
iter
- the current iterationprotected void cleanup() throws LibrecException
LibrecException
- if error occurs during cleaning uppublic double evaluate(RecommenderEvaluator evaluator) throws LibrecException
Recommender
evaluate
in interface Recommender
evaluator
- recommender evaluatorLibrecException
- if error occurs during evaluatingpublic java.util.Map<Measure.MeasureValue,java.lang.Double> evaluateMap() throws LibrecException
Recommender
evaluateMap
in interface Recommender
LibrecException
- if error occurs during constructing evaluate mappublic DataModel getDataModel()
Recommender
getDataModel
in interface Recommender
public void loadModel(java.lang.String filePath)
Recommender
loadModel
in interface Recommender
filePath
- file pathpublic void saveModel(java.lang.String filePath)
Recommender
saveModel
in interface Recommender
filePath
- file pathpublic java.util.List<RecommendedItem> getRecommendedList()
Recommender
getRecommendedList
in interface Recommender
public void setContext(RecommenderContext context)
Recommender
setContext
in interface Recommender
context
- the context to setCopyright © 2017. All Rights Reserved.