首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 其他教程 > 开源软件 >

mahout推荐发动机使用hadoop(三) 协同矩阵与用户向量相乘

2013-03-06 
mahout推荐引擎使用hadoop(三) 协同矩阵与用户向量相乘??下边也是同样分析一下这个三个MapReduce的细节:?1

mahout推荐引擎使用hadoop(三) 协同矩阵与用户向量相乘

?

?下边也是同样分析一下这个三个MapReduce的细节:

?

1、Mapper: SimilarityMatrixRowWrapperMapper 类,将协同矩阵的一行拿出来,通过包装,封装成VectorOrPrefWritable类,与那边的UserVectorSplitterMapper 的输出类型一致

?

第四步,协同矩阵和用户向量相乘,得到推荐结果

?

public final class PartialMultiplyMapper extends    Mapper<VarIntWritable,VectorAndPrefsWritable,VarLongWritable,PrefAndSimilarityColumnWritable> {  @Override  protected void map(VarIntWritable key,                     VectorAndPrefsWritable vectorAndPrefsWritable,                     Context context) throws IOException, InterruptedException {    Vector similarityMatrixColumn = vectorAndPrefsWritable.getVector();    List<Long> userIDs = vectorAndPrefsWritable.getUserIDs();    List<Float> prefValues = vectorAndPrefsWritable.getValues();    VarLongWritable userIDWritable = new VarLongWritable();    PrefAndSimilarityColumnWritable prefAndSimilarityColumn = new PrefAndSimilarityColumnWritable();    for (int i = 0; i < userIDs.size(); i++) {      long userID = userIDs.get(i);      float prefValue = prefValues.get(i);      if (!Float.isNaN(prefValue)) {        prefAndSimilarityColumn.set(prefValue, similarityMatrixColumn);        userIDWritable.set(userID);        context.write(userIDWritable, prefAndSimilarityColumn);      }    }  }}
?

?

?

?

?

热点排行