hadoop——倒排索引

【Hadoop基础教程】9、Hadoop之倒排索引 倒排索引是文档检索系统中最常用的数据结构,被广泛用于全文搜索引擎。它主要是用来存储某个单词(或词组)在一个文档或一组文档的存储位置的映射,即提供了一种根据内容来查找文档的方式。由于不是根据文档来确定文档所包含的内容,而是进行了相反的操作(根据关键字来查找文档),因而称为倒排索引(Inverted Index)。通常情况下,倒排索引由一个单词(词组)以及相关的文档列表(标示文档的ID号,或者是指定文档所在位置的URI) 阅读详情

原文:http://blog.jobbole.com/82607/ (侵删)


1.倒排索引简介

倒排索引(Inverted index),也常被称为反向索引、置入档案或反向档案,是一种索引方法,被用来存储在全文搜索下某个单词在一个文档或者一组文档中的存储位置的映射。它是文档检索系统中最常用的数据结构。

有两种不同的反向索引形式:

  • 一条记录的水平反向索引(或者反向档案索引)包含每个引用单词的文档的列表。
  • 一个单词的水平反向索引(或者完全反向索引)又包含每个单词在一个文档中的位置。

后者的形式提供了更多的兼容性(比如短语搜索),但是需要更多的时间和空间来创建。

举例:

以英文为例,下面是要被索引的文本:

  • T0 = "it is what it is"
  • T1 = "what is it"
  • T2 = "it is a banana"

我们就能得到下面的反向文件索引:

1
2
3
4
5
"a":      {2}
"banana": {2}
"is":     {0, 1, 2}
"it":     {0, 1, 2}
"what":   {0, 1}

检索的条件"what", "is" 和 "it" 将对应这个集合:{0,1}∩{0,1,2}∩{0,1,2}={0,1}。

对相同的文字,我们得到后面这些完全反向索引,有文档数量和当前查询的单词结果组成的的成对数据。 同样,文档数量和当前查询的单词结果都从零开始。

所以,"banana": {(2, 3)} 就是说 “banana”在第三个文档里 (T2),而且在第三个文档的位置是第四个单词(地址为 3)。

1
2
3
4
5
"a":      {(2, 2)}
"banana": {(2, 3)}
"is":     {(0, 1), (0, 4), (1, 1), (2, 1)}
"it":     {(0, 0), (0, 3), (1, 2), (2, 0)}
"what":   {(0, 2), (1, 0)}

如果我们执行短语搜索"what is it" 我们得到这个短语的全部单词各自的结果所在文档为文档0和文档1。但是这个短语检索的连续的条件仅仅在文档1得到。

2.分析和设计

(1)Map过程

首先使用默认的TextInputFormat类对输入文件进行处理,得到文本中每行的偏移量及其内容,Map过程首先必须分析输入的<key, value>对,得到倒排索引中需要的三个信息:单词、文档URI和词频,如图所示:

182227128605743

存在两个问题,第一:<key, value>对只能有两个值,在不使用Hadoop自定义数据类型的情况下,需要根据情况将其中的两个值合并成一个值,作为value或key值;

第二,通过一个Reduce过程无法同时完成词频统计和生成文档列表,所以必须增加一个Combine过程完成词频统计

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
public static class InvertedIndexMapper extends Mapper<Object, Text, Text, Text> {
     private Text keyInfo = new Text();  //存储单词和URI的组合
     private Text valueInfo = new Text(); //存储词频
     private FileSplit split;            //存储Split对象
     
     public void map(Object key, Text value, Context context) throws IOException, InterruptedException {
         //获得<key,value>对所属的FileSplit对象
         split = (FileSplit)context.getInputSplit();
         StringTokenizer itr = new StringTokenizer(value.toString());
         
         while (itr.hasMoreTokens()) {
             //key值由单词和URI组成,如"MapReduce:1.txt"
             keyInfo.set(itr.nextToken() + ":" + split.getPath().toString());
             // 词频初始为1
             valueInfo.set( "1" );
             context.write(keyInfo, valueInfo);
         }
     }
}

(2)Combine过程

将key值相同的value值累加,得到一个单词在文档中的词频,如图

221942393901921

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
public static class InvertedIndexCombiner extends Reducer<Text, Text, Text, Text> {
     private Text info = new Text();
     public void reduce(Text key, Iterable<Text>values, Context context) throws IOException, InterruptedException {
         //统计词频
         int sum = 0 ;
         for (Text value : values) {
             sum += Integer.parseInt(value.toString());
         }
         int splitIndex= key.toString().indexOf( ":" );
         
         //重新设置value值由URI和词频组成
         info.set(key.toString().substring(splitIndex + 1 ) + ":" + sum);
         //重新设置key值为单词
         key.set(key.toString().substring( 0 , splitIndex));
         context.write(key, info);
     }
}

