Mahout版本:0.7,hadoop版本:1.0.4,jdk:1.7.0_25 64bit。

接上篇,分析完3个Job后得到继续往下:其实就剩下两个函数了:

 List<Map.Entry<MatrixSlice, EigenStatus>> prunedEigenMeta = pruneEigens(eigenMetaData);

    saveCleanEigens(new Configuration(), prunedEigenMeta);

看pruneEigens函数:

private List<Map.Entry<MatrixSlice, EigenStatus>> pruneEigens(Map<MatrixSlice, EigenStatus> eigenMetaData) {
List<Map.Entry<MatrixSlice, EigenStatus>> prunedEigenMeta = Lists.newArrayList(); for (Map.Entry<MatrixSlice, EigenStatus> entry : eigenMetaData.entrySet()) {
if (Math.abs(1 - entry.getValue().getCosAngle()) < maxError && entry.getValue().getEigenValue() > minEigenValue) {
prunedEigenMeta.add(entry);
}
}

看到这里其实是做筛选的,三个job生成了三个eigenStatus,每个eigenStatus都有一个cosAngle和eigenValue,用这两个参数来判断是否应该保留,这三个总结如下:

第一个;
resultantVector:
[-285.43017035605783, -61.30237570857193, -68.94124551381431, -520.2302762811703, -3232.201254912267, -32.31785150049481, -37.63572264009423, -12.025276244275622, -28.58260635344015, -6.8801603142200065, -28.491567864130573, -68.13521243410383, 4382.173720122737]
vector:
[0.01671441233225078, 0.0935655369363106, 0.09132650234523473, -0.0680324702834075, -0.9461123439509093, 0.10210271255992123, 0.10042714365337412, 0.11137954332150339, 0.10331974823993555, 0.10621406378767596, 0.10586960137353602, 0.09262650242313884, 0.09059904726143547]
eigenValue=newNorm/oldNorm=5479.061620543984/1=5479.061620543984;
cosAngle=resultantVector.dot(vector) / newNorm * oldNorm=0.6300724679092792 第二个:
resultantVector:
vector:
[0.01180448947054423, 0.001703710024210367, 0.002100735590662567, 0.014221147454610283, 0.09654151173375553, 0.0025666815984826535, 0.0026147055494762234, 1.753144283209579E-4, 0.0017595900141802873, 0.0049406361794682024, 7.881250692924197E-4, 0.002873479530226361, 0.9951286321096425]
eigenValue:6433335.386819993
cosAngle=0.9999998030863401
第三个:
vector:
[-0.2883450858059115, -0.29170231535763447, -0.29157035465385267, -0.28754185317979386, -0.26018076078737895, -0.2914154866344813, -0.2913995247546756, -0.2922103132689348, -0.2916837423401091, -0.29062644748002026, -0.2920066313645422, -0.2913135151887795, 0.03848561950058266]
eigenValue=1442.6143913921014
cosAngle=0.3671147029085018

可以看到只有第二个可以通过筛选,得到的prunedEigenMeta如下:


看下一个函数saveCleanEigens:

private void saveCleanEigens(Configuration conf, Collection<Map.Entry<MatrixSlice, EigenStatus>> prunedEigenMeta)
throws IOException {
Path path = new Path(outPath, CLEAN_EIGENVECTORS);
FileSystem fs = FileSystem.get(path.toUri(), conf);
SequenceFile.Writer seqWriter = new SequenceFile.Writer(fs, conf, path, IntWritable.class, VectorWritable.class);
try {
IntWritable iw = new IntWritable();
int numEigensWritten = 0;
for (Map.Entry<MatrixSlice, EigenStatus> pruneSlice : prunedEigenMeta) {
MatrixSlice s = pruneSlice.getKey();
EigenStatus meta = pruneSlice.getValue();
EigenVector ev = new EigenVector(s.vector(),
meta.getEigenValue(),
Math.abs(1 - meta.getCosAngle()),
s.index());
//log.info("appending {} to {}", ev, path);
Writable vw = new VectorWritable(ev);
iw.set(s.index());
seqWriter.append(iw, vw); // increment the number of eigenvectors written and see if we've
// reached our specified limit, or if we wish to write all eigenvectors
// (latter is built-in, since numEigensWritten will always be > 0
numEigensWritten++;
if (numEigensWritten == maxEigensToKeep) {
log.info("{} of the {} total eigens have been written", maxEigensToKeep, prunedEigenMeta.size());
break;
}
}
} finally {
Closeables.closeQuietly(seqWriter);
}
cleanedEigensPath = path;
}

看保存的ev是什么吧:


还不是筛选出来的那个值,不过这里的误差就是1-cosAngle了;

分享,成长,快乐

转载请注明blog地址:http://blog.csdn.net/fansy1990

mahout源码分析之DistributedLanczosSolver(六)完结篇的更多相关文章

  1. mahout源码分析之DistributedLanczosSolver(五)Job over

    Mahout版本:0.7,hadoop版本:1.0.4,jdk:1.7.0_25 64bit. 1. Job 篇 接上篇,分析到EigenVerificationJob的run方法: public i ...

  2. 手机自动化测试:appium源码分析之bootstrap六

    手机自动化测试:appium源码分析之bootstrap六   poptest是国内唯一一家培养测试开发工程师的培训机构,以学员能胜任自动化测试,性能测试,测试工具开发等工作为目标.poptest测试 ...

  3. 一步步实现windows版ijkplayer系列文章之二——Ijkplayer播放器源码分析之音视频输出——视频篇

    一步步实现windows版ijkplayer系列文章之一--Windows10平台编译ffmpeg 4.0.2,生成ffplay 一步步实现windows版ijkplayer系列文章之二--Ijkpl ...

  4. 一步步实现windows版ijkplayer系列文章之三——Ijkplayer播放器源码分析之音视频输出——音频篇

    一步步实现windows版ijkplayer系列文章之一--Windows10平台编译ffmpeg 4.0.2,生成ffplay 一步步实现windows版ijkplayer系列文章之二--Ijkpl ...

  5. Mahout源码分析之 -- 文档向量化TF-IDF

    fesh个人实践,欢迎经验交流!Blog地址:http://www.cnblogs.com/fesh/p/3775429.html Mahout之SparseVectorsFromSequenceFi ...

  6. Mahout源码分析:并行化FP-Growth算法

    FP-Growth是一种常被用来进行关联分析,挖掘频繁项的算法.与Aprior算法相比,FP-Growth算法采用前缀树的形式来表征数据,减少了扫描事务数据库的次数,通过递归地生成条件FP-tree来 ...

  7. Android源码分析(十六)----adb shell 命令进行OTA升级

    一: 进入shell命令界面 adb shell 二:创建目录/cache/recovery mkdir /cache/recovery 如果系统中已有此目录,则会提示已存在. 三: 修改文件夹权限 ...

  8. ABP源码分析二十六:核心框架中的一些其他功能

    本文是ABP核心项目源码分析的最后一篇,介绍一些前面遗漏的功能 AbpSession AbpSession: 目前这个和CLR的Session没有什么直接的联系.当然可以自定义的去实现IAbpSess ...

  9. ABP源码分析三十六:ABP.Web.Api

    这里的内容和ABP 动态webapi没有关系.除了动态webapi,ABP必然是支持使用传统的webApi.ABP.Web.Api模块中实现了一些同意的基础功能,以方便我们创建和使用asp.net w ...

随机推荐

  1. Linux 服务器上Redis安装和配置

    1.下载安装redis 在Linux服务器上,命令行执行以下命令(cd ./usr local/src 一般源码放在这里(推荐源码安装)) wget http://download.redis.io/ ...

  2. thinkphp中如何是实现多表查询

    多表查询经常使用到,但如何在thinkphp中实现多表查询呢,其实有三种方法. 1 2 3 4 5 6 7 8 9 10 11 12 // 1.原生查询示例: $Model = new Model() ...

  3. Web安全漏洞深入分析及其安全编码

    摘自:http://blog.nsfocus.net/web-vulnerability-analysis-coding-security/ 超全Web漏洞详解及其对应的安全编码规则,包括:SQL注入 ...

  4. "characterEncoding" must end with the ';' delimiter.

    17/04/20 17:27:10 FATAL conf.Configuration: error parsing conf file:/usr/local/apache-hive-1.2.2-bin ...

  5. 【定时任务】Timer

    Java原生api Timer类就可以实现简单的定时任务.下面将简单介绍一下Timer. 一.使用 Timer 实现定时任务 具体代码如下. 可以看到我们主要是分三步进行的 1.new Timer() ...

  6. Anaconda 安装好了,却无法运行?

    使用管理员运行:conda prompt 或者 Windows PowerShell 执行命令 conda update anaconda-navigator 还是不行就试试命令: anaconda- ...

  7. poj-2777线段树刷题

    title: poj-2777线段树刷题 date: 2018-10-16 20:01:07 tags: acm 刷题 categories: ACM-线段树 概述 这道题是一道线段树的染色问题,,, ...

  8. 不要62 hdu 2089 dfs记忆化搜索

    题目:http://acm.hdu.edu.cn/showproblem.php?pid=2089 题意: 给你两个数作为一个闭区间的端点,求出该区间中不包含数字4和62的数的个数 思路: 数位dp中 ...

  9. Linux命令学习<不断更新>

    没有系统的学习过Linux命令,遇到了就学习一下,慢慢积累. 1.echo 命令,学习网站『https://linux.cn/article-3948-1.html』. echo单词有回声.共鸣的意思 ...

  10. lua协程----ngx-lua线程学习笔记

    --[[ - @desc lua数据输出 - @param string 字符串 - return string --]] function dump(v) if not __dump then fu ...