lucene索引删除,恢复,更新

报错:Exception in thread “main“ org.apache.ibatis.exceptions.PersistenceException: (解决办法) Exception in thread "main" org.apache.ibatis.exceptions.PersistenceException: ### Error updating database. Cause: java.sql.SQLException: The server time 遇到红色这种问题的原因有很多,那就要根据第二行来判断。说明数据库连接的问题报错了,改数据库时区就好了。用mybatis去sql语句的时候报错了。:mishop是自己的数据库名称。第二行黄色报的这个是。 阅读详情
  1. package org.se.lucene;  
  2.   
  3. //主类  
  4. import java.io.File;  
  5. import java.io.IOException;  
  6. import org.apache.lucene.analysis.standard.StandardAnalyzer;  
  7. import org.apache.lucene.document.Document;  
  8. import org.apache.lucene.document.Field;  
  9. import org.apache.lucene.index.CorruptIndexException;  
  10. import org.apache.lucene.index.IndexReader;  
  11. import org.apache.lucene.index.IndexWriter;  
  12. import org.apache.lucene.index.IndexWriterConfig;  
  13. import org.apache.lucene.index.Term;  
  14. import org.apache.lucene.store.Directory;  
  15. import org.apache.lucene.store.FSDirectory;  
  16. import org.apache.lucene.store.LockObtainFailedException;  
  17. import org.apache.lucene.util.Version;  
  18.   
  19. public class lucene_index {  
  20.         private String[] ids={"1","2","3","4","5","6"};  
  21.         private String[] emails={"aa@aa.org","cc@cc.org","dd@@dd.org","bb@bb.org","ee@ee.org","ff@ff.org"};  
  22.         private String[] contents={"welcometotyu","hellowboy","higirl","howareyou","googluck","badgosh"};  
  23.         private int[] attachs={1,2,3,4,5,6};  
  24.         private String[] names={"liwu","zhangsan","xiaoqinag","laona","dabao","lisi"};  
  25.         private Directory directory=null;  
  26.           
  27.         public lucene_index()  
  28.         {  
  29.             try {  
  30.                 directory=FSDirectory.open(new File("f:/lucene/index02"));  
  31.             } catch (IOException e) {  
  32.                 // TODO Auto-generated catch block  
  33.                 e.printStackTrace();  
  34.             }  
  35.         }  
  36.         public void quary()  
  37.         {  
  38.             try {  
  39.                 IndexReader reader=IndexReader.open(directory);  
  40.                 System.out.println("numdocs"+reader.numDocs());  
  41.                 System.out.println("maxDocs"+reader.maxDoc());  
  42.                 System.out.println("detelemaxDocs"+reader.numDeletedDocs());  
  43.                 reader.close();  
  44.             } catch (CorruptIndexException e) {  
  45.                 // TODO Auto-generated catch block  
  46.                 e.printStackTrace();  
  47.             } catch (IOException e) {  
  48.                 // TODO Auto-generated catch block   
  49.                 e.printStackTrace();  
  50.             }  
  51.               
  52.         }  
  53.           
  54.         @SuppressWarnings("deprecation")  
  55.         public void undelete()  
  56.         {  
  57.             try {  
  58.                 //回复时必须把reader的只读设为false  
  59.                 IndexReader reader=IndexReader.open(directory,false);  
  60.                 reader.undeleteAll();  
  61.                 reader.close();  
  62.             } catch (CorruptIndexException e) {  
  63.                 // TODO Auto-generated catch block  
  64.                 e.printStackTrace();  
  65.             } catch (IOException e) {  
  66.                 // TODO Auto-generated catch block  
  67.                 e.printStackTrace();  
  68.             }  
  69.               
  70.         }  
  71.       
  72.         //清空回收站,强制优化  
  73.         public void forceDelete()  
  74.         {  
  75.             IndexWriter writer=null;  
  76.             try {  
  77.                 writer=new IndexWriter(directory, new IndexWriterConfig(Version.LUCENE_36,  
  78.                         new StandardAnalyzer(Version.LUCENE_36)));  
  79.                 //参数十一个选项,可以是一个query,也可以是一个term  term就是一个精确查找的值  
  80.                 //此时删除的文档并未完全删除,而是存储在回收站中,可以恢复的  
  81.                 writer.forceMergeDeletes();  
  82.             } catch (CorruptIndexException e) {  
  83.                 e.printStackTrace();  
  84.             } catch (LockObtainFailedException e) {  
  85.                 e.printStackTrace();  
  86.             } catch (IOException e) {  
  87.                 e.printStackTrace();  
  88.             }  
  89.             finally{  
  90.                 if (writer!=null) {  
  91.                     try {  
  92.                         writer.close();  
  93.                     } catch (CorruptIndexException e) {  
  94.                         // TODO Auto-generated catch block  
  95.                         e.printStackTrace();  
  96.                     } catch (IOException e) {  
  97.                         // TODO Auto-generated catch block  
  98.                         e.printStackTrace();  
  99.                     }  
  100.                 }  
  101.             }  
  102.         }  
  103.           
  104.         public void merge()  
  105.         {  
  106.             IndexWriter writer=null;  
  107.             try {  
  108.                 writer=new IndexWriter(directory, new IndexWriterConfig(Version.LUCENE_36,  
  109.                         new StandardAnalyzer(Version.LUCENE_36)));  
  110.                   
  111.                 writer.forceMerge(2);  
  112.             } catch (CorruptIndexException e) {  
  113.                 e.printStackTrace();  
  114.             } catch (LockObtainFailedException e) {  
  115.                 e.printStackTrace();  
  116.             } catch (IOException e) {  
  117.                 e.printStackTrace();  
  118.             }  
  119.             finally{  
  120.                 if (writer!=null) {  
  121.                     try {  
  122.                         writer.close();  
  123.                     } catch (CorruptIndexException e) {  
  124.                         // TODO Auto-generated catch block  
  125.                         e.printStackTrace();  
  126.                     } catch (IOException e) {  
  127.                         // TODO Auto-generated catch block  
  128.                         e.printStackTrace();  
  129.                     }  
  130.                 }  
  131.             }  
  132.         }  
  133.           
  134.         public void delete()  
  135.         {  
  136.             IndexWriter writer=null;  
  137.             try {  
  138.                 writer=new IndexWriter(directory, new IndexWriterConfig(Version.LUCENE_36,  
  139.                         new StandardAnalyzer(Version.LUCENE_36)));  
  140.                 //参数十一个选项,可以是一个query,也可以是一个term  term就是一个精确查找的值  
  141.                 //此时删除的文档并未完全删除,而是存储在回收站中,可以恢复的  
  142.                 writer.deleteDocuments(new Term("id","1"));  
  143.             } catch (CorruptIndexException e) {  
  144.                 e.printStackTrace();  
  145.             } catch (LockObtainFailedException e) {  
  146.                 e.printStackTrace();  
  147.             } catch (IOException e) {  
  148.                 e.printStackTrace();  
  149.             }  
  150.             finally{  
  151.                 if (writer!=null) {  
  152.                     try {  
  153.                         writer.close();  
  154.                     } catch (CorruptIndexException e) {  
  155.                         // TODO Auto-generated catch block  
  156.                         e.printStackTrace();  
  157.                     } catch (IOException e) {  
  158.                         // TODO Auto-generated catch block  
  159.                         e.printStackTrace();  
  160.                     }  
  161.                 }  
  162.             }  
  163.         }  
  164.         public void index()  
  165.         {  
  166.                IndexWriter writer=null;  
  167.                Document doc=null;  
  168.                try {  
  169.                 writer =new IndexWriter(directory,new IndexWriterConfig(Version.LUCENE_36,   
  170.                            new StandardAnalyzer(Version.LUCENE_36)));  
  171.                 //writer.deleteAll();  
  172.                 for(int i=0;i<ids.length;i++)  
  173.                 {  
  174.                     doc=new Document();  
  175.                     doc.add(new Field("id",ids[i],Field.Store.YES,Field.Index.NOT_ANALYZED_NO_NORMS));  
  176.                     doc.add(new Field("emails",emails[i],Field.Store.YES,Field.Index.NOT_ANALYZED));  
  177.                     doc.add(new Field("contents",contents[i],Field.Store.YES,Field.Index.ANALYZED));  
  178.                     doc.add(new Field("name",names[i],Field.Store.YES,Field.Index.NOT_ANALYZED_NO_NORMS));  
  179.                     writer.addDocument(doc);   
  180.                 }  
  181.             } catch (CorruptIndexException e) {  
  182.                 // TODO Auto-generated catch block  
  183.                 e.printStackTrace();  
  184.             } catch (LockObtainFailedException e) {  
  185.                 // TODO Auto-generated catch block  
  186.                 e.printStackTrace();  
  187.             } catch (IOException e) {  
  188.                 // TODO Auto-generated catch block  
  189.                 e.printStackTrace();  
  190.             }  
  191.                finally{  
  192.                    if(writer!=null)  
  193.                    {  
  194.                       try {  
  195.                         writer.close();  
  196.                     } catch (CorruptIndexException e) {  
  197.                         // TODO Auto-generated catch block  
  198.                         e.printStackTrace();  
  199.                     } catch (IOException e) {  
  200.                         // TODO Auto-generated catch block  
  201.                         e.printStackTrace();  
  202.                     }     
  203.                    }  
  204.                }  
  205.         }  
  206.        //更新索引  
  207.         public void update()  
  208.         {  
  209.             /*lucene本身不支持更新 
  210.              *  
  211.              * 通过删除索引然后再建立索引来更新 
  212.              */  
  213.               IndexWriter writer=null;  
  214.                Document doc=null;  
  215.                try {  
  216.                 writer =new IndexWriter(directory,new IndexWriterConfig(Version.LUCENE_36,   
  217.                            new StandardAnalyzer(Version.LUCENE_36)));  
  218.                 writer.deleteAll();  
  219.                 for(int i=0;i<ids.length;i++)  
  220.                 {  
  221.                     doc=new Document();  
  222.                     doc.add(new Field("id",ids[i],Field.Store.YES,Field.Index.NOT_ANALYZED_NO_NORMS));  
  223.                     doc.add(new Field("emails",emails[i],Field.Store.YES,Field.Index.NOT_ANALYZED));  
  224.                     doc.add(new Field("contents",contents[i],Field.Store.YES,Field.Index.ANALYZED));  
  225.                     doc.add(new Field("name",names[i],Field.Store.YES,Field.Index.NOT_ANALYZED_NO_NORMS));  
  226.                     writer.updateDocument(new Term("id","1"), doc);   
  227.                 }  
  228.             } catch (CorruptIndexException e) {  
  229.                 // TODO Auto-generated catch block  
  230.                 e.printStackTrace();  
  231.             } catch (LockObtainFailedException e) {  
  232.                 // TODO Auto-generated catch block  
  233.                 e.printStackTrace();  
  234.             } catch (IOException e) {  
  235.                 // TODO Auto-generated catch block  
  236.                 e.printStackTrace();  
  237.             }  
  238.                finally{  
  239.                    if(writer!=null)  
  240.                    {  
  241.                       try {  
  242.                         writer.close();  
  243.                     } catch (CorruptIndexException e) {  
  244.                         // TODO Auto-generated catch block  
  245.                         e.printStackTrace();  
  246.                     } catch (IOException e) {  
  247.                         // TODO Auto-generated catch block  
  248.                         e.printStackTrace();  
  249.                     }     
  250.                    }  
  251.                }      
  252.         }  
  253. }  
  254.   
  255.   
  256. //测试类  
  257. package org.se.lucene;  
  258.   
  259. import org.junit.Test;  
  260.   
  261. public class test {  
  262.   
  263.     @Test  
  264.     public void testIndex()  
  265.     {  
  266.         lucene_index l_index=new lucene_index();  
  267.         l_index.index();  
  268.     }  
  269.     @Test  
  270.       
  271.     public void testquary()  
  272.     {  
  273.         lucene_index l_index=new lucene_index();  
  274.         l_index.quary();  
  275.     }  
  276.     @Test  
  277.     public void testDelete()  
  278.     {  
  279.         lucene_index l_index=new lucene_index();  
  280.         l_index.delete();  
  281.     }  
  282.     @Test  
  283.     public void testunDelete()  
  284.     {  
  285.         lucene_index l_index=new lucene_index();  
  286.         l_index.undelete();  
  287.     }  
  288.     @Test  
  289.     public void testForceDelete()  
  290.     {  
  291.         lucene_index l_index=new lucene_index();  
  292.         l_index.forceDelete();  
  293.     }  
  294.     @Test  
  295.     public void testmerge()  
  296.     {  
  297.         lucene_index l_index=new lucene_index();  
  298.         l_index.merge();  
  299.     }  
  300.       
  301.     @Test  
  302.     public void upDate()  
  303.     {  
  304.         lucene_index l_index=new lucene_index();  
  305.         l_index.update();  
  306.     }  
  307.       
  308. }  