(3)Reduce过程

讲过上述两个过程后,Reduce过程只需将相同key值的value值组合成倒排索引文件所需的格式即可,剩下的事情就可以直接交给MapReduce框架进行处理了

3

1
2
3
4
5
6
7
8
9
10
11
12
public static class InvertedIndexReducer extends Reducer<Text, Text, Text, Text> {
     private Text result = new Text();
     public void reducer(Text key, Iterable<Text>values, Context context) throws IOException, InterruptedException {
         //生成文档列表
         String fileList = new String();
         for (Text value : values) {
             fileList += value.toString() + ";" ;
         }
         result.set(fileList);
         context.write(key, result);
     }
}

完整代码如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
import java.io.IOException;
import java.util.StringTokenizer;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.Mapper;
import org.apache.hadoop.mapreduce.Reducer;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.input.FileSplit;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;
import org.apache.hadoop.util.GenericOptionsParser;
 
public class InvertedIndex {
     public static class InvertedIndexMapper extends Mapper<Object, Text, Text, Text> {
         private Text keyInfo = new Text();
         private Text valueInfo = new Text();
         private FileSplit split;
         
         public void map(Object key, Text value, Context context) throws IOException, InterruptedException {
             split = (FileSplit)context.getInputSplit();
             StringTokenizer itr = new StringTokenizer(value.toString());
             
             while (itr.hasMoreTokens()) {
                 keyInfo.set(itr.nextToken() + ":" + split.getPath().toString());
                 valueInfo.set( "1" );
                 context.write(keyInfo, valueInfo);
             }
         }
         
     }
     public static class InvertedIndexCombiner extends Reducer<Text, Text, Text, Text> {
         private Text info = new Text();
         public void reduce(Text key, Iterable<Text>values, Context context) throws IOException, InterruptedException {
             int sum = 0 ;
             for (Text value : values) {
                 sum += Integer.parseInt(value.toString());
             }
             int splitIndex= key.toString().indexOf( ":" );
             info.set(key.toString().substring(splitIndex + 1 ) + ":" + sum);
             key.set(key.toString().substring( 0 , splitIndex));
             context.write(key, info);
         }
     }
     public static class InvertedIndexReducer extends Reducer<Text, Text, Text, Text> {
         private Text result = new Text();
         public void reducer(Text key, Iterable<Text>values, Context context) throws IOException, InterruptedException {
             String fileList = new String();
             for (Text value : values) {
                 fileList += value.toString() + ";" ;
             }
             result.set(fileList);
             context.write(key, result);
         }
     }
     public static void main(String[] args) throws Exception{
         // TODO Auto-generated method stub
         Configuration conf = new Configuration();
         String[] otherArgs = new GenericOptionsParser(conf, args).getRemainingArgs();
         if (otherArgs.length != 2 ) {
             System.err.println( "Usage: wordcount <in> <out>" );
             System.exit( 2 );
         }
         Job job = new Job(conf, "InvertedIndex" );
         job.setJarByClass(InvertedIndex. class );
         job.setMapperClass(InvertedIndexMapper. class );
         job.setMapOutputKeyClass(Text. class );
         job.setMapOutputValueClass(Text. class );
         job.setCombinerClass(InvertedIndexCombiner. class );
         job.setReducerClass(InvertedIndexReducer. class );
         
         job.setOutputKeyClass(Text. class );
         job.setOutputValueClass(Text. class );
         
         FileInputFormat.addInputPath(job, new Path(otherArgs[ 0 ]));
         FileOutputFormat.setOutputPath(job, new Path(otherArgs[ 1 ]));
         System.exit(job.waitForCompletion( true ) ? 0 : 1 );
     }
}

参考资料

http://zh.wikipedia.org/wiki/%E5%80%92%E6%8E%92%E7%B4%A2%E5%BC%95

《实战Hadop:开启通向云计算的捷径.刘鹏》

PS:

上传文件在配好环境的eclipse中直接复制粘贴即可使用,之一配置main函数参数;

也可export为jar包,上传到hadoop使用,依旧是参数问题

Hadoop环境搭建及实现倒排索引 目 录 1.应用介绍 3 1.1实验环境介绍 3 1.2应用背景介绍 3 1.3应用的意义与价值 4 2.数据及存储 5 2.1数据来源及数据量 5 2.2数据存储解决方案 5 3.分析处理架构 5 3.1架构设计和处理方法 5 3.2核心处理算法代码 7 4.系统实现 9 5.总结 271.应用介绍 1.1实验环境介绍 本实验是在hadoo 阅读详情

