已开始琢磨Dtrace, 既然有人喜欢,就分享下对Dtrace的印象
1997年,供职于Sun而现已是Solaris内核开发部高级工程师的Bryan Cantrill 与他的工作组在紧张地研究一个性能问题,它出现在刚刚提及的Sun E10000服务器。该服务器在运行基准测试时,速度突然在一段时间内奇怪地降低。工作组经过六天夜以继日的工作后,终于发现了问题的根本原因。某个“愚蠢之极”的配置错误将服务器配置成了路由器。
“我很受震惊,”Cantrill 说到, “这是任何一个客户都可能遇到的问题,但是他们可不敢奢望让内核开发人员为之夜以继日地工作,编写自定义代码以弄清楚问题。我们得找出一个更好的方法。”
经过两年半的紧张开发,Cantrill和他的工作组终于研究出了这个更好的方法: Dtrace
DTrace是过去十年中在操作系统方面最具意义的革新之一:
Probe,Solaris中分散着30,000多的位置指针,也叫探测器probes,DTrace可激活成千上万的探测器,记录所关注的位置指定的数据,如命中,即可从该地址显示用户进程或系统内核的数据,从而了解系统,包括:
1。任何函数的参数
2。内核的任何全局变量
3。函数调用的时间(NS,十亿分之一秒,无任何其它PC/Unix在ns一级精度)
4。跟踪堆栈,包括指明函数调用的代码
5。函数调用时运行的进程
6。产生函数调用的线程
Probe于自定义D语言程序相关联,probe表示的格式为:
provider:module:function:name
1。显示当前动态系统中的动态Dtrace探针probe:
# dtrace -l |more
ID PROVIDER MODULE FUNCTION NAME
1 dtrace BEGIN
2 dtrace END
3 dtrace ERROR
4 vminfo fasttrap fasttrap_uwrite softlock
5 vminfo fasttrap fasttrap_uread softlock
6 fbt pool pool_open entry
7 fbt pool pool_open return
8 fbt pool pool_close entry
9 fbt pool pool_close return
10 fbt pool pool_ioctl entry
11 fbt pool pool_ioctl return
12 fbt pool pool_info entry
13 fbt pool pool_info return
。。。
43545 fbt zmod z_strerror return
43546 fbt zmod z_uncompress entry
43547 fbt zmod z_uncompress return
即当前本人V210上有43547个probe。
2。体验 dtrace 与 Unix ps 命令:
如用ps看mozilla进程:
# ps -e |grep mozilla
2386 pts/11 0:00 mozilla
2436 pts/11 10:12 mozilla-
也可使用dtrace 通过probe探针看:
# dtrace -n 'syscall::exece:return { trace(execname);}'
dtrace: description 'syscall::exece:return ' matched 1 probe
CPU ID FUNCTION:NAME
0 11082 exece:return uname
0 11082 exece:return uname
0 11082 exece:return basename
。。。
0 11082 exece:return sed
0 11082 exece:return mozilla-bin
1 11082 exece:return csh
1 11082 exece:return mozilla
。。。
2。实际dtrace看的更细,
如用date显示系统时间,很快就结束了,无法跟踪,体验dtrace跟踪效果:
% date
2005年05月24日 星期二 20时39分03秒 CST
# dtrace -n 'syscall::exece: '
ddtrace: description 'syscall::exece: ' matched 2 probes
CPU ID FUNCTION:NAME
0 11081 exece:entry 102890531281542
0 11082 exece:return 102890532181875
即可跟踪其在第102890531281542纳秒开始读取,第102890532181875返回结果。
3。体验Dtrace 对系统调用更多的观察:
如看机器忙闲状态,常用vmstat:
# vmstat 1
kthr memory page disk faults cpu
r b w swap free re mf pi po fr de sr s0 s3 s1 s1 in sy cs us sy id
0 0 0 5523680 1378352 14 48 84 1 0 0 1 0 1 0 0 341 2058 883 3 1 96
0 0 0 5368296 1218688 0 23 15 0 0 0 0 0 0 0 0 336 2605 722 10 1 89
得知产生2605多系统调用,但无和简单查找哪个进程的问题呢,试用dtrace看:
# dtrace -n 'syscall::read:entry {@NUM[execname] = count();}'
ddtrace: description 'syscall::read:entry ' matched 1 probe
^C
dtfile 5
sdtperfmeter 12
soffice.bin 23
dic 23
dtterm 53
mozilla-bin 394
Xsun 545
显然发现CDE和Mozilla是产生大量系统调用的程序,看I/O分布也可:
如还是Mozilla:
# dtrace -n 'syscall::write:entry {@NUM[execname] = quantize(arg2);}'
...
mozilla-bin
value ------------- Distribution ------------- count
0 | 0
1 |@@@@@@@@@@@@@@@@@@@@@ 470
2 | 0
4 | 7
8 | 0
16 | 0
32 | 0
64 | 0
128 | 10
256 |@@@@@@@@ 184
512 |@@@@@@ 146
1024 |@@@ 78
2048 | 8
4096 | 1
8192 | 0
...
可观察到大量Mozilla产生的I/O在256-512字节间。
4。 想再仔细看程序内部情况?
truss不错:
# truss /usr/sfw/bin/mozilla
execve("/usr/bin/ksh", 0xFFBFF564, 0xFFBFF574) argc = 3
resolvepath("/usr/bin/ksh", "/usr/bin/ksh", 1023) = 12
resolvepath("/usr/lib/ld.so.1", "/lib/ld.so.1", 1023) = 12
stat("/usr/bin/ksh", 0xFFBFF340) = 0
open("/var/ld/ld.config", O_RDONLY) Err#2 ENOENT
stat("/lib/libc.so.1", 0xFFBFEE70) = 0
resolvepath("/lib/libc.so.1", "/lib/libc.so.1", 1023) = 14
open("/lib/libc.so.1", O_RDONLY) = 3
mmap(0x00010000, 8192, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_ALIGN, 3, 。。。
试下dtrace:
# dtrace -n 'syscall::read:return /execname =="mozilla" /{ ustack();}'
dtrace: description 'syscall::read:return ' matched 1 probe
CPU ID FUNCTION:NAME
0 10984 read:return
libc.so.1`_read+0x8
ksh`io_readbuff+0x264
ksh`0x245e4
ksh`io_readc+0x2c
ksh`0x29c54
ksh`main+0xa30
ksh`_start+0x108
0 10984 read:return
libc.so.1`_read+0x8
ksh`io_readbuff+0x264
ksh`0x245e4
ksh`io_readc+0x2c
ksh`0x28938
ksh`0x28654
...
看到n多调用,开始和返回,够开发人员分析的。
总结,Dtrace功能强大,精度高,轻量,truss有时降低系统30%CPU利用率。但复杂,需对系统内核和应用熟悉,否则看不懂跟踪到的数据,估计以后CU该开Dtrace编程板块了。
相关推荐
如何使用Datadog ddtrace监控LangChain应用的性能
Datadog的ddtrace集成使得LangChain应用的监控和调试变得简单直接。通过本文中的步骤,你可以快速上手并开始监控你的应用性能。
快速高效实现Django前端数据、链路追踪、日志数据关联之ddtrace
用户访问前端应用(已添加 rum 监控且已配置。
使用 Datadog ddtrace 监控 LangChain 应用性能
通过前缀如果希望在代码中启用 LangChain 集成,可以使用patch。
ddtrace 系列篇之 dd-trace-java 项目编译
是 Datadog 开源的 java APM 框架,本文主要讲解如何编译 dd-trace-java 项目。
利用Datadog ddtrace优化LangChain应用性能监控
使用Datadog ddtrace可以显著提升LangChain应用的性能监控能力。Datadog APM Python库文档LangChain官方文档Datadog支持。
使用Datadog ddtrace监控LangChain应用性能的全面指南
通过Datadog的ddtrace库,开发者可以轻松地对LangChain应用进行全面监控。更多高级使用方法,请参考APM Python库文档。
浅谈动态跟踪技术之DTrace
什么是动态追踪(Dynamic Tracing) 举个简单例子,一个人正在健身房里跑步,我们用摄像机
dd-trace-py:Datadog Python APM客户端
dd-trace-py ddtrace是Datadog的Python跟踪库。 它用于跟踪在Web服务器,数据库和微服务之间流动的请求,从而使开发人员可以很好地查看瓶颈和棘手的请求。 入门 有关产品的基本概述,安装和快速入门,请查阅我们的。 有关更高级的用法和配置,请查看我们的。 有关APM中使用的术语的说明,请查看。 发展历程 贡献 参见 。 测验 环境 该测试套件需要许多支持服务,例如PostgreSQL,MySQL,Redis等。 我们使用docker和docker-compose在CI中运行服务并进行开发。 要运行测试矩阵,请按照平台提供的说明和 。 然后通过以下方式启动它们: $ docker-compose up -d 在Docker中运行测试 docker-compose环境运行后,即可运行测试运行器映像: $ docker-compose run --rm test
Dynamic Tracing with DTrace & SystemTap
Dynamic Tracing with DTrace & SystemTap http://myaut.github.io/dtrace-stap-book/ DTrace: Dynamic Tracing in Oracle Solaris, Mac OS X and FreeBSD
dd-trace-go, Datadog APM的转到跟踪包.zip
dd-trace-go, Datadog APM的转到跟踪包 Datadog APM客户端实现 OpenTracing 跟踪。初始化要使用 OpenTracing API开始使用Datadog跟踪器,你应该首先使用适当的Configuration 对象初始化跟踪程序:import
OCC WebGL案例编译实战:从FreeType配置到静态库生成
本文详细记录了将OCC(Open CASCADE Technology)3D图形库编译为WebAssembly(Wasm)并在浏览器中通过WebGL渲染的实战过程。重点解决了FreeType库的交叉编译配置、OCC核心库的裁剪与静态库生成,以及WebGL样例项目的CMake改造等关键步骤,为开发者提供了从环境搭建到最终集成的完整指南。
DTrace(Dynamic Tracing):Solaris 10 的新特性
Solaris 10 的新特性中和 DBA 关系最大的恐怕就是这个 Dtrace 了。Dtrace(Dynamic Tracing)是“Solaris 操作系统的一种复杂动态跟踪框架”。与其他商用 Unix 提供的性能工具有本质区别,据称“Dtrace 在 Solaris OS 内部构建,其在内核中采用了 25,000 个探测器”(SPARC 和 X86 平台都可...
国产信创麒麟操作系统 (kylin v10 x86架构) 离线安装nginx步骤(亲测,超详细步骤)、修改nginx配置文件、启动、重启、关闭nginx记录(亲测有效)
国产信创麒麟操作系统 (kylin v10 x86架构) 离线安装nginx步骤(亲测,超详细步骤)、修改nginx配置文件、启动、重启、关闭nginx记录(亲测有效)
Windows 10 加入了对内核分析工具 DTrace 的支持
微软宣布 Windows 10 支持 DTrace。DTrace 是一个动态跟踪框架,于 21 世纪初诞生于 Sun 公司的 Solaris 操作系统,提供了性能分析和调试功能。开发人员...
你需要这样一个Ros软路由—— 路由器+外网+一号通ip线路=动态ip的WiFi信号
功能强大 管理便捷—给您全新的路由体验 一键更换指定线路or批量更换所有IP/MAC/SSID 自定义走本地网络策略的分流功能 设备批发价、不限制拨号账号服务商 强大的单设备/多设备IP去重功能 批量导入、管理一号通线路 一键任意切换5G_WiFi(推荐)/2.4G_WiFi(建议不用) 设备支持PPTP/L2TP/SSTP/openVP.N等协议 独家支持openVPN,适用于网络受限用户 支持自行接入AP和交换机扩容 一键打开/关闭所有虚拟WiFi 一键隐藏/显示设备WiFi...
量化爬虫第一步:手把手教你搞定同花顺问财的hexin-v参数(附JS逆向实战)
本文详细介绍了如何通过JS逆向技术破解同花顺问财数据接口的核心加密参数hexin-v,构建稳定可靠的量化数据采集方案。从抓包分析到Cookie Hook技术应用,再到环境补全与参数生成实现,手把手教你完成量化爬虫的第一步。文章还提供了实战注意事项与优化建议,帮助开发者规避常见问题。
快速高效监控Django的链路追踪之ddtrace
最近在研究前端的页面数据收集,踩了一些坑,现在分享一下接入过程。
告别黑窗口!用VSCode+Native Debug调试C/C++程序,比GDB命令行舒服多了
本文介绍了如何使用VSCode配合Native Debug扩展来调试C/C++程序,替代传统的GDB命令行方式。通过可视化调试环境,开发者可以更高效地管理断点、查看变量和调用栈,大幅提升调试效率。文章详细讲解了环境配置、核心调试功能及高级技巧,帮助开发者快速上手这一现代调试工具。
Python - APM 链路跟踪探针之DDtrace
Python - APM 探针之DDtrace Max.Bai 2021-03 APM ()系统简单来说由负责收集数据的探针和数据展示分析两部分组成,这个DDtrace就是python的探针。 DDtrace 是DataDog开源的python探针,官网地址 https://docs.datadoghq.com/tracing/setup_overview/compatibility_requirements/python/, 兼容大部分WEB框架,Flask,Django等等。 这里就测试一个Fla
C++实现复制粘贴文本功能
要实现这个功能,我们需要使用操作系统提供的函数来操作剪贴板。在Windows操作系统中,我们可以使用Windows API函数来访问剪贴板。总结起来,使用C++实现复制和粘贴文本功能涉及使用操作系统提供的API函数来操作剪贴板。在本篇文章中,我将向您展示如何使用C++编程语言实现复制和粘贴文本的功能。我们将使用操作系统提供的API来进行剪贴板操作,并编写相应的代码来完成这个任务。如果您使用的是Linux操作系统,您需要使用适当的库和函数来访问剪贴板。函数中,我们首先将一个字符串复制到剪贴板中,然后使用。
那些年我们create generate clock遇到的坑
想必大家对create_generate_clock这个命令熟悉的不能再熟悉了,然而,在真正做实际项目的时候,会出现各式各样的问题,比如在report timing时,generate clock路径不是我们预想的,source latency丢失等等,今天小编就跟大家重点聊聊source latency丢失的情况。clock时,首先我们要对一个项目的时钟结构要比较清晰,同时针对一些复杂的生成时钟,我们也要学会画波形图进行分析;接下来,我们就来看看哪些case会导致source latency丢失。
探索DD Trace-Py:全面的Python性能监控解决方案
在现代的软件开发中,实时、深入地理解代码执行情况是至关重要的。DD Trace-Py是一个由Datadog提供的强大Python库,它提供了一种简单且灵活的方式来跟踪和分析你的应用程序性能。通过集成到各种框架和库中,DD Trace-Py可以帮助开发者识别瓶颈,优化性能,并确保服务的健康运行。 ## 项目简介 DD Trace-Py是一个全面的分布式追踪解决方案,旨在与Datadog平台无缝配
Transformers 实战修炼与源码剖析专栏大纲
本专栏以 Hugging Face Transformers 为主线,围绕“能用、会调、敢上线、懂源码”四个目标展开。内容不把理论堆成公式墙,而是用真实或拟真的业务场景驱动:客服分类、合同抽取、知识库问答、模型微调、推理服务、监控告警、源码扩展等。采用“业务痛点 → 三人剧本对话 → 代码实战 → 总结思考”的四段式结构,让读者在动手完成一个个小项目的过程中,逐步理解 Tokenizer、Model、Pipeline、Trainer、Generation、PEFT、Accelerate、Serving等概念
使用Datadog ddtrace监控LangChain应用:全面指南
在现代应用开发中,监控和调优是保持应用性能和稳定性的重要环节。Datadog的应用性能监控(APM)库ddtrace,为LangChain应用提供了强大的集成能力,帮助开发者捕获请求、参数、延迟、错误等关键数据。本篇文章将深入探讨如何使用ddtrace监控LangChain应用。首先,确保在Datadog Agent中启用了APM和StatsD。以下示例展示了使用Docker的设置方法: 接下来,安装Datadog APM Python库: 默认情况下,你可以在LangChain应用命令前加上来启用集成:
android 蓝牙通讯demo
android 下蓝牙通讯demo,实现了发现蓝牙,使能蓝牙,通过蓝牙发送消息。
锂电池充电器电路设计 里面有电路
锂电池充电器电路设计 里面有电路 3.7V升压到5V电路设计。
NoCableLauncher终极教程:如何免费畅玩Rocksmith 2014吉他游戏 [特殊字符]
还在为Rocksmith 2014的RealTone线缆而烦恼吗?NoCableLauncher为你提供了完美的免线缆解决方案!这款开源启动器让每个吉他爱好者都能用任何音频设备享受游戏乐趣,无需昂贵的官方配件。 ## 🎯 为什么你需要这个免线缆启动器? **省钱又省心**:告别数百元的RealTone线缆,使用你现有的USB音频接口或电脑麦克风就能直接游戏。NoCableLauncher通过
Camera2Demo
在Camera2 的基础上进行封装,使得Camera2一堆初始化逻辑与Activity分离,降低耦合度,完成预览拍照并保存的操作
使用 Datadog Tracing 监控和优化 LangChain 应用性能
Datadog 的应用性能监控(APM)库ddtrace提供了与 LangChain 的集成,让你能够全面监控 LangChain 应用。追踪(Traces):捕获 LangChain 请求、参数、提示-完成过程,并可视化 LangChain 操作。指标(Metrics):记录 LangChain 请求延迟、错误率,以及令牌/成本使用情况(适用于 OpenAI LLMs 和聊天模型)。日志(Logs):存储每个 LangChain 操作的提示完成数据。仪表板(Dashboard)
深度学习工具包 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');```[](https://bitdeli.com/free "Bitdeli Badge")
1019



被折叠的 条评论
为什么被折叠?