Blender软件导出地形到Gazebo中 Blender软件导出地形到Gazebo中,并配置纹理、刚度、高度。 阅读详情

相关推荐

5G NR 双连接与载波聚合:PCell、SCell、PScell、SpCell 角色全解析

本文全面解析了5G NR中双连接与载波聚合技术的关键概念,详细介绍了PCell、SCell、PScell和SpCell的角色与功能。通过实际案例和配置示例,帮助读者理解这些小区在提升网络覆盖和速率方面的作用,以及在实际组网中的优化策略。

weixin_33220360的博客 373

Luence建索中的一个异常

异常:org.apache.lucene.index.CorruptIndexException: failed to locate current segments_N file at org.apache.lucene.index.IndexFileDeleter.&lt;init&gt;(IndexFileDeleter.java:223) at org.apache.lucene.in...

香辣虾虾 679

scratch lenet(4): 开根号的C语言实现

使用C语言,分别使用二分法、牛顿法、卡马克快速法,求解正实数的开根号。包括公式推导、代码实现、运行结果,不使用任何第三方库和C标准库的数学库。

baiyu33的博客 4969

elasticsearch7.5.1集群断电故障解决方案

错误信息如下 { "state": "UNASSIGNED", "primary": true, "node": null, "relocating_node": null, "shard": 3, "index": "device_search_20201204", "recovery_source": { "type": "EXISTING_STORE","bootstrap_new_history_uuid": false}, "unassigned_info": { "reason": "ALLOC

Mr小川的博客 1578

【全网最新】使用 1panel面板 部署若依系统( springboot 和 vue)项目

打开前端项目的vue.config.js文件,检查devServer下的proxy代理部分,然后将下面这个端口修改为你要在打包后访问的端口,即使用nginx代理前的接口。这个端口默认是80端口,这里把其修改为不会冲突的8010端口,后台接口的地址配置为9080,不过感觉这里设置的8010和9080可能没有用,因为部署前端静态页面是,也配置了一次网页的外部接口和api的接口,后期有空了再验证。打开右侧的Maven,点击:生存期->package,然后点击运行,等待打包成功,包在如图所示的文件夹中。

老薛的专栏 1755

Tushare Pro的安装使用——“抱歉,您没有访问该接口的权限,权限的具体详情访问:https://tushare.pro/document/1?doc_id=108”问题

最近做毕设关于量化交易的, 因此一直使用tushare作数据源,但是过程中到一些问题,因此这里写篇文章,供大家一起交流下。 Tushare简介 Tushare是一个免费、开源的python财经数据接口包。拥有如股票、基金、期货等行情数据,公司财务、基金经理等基本面数据,以及债券、外汇、行业、大数据、区块链。Tushare返回的绝大部分的数据格式都是pandas DataFrame类型,因此非常方便...

sinat_40875078的博客 1万+

智能查询功能lucene使用情况及遇到的问题

[color=orange][/color]系统智能查询功能lucene使用情况及遇到的问题 根据客户反映我们要实现的搜索功能。 【范例】 • 【自然语查询】输入「百草」,可以查到「百草路」 • 【同音字查询】输入「白超路」,可以查到「百草路」 第一. 自然语句查询。 这是lucene大众化的搜索功能,但是单纯使用lucene官方包内的提供中文分词器,不能很好的实现我们需

skiof007的专栏 1125

一定能解决ROS系统 rosdep update超时问题de简单方法

rosdep update命令使用 1.首先将下面仓库的内容clone到本地 git clone https://github.com/ros/rosdistro.git 记录rosdistro存放地址,例如/home/gec/rosdistro 如果是自己的改成/home/user/rosdistro,其中user表示用户名 2.修改/usr/lib/python2/dist-packages/rosdep2/rep3.py文件 cd /usr/lib/python2/dist-packages/ros

努力是明天快乐的源泉 5万+

Lucene小练三——索引删除,恢复,更新

package org.se.lucene; //主类 import java.io.File; import java.io.IOException; import org.apache.lucene.analysis.standard.StandardAnalyzer; import org.apache.lucene.document.Document; import org.apache...

Smallearth的专栏 148

出现 RuntimeError: adaptive_avg_pool2d_backward_cuda does not have a deterministic implementation的解决方法

大致就是在执行主函数的训练函数中,在反向传播这一块出现了问题。解决方法就是添加如下代码块。找到提示bug的行数。

码农研究僧的博客 5532

【ODX介绍】-4.2-UDS诊断$27服务在ODX-D诊断描述文件中如何描述

共25页精讲:附ODX-D XML:UDS $27 Security服务0x61和0x62 Sub-Function,其它Sub-Function可参照其格式。 目录 1 ODX-D描述一个UDS $27 Security服务Sub-Function的结构 2 标签DIAG-SERVICE描述的内容 2.1 举例:DIAG-SERVICE的XML描述 3 标签REQUEST描述的内容 3.1 举例:REQUEST的XML描述 4 标签POS-RESPONSE描述的内容 4.1 举例:PO..

「汽车电子助手」的博客 1121

Lucene索引删除、更新、恢复和加权操作

Lucene索引删除、更新、恢复和加权操作

高興 1097

Python 爬虫 + 数据分析:社会调查数据抓取与结果可视化分析

在当今数字化时代,数据已成为推动社会发展的关键资源之一。无论是市场调研、学术研究还是政策制定,社会调查数据都扮演着至关重要的角色。通过 Python 爬虫技术,我们可以高效地获取这些数据,并结合数据分析与可视化工具,深入挖掘数据背后的价值。本文将通过一个完整的实战项目,带你掌握如何使用 Python 爬虫抓取社会调查数据,并进行可视化分析。

yansideyucsdn的博客 126

Lucene中索引的删除,更新与查找以及恢复(lucene3.5)

package org.itat.text1; import java.io.File; import java.io.IOException; import javax.management.Query; import org.apache.lucene.analysis.standard.StandardAnalyzer; import org.apache.lucene.document

Lves Li的专栏 2498

温度PID控制PLC程序

温度PID稳定控制程序,适用于欧姆龙PLC,对其他PLC也具有很大参考价值

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

Lucene笔记04-Lucene索引的删除与更新

一、删除索引 public void delete() { IndexWriter indexWriter = null; try { indexWriter = new IndexWriter(directory, new IndexWriterConfig(Version.LUCENE_35, new StandardAnalyzer(Version.LUC...

王劭阳的博客 822

SIMATIC S7-1200, S7-1500 PID 控制[手册]

SIMATIC S7-1200, S7-1500 PID 控制[手册]

lucene-索引文档的删除、更新及增强加权

1、删除1)使用IndexReader类实现,这个类并没有立即从索引中删除文档,而只是在这些文档上加一个删除标记,直到IndexReader调用close()后才真正将它们删除。2)maxDoc()返回下一个可得到的文档的内部编号。numDocs()返回索引中的文档数量。 文档编号从0开始3)public class DocumentDeleteTest extends

深未来技术 691

VB摄像头监控

该VB模块可对摄像头捕获的画面进行录像等,可在创建的窗口进行控制

Lucene入门之索引的管理

Normal 0 7.8 磅 0 2 false false false EN-US ZH-CN X-NONE

snowteng17的专栏 1180

Lucene3.5 之 索引删除和更新

package com.ethan.index;    import java.io.File;  import java.io.IOException;    import org.apache.commons.io.FileUtils;  import org.apache.lucene.analysis.standard.StandardAnalyzer;  import org.apach

退思园 3563

索引的删除和更新

【删除索引】 1 /** 2 * 测试删除索引 3 */ 4 @Test 5 public void testDelete(){ 6 IndexWriter writer = null; 7 8 try { 9 //1、创建D...

weixin_34266504的博客 174

4、学习Lucene3.5之索引删除、更新

(1)删除索引 /** * 删除索引 */ public void deleteIndex(){ IndexWriter indexWriter = createIndexWriter(); /** * deleteDocuments()参数解析: * 第一种:Term term 删除特定的索引(

panchang199266的博客 339

Lucene3.5 的索引的创建,删除,更新,加权

==注意:在涉及到删除,更改之类的改变索引的操作时,要先重新创建一遍索引,然后再执行相关方法才可以看到效果,否则索引仍然是之前的 1. 索引的创建 (1). 第一步先创建模拟的内容,用于创建索引 private String[] ids = {"1","2","3","4","5"}; private String[] names = {"zhi","dan","feng","zhida

zhidanfeng的专栏 867

Lucene教程(四) 索引的更新和删除

这篇文章是基于上一篇文章来写的,使用的是IndexUtil类,下面的例子不在贴出整个类的内容,只贴出具体的方法内容。 3.5版本: 先写了一个check()方法来查看索引文件的变化: /** * 检查一下索引文件 */ public static void check() { IndexReader indexReader = null;

三丰的专栏 8657

索引维护

索引维护 1. 删除索引 1.1删除指定索引 根据Term项删除索引,满足条件的将全部删除。 @Test public void testIndexDelete() throws Exception { // 创建Directory流对象 Analyzer analyzer = new IKAnalyzer(); Directory directory = ...

少营营的博客 525

Lucene索引操作,删除,更新,优化

IndexUtil.java import java.io.File; import java.io.IOException;  import org.apache.lucene.analysis.standard.StandardAnalyzer; import org.apache.lucene.document.Document; import org.apache.lucene.docum

Kenan 408
上一篇: Lucene索引删除详解
下一篇: Lucene 的认识学习
OnePiece_Sky
博客等级 码龄15年 9粉丝 63原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值