相关推荐

Hadoop倒排索引原理解析

倒排索引源于实际应用中需要根据属性的值来查找记录,这种索引表中的每一项都包括一个属性值和具有该属性值的各记录的地址,由于不是由记录来确定属性值,而是由属性值来确定记录的位置,因而称为倒排索引,我查阅了很多资料去学习,下面是我自己对倒排索引的理解 假设我现在有两个文件 123.txt 和 456.txt,内容分别是 123.txt Hello world nice to meet you happ...

weixin_43311978的博客 762

MapReduce经典案例—倒排索引

目录一、问题介绍(一)案例分析1. 倒排索引介绍2. 案例需求及分析(二)案例实现 1. Map阶段实现2. Combine阶段实现3. Reduce阶段实现4. Driver程序主类实现5. 效果测试二、完整代码 三、运行结果倒排索引是文档检索系统中最常用的数据结构,被广泛应用于全文搜索引擎。倒排索引主要用来存储某个单词(或词组)在一组文档中的存储位置的映射,提供了可以根据内容来查找文档的方式,而不是根据文档来确定内容,因此称为倒排索引(Inverted Index)。带有倒排索引的文件我们称为

一指流沙的博客 5782

基于Hadoop的带词频属性的文档倒排索引

Inverted Index(倒排索引)是目前几乎所有支持全文检索的搜索引擎都要依赖的一个数据结构。基于索引结构,给出一个词(term),能取得含有这个term的文档列表(the list of documents)。例如: 如果考虑单词在每个文档中出现的词频、位置、对应Web文档的URL等诸多属性,简单的倒排算法就不足以有效工作。我们把这些词频、位置等诸多属性称为有效负载(Payload)。

ifromearth的专栏 3189

Mapreduce实例(六):倒排索引

MR实现倒排索引

笑看风云路的博客 3359

文件倒排索引算法及其hadoop实现

本文将以hadoop实现倒排索引 什么是文件的倒排索引? 简单讲就是一种搜索引擎的算法。过倒排索引,可以根据单词快速获取包含这个单词的文档列表。倒排索引主要由两个部分组成:“单词”和对应出现的“倒排文件”。

无名山丘,崛起成峰 4166

hadoop学习-倒排索引

倒排索引是文档搜索系统中常用的数据结构。它主要用来存储某个词组在一个或多个文档中的位置映射。通常情况下,倒排索引由词组以及相关的文档列表组成。如下表所示。 表1:   单词      文档列表 单词1 文档1 文档2 文档3 单词2 文档2 文档4 文档5 单词3 文档3 文档5 文档6 倒排索引 从表1可以看出单

wenyusuran的专栏 1067

ES 倒排索引

参考:https://www.cnblogs.com/cjsblog/p/10327673.html 正向索引和倒排索引,都是索引,方便快速查找;两者实现原理不一样,应用场景不一样。 正向索引是通过 key找到value 倒排索引是通过value找到key 倒排索引由以下几个部分组成: term:分词器分析后,形成的一个个单词叫做term term dictionary:单词字典,term的集合 term index:单词索引,可以快速找到这个单词,一般用B-Tree索引。是不是可以.

aganliang的专栏 648

MapReduce操作实例-倒排索引.pdf

MapReduce操作实例-倒排索引.pdf 学习资料 复习资料 教学资源

MapReduce实战--倒排索引

本文地址:http://www.cnblogs.com/archimedes/p/mapreduce-inverted-index.html,转载请注明源地址。 1.倒排索引简介 倒排索引(Inverted index),也常被称为反向索引、置入档案或反向档案,是一种索引方法,被用来存储在全文搜索下某个单词在一个文档或者一组文档中的存储位置的映射。它是文档检索系统中最常用的数据结构。 有两种...

weixin_33757609的博客 396

RU.EXE实用指南:从基础操作到高级调试技巧

本文是RU.EXE(RW Everything)的实用指南,详细介绍了这款硬件调试工具从基础操作到高级技巧的全过程。文章阐述了RU.EXE作为直接读写硬件寄存器、内存和PCI配置空间的强大工具,如何帮助硬件工程师和开发人员高效进行底层系统调试与故障排查,并强调了安全操作的重要性。

weixin_29228203的博客 278

使用Termux在Android设备上编译运行SpecCPU2006

SPEC2006搭配Termux,竟然还能这么玩?!

