XPath语法 在C#中使用XPath示例

高通GAIA V3命令参考手册的研读学习(15):自定制命令的详细工作描述 里的示例一样,手机APP发出这个GetManuFacturer的命令发0x0000,那么耳机回复:0x8000, 同时在回复的playload部分,用最多15个字节的ACSII码来表达制造商信息(因此最多15个字母)。那么这个APP在通过GAIA协议控制这个耳机时,不仅可以通过前面讲过的vendor ID来识别,也可以更进一步通过这个命令来识别这个耳机,到底是不是本公司的。通过这个可变长度的playload,真的是可以传达极多的事先约定的信息,相当的灵活,真是不错!这个命令用来得到设备的制造商信息。 阅读详情

http://www.cnblogs.com/yukaizhao/archive/2011/07/25/xpath.html


XPath可以快速定位到Xml中的节点或者属性。XPath语法很简单,但是强大够用,它也是使用xslt的基础知识。

示例Xml:

01<?xml version="1.0" encoding="utf-8" ?>
02<pets>
03  <cat color="black" weight="10">
04    <price>100</price>
05    <desc>this is a black cat</desc>
06  </cat>
07  <cat color="white" weight="9">
08    <price>80</price>
09    <desc>this is a white cat</desc>
10  </cat>
11  <cat color="yellow" weight="15">
12    <price>80</price>
13    <desc>this is a yellow cat</desc>
14  </cat>
15 
16 
17  <dog color="black" weight="10">
18    <price>100</price>
19    <desc>this is a black dog</desc>
20  </dog>
21  <dog color="white" weight="9">
22    <price>80</price>
23    <desc>this is a white dog</desc>
24  </dog>
25  <dog color="yellow" weight="15">
26    <price>80</price>
27    <desc>this is a yellow dog</desc>
28  </dog>
29</pets>

XPath的语法:

1. XPath中的符号

符号

说明

示例

示例说明

/

表示从根节点开始选择

/pets

选择根节点pets

表示节点和子节点之间的间隔符

/pets/dog

选择pets节点下的dog节点

//xx

表示从整个xml文档中查找,而不考虑当前节点位置

//price

选择文档中所有的price节点

.

单个英文半角句点表示选择当前节点

/pets/.

选择pets节点

..

双点,表示选择父节点

/pets/dog[0]/..

表示pets节点,也就是第一个dog节点的父节点

@xx

表示选择属性

//dog/@color

表示选择所有dog节点的color属性集合

[…]

中括号表示选择条件,括号内为条件

//dog[@color=’white’]

所有color为white的dog节点

//dog[/price<100]

所有price字节点值小于100的dog节点

中括号内数字为节点索引,类似c#等语言中的数组,数组下标是从1开始的

//dog[1]

第1个dog节点

//dog[last()]

最后一个dog节点,last()是xPath内置函数

|

单竖杠表示合并节点结合

//dog[@color=’white’] | //cat[@color=’white’]

color属性为white的dog节点和color属性为white的cat节点

*

星号表示任何名字的节点或者属性

//dog/*

表示dog节点的所有子节点

//dog/@*

表示dog节点的所有属性节点

2. XPath数学运算符
+ 加号表示加
- 表示数字相减
* 表示乘以
div 表示除以,这里数学上的除号/已经被用作节点之间分隔符了
mod 表示取余
3. XPath逻辑运算符
= 等于,相当于c#中的 ==
!= 不等于
> 大于
>= 大于等于
< 小于
<= 小于等于
and 并且 与关系
or 或者 或关系
4. XPath Axes 从字面翻译这个是XPath轴的意思,但根据我的理解这个翻译成XPath节点关系运算关键字更合适,就是一组关键字加上::双冒号表示和当前节点有关系的一个或者一组节点.
使用语法: axisname::nodetest[predicate] 即轴名字::节点名字[取节点条件]
具体说明如下:

关键字

说明

示例

示例说明

ancestor

当前节点的父祖节点

ancestor::pig

当前节点的祖先节点中的pig节点

ancestor-or-self

当前节点以及其父祖节点

ancestor::pig

 

attribute

当前节点的所有属性

attribute::weight

相当于@weight,attribute::和@是等价的

child

当前节点的所有字节点

child::*[name()!=’price’]

选择名字不是price的子节点

descendant

子孙节点

descendant::*[@*]

有属性的子孙节点

descendant-or-self

子孙节点以及当前节点

descendant-or-self::*

 

following

Xml文档中当前节点之后的所有节点

following::*

 

following-sibling

当前节点的同父弟弟节点

