基于 Hive 的文件格式:RCFile 简介及其应用

Hive数据存储格式有哪些?TextFile、SequenceFile、RCFile、ORCFile、Parquet有什么区别?为什么绝大多数都使用ORCFile、Parquet格式? 通过 ORC 这些索引,可以快速定位满足查询的数据块,规避大部分不满足查询条件的文件和数据块,相比于读取传统的数据文件,进行查找时需要遍历全部的数据,使用 ORC 可以避免磁盘和网络 I/O 的浪费,提升程序的查找效率,提升整个集群的工作负载。Parquet 在存储数据时,也同 ORC 一样记录这些数据的元数据,这些元数据也同 Parquet 的文件结构一样,被分成多层文件级别的元数据、列块级别的元数据及页级别的元数据。Hive 是面向 OLAP 的,所以它的事务也和 RDMBS 的事务有一定的区别。 阅读详情
转载自: https://my.oschina.net/leejun2005/blog/280896

Hadoop 作为MR 的开源实现,一直以动态运行解析文件格式并获得比MPP数据库快上几倍的装载速度为优势。不过,MPP数据库社区也一直批评Hadoop由于文件格式并非为特定目的而建,因此序列化和反序列化的成本过高。

1、hadoop 文件格式简介

目前 hadoop 中流行的文件格式有如下几种:

(1)SequenceFile

SequenceFile是Hadoop API 提供的一种二进制文件,它将数据以<key,value>的形式序列化到文件中。这种二进制文件内部使用Hadoop 的标准的Writable 接口实现序列化和反序列化。它与Hadoop API中的MapFile 是互相兼容的。Hive 中的SequenceFile 继承自Hadoop API 的SequenceFile,不过它的key为空,使用value 存放实际的值, 这样是为了避免MR 在运行map 阶段的排序过程。如果你用Java API 编写SequenceFile,并让Hive 读取的话,请确保使用value字段存放数据,否则你需要自定义读取这种SequenceFile 的InputFormat class 和OutputFormat class。

(2)RCFile

RCFile是Hive推出的一种专门面向列的数据格式。 它遵循“先按列划分,再垂直划分”的设计理念。当查询过程中,针对它并不关心的列时,它会在IO上跳过这些列。需要说明的是,RCFile在map阶段从远端拷贝仍然是拷贝整个数据块,并且拷贝到本地目录后RCFile并不是真正直接跳过不需要的列,并跳到需要读取的列, 而是通过扫描每一个row group的头部定义来实现的,但是在整个HDFS Block 级别的头部并没有定义每个列从哪个row group起始到哪个row group结束。所以在读取所有列的情况下,RCFile的性能反而没有SequenceFile高。

HDFS块内行存储的例子

HDFS块内列存储的例子

HDFS块内RCFile方式存储的例子

(3)Avro

Avro是一种用于支持数据密集型的二进制文件格式。它的文件格式更为紧凑,若要读取大量数据时,Avro能够提供更好的序列化和反序列化性能。并且Avro数据文件天生是带Schema定义的,所以它不需要开发者在API 级别实现自己的Writable对象。最近多个Hadoop 子项目都支持Avro 数据格式,如Pig 、Hive、Flume、Sqoop和Hcatalog。

(4)文本格式

除上面提到的3种二进制格式之外,文本格式的数据也是Hadoop中经常碰到的。如TextFile 、XML和JSON。 文本格式除了会占用更多磁盘资源外,对它的解析开销一般会比二进制格式高几十倍以上,尤其是XML 和JSON,它们的解析开销比Textfile 还要大,因此强烈不建议在生产系统中使用这些格式进行储存。 如果需要输出这些格式,请在客户端做相应的转换操作。 文本格式经常会用于日志收集,数据库导入,Hive默认配置也是使用文本格式,而且常常容易忘了压缩,所以请确保使用了正确的格式。另外文本格式的一个缺点是它不具备类型和模式,比如销售金额、利润这类数值数据或者日期时间类型的数据,如果使用文本格式保存,由于它们本身的字符串类型的长短不一,或者含有负数,导致MR没有办法排序,所以往往需要将它们预处理成含有模式的二进制格式,这又导致了不必要的预处理步骤的开销和储存资源的浪费。