菜菜的菜园子 2960

hadoop–MapReduce倒排索引

hadoop–MapReduce倒排索引 1.倒排索引介绍 倒排索引是文档检索系统中最常用的数据结构,被广泛应用于全文搜索引擎。倒排索引主要用来存储某个单词(或词组)在一组文档中的存储位置的映射,提供了可以根据内容来查找文档的方式,而不是根据文档来确定内容,因此称为倒排索引(Inverted Index)。带有倒排索引的文件我们称为倒排索引文件,简称倒排文件(Inverted File)。 2.案例需求及分析 假设有三个源文件file1.txt,file2.txt,file3.txt,需要使用倒排

qq_41135504的博客 3433

Innovus时钟树综合CTS实战:从原理到signoff的完整指南

时钟树综合(CTS)是数字后端实现中保障同步电路时序收敛的核心环节,其本质是在物理层面构建低偏斜、可控延迟的全局时钟分发网络。它基于静态时序分析(STA)原理,通过平衡clock skew、insertion delay、transition time与功耗面积等多维约束,对抗工艺电压温度(PVT)变异带来的时序不确定性。技术价值在于支撑GHz级高频芯片的setup/hold签核,广泛应用于CPU、GPU、AI加速器等复杂SoC的Innovus后端流程。本文聚焦CTS在Innovus工具链中的工程落地,覆盖

weixin_28523493的博客 223

hadoop中倒排索引的实践

倒排索引是文档检索系统中最常用的数据结构,被广泛的应用于全文搜索引擎。它主要用来存储某个单词(或词组),在一个文档或一组文档中的存储位置的映射,即提供了一种根据内容来查找文档的方式,由于不是根据文档来确定文档所包含的内容,而是进行了相反的操作,因而被称为倒排索引。

鼻孔猫加油站 1154

【DRAM存储器五十六】LPDDR5介绍--WCK2CK Leveling和Read gate training

简述LPDDR5 WCK2CK leveling和read gate traning基本原理与操作步骤

highman110的博客 8791

杰理AC695N系列芯片 LED7数码管使用教程

杰理AC695N数码管使用摘要 本教程介绍了杰理AC695N芯片驱动LED7数码管的实现方法: 硬件配置:支持7/12/13脚三种数码管类型,详细说明了7脚数码管的标准段码定义和GPIO接线方式。 软件设置: 通过修改配置文件启用LED7功能 配置GPIO引脚映射(PORTC/PORTA组) 选择与硬件匹配的真值表 层次架构:包含硬件层、驱动层、UI层和应用层的完整设计,支持数字、字符和图标显示功能。 实现要点包括正确配置引脚类型、选择真值表,并通过UI风格设置为LED7模式。

qq_42014563的博客 1346

你有想过,如何用Hadoop实现【倒排索引】?

写在前面: 博主是一名大数据的初学者,昵称来源于《爱丽丝梦游仙境》中的Alice和自己的昵称。作为一名互联网小白,写博客一方面是为了记录自己的学习历程,一方面是希望能够帮助到很多和自己一样处于起步阶段的萌新。由于水平有限,博客中难免会有一些错误,有纰漏之处恳请各位大佬不吝赐教!个人小站:http://alices.ibilibili.xyz/ , 博客主页:https://alice.blog.csdn.net/ 尽管当前水平可能不及各位大佬,但我还是希望自己能够做得更好,因为一天的生活就是一生的缩影。.

大数据梦想家 4468

LPDDR6 技术标准详解(JESD209-6)

是继 LPDDR5/5X 之后的新一代低功耗 DRAM 标准,专为满足移动终端、AI、边缘计算等高带宽、低功耗场景而设计。该标准通过全新架构、动态功耗控制机制和增强型数据完整性机制,实现性能、能效与可靠性的全面升级。LPDDR6 并非仅是速度升级,更是内存架构设计思路的演进,围绕“低功耗 + 高带宽 + 强安全”的三维目标,构建下一代 SoC 平台关键基础。✅ 高带宽:支持 32B/64B 动态突发✅ 低功耗:动态电压、通道切换✅ 高可靠性:ECC + 自测试 + 安全区。

weixin_43199439的博客 2578

Hadoop之倒排索引

从上面的Map—> Combine ----> Reduce操作过程中,我们可以体会到“倒排索引”的过程其实也就是不断组合并拆分字符串的过程,而这也就是Hadoop中MapReduce并行计算的体现。在现今的大部分企业当中,Hadoop主要应用之一就是针对日志进行处理,所以想进军大数据领域的朋友,对于Hadoop的Map/Reduce实现原理可以通过更多的实战操作加深理解。转载于:https://www.cnblogs.com/SeaSky0606/p/4820786.html。