following-sibling::

 

preceding

Xml文档中当前节点之前的所有节点

preceding::*

 

namespace

选取当前节点的所有命名空间节点

namespace::*

 

parent

当前节点的父节点

parent::

相当于双点..

preceding-sibling

当前节点之后的同父兄节点

preceding-sibling::*

 

self

当前节点

self::*

相当于单点.


5. 常用的XPath函数介绍:
在XPath表达式中常用的函数有下面两个:
position() 表示节点的序号例如 //cat[position() = 2] 表示取序号为2的dog节点
last() 表示取最后一个节点 //cat[last()] 
name() 表示当前节点名字 /pets/*[name() != 'pig'] 表示/pets下名字不是pig的子节点
XPath的函数还有很多,包括字符串函数,数字函数和时间函数等,具体可以参考w3的网站。
以上是XPath的语法,下面我们看下如何在.Net中使用XPath
在.Net中可以通过XPathDocument或者XmlDocument类使用XPath。XPathDocument是只读的方式定位Xml节点或者属性文本等,而XmlDocument则是可读写的。
如下代码示例展示了如何使用XPathDocument和XmlDocument。
01using System;
02using System.Collections.Generic;
03using System.Linq;
04using System.Text;
05using System.Xml.XPath;
06using System.Xml;
07 
08namespace UseXPathDotNet
09{
10    class Program
11    {
12        static void Main(string[] args)
13        {
14            UseXPathWithXPathDocument();
15 
16            UseXPathWithXmlDocument();
17 
18            Console.Read();
19        }
20 
21        static void UseXPathWithXmlDocument()
22        {
23            XmlDocument doc = new XmlDocument();
24            doc.Load("http://www.cnblogs.com/yukaizhao/rss");
25            //使用xPath选择需要的节点
26            XmlNodeList nodes = doc.SelectNodes("/rss/channel/item[position()<=10]");
27            foreach (XmlNode item in nodes)
28            {
29                string title = item.SelectSingleNode("title").InnerText;
30                string url = item.SelectSingleNode("link").InnerText;
31                Console.WriteLine("{0} = {1}", title, url);
32            }
33        }
34 
35        static void UseXPathWithXPathDocument()
36        {
37            XPathDocument doc = new XPathDocument("http://www.cnblogs.com/yukaizhao/rss");
38            XPathNavigator xPathNav = doc.CreateNavigator();
39            //使用xPath取rss中最新的10条随笔
40            XPathNodeIterator nodeIterator = xPathNav.Select("/rss/channel/item[position()<=10]");
41            while (nodeIterator.MoveNext())
42            {
43                XPathNavigator itemNav = nodeIterator.Current;
44                string title = itemNav.SelectSingleNode("title").Value;
45                string url = itemNav.SelectSingleNode("link").Value;
46                Console.WriteLine("{0} = {1}",title,url);
47            }
48 
49        }
50    }
51}

XPath使用示例,请看下面的代码注释 

01using System;
02using System.Collections.Generic;
03using System.Linq;
04using System.Text;
05using System.IO;
06using System.Xml;
07 
08namespace UseXPath1
09{
10    class Program
11    {
12        static void Main(string[] args)
13        {
14            string xml = @"<?xml version=""1.0"" encoding=""utf-8"" ?>
15<pets>
16  <cat color=""black"" weight=""10"" count=""4"">
17    <price>100</price>
18    <desc>this is a black cat</desc>
19  </cat>
20  <cat color=""white"" weight=""9"" count=""5"">
21    <price>80</price>
22    <desc>this is a white cat</desc>
23  </cat>
24  <cat color=""yellow"" weight=""15"" count=""1"">
25    <price>110</price>
26    <desc>this is a yellow cat</desc>
27  </cat>
28 
29 
30  <dog color=""black"" weight=""10"" count=""7"">
31    <price>114</price>
32    <desc>this is a black dog</desc>
33  </dog>
34  <dog color=""white"" weight=""9"" count=""4"">
35    <price>80</price>
36    <desc>this is a white dog</desc>
37  </dog>
38  <dog color=""yellow"" weight=""15"" count=""15"">
39    <price>80</price>
40    <desc>this is a yellow dog</desc>
41  </dog>
42 
43    <pig color=""white"" weight=""100"" count=""2"">
44    <price>8000</price>
45    <desc>this is a white pig</desc>   
46    </pig>
47</pets>";
48 
49            using (StringReader rdr = new StringReader(xml))
50            {
51                XmlDocument doc = new XmlDocument();
52                doc.Load(rdr);
53 
54                //取所有pets节点下的dog字节点
55                XmlNodeList nodeListAllDog = doc.SelectNodes("/pets/dog");
56 
57                //所有的price节点
58                XmlNodeList allPriceNodes = doc.SelectNodes("//price");
59 
60                //取最后一个price节点
61                XmlNode lastPriceNode = doc.SelectSingleNode("//price[last()]");
62 
63                //用双点号取price节点的父节点
64                XmlNode lastPriceParentNode = lastPriceNode.SelectSingleNode("..");
65 
66                //选择weight*count=40的所有动物,使用通配符*
67                XmlNodeList nodeList = doc.SelectNodes("/pets/*[@weight*@count=40]");
68 
69                //选择除了pig之外的所有动物,使用name()函数返回节点名字
70                XmlNodeList animalsExceptPigNodes = doc.SelectNodes("/pets/*[name() != 'pig']");
71                
72 
73                //选择价格大于100而不是pig的动物
74                XmlNodeList priceGreaterThan100s = doc.SelectNodes("/pets/*[price div @weight >10 and name() != 'pig']");
75                foreach (XmlNode item in priceGreaterThan100s)
76                {
77                    Console.WriteLine(item.OuterXml);
78                }
79 
80                //选择第二个dog节点
81                XmlNode theSecondDogNode = doc.SelectSingleNode("//dog[position() = 2]");
82 
83                //使用xpath ,axes 的 parent 取父节点
84                XmlNode parentNode = theSecondDogNode.SelectSingleNode("parent::*");
85 
86                //使用xPath选择第二个dog节点前面的所有dog节点
87                XmlNodeList dogPresibling = theSecondDogNode.SelectNodes("preceding::dog");
88 
89                //取文档的所有子孙节点price
90                XmlNodeList childrenNodes = doc.SelectNodes("descendant::price");
91            }
92 
93            Console.Read();
94        }
95    }
96}

C#处理Xml的相关随笔:



损失函数大汇总(六十一)(Signed Distance Map Loss附公式推导与代码) 摘要 本文介绍了Signed Distance Map (SDM) Loss,一种将形状先验直接融入分割任务的方法。SDM将每个像素表示为到目标边界的带符号距离(内部为负,外部为正),相比二值mask能更连续地表达形状几何信息。SDM Loss的核心思想是让网络学习这个隐式形状场,通过可微的Heaviside函数近似将SDM转换为分割结果。文中重点分析了一种product-based regression loss,它能同时关注距离数值和内外符号的正确性,对边界区域尤为敏感。SDM Loss通常与传统的分割 阅读详情

相关推荐

手把手调试Android 14 ShellTransitions:用Log追踪ActiveTransition与Handler匹配过程

本文详细介绍了在Android 14中调试ShellTransitions机制的方法,重点通过Log追踪ActiveTransition与Handler的匹配过程。文章提供了关键日志点植入策略、Handler匹配机制解析及实战调试案例,帮助开发者解决窗口转场动画中的卡顿和错乱问题,提升系统动画性能。

weixin_42652674的博客 438

C#----XPath

XML 文档对象模型 (DOM) 包含的方法使您可以使用 XML 路径语言 (XPath) 浏览功能查询 DOM 中的信息。 可以使用 XPath 查找单个特定节点,或查找与某个条件匹配的所有节点。XPath 选择方法 如果不使用 XPath,则检索 DOM 中的一个或多个节点将需要大量导航代码。 而使用 XPath 只需要一行代码。 DOM 类提供两种 XPath 选择方法。 SelectSingleNode 方法返回符合选择条件的第一个节点。 SelectNodes 方法返回包含匹配节点的 XmlNod

Xiuming1126的专栏 2013

YOLOv8实例分割实战:从LabelMe标注到模型训练全流程(附完整代码)

本文详细介绍了YOLOv8实例分割的完整实战流程,涵盖从使用LabelMe进行数据标注、格式转换,到构建数据集、配置参数并完成模型训练的全过程。文章提供了详尽的代码示例和常见问题解决方案,旨在帮助开发者高效掌握YOLOv8实例分割技术,快速应用于实际项目。

java5的博客 829

C# XPath的概念

Xpath

钢铁男儿 1719

一阶电路基础知识

一阶电路(First-order circuit)是指由一个电感(L)或一个电容(C)和一个电阻(R)组成的电路。根据电感或电容的位置,一阶电路可以分为RC电路、RL电路、LC电路、RLC电路。一阶电路常用于滤波、放大、时序控制等各种电子设备和系统中。通过调整电阻、电容或电感的数值,可以改变电路的频率响应、滞后/提前相位等特性,实现不同的功能和性能一阶、二阶电路区别一阶电路由一个电容或一个电感与一个电阻组成,而二阶电路则由两个电容或两个电感与一个电阻组成。

weixin_45365488的博客 1万+

HyperMesh实战:用Field工具搞定复杂载荷映射(附TCL脚本示例)

本文深入探讨了HyperMesh中Field工具在复杂载荷映射中的高级应用,包括从CSV到有限元网格的温度场映射全流程、稀疏数据处理技巧及TCL自动化脚本示例。通过Field工具,工程师可以高效实现CFD温度场到结构网格的精准映射,显著提升有限元分析的精度与效率。

white的博客 270

C# 网络爬虫+HtmlAgilityPack+Xpath+爬虫工具类的封装的使用

C# 网络爬虫+HtmlAgilityPack+Xpath的使用

qq_53679247的博客 3398

RFSOC实战解析(一):深入RF Data Converter的时钟与数据接口设计

本文深入解析RFSOC中RF Data Converter的时钟与数据接口设计,涵盖GHz采样、数据流处理、时钟树同步及AXI-Stream接口实战。通过详细案例和调试技巧,帮助工程师高效配置IP核,优化ADC/DAC性能,解决跨时钟域和信号完整性等关键问题。

weixin_30955617的博客 487

C#使用Linq to XML进行XPath查询

最近在用到HtmlAgliltyPack进行结点查询时,发现这里选择结点使用的是XPath。所以这里总结一下在C#中使用XPath查询XML的方法。习惯了用Linq,这里也是用的Linq to xml的。 Linq To XML的核心类是XDocument和XElement、XAttribute,需要引用using System.Xml.Linq命名空间。 这三个类简单理解为:...

weixin_30512043的博客 564

从 ST22 到根因定位:ABAP Dumps 全景排查指南(含典型 Dump 案例、修复套路与云时代实践)

本文系统介绍了SAP系统中ABAP短转储(Dump)的分析方法。首先指出短转储是程序运行时无法处理的错误导致系统强制终止执行。文章详细解析了短转储报告各区块的作用:从概述性的Short Text和What happened,到核心的Error Analysis和Source Code Extract,再到关键的系统字段Contents of system fields和调用栈Active Calls/Events。针对不同场景提供了排查建议:客户代码应建立可控边界,标准对象优先查阅SAP Notes。最后推

2007 年 ~ 2025 年,深耕 SAP 技术 18 年 507

vite打包文件如何支持files协议,支持双击即可打开网页,支持electron打包文件。

原本的所需框架为vite + element-plus项目,需要打包之后用eletron打包为桌面应用。但遇到一个问题,耗费了整整一下午时间。vite的配置也没有考虑过纯静态页面的情况。打包之后的页面只支持https协议。不断是百度以及问AI然后看vite官网文档,最后终于配置好了。这里有一个问题就是上面箭头所指位置,不支持跨域,也是es6的语法也不支持。配置完之后打包文件如下。

guiplan 1563

XPath语法 在C#中使用XPath示例(转)

XPath语法 在C#中使用XPath示例 XPath可以快速定位到Xml中的节点或者属性。XPath语法很简单,但是强大够用,它也是使用xslt的基础知识。 示例Xml: <?xml version="1.0" encoding="utf-8" ?> <pets> <cat color="black" weight="10"> ...

a4600646的博客 289

ModuleNotFoundError: No module named‘langchain.schema.output parserlangchain.schema is not a package

电脑里现有的langchain库版本与import所需的不同,卸载原有langchain,重新下载最新的langchain。在步骤1后,若仍不可运行。在确保已重新下载新langchain后,重启python后,可正常运行。在版本号中填入所需的langchain版本号,可在requirements.txt查看。运行如下代码时,出现error。

weixin_45751925的博客 1718

XPath语法在C#中使用XPath示例第二讲

XPath语法在C#中使用XPath示例 XPath可以快速定位到Xml中的节点或者属性。XPath语法很简单,但是强大够用,它也是使用xslt的基础知识。 示例Xml: ? <?xmlversion="1.0"encoding="utf-8"?> <pets> <catcolor="black"weight="1...

weixin_34323858的博客 141

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

jdk-8u144-linux-x64.tar.gz.

该资源为搭建Linux系统Java环境用,资源的后缀为tar.gz格式的压缩包

上一篇: c# .ToString()格式化
下一篇: C# Dictionary 的几种遍历方法
plean
博客等级 码龄25年 64粉丝 3原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值