(5)外部格式

Hadoop实际上支持任意文件格式,只要能够实现对应的RecordWriter和RecordReader即可。其中数据库格式也是会经常储存在Hadoop中,比如Hbase,Mysql,Cassandra,MongoDB。 这些格式一般是为了避免大量的数据移动和快速装载的需求而用的。他们的序列化和反序列化都是由这些数据库格式的客户端完成,并且文件的储存位置和数据布局(Data Layout)不由Hadoop控制,他们的文件切分也不是按HDFS的块大小(blocksize)进行切割。

2、为什么需要 RCFile

Facebook曾在2010 ICDE(IEEE International Conference on Data Engineering)会议上介绍了数据仓库Hive。Hive存储海量数据在Hadoop系统中,提供了一套类数据库的数据存储和处理机制。它采用类SQL语言对数据进行自动化管理和处理,经过语句解析和转换,最终生成基于Hadoop的MapReduce任务,通过执行这些任务完成数据处理。下图显示了Hive数据仓库的系统结构。 

Facebook在数据仓库上遇到的存储可扩展性的挑战是独一无二的。他们在基于Hive的数据仓库中存储了超过300PB的数据,并且以每日新增600TB的速度增长。去年这个数据仓库所存储的数据量增长了3倍。考虑到这个增长趋势,存储效率问题是facebook数据仓库基础设施方面目前乃至将来一段时间内最需要关注的。facebook工程师发表的RCFile: A Fast and Spaceefficient Data Placement Structure in MapReducebased Warehouse Systems一文,介绍了一种高效的数据存储结构——RCFile(Record Columnar File),并将其应用于Facebook的数据仓库Hive中。与传统数据库的数据存储结构相比,RCFile更有效地满足了基于MapReduce的数据仓库的四个关键需求,即Fast data loading、Fast query processing、Highly efficient storage space utilization和Strong adaptivity to highly dynamic workload patterns。RCFile 广泛应用于Facebook公司的数据分析系统Hive中。首先,RCFile具备相当于行存储的数据加载速度和负载适应能力;其次,RCFile的读优化可以在扫描表格时避免不必要的列读取,测试显示在多数情况下,它比其他结构拥有更好的性能;再次,RCFile使用列维度的压缩,因此能够有效提升存储空间利用率。
为了提高存储空间利用率,Facebook各产品线应用产生的数据从2010年起均采用RCFile结构存储,按行存储(SequenceFile/TextFile)结构保存的数据集也转存为RCFile格式。此外,Yahoo公司也在Pig数据分析系统中集成了RCFile,RCFile正在用于另一个基于Hadoop的数据管理系统Howl(http://wiki.apache.org/pig/Howl)。而且,根据Hive开发社区的交流,RCFile也成功整合加入其他基于MapReduce的数据分析平台。有理由相信,作为数据存储标准的RCFile,将继续在MapReduce环境下的大规模数据分析中扮演重要角色。

3、RCFile 简介

facebook 的数据仓库中数据被加载到表里面时首先使用的存储格式是Facebook自己开发的Record-Columnar File Format(RCFile)。RCFile是一种“允许按行查询,提供了列存储的压缩效率”的混合列存储格式。它的核心思想是首先把Hive表水平切分成多个行组(row groups),然后组内按照列垂直切分,这样列与列的数据在磁盘上就是连续的存储块了。
当一个行组内的所有列写到磁盘时,RCFile就会以列为单位对数据使用类似zlib/lzo的算法进行压缩。当读取列数据的时候使用惰性解压策略( lazy decompression),也就是说用户的某个查询如果只是涉及到一个表中的部分列的时候,RCFile会跳过不需要的列的解压缩和反序列化的过程。通过在facebook的数据仓库中选取有代表性的例子实验,RCFile能够提供5倍的压缩比。

4、超越RCFile,下一步采用什么方法

随着数据仓库中存储的数据量持续增长,FB组内的工程师开始研究提高压缩效率的技术和方法。研究的焦点集中在列级别的编码方法,例如行程长度编码(run-length encoding)、词典编码(dictionary encoding)、参考帧编码(frame of reference encoding)、能够在通用压缩过程之前更好的在列级别降低逻辑冗余的数值编码方法。FB也尝试过新的列类型(例如JSON是在Facebook内部广泛使用的格式,把JSON格式的数据按照结构化的方式存储既可以满足高效查询的需求,同时也降低了JSON元数据存储的冗余)。FB的实验表明列级别的编码如果使用得当的话能够显著提高RCFile的压缩比。
与此同时,Hortonworks也在尝试类似的思路去改进Hive的存储格式。Hortonworks的工程团队设计和实现了ORCFile(包括存储格式和读写接口),这帮助Facebook的数据仓库设计和实现新的存储格式提供了一个很好的开始。

关于 ORCFile 的介绍请见这里:http://yanbohappy.sinaapp.com/?p=478

关于性能评测,笔者这里暂时没有条件,贴一张某次 hive 技术峰会演讲嘉宾的截图:

5、如何生成 RCFile 文件

上面说了这么多,想必你已经知道 RCFile 主要用于提升 hive 的查询效率,那如何生成这种格式的文件呢?

(1)hive 中直接通过textfile表进行insert转换

例如:

insert overwrite table http_RCTable partition(dt='2013-09-30') select p_id,tm,idate,phone from tmp_testp where dt='2013-09-30';
(2)通过 mapreduce 生成

目前为止,mapreduce 并没有提供内置 API 对 RCFile 进行支持,倒是 pig、hive、hcatalog 等 hadoop生态圈里的其他项目进行了支持,究其原因是因为 RCFile 相比 textfile 等其它文件格式,对于 mapreduce 的应用场景来说没有显著的优势。

为了避免重复造轮子,下面的生成 RCFile 的 mapreduce 代码调用了 hive 和 hcatalog 的相关类,注意你在测试下面的代码时,你的 hadoop、hive、hcatalog 版本要一致,否则。。。你懂的。。。

比如我用的 hive-0.10.0+198-1.cdh4.4.0,那么就应该下载对应的版本:http://archive.cloudera.com/cdh4/cdh/4/

PS:下面的代码已经测试通过,木有问题。

import java.io.IOException;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.conf.Configured;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.hive.serde2.columnar.BytesRefArrayWritable;
import org.apache.hadoop.hive.serde2.columnar.BytesRefWritable;
import org.apache.hadoop.io.NullWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.Mapper;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.util.GenericOptionsParser;
import org.apache.hadoop.util.Tool;
import org.apache.hadoop.util.ToolRunner;
import org.apache.hcatalog.rcfile.RCFileMapReduceInputFormat;
import org.apache.hcatalog.rcfile.RCFileMapReduceOutputFormat;



public class TextToRCFile extends Configured implements Tool{

    
    
    public static class Map 
        extends Mapper<Object, Text, NullWritable, BytesRefArrayWritable>{
        
        private byte[] fieldData;
        private int numCols;
        private BytesRefArrayWritable bytes;
        
        @Override
        protected void setup(Context context) throws IOException, InterruptedException {
            numCols = context.getConfiguration().getInt("hive.io.rcfile.column.number.conf", 0);
            bytes = new BytesRefArrayWritable(numCols);
        }
        
        public void map(Object key, Text line, Context context
                ) throws IOException, InterruptedException {
            bytes.clear();
            String[] cols = line.toString().split("\\|");
            System.out.println("SIZE : "+cols.length);
            for (int i=0; i<numCols; i++){
                fieldData = cols[i].getBytes("UTF-8");
                BytesRefWritable cu = null;
                cu = new BytesRefWritable(fieldData, 0, fieldData.length);
                bytes.set(i, cu);
            }
            context.write(NullWritable.get(), bytes);
        }
    }
    
    @Override
    public int run(String[] args) throws Exception {
        Configuration conf = new Configuration();
        String[] otherArgs = new GenericOptionsParser(conf, args).getRemainingArgs();
        if(otherArgs.length < 2){
            System.out.println("Usage: " +
                    "hadoop jar RCFileLoader.jar <main class> " +
                    "-tableName <tableName> -numCols <numberOfColumns> -input <input path> " +
                    "-output <output path> -rowGroupSize <rowGroupSize> -ioBufferSize <ioBufferSize>");
            System.out.println("For test");
            System.out.println("$HADOOP jar RCFileLoader.jar edu.osu.cse.rsam.rcfile.mapreduce.LoadTable " +
                    "-tableName test1 -numCols 10 -input RCFileLoaderTest/test1 " +
                    "-output RCFileLoaderTest/RCFile_test1");
            System.out.println("$HADOOP jar RCFileLoader.jar edu.osu.cse.rsam.rcfile.mapreduce.LoadTable " +
                    "-tableName test2 -numCols 5 -input RCFileLoaderTest/test2 " +
                    "-output RCFileLoaderTest/RCFile_test2");
            return 2;
        }
        
        /* For test
           
         */
        
        
        String tableName = "";
        int numCols = 0;
        String inputPath = "";
        String outputPath = "";
        int rowGroupSize = 16 *1024*1024;
        int ioBufferSize = 128*1024;
        for (int i=0; i<otherArgs.length - 1; i++){
            if("-tableName".equals(otherArgs[i])){
                tableName = otherArgs[i+1];
            }else if ("-numCols".equals(otherArgs[i])){
                numCols = Integer.parseInt(otherArgs[i+1]);
            }else if ("-input".equals(otherArgs[i])){
                inputPath = otherArgs[i+1];
            }else if("-output".equals(otherArgs[i])){
                outputPath = otherArgs[i+1];
            }else if("-rowGroupSize".equals(otherArgs[i])){
                rowGroupSize = Integer.parseInt(otherArgs[i+1]);
            }else if("-ioBufferSize".equals(otherArgs[i])){
                ioBufferSize = Integer.parseInt(otherArgs[i+1]);
            }
            
        }
        
        conf.setInt("hive.io.rcfile.record.buffer.size", rowGroupSize);
        conf.setInt("io.file.buffer.size", ioBufferSize);
        
        Job job = new Job(conf, "RCFile loader: loading table " + tableName + " with " + numCols + " columns");
        
        job.setJarByClass(TextToRCFile.class);
        job.setMapperClass(Map.class);
        job.setMapOutputKeyClass(NullWritable.class);
        job.setMapOutputValueClass(BytesRefArrayWritable.class);
//        job.setNumReduceTasks(0);
        
        FileInputFormat.addInputPath(job, new Path(inputPath));
        
        job.setOutputFormatClass(RCFileMapReduceOutputFormat.class);
        RCFileMapReduceOutputFormat.setColumnNumber(job.getConfiguration(), numCols);
        RCFileMapReduceOutputFormat.setOutputPath(job, new Path(outputPath));
        RCFileMapReduceOutputFormat.setCompressOutput(job, false);
        
        
        System.out.println("Loading table " + tableName + " from " + inputPath + " to RCFile located at " + outputPath);
        System.out.println("number of columns:" + job.getConfiguration().get("hive.io.rcfile.column.number.conf"));
        System.out.println("RCFile row group size:" + job.getConfiguration().get("hive.io.rcfile.record.buffer.size"));
        System.out.println("io bufer size:" + job.getConfiguration().get("io.file.buffer.size"));
        
        return (job.waitForCompletion(true) ? 0 : 1);
    }
    
    public static void main(String[] args) throws Exception {
        int res = ToolRunner.run(new Configuration(), new TextToRCFile(), args);
        System.exit(res);
    }

}
6、Refer:

(1)浅析Hadoop文件格式 http://www.infoq.com/cn/articles/hadoop-file-format

(2)Facebook数据仓库揭秘:RCFile高效存储结构  http://www.youkuaiyun.com/article/2011-04-29/296900

(3)Facebook的数据仓库是如何扩展到300PB的  http://yanbohappy.sinaapp.com/?p=478

(4)Hive架构  http://www.jdon.com/bigdata/hive.html

(5)Hive:ORC File Format存储格式详解  http://www.iteblog.com/archives/1014

(6)普通文本压缩成RcFile的通用类  https://github.com/ysmart-xx/ysmart/blob/master/javatest/TextToRCFile.java

http://hugh-wangp.iteye.com/blog/1405804 基于HIVE文件格式的map reduce代码编写
http://smallboby.iteye.com/blog/1596776  普通文本压缩成RcFile的通用类
http://smallboby.iteye.com/blog/1592531  RcFile存储和读取操作
https://github.com/kevinweil/elephant-bird/blob/master/rcfile/src/main/java/com/twitter/elephantbird/mapreduce/output/RCFileOutputFormat.java

http://blog.youkuaiyun.com/liuzhoulong/article/details/7909863

Hive学习笔记 --- RCFile介绍 阅读详情

相关推荐

Hive文件格式

hive文件存储格式包括以下几类: TEXTFILE SEQUENCEFILE RCFILE ORCFILE(0.11以后出现) 其中TEXTFILE为默认格式,建表时不指定默认为这个格式,导入数据时会直接把数据文件拷贝到hdfs上不进行处理; SEQUENCEFILE,RCFILE,ORCFILE格式的表不能直接从本地文件导入数据,数据要先导入到textfile格式的表中, 然后再从表中用i...

九师兄 1543

Qt之RC_FILE宏

DISTFILES += \ app.rc RC_FILE = app.rc DESTDIR = $$PWD/bin app.rc文件的内容为:IDI_ICON1 ICON "app.ico"这样应用程序运行时会显示图标 如果把app.rc文件的内容改为:IDI_ICON ICON "app.ico"应用

bladeandmaster88的博客 3513

避坑指南:RK3576+Android14适配移远5G模组(RG200U)时,我遇到的3个‘巨坑’及解决方案

本文详细记录了RK3576芯片适配Android14系统与移远RG200U 5G模组过程中遇到的三大技术难题:RIL服务启动失败、HIDL兼容性矩阵配置错误及ttyUSB权限冲突。通过实战案例提供了动态库拷贝、HIDL版本链声明和SELinux策略调整等解决方案,帮助开发者高效完成5G模组集成,特别适用于基于kernel6.1的嵌入式开发场景。

weixin_30664051的博客 390

RCFile和ORCFile

1. RCFileRCFile文件格式是FaceBook开源的一种Hive的文件存储格式,首先将表分为几个行组,对每个行组内的数据进行按列存储,每一列的数据都是分开存储,正是先水平划分,再垂直划分的理念。在存储结构上: 如上图是HDFS内RCFile的存储结构,我们可以看到,首先对表进行行划分,分成多个行组。一个行组主要包括:16字节的HDFS同步块信息,主要是为了区分一个HDFS块上的相邻行组;

夫唯不争,故天下莫能与之争。 2万+

【CarMaker实战指南】从零构建环形测试场景与车辆连续仿真

本文详细介绍了如何使用CarMaker软件从零构建环形测试场景与实现车辆连续仿真。通过分步指导搭建闭环道路、连接交叉路口、规划车辆轨迹等核心操作,帮助用户掌握CarMaker的基础应用技巧,并提供了常见问题排查与进阶优化建议,适用于车辆耐久性测试和自动驾驶算法验证等场景。

weixin_29274969的博客 234

高通Camx功能feature分析之一:remosaic功能导通

本文详细介绍了S5K3P9S传感器前置场景中SW Remosaic功能的实现流程。首先需在sensorxml中确认支持SW Remosaic类型,并集成remosaic相关库文件(libremosaic_wrapper.so等)。核心实现包括:初始化阶段调用InitFrontSamsungRemosaic();执行线程DeferFrontInitThread()读取校准数据;通过DoSamsungRemosaic()执行remosaic算法处理;最后在析构函数中调用DeinitFrontSamsungRem

1700

基于Hive 的文件格式:RCFile 简介及其应用

目录[-] 1、hadoop 文件格式简介 (1)SequenceFile (2)RCFile (3)Avro (4)文本格式 (5)外部格式 2、为什么需要 RCFile 3、RCFile 简介 4、超越RCFile,下一步采用什么方法 5、如何生成 RCFile 文件 (1)hive 中直接通过textfile表进行insert转换 (2)通过 mapreduc

DataFlow范式 1797

5.7 BGP属-ORIGIN

注意:当去往同一个目的地存在多条不同Origin属性的路由时,在其他条件都相同的情况下,BGP将按如Origin的下顺序优选路由:IGP > EGP > Incomplete。通过以上输出可以看到路由表选择了R3发过来的路由,因为R1的路由的起源为?通过以上输出我们可以看到针对于1.1.1.1这条路由有两条,从R1和R3传过来的起源都属于IGP。(4)把从R1传过来的路由的起源改为incomplete。通过以上输出可以看到,从R1传过来的路由是最优的。(2)在R2上查看1.1.1.1的路由详细信息。

lwljh134的博客 308

转载:基于 Hive 的文件格式:RCFile 简介及其应用---推酷

Hadoop 作为MR 的开源实现,一直以动态运行解析文件格式并获得比MPP数据库快上几倍的装载速度为优势。不过,MPP数据库社区也一直批评Hadoop由于文件格式并非为特定目的而建,因此序列化和反序列化的成本过高。 1、hadoop 文件格 式简介 目前 hadoop 中流行的文件格式有如下几种: (1 ) Seque nceFile SequenceFile是Hadoop API 提供...

weixin_30487701的博客 89

【Arduino 动手做】六舵机自平衡 Rotary Stewart 平台

《Arduino六舵机自平衡Rotary Stewart平台项目》 该项目展示了一个基于Arduino的六自由度Rotary Stewart平台,通过六个舵机实现动态平衡控制。设计采用激光切割框架和TAMIYA 70171套件,提供详细组装指南和开源固件(GitHub可获取)。开发者丹·罗耶分享了3D打印文件、视频演示及运动学优化需求,强调该平台可扩展应用于游戏控制(如Kerbal Space Program)或教育领域。项目链接包含完整资源包,鼓励用户参与改进并分享创作成果。该案例体现了Arduino在机

雕爷学编程 1092

双像素传感器的AI计算摄影实战:单目深度估计与图像去模糊的融合创新

本文介绍了双像素传感器技术在计算机视觉中的应用,包括深度估计、图像去模糊和图像重建等任务。双像素传感器通过两个子单元捕捉视差信息,使摄像头能够分析场景的三维结构和运动轨迹。文章以图像去模糊为例,详细展示了从数据准备到模型训练的完整流程,包括构建自定义数据集、设计双像素特征提取模块、训练去模糊模型及推理测试。通过模拟双像素的"双视角"信息融合,该AI算法能有效恢复模糊图像的清晰细节。

know_F0727的博客 256

Hive文件格式-textfile,sequencefile,rcfile,orcfile, Parquet

目录 概述 hive文件存储格式包括以下几类 一、TEXTFILE 二、SEQUENCEFILE 三、RCFile文件格式 概述历史 RCFile使用 基于行存储的优点和缺点 基于列存储的优点和缺点 源码分析 1. Writer 2. append RCFile的索引机制 flushRecords的具体逻辑 RCFile的Sync机制 RCFileclose过程 ...

m0_37657725的博客 8736

基于Simulink的PMSM轮毂电机崎岖路面悬架协同控制仿真

本文完成了基于Simulink的PMSM轮毂电机崎岖路面悬架协同控制仿真,实现了:✅ 构建了四轮独立驱动+主动悬架高保真整车模型✅ 实现了Skyhook主动悬架控制✅ 设计了驱动-悬架状态共享与协同决策机制✅ 验证了5 m/s高速下连续颠簸路面稳定通过能力✅ 为高性能移动机器人提供一体化底盘解决方案。

xiaoheshang_123的博客 190

RCFile 简介及其应用

基于 Hive 的文件格式:RCFile 简介及其应用 时间 2014-06-18 02:54:04  xrzs 原文  http://my.oschina.net/leejun2005/blog/280896 主题 RCFile Hive Hadoop 作为MR 的开源实现,一直以动态运行解析文件格式并获得比MPP数据库快上几倍的装载速度为优势。不过,MPP数据库社区

CCJHDOPC的专栏: 1599

131、高通骁龙影像平台总览:Spectra ISP 各代架构演进与特性对比

摘要:本文深入分析了高通骁龙Spectra ISP从250到780代的架构演进与技术痛点,揭示了各代关键改进与隐藏问题。重点剖析了双ISP带宽分配、AI ISP黑盒决策、温度控制等实战问题,并给出具体解决方案(如寄存器配置、QoS调整等)。文章强调工程师需平衡带宽、功耗与画质的三角关系,建议调试时先关闭AI模块建立基线,关注统计引擎配置,并建立温度监控机制。最后指出理解架构局限比追求完美设计更重要,需要针对不同场景找到合适的妥协方案。(148字)

sundong_81的博客 207

深度学习工具包 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")

hive 支持的文件格式

hive 支持的文件格式hive支持的文件格式TEXTFILE 格式SEQUENCEFILE 格式RCFILE 文件格式 hive支持的文件格式 Hive文件存储格式包括以下几类: 1、TEXTFILE 2、SEQUENCEFILE 3、RCFILE 4、ORCFILE(0.11以后出现) 其中TEXTFILE为默认格式,建表时不指定默认为这个格式,导入数据时会直接把数据文件拷贝到hdfs上不进行处理。 SEQUENCEFILE,RCFILE,ORCFILE格式的表不能直接从本地文件导入数据,数据要

Joie_TJ的博客 1247

IDEA的使用指南

IDEA基于java的使用手册,可以最快速的上手,在使用中不断的丰富自己的使用技巧.

hive优化-文件格式-rcfile-textfile-seqfile

[数据文件] 1.文件格式,hive支持TEXTFILE, SEQUENCEFILE, RCFILE, ORC, and PARQUET. 修改文件格式: //创建表 CREATE TABLE… STORED AS //修改表指定格式 ALTER TABLE… [PARTITION partition_spec] SET FILEFORMAT //设置默认的表格式 SET hi

tianqinglei的博客 1063

Outlook Express 6 (OE6) for Win7/Win8/Win10

英文版 Outlook Express6.0, 兼容Win7/Win10/WinXP,解压就可用。

android 蓝牙通讯demo

android 下蓝牙通讯demo,实现了发现蓝牙,使能蓝牙,通过蓝牙发送消息。

hive的存储格式TextFile、RCFile、ORC

hived的存储格式TextFile、RCFile、ORC 说明:所谓的存储格式就是hive的数据在hdfs上存放的具体方式;通过下面的文件我们看出hive的存储格式是一共有六种,每一种都是由自己的规则。 file_format: : SEQUENCEFILE | TEXTFILE -- (Default, depending on hive.default.fileformat...

lds_include 2836

Hive中rcfile格式

首先声明,此文是属于纯粹收藏文,感觉讲的很不错。 本文介绍了Facebook公司数据分析系统中的RCFile存储结构,该结构集行存储和列存储的优点于一身,在MapReduce环境下的大规模数据分析中扮演重要角色。 Facebook曾在2010 ICDE(IEEE International Conference on Data Engineering)会议上介绍了数据仓库Hive。Hive存储...

LMR的博客 8428

hive中的文件格式的简介

【hive中的file_format】 SEQUENCEFILE:生产中绝对不会用,k-v格式,比源文本格式占用磁盘更多 TEXTFILE:生产中用的多,行式存储 RCFILE:生产中用的少,行列混合存储,OCR是他得升级版 ORC:生产中最常用,列式存储 PARQUET:生产中最常用,列式存储 AVRO:生产中几乎不用,不用考虑 JSONFILE:生产中几乎不用,不用考虑 I...

weixin_30243533的博客 340
上一篇: Gobblin采集kafka数据
下一篇: RDD、DataFrame和DataSet的区别
Syn良子
博客等级 码龄15年 7粉丝 45原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值