qq_46416934的博客 1073

火灾图像检测识别:cnn卷积神经网络 Adaboost 支持向量机 随机森林 决策树 完整代码数据

火灾图像检测识别:cnn卷积神经网络 Adaboost 支持向量机 随机森林 决策树 完整代码数据

862

2024年广东省职业院校技能大赛“区块链技术应用”任务书—区块链应用系统开发参考答案

摘要 本文档提供了2024年广东省职业院校技能大赛"区块链技术应用"项目中区块链电子签章前端功能开发的参考答案。主要内容包括:1)注册页面开发,实现身份证号码双向绑定和注册请求发送;2)登录页面开发,实现用户认证、状态保存和页面跳转;3)个人印章页面开发,实现注销功能和印章信息展示。每个任务均包含具体实现代码片段和功能测试要点,涵盖Vue.js框架下的数据绑定、axios请求处理和本地存储等关键技术点。

我是网络安全兼技能大赛工程师,专注网络安全技术学习与技能大赛实战!持续分享最新的技术文章,帮你少走弯路,一起在技术赛道上进步~ 343

用hadoop实现倒排索引简单实例

用hadoop实现倒排索引简单实例倒排索引是文档搜索系统中常用的数据结构,即根据内容进行文档的搜索,本次我们利用mapReduce来分析和统计单词在每个文档中的权重,输入2个单词的txt文本,经过mapreduce的处理,将结果以{单词 1.txt:权重,2.txt:权重}逐行输出到output目录下。切记单个文件不要超过HDFS单个块的大小,保证一个文件一个split.否则会出现词频统计不完全。

lucky_ly的博客 3117

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

hadoop倒排索引

看到很多的hadoop关于倒排索引的例子,但是我想写一个属于我自己的,加入了本人对于hadoop中mapreduce的理解。 有下面三篇文章: accident.txt CHENGDU - Death toll from a colliery blast on Saturday in southwest China's Sichuan Province rose to 27, local

提炼技能,形成智慧 2431

汉书HE8,好用的汇编代码编写工具

汉书HE8,好用的汇编代码编写工具早期编写汇编代码所用功能强大

win10 跳过U8环境检测的IE WebControls.rar

win10 安装u8的时候 提示IE WebControls 不通过,这个工具可以欺骗u8的检查。 跳过U8环境检测的IE WebControls。提示导入失败后,重新检测通过。

hadoop实现倒排索引

倒排索引是文档检索系统中最常用的数据结构,被广泛用于全文搜索引擎,它主要使用来存储某个单词(或词组)在一个文档或一组文档中的存储位置的映射,即提供了一种根据内容来查找文档的方式。        以前不使用hadoop时,实现倒排索引真是费劲啊,尤其是当处理大量文本时,更是让人头疼啊。自从有了hadoop爸爸妈妈再也不用担心我们处理大数据了,呵呵,废话就说到这,下面实现简单的倒排索引:

z595054650的专栏 1227

大中型超市收银系统(可直接运行)

光步前台收银系统系统功能:商品销售、商品退货、挂单、收银员权限、会员销售、单品取消、整单取消、商品查询、脱机销售、脱机数据上传,基本资料下载,开钱箱、小票打印、收款结算,支持多币种付款方式(现金、储值卡、礼券、微信等),支持多种促销。运行环境:.net 4.0登陆信息用户名:1001 密码:123456内置商品信息,商品编码可输入00001000 - 00010000,测试效果相关功能键F5 结算 F9挂单 F11商品查询 F8退货 Insert单品取消 Del整单取消 F12开钱箱F2 会员 Ctrl+Z退出系统 Home 锁屏 相关源码待公开

hadoop--之搜索引擎,倒排索引

倒排索引的用处 搜索引擎的关键步骤就是建立倒排索引,所谓倒排索引一般表示为一个关键词,然后是它的频度(出现的次数),位置(出现在哪一篇文章或网页中,及有关的日期,作者等信息),它相当于为互联网上几千亿页网页做了一个索引,好比一本书的目录、标签一般。读者想看哪一个主题相关的章节,直接根据目录即可找到相关的页面。不必再从书的第一页到最后一页,一页一页的查找。倒排索引是搜索引擎之基石。建成了倒排索引后

Gedeon 4472
上一篇: grunt学习笔记九:新建project
下一篇: 前端开发者都应知道的 jQuery 小技巧
JhonPang
博客等级 码龄12年 0粉丝 16原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值