深入学习Heritrix---解析Frontier(链接工厂)

GHUB LUA脚本 压枪脚本 推荐APEX用 废话少说直接lua源码 ScrtptOpen = false xVibrationAmplitude = 15 --左右震动幅度 yVibrationAmplitude = 18 --垂直震动幅度 VibrationSpeed = 5 --震动速度 function OnEvent(event, arg) EnablePrimaryMouseButtonEvents(true) if (event == "MOUSE_BUTTON_PRESSED" and arg == 7) then ... 阅读详情

Frontier是Heritrix最核心的组成部分之一,也是最复杂的组成部分.它主要功能是为处理链接的线程提供URL,并负责链接处理完成后的一些后续调度操作.并且为了提高效率,它在内部使用了Berkeley DB.本节将对它的内部机理进行详细解剖.

在Heritrix的官方文档上有一个Frontier的例子,虽然很简单,但是它却解释Frontier实现的基本原理.在这里就不讨论,有兴趣的读者可以参考相应文档.但是不得不提它的三个核心方法:
(1)next(int timeout):为处理线程提供一个链接.Heritrix的所有处理线程(ToeThread)都是通过调用该方法获取链接的.

(2)schedule(CandidateURI caURI):调度待处理的链接.

(3)finished(CrawlURI cURI):完成一个已处理的链接.

整体结构如下:

BdbMultipleWorkQueues:

它是对Berkeley DB的简单封装.在内部有一个Berkeley Database,存放所有待处理的链接.

 


package  org.archive.crawler.frontier;
public   class  BdbMultipleWorkQueues 
{
// 存放所有待处理的URL的数据库
     private  Database pendingUrisDB  =   null ;


 
// 由key获取一个链接
     public  CrawlURI get(DatabaseEntry headKey)
    
throws  DatabaseException  {
        DatabaseEntry result 
=   new  DatabaseEntry();
        
        
//  From Linda Lee of sleepycat:
        
//  "You want to check the status returned from Cursor.getSearchKeyRange
        
//  to make sure that you have OperationStatus.SUCCESS. In that case,
        
//  you have found a valid data record, and result.getData()
        
//  (called by internally by the binding code, in this case) will be
        
//  non-null. The other possible status return is
        
//  OperationStatus.NOTFOUND, in which case no data record matched
        
//  the criteria. "
        
// 由key获取相应的链接
        OperationStatus status  =  getNextNearestItem(headKey, result);
        CrawlURI retVal 
=   null ;
        
if  (status  !=  OperationStatus.SUCCESS)  {
            LOGGER.severe(
" See '1219854 NPE je-2.0  "
                    
+   " entryToObject '. OperationStatus  "
                    
+   "  was not SUCCESS:  "
                    
+  status
                    
+   " , headKey  "
                    
+  BdbWorkQueue.getPrefixClassKey(headKey.getData()));
            
return   null ;
        }

        
try   {
            retVal 
=  (CrawlURI)crawlUriBinding.entryToObject(result);
        }
  catch  (RuntimeExceptionWrapper rw)  {
            LOGGER.log(
                Level.SEVERE,
                
" expected object missing in queue  "   +
                BdbWorkQueue.getPrefixClassKey(headKey.getData()),
                rw);
            
return   null ; 
        }

        retVal.setHolderKey(headKey);
        
return  retVal; // 返回链接
    }


    
// 从等处理列表获取一个链接
     protected  OperationStatus getNextNearestItem(DatabaseEntry headKey,
            DatabaseEntry result) 
throws  DatabaseException  {
        Cursor cursor 
=   null ;
        OperationStatus status;
        
try   {
            
// 打开游标
            cursor  =   this .pendingUrisDB.openCursor( null ,  null );
            
//  get cap; headKey at this point should always point to 
            
//  a queue-beginning cap entry (zero-length value)
            status  =  cursor.getSearchKey(headKey, result,  null );
            
if (status != OperationStatus.SUCCESS  ||  result.getData().length  >   0 )  {
                
//  cap missing
                 throw   new  DatabaseException( " bdb queue cap missing " );
            }

            
//  get next item (real first item of queue)
            status  =  cursor.getNext(headKey,result, null );
        }
  finally   { 
            
if (cursor != null )  {
                cursor.close();
            }

        }

        
return  status;
    }


 
/**
     * Put the given CrawlURI in at the appropriate place. 
     * 添加URL到数据库
     * 
@param  curi
     * 
@throws  DatabaseException
     
*/

    
public   void  put(CrawlURI curi,  boolean  overwriteIfPresent) 
    
throws  DatabaseException  {
        DatabaseEntry insertKey 
=  (DatabaseEntry)curi.getHolderKey();
        
if  (insertKey  ==   null )  {
            insertKey 
=  calculateInsertKey(curi);
            curi.setHolderKey(insertKey);
        }

        DatabaseEntry value 
=   new  DatabaseEntry();
        crawlUriBinding.objectToEntry(curi, value);
        
//  Output tally on avg. size if level is FINE or greater.
         if  (LOGGER.isLoggable(Level.FINE))  {
            tallyAverageEntrySize(curi, value);
        }

        OperationStatus status; 
        
if (overwriteIfPresent)  {
            
// 添加
            status  =  pendingUrisDB.put( null , insertKey, value);
        }
  else   {
            status 
=  pendingUrisDB.putNoOverwrite( null , insertKey, value);
        }

        
if (status != OperationStatus.SUCCESS)  {
            LOGGER.severe(
" failed;  " + status +   "   " + curi);
        }

    }

    
}

 BdbWorkQueue:

代表一个链接队列,该队列中所有的链接都具有相同的键值.它实际上是通过调用BdbMultipleWorkQueues的get方法从等处理链接数据库中取得一个链接的.


package  org.archive.crawler.frontier;

public   class  BdbWorkQueue  extends  WorkQueue
implements  Comparable, Serializabl
{
// 获取一个URL
     protected  CrawlURI peekItem( final  WorkQueueFrontier frontier)
    
throws  IOException {
        
/**
         * 关键:从BdbFrontier中返回pendingUris
         
*/
        
final  BdbMultipleWorkQueues queues  =  ((BdbFrontier) frontier)
            .getWorkQueues();
        
        DatabaseEntry key 
=   new  DatabaseEntry(origin);
        CrawlURI curi 
=   null ;
        
int  tries  =   1 ;
        
while ( true ) {
            
try  {
                
// 获取链接
                curi  =  queues.get(key);
            } 
catch  (DatabaseException e) {
                LOGGER.log(Level.SEVERE,
" peekItem failure; retrying " ,e);
            }
         
    
return  curi;
    }
}

 WorkQueueFrontier:

实现了最核心的三个方法.


public  CrawlURI next()
    
throws  InterruptedException, EndedException {
        
while  ( true ) {  //  loop left only by explicit return or exception
             long  now  =  System.currentTimeMillis();

            
//  Do common checks for pause, terminate, bandwidth-hold
            preNext(now);
            
            
synchronized (readyClassQueues) {
                
int  activationsNeeded  =  targetSizeForReadyQueues()  -  readyClassQueues.size();
                
while (activationsNeeded  >   0   &&   ! inactiveQueues.isEmpty()) {
                    activateInactiveQueue();
                    activationsNeeded
-- ;
                }
            }
                   
            WorkQueue readyQ 
=   null ;
            Object key 
=  readyClassQueues.poll(DEFAULT_WAIT,TimeUnit.MILLISECONDS);
            
if  (key  !=   null ) {
                readyQ 
=  (WorkQueue) this .allQueues.get(key);
            }
            
if  (readyQ  !=   null ) {
                
while ( true ) {  //  loop left by explicit return or break on empty
                    CrawlURI curi  =   null ;
                    
synchronized (readyQ) {
                        
/** 取出一个URL,最终从子类BdbFrontier的
                         * pendingUris中取出一个链接
                         
*/
                        curi 
=  readyQ.peek( this );                     
                        
if  (curi  !=   null ) {
                            
//  check if curi belongs in different queue
                            String currentQueueKey  =  getClassKey(curi);
                            
if  (currentQueueKey.equals(curi.getClassKey())) {
                                
//  curi was in right queue, emit
                                noteAboutToEmit(curi, readyQ);
                                
// 加入正在处理队列中
                                inProcessQueues.add(readyQ);
                                
return  curi;  // 返回
                            }
                            
//  URI's assigned queue has changed since it
                            
//  was queued (eg because its IP has become
                            
//  known). Requeue to new queue.
                            curi.setClassKey(currentQueueKey);
                            readyQ.dequeue(
this ); // 出队列
                            decrementQueuedCount( 1 );
                            curi.setHolderKey(
null );
                            
//  curi will be requeued to true queue after lock
                            
//   on readyQ is released, to prevent deadlock
                        }  else  {
                            
//  readyQ is empty and ready: it's exhausted
                            
//  release held status, allowing any subsequent 
                            
//  enqueues to again put queue in ready
                            readyQ.clearHeld();
                            
break ;
                        }
                    }
                    
if (curi != null ) {
                        
//  complete the requeuing begun earlier
                        sendToQueue(curi);
                    }
                }
            } 
else  {
                
//  ReadyQ key wasn't in all queues: unexpected
                 if  (key  !=   null ) {
                    logger.severe(
" Key  " +  key  +
                        
"  in readyClassQueues but not allQueues " );
                }
            }

            
if (shouldTerminate) {
                
//  skip subsequent steps if already on last legs
                 throw   new  EndedException( " shouldTerminate is true " );
            }
                
            
if (inProcessQueues.size() == 0 ) {
                
//  Nothing was ready or in progress or imminent to wake; ensure 
                
//  any piled-up pending-scheduled URIs are considered
                 this .alreadyIncluded.requestFlush();
            }    
        }
    }


// 将URL加入待处理队列
     public   void  schedule(CandidateURI caUri) {
        
//  Canonicalization may set forceFetch flag.  See
        
//  #canonicalization(CandidateURI) javadoc for circumstance.
        String canon  =  canonicalize(caUri);
        
if  (caUri.forceFetch()) {
            alreadyIncluded.addForce(canon, caUri);
        } 
else  {
            alreadyIncluded.add(canon, caUri);
        }
    }
 
 

BdbFrontier:

继承了WorkQueueFrontier,是Heritrix唯一个具有实际意义的链接工厂.


package  org.archive.crawler.frontier;
public   class  BdbFrontier  extends  WorkQueueFrontier  implements  Serializable 
{
    
/**  所有待抓取的链接 */
    
protected   transient  BdbMultipleWorkQueues pendingUris;

    
// 初始化pendingUris,父类为抽象方法
     protected   void  initQueue()  throws  IOException {
        
try  {
            
this .pendingUris  =  createMultipleWorkQueues();
        } 
catch (DatabaseException e) {
            
throw  (IOException) new  IOException(e.getMessage()).initCause(e);
        }
    }

   
private  BdbMultipleWorkQueues createMultipleWorkQueues()
    
throws  DatabaseException {
        
return   new  BdbMultipleWorkQueues( this .controller.getBdbEnvironment(),
            
this .controller.getBdbEnvironment().getClassCatalog(),
            
this .controller.isCheckpointRecover());
    }
    
protected  BdbMultipleWorkQueues getWorkQueues() {
        
return  pendingUris;
    }


}

BdbUriUniqFilter:
实际上是一个过滤器,它用来检查一个要进入等待队列的链接是否已经被抓取过.


// 添加URL
     protected   boolean  setAdd(CharSequence uri) {
        DatabaseEntry key 
=   new  DatabaseEntry();
        LongBinding.longToEntry(createKey(uri), key);
        
long  started  =   0 ;
        
        OperationStatus status 
=   null ;
        
try  {
            
if  (logger.isLoggable(Level.INFO)) {
                started 
=  System.currentTimeMillis();
            }
            
// 添加到数据库
            status  =  alreadySeen.putNoOverwrite( null , key, ZERO_LENGTH_ENTRY);
            
if  (logger.isLoggable(Level.INFO)) {
                aggregatedLookupTime 
+=
                    (System.currentTimeMillis() 
-  started);
            }
        } 
catch  (DatabaseException e) {
            logger.severe(e.getMessage());
        }
        
if  (status  ==  OperationStatus.SUCCESS) {
            count
++ ;
            
if  (logger.isLoggable(Level.INFO)) {
                
final   int  logAt  =   10000 ;
                
if  (count  >   0   &&  ((count  %  logAt)  ==   0 )) {
                    logger.info(
" Average lookup  "   +
                        (aggregatedLookupTime 
/  logAt)  +   " ms. " );
                    aggregatedLookupTime 
=   0 ;
                }
            }
        }
        
// 如果存在,返回false
         if (status  ==  OperationStatus.KEYEXIST) {
            
return   false ;  //  not added
        }  else  {
            
return   true ;
        }
    }
 
别再乱调参数了!APEX压枪宏原理详解:从罗技Lua脚本看鼠标移动模拟 本文深入解析APEX压枪宏的底层逻辑,从罗技Lua脚本的编写到精准控制鼠标移动的科学方法。通过分析游戏物理引擎与输入设备的交互原理,解码Lua脚本中的时间控制艺术,建立参数计算模型,帮助玩家从试错转向科学调整。文章还提供了高级调试技巧与性能优化方案,以及不同武器的参数化配置建议,全面提升压枪效果。 阅读详情

相关推荐

APEX压枪宏安全使用指南:罗技G Hub脚本配置、风险与社区规则详解

本文详细解析了APEX压枪宏在罗技G Hub中的安全配置方法,包括脚本参数调整、反作弊规避策略及游戏公平性探讨。针对Respawn官方政策和社区规则,提供了降低账号风险的实用建议,帮助玩家在合规边界内使用硬件宏功能。

weixin_33146151的博客 416

APEX罗技压枪代码可修改

修个这里不要动其他代码滚轮键按下开启再次按下关闭。可修改代码x,y,来修改压枪位置。

weixin_69791580的博客 1万+

鼠标宏压枪源码

次程序仅供学习使用请勿拿来做一些特殊用途 。

给我一个apex的罗技鼠标宏,

首先,在使用宏前请确保您的游戏和鼠标都已正确设置,并且允许使用宏。如果您已经做到了这一点,您可以使用以下代码作为您的Apex Legends的Logitech鼠标宏: F1:: Loop { GetKeyState, LButton,state if state = U break Click Sleep, 10 } return 这是一个简单的宏,它将模拟您按下和松开的...

weixin_42605397的博客 1万+

别再折腾Windows了!Ubuntu 22.04下USRP X310 + RFNoC + Vivado 2021.1开发环境保姆级搭建指南

本文提供Ubuntu 22.04下USRP X310 + RFNoC + Vivado 2021.1开发环境的详细搭建指南,涵盖系统优化、UHD驱动编译、Vivado配置及硬件验证等关键步骤,帮助射频工程师高效构建稳定的开发环境,显著提升FPGA开发效率。

weixin_29168675的博客 263

【操作系统】Hello CTF-专为CTF比赛封装的虚拟机 Beta版

很多师傅在学习与研究CTF的道路上,总是碰到想提升自我水平,但缺少本地化的训练环境以及安装各类软件的烦恼现象;因此拥有一些趁手“武器”,干起活来将会事半功倍。CTFos是探姬(ProbiusOfficial)专为CTF比赛封装的虚拟机,基于工具集封装多个版本和系统。CTF入门选手各行业网络/信息从业人员安全相关工作人员但不想在工作机上安装CTF一些奇葩的软件…该系统是通过虚拟机封装的,需要使用打开!一个专为CTF比赛封装的虚拟机,开箱即用。

qq_47493625的博客 1万+

深入学习Heritrix---解析Frontier(链接工厂)(转)

深入学习Heritrix---解析Frontier(链接工厂) Frontier是Heritrix最核心的组成部分之一,也是最复杂的组成部分.它主要功能是为处理链接的线程提供URL,并负责链接处理完成后的一些后续调度操作.并且为了提高效率,它在内部使用了Berkeley DB.本节将对它的内部机理进行详细解剖.在Heritrix的官方文档上有一个Frontier的例子,虽然很简单,但是它却解释F...

weixin_34227447的博客 147

台达PLC的Ethernet/IP通讯详解

EtherNet/IP 为由 ODVA 协会( Open DeviceNet Vendors Association )管理的工业以太网通讯协议,其名称 中IP是工业协议(Industrial Protocol)的缩写。(本文中简称EIP)EtherNet/IP架构于TCP/IP通讯协议上,可兼容一般IT网络,提供工厂自动化(FA)、楼宇自动化(BA)和程序自动化(PA)等应用高速稳定的应用。设备与联机建立完成后,通过数据交换表建立设备与设备间的数据交换。主站:台达AS300系列PLC(AS332T)

u010123476的专栏 4457

heritrix中的Frontier学习

  (1)BdbFrontier链接工厂,initQueue()初始化等待队列 public class BdbFrontier extends WorkQueueFrontier implements Serializable { /** 所有待抓取的链接*/ protected transient BdbMultipleWorkQueues pendingUris; //初始化pend...

iteye_14896的博客 210

《算法第四版》学习心得一——怎么学算法

 一、算法的两个核心 算法的核心内容实际上有两个: 算法的概念和思路。 算法的编程实现。 两者相互关联影响,缺一不可。 不理解基本概念和思路,就算把实现代码背下来,也无济于事,因为脑袋里依然是一片模糊。理解了概念和思路,不去用代码实现,脑袋里有的只是概念,无法根据真实需求实现解决方案。 二、学算法需要什么基础 首先,必须要有一定的编程语言基础,要理解语言中最基本的概念:数据类型,类,成...

illikang的博客 3912

告别Keil4!手把手教你用Keil C51 V9.61编译51单片机代码(附最新激活方法)

本文详细介绍了Keil C51 V9.61在51单片机开发中的全栈升级指南,包括编译速度提升、调试器性能优化和现代开发支持等核心优势。通过智能安装方案、项目迁移实战和新特性深度应用,帮助开发者告别Keil4,大幅提升开发效率。附有最新激活方法和实用技巧,适用于嵌入式开发工程师。

weixin_26886855的博客 427

Frontier链接制造工厂

Frontier在英文中的意思是“前线,领域”,在Heritrix中,它表示一种具。它通过一些特定的算法来决定哪个链接将接下来被送入处理器链中,同时,它本身也负责一定的日志和状态报告功能。 事实上,要写出一个合格并且真正能够使用的Frontier绝非一件简单的事情,尽管有了Frontier接口,其中的方法约束了Frontier的行为,也给编码带来了一定的指示。但是其中还存在着很多问题,需要很

lycos的六度空间 634

HRNet训练自己的分类数据

1.搭建环境 为了防止和服务器上的环境冲突,这里利用conda搭建环境。 Install PyTorch=0.4.1 following theofficial instructions git clonehttps://github.com/HRNet/HRNet-Image-Classification Install dependencies: pip install -r requirements.txt ...

C/C++、嵌入式开发、深度学习算法、模型部署与推理优化 5852

heritrix中的Frontier分析

Frontier是Heritrix最核心的组成部分之一,也是最复杂的组成部分.它主要功能是为处理链接的线程提供URL,并负责链接处理完成后的一些后续调度操作.并且为了提高效率,它在内部使用了Berkeley DB.本节将对它的内部机理进行详细解剖. 在Heritrix的官方文档上有一个Frontier的例子,虽然很简单,但是它却解释Frontier实现的基本原理.在这里...

weixin_34354945的博客 202

《拉依达的嵌入式\驱动面试宝典》—操作系统篇(二)

《拉依达的嵌入式\驱动面试宝典》 整合了所有我认为可能遇到的技术面试问题。所有问题及其答案均是我个人学习后查阅资料总结,每个回答都做了仔细的分析,在嵌入式及其驱动面试相关问题解析做到全网独一无二。学习或者转行到嵌入式、驱动开发领域学习的不二之选

拉依达不拉跨的博客 474

硬件知识点-----SPI串联电阻、振铃、过冲

电阻取值,没有公式,一被传输线的特征阻抗为50欧姆左右,而TTL电路输出电阻大桃为13欧姆左右,在源端串一个33姆,大致和50相当,这样就可以柳制从终端反射回来的倍号,防止再次反射。传输时间tp=L/V,其中L是导线长度,V是电磁波在电路板中的传输速度V=C/sqrDk,其中Dk是光速衰减因子,对于电路板而言是铜线,Dk=4电磁波在电路板中的速度都是慢于光速的。实际上串联多大的电阻与传输线的阻抗有关,为了保证阻抗的连续性,如果传输线的特性阻抗 Z0与驱动源的输出阻抗 Zd不匹配,会引发信号的反射。

贾saisai的博客 2742

开发自己的搜索引擎——Lucene 2.0+Heriterx——Heritrix的架构

 http://book.csdn.net/bookfiles/312/10031212849.shtml10.2  Heritrix的架构在上一节中,详细介绍了Heritrix的使用入门。读者通过上一节的介绍,应该已经能够使用Heritrix来进行简单的网页抓取了。那么,Heritrix的内容究竟是如何工作的呢?它的设计方面有什么突出之处?本节就将介绍Heritrix的几个主要组件,

gris的专栏 2486

老版QQ原生表情gif动态

这是老版的QQ表情,不过全是动态的的,Windows照片查看器是不会动的,可以右击用浏览器打开查看,再说一遍是老版的,只是分享给宁愿用老版也要动态的人。

heritrix的主要功能模块

1、Frontier(链接工厂)是Heritrix最核心的部分,有三个核心的方法:next,schedule,finished,其原型及作用如下: a) 程提供一个链接.Heritrix的所有处理线程(ToeThread)都是通过调用该方法获取链接的 b) schedule(CandidateURI caURI):调度待处理的链接 c) finished(CrawlURI cURI):

kivcare的专栏 1069

Probability and Statistics - 4th edition

Probability and Statistics - 4th edition

IDEA的使用指南

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

Heritrix架构学习笔记(三)

3、Frontier链接制造工厂在heritrix-1.12.1/docs/articles/developer_manual/frontier.html下可找到Heritrix的官方文档的一个Frontier例子: /**  * A simple Frontier implem

每天=生命的最后一天 1429

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

Heritrix的架构

[b]10.2 Heritrix的架构[/b] 在上一节中,详细介绍了Heritrix的使用入门。读者通过上一节的介绍,应该已经能够使用Heritrix来进行简单的网页抓取了。那么,Heritrix的内容究竟是如何工作的呢?它的设计方面有什么突出之处? 本节就将介绍Heritrix的几个主要组件,以此让读者了解其主要架构和工作方式。为后续的扩展Heritrix做一些铺垫。 10.2.1 ...

java12616383的博客 282
上一篇: URL散列算法-ELF Hash法
下一篇: java正则表达式:group()详解
Java2King
博客等级 码龄18年 221粉丝 77原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值
⌂ 换网址