VCL中消息处理初探

mORMot 学习记录2 -- TSQLRestStorageInMemory数据库 使用TSQLRestStorageInMemory 创建数据库的数据,增加10万数量大概400毫秒 测试环境: delphi 10.2     moRMOT : 1.18.2975 unit Unit2; interface uses Winapi.Windows, Winapi.Messages, System.SysUtils, S 阅读详情

TObject是基类,所以我们先看一下TObject的DISPATCH方法。Dispatch根据传入的message来寻找相应的消息处理方法,如果找不到的话,就继续向上到父类的消息处理方法表中寻找响应的处理方法,一直到找到为止,如果找到顶还没有,则调用DefaultHandle来处理该消息。message可以是任何的类型,Dispatch假设message的头两位是消息的ID,它就是根据ID来寻找消息处理方法的。虽然任何类型的message都可以被接受,但是TObject的子类还是希望传入的message参数是TMessage的记录类型或其他证明的记录类型。

以下声明和注释摘自与system.pas:

{ TObject.Dispatch accepts any data type as its Message parameter. The

first 2 bytes of the data are taken as the message id to search for

in the object's message methods. TDispatchMessage is an example of

such a structure with a word field for the message id.

}

TDispatchMessage = record

MsgID: word;

end;

类的继承关系如下:

TObject->TPersistent->TComponent->TControl

TControl是所以可视化组件的父类,TControl提供了一个新的方法,WndProc:

procedure TControl.WndProc(var Message: TMessage);

var

Form: TCustomForm;

KeyState: TKeyboardState;

WheelMsg: TCMMouseWheel;

begin

//如果处在设计期

if (csDesigning in ComponentState) then

begin

Form := GetParentForm(Self);//得到拥有该组件的窗体

if (Form <> nil) and (Form.Designer <> nil) and

Form.Designer.IsDesignMsg(Self, Message) then Exit //消息由窗体来处理

end;

//窗体可以为其拥有的组件来处理键盘消息。

if (Message.Msg >= WM_KEYFIRST) and (Message.Msg <= WM_KEYLAST) then

begin

Form := GetParentForm(Self);

if (Form <> nil) and Form.WantChildKey(Self, Message) then Exit;

end

//关于鼠标的消息

else if (Message.Msg >= WM_MOUSEFIRST) and (Message.Msg <= WM_MOUSELAST) then

begin

//如果组件不可以接受和处理双击消息,就将双击消息映射为单击消息。

if not (csDoubleClicks in ControlStyle) then

case Message.Msg of

WM_LBUTTONDBLCLK, WM_RBUTTONDBLCLK, WM_MBUTTONDBLCLK:

Dec(Message.Msg, WM_LBUTTONDBLCLK - WM_LBUTTONDOWN);

end;

case Message.Msg of

WM_MOUSEMOVE: Application.HintMouseMessage(Self, Message);//如果是鼠标移动的消息,则出现hint窗口

WM_LBUTTONDOWN, WM_LBUTTONDBLCLK://如果是左键被按下,或者双击,如果是自动拖动模式,则开始拖动,并将左键按下的状态加入组件的状态。

begin

if FDragMode = dmAutomatic then

begin

BeginAutoDrag;

Exit;

end;

Include(FControlState, csLButtonDown);

end;

WM_LBUTTONUP:

Exclude(FControlState, csLButtonDown); //如果是左键放开,则将左键按下的状态剔除。

else

with Mouse do

if WheelPresent and (RegWheelMessage <> 0) and //如果鼠标有滚轮,并且滚轮滑动时发出了消息

(Message.Msg = RegWheelMessage) then

begin

GetKeyboardState(KeyState); //将256虚拟键的状态拷贝到缓存中去

with WheelMsg do //填充记录

begin

Msg := Message.Msg;

ShiftState := KeyboardStateToShiftState(KeyState);

WheelDelta := Message.WParam;

Pos := TSmallPoint(Message.LParam);

end;

MouseWheelHandler(TMessage( WheelMsg)); //派发鼠标滚轮的消息

Exit;

end;

end;

end

else if Message.Msg = CM_VISIBLECHANGED then

with Message do

SendDockNotification(Msg, WParam, LParam); //处理自定义消息

Dispatch(Message); //派发未处理的消息

end;

但是只有TWinControl可以获得焦点:

procedure TWinControl.WndProc(var Message: TMessage);

var

Form: TCustomForm;

begin

case Message.Msg of

WM_SETFOCUS: //设置控件的焦点

begin

Form := GetParentForm(Self);

if (Form <> nil) and not Form.SetFocusedControl(Self) then Exit;

end;

WM_KILLFOCUS:

if csFocusing in ControlState then Exit;

//当鼠标有活动的时候发出该消息,如果鼠标没有被捕捉到,则消息发往鼠标下面的那个窗口,否则消息将发往捕捉到鼠标的那个窗口。

WM_NCHITTEST:

begin

inherited WndProc(Message); //调用父类的处理方法

//如果窗体被挡住并且在指定的点没有控件,则返回结果为在client区。

if (Message.Result = HTTRANSPARENT) and (ControlAtPos(ScreenToClient(

SmallPointToPoint(TWMNCHitTest(Message).Pos)), False) <> nil) then

Message.Result := HTCLieNT;

Exit;

end;

WM_MOUSEFIRST..WM_MOUSELAST:

if IsControlMouseMsg(TWMMouse(Message)) then //鼠标消息是否直接发往组件的窗体子组件

begin

{ Check HandleAllocated because IsControlMouseMsg might have freed the

window if user code executed something like Parent := nil. }

if (Message.Result = 0) and HandleAllocated then

DefWindowProc(Handle, Message.Msg, Message.wParam, Message.lParam);//调用默认的的消息处理方法对该消息进行默认处理。

Exit;

end;

WM_KEYFIRST..WM_KEYLAST:

if Dragging then Exit;

WM_CANCELMODE:

if (GetCapture = Handle) and (CaptureControl <> nil) and

(CaptureControl.Parent = Self) then

CaptureControl.Perform(WM_CANCELMODE, 0, 0);

end;

inherited WndProc(Message);

end;

TApplication在程序中发挥着重要的作用:

Application.Run;

procedure TApplication.Run;

begin

FRunning := True;

try

AddExitProc(DoneApplication);

if FMainForm <> nil then

begin

case CmdShow of

SW_SHOWMINNOACTIVE: FMainForm.FWindowstate := wsMinimized;

SW_SHOWMAXIMIZED: MainForm.Windowstate := wsMaximized;

end;

if FShowMainForm then

if FMainForm.FWindowstate = wsMinimized then

Minimize else

FMainForm.Visible := True;

//一个消息循环直到Terminated为True时才退出。

repeat

try

HandleMessage;

except

HandleException( Self);

end;

until Terminated;

end;

finally

FRunning := False;

end;

end;

procedure TApplication.HandleMessage;

var

Msg: TMsg;

begin

if not ProcessMessage(Msg) then Idle(Msg);

end;

function TApplication.ProcessMessage(var Msg: TMsg): Boolean;

var

Handled: Boolean;

begin

Result := False;

if PeekMessage(Msg, 0, 0, 0, PM_REMOVE) then //从现成的消息循环中取出消息并放入指定的消息结构中。

begin

Result := True;

if Msg.Message <> WM_QUIT then //如果不是退出消息则进行相应的处理

begin

Handled := False;

if Assigned(FOnMessage) then FOnMessage(Msg, Handled);

if not IsHintMsg(Msg) and not Handled and not IsMDIMsg(Msg) and

not IsKeyMsg(Msg) and not IsDlgMsg(Msg) then

begin

TranslateMessage(Msg);

DispatchMessage(Msg);

end;

end

else

FTerminate := True;

end;

end;

TSQLRestStorageInMemory 内存数据库 moRMOT 框架使用TSQLRestStorageInMemory 创建内存数据库初步研究 立即下载

相关推荐

Gnostice PDFtoolkit 5.0 VCL

Introduction ============ Gnostice PDFtoolkit is a powerful component suite for users of Delphi and C++Builder to edit, enhance, secure, merge, split, view, print, PDF documents and also process AcroForms documents. PDFtoolkit does not require PDF software such as Adobe PDF library, Adobe Acrobat Professional or Ghostscript. The ReadMe file contains information on where to start and how to get access to additional resources so that you can get the best out of Gnostice PDFtoolkit.

VCL的命令消息[转自csdn中myfirenze的专栏]

VCL的命令消息 Windows中的消息有三种:标准的窗口消息,命令消息,控件通知消息,再加上我们自定义的消息,所以Windows程序我们要处理四种消息,幸运的我们常用的开发工具都带了自己的Framwork,Visual C++中用的是MFC,Delphi和BCB用的VCL,这些Framwork都有一套自己的消息处理机制,它们处理前面三种系统已经定义的消息,所以我们要...

weixin_34241036的博客 246

RPMP:用于Pascal的RPMP-Restful插件中间件是基于mORmot和Qplugins框架二次开发的中间件插件框架,这是一个快速开发的业务框架。主要是中间件开发提供了一种解决方案。它的特点就是简单,通讯和通信和业务可以随意搭配,只要你愿意,非常直接灵活。对外提供Restful接口,可以很容易定制你的中间件,一件移动App前端服务器,Web服务器等。站在巨人的肩上才能看的更远... mORmot下载地址:https

RPMP 用于Pascal的RPMP-Restful插件中间件是基于mORmot和Qplugins框架二次开发的中间件插件框架,这是一个快速开发的业务框架。主要是中间件开发提供了一种解决方案。它的特点就是简单,通讯和通信和业务可以随意搭配,只要你愿意,非常直接灵活。对外提供Restful接口,可以很容易定制你的中间件,一件站在巨人的肩上才能看的更远... mORmot下载地址: : Qplugins下载地址: 未来更新计划 1,完善插件热更新功能 2,支持身份认证(jwt \ OAuth 2.0等) 3,访问控制,api接口管理(有好的建议可以提) 4,文档及偏业务插件完整流程 5,该框架完善完毕,后续会分出针对不同的应用场景的RPMP系列服务器 6,..... 关于作品 如果您基于该开源产品开发了产品,请给作者发送一个截图,主要为了宣传,完全自愿。谢谢 基于该框架所做的应用截图

TObject.Dispatch

由于TObject.Dispatch几乎被大量执行,为了提高效率,使用汇编语言撰写。在Dispatch方法中首先检查触发的消息ID是否在0~c000H之中,如果不在此范围调用DefaultHandler;如果是的话就调用GetDynaMethod从VCL组件中根据消息ID在动态方法表格中搜寻。如果找到能够处理消息的VCL事件处理函数就跳到此事件处理函数执行,否则就调用DefaultHandler虚...

weixin_30672019的博客 148

Gnostice_PDF_Toolkit_Pro_Plus_5.0.0.402_With_Source_for_DXE10.2_Downloadly.ir.rar

Gnostice_PDF_Toolkit_Pro_Plus_5.0.0.402_With_Source_for_DXE10.2_Downloadly.ir.rar

Synopse mORMot Framework SAD 1.18.pdf

Synopse mORMot Framework 的文档说明书。pdf格式的文档不太好找,我上传到这里共有需要的朋友下载。

Delphi与消息1:TObject中的Dispatch和DefaultHandler

 TObject是Delphi中的基类,它提供了消息的基本分装 TObject = class ....... procedure Dispatch(var Message); virtual; procedure DefaultHandler(var Message); virtual;end; 主要通过Dispatch和DefaultHandler方法

徐艳成的Blog 1271

Delphi使用SQLite3内存数据库

Delphi使用SQLite3,包括本地数据库和内存数据库,本地数据库加载到内存,内存数据库备份到本地,使用sqlite simple delphi包装类。

VCL中消息处理初探 (转)

VCL中消息处理初探 (转)[@more@]Tobject是基类,所以我们先看一下TObject的DISPATCH方法。Dispatch根据传入的message来寻找相应的消息处理方法,如果找不到的话,就继续向上到父类的消息处理...

cuiji1279的博客 119

TwinCAT 3 实战:手把手教你用PLC和C++读写第三方伺服驱动器的CoE参数

本文详细介绍了在TwinCAT 3环境中通过PLC和C++两种技术路线实现对第三方伺服驱动器CoE参数的精准操控。从环境准备到具体实现,包括硬件配置、核心函数使用及性能优化策略,为工程师提供了全面的实战指南。特别针对CoE参数访问的效率和稳定性问题,给出了实用的调试技巧和异常处理方案。

weixin_33743248的博客 443

基于FSL的DTI数据预处理流程

最近在学习处理DTI数据,总结了一份应用FSL做DTI数据预处理的流程与大家交流交流。如果有错误的地方欢迎大家指正!        我用的数据是Philips的数据,如果是GE或者西门子的数据可能会有所不同。   原始数据:包括3DT1数据和高分辨率DTI数据,均是dicom格式。 工具:MRICRON和FSL,所有的命令均在Linux的终端中运行。   1.格式转换:将后缀名为dcm

zaza_zaza的博客 2万+

由VCL中的代码理解VCL中的消息处理机制

 Delphi,一个非常优秀的开发工具,拥有强大的可视化开发环境、面向组件的快速开发模式、优秀的VCL类库、快速的代码编译器、强大的数据库和WEB开发能力、还有众多的第三方控件支持...(此处省略x千字,既然大家都知道了,不浪费口水了 ^_^)说到VCL的优秀就不能不提到其对Windows消息及API的较全面和完美的封装,正因为如此开发者在大多数情况下甚至不需理会Windows消息处理的细节,

drawwingmap的日记本 1562

Android逆向进阶篇 Charles + Drony Vpn绕过代理检测方案 获取猫眼App数据

Android逆向进阶篇 Charles + Drony Vpn绕过代理检测方案 获取猫眼App数据

曾用名:极客柒 1852

我所理解的VCL消息處理流程

一、VCL消息處理流程:1.Application從windows消息隊列中取得屬於當前線程的所有消息。2.Application:translatemessage.3.Application:dispatchmessage分派消息  3.1 dispatchmessage根據消息中的handle來找到目標元件的回調函數,並調用這個回調函數(wndproc)。4.每個元件(TWincontrol及

ssz的技术博客 1342

链家二手房信息爬取(内附完整代码)

链家二手房信息爬取1.简介2. 爬虫思路2.1 网页分析2.2 详情页分析2.3 不同页码的爬取2.4 解决链家只显示100页数据2.5 简单的反爬与进度条显示3. 总结 1.简介   最近帮同学爬取了链家在售二手房的信息,这是本人学习爬虫以来爬取数据最多的一次,就想着写个博客记录一下。   本次爬虫是利用python+jupyter notebook实现的,用到的第三方库如下: import pandas as pd # 数据存储 import requests # 网页内容获取 import re #

qq_46256922的博客 3万+

TC3XX - MCAL知识点(三十三):基于EB Tresos配置Tc3xx的MCAL代码如何产生中心对称的三相六路发波波形

本文用于记录如何在英飞凌 tc3xx 芯片的应用开发中,借助 EB Tresos 配置工具生成的配置代码与 MCAL 源码相结合,进而实现三相六路中心对称互补的 PWM 输出效果。外部资源需求:EB Tresos23.0以上、Tasking\Hightec编译器、示波器\逻辑分析仪。

梦想技术家 1211

VCL消息处理机制

说到VCL中的消息处理就不能不提到TApplication,Windows会为每一个当前运行的程序建立一个消息队列,用来完成用户与程序的交互,正是通过Application完成了对Windows消息的集中处理! 首先通过Application.Run进入消息循环进行消息的处理,其中调用了HandleMessage。 procedure TApplication.Han...

189

垂类大模型 研发方向与具体方案调研

领域知识库加上通用大模型,针对通用大模型见过的知识比较少的问题,利用向量数据库等方式根据问题在领域知识库中找到相关内容,再利用通用大模型强大的summarization和qa的能力生成回复,完成本次垂直大模型研发。目前很多企业希望将大模型的能力应用到企业内部当中,但很多通用大模型只是一个预训练模型,其所能回答的知识主要来源于互联网上公开的通用知识库,对于部分垂直领域和企业内部的私有知识库的问答,给出的回答。:垂类大模型的效果与底座性能息息相关,研发垂类大模型第一步就是确定开源大模型解决方案。

风吹落叶的博客 3329

VCL消息处理机制的内幕

由VCL中的代码理解VCL中的消息处理机制 Delphi,一个非常优秀的开发工具,拥有强大的可视化开发环境、面向组件的快速开发模式、优秀的VCL类库、快速的代码编译器、强大的数据库和WEB开发能力、还有众多的第三方控件支持...(此处省略x千字,既然大家都知道了,不浪费口水了 ^_^) 说到VCL的优秀就不能不提到其对Windows消息及API的较全面和完美的封装,正因为如此开发者在大多数

Jenhy的专栏 702

把数据库事务边界握在手里:ABAP 里的 COMMIT CONNECTION 与 ROLLBACK CONNECTION 深度拆解

与表面是两条很短的语句,背后却牵动了连接管理、数据库 LUW、SAP LUW、隐式提交、游标生命周期、GTT 平台差异等一整片工程现实。把它们用对,你就能在不破坏主业务事务的前提下,实现跨库写入、审计落库、隔离型日志、数据集成落地等一系列“看似矛盾”的目标;用错了,它们也会悄无声息地制造一致性缺口,让问题在高峰期以 dump 或数据异常的方式爆出来。

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

基于matlab的CNN手写数字图像矫正系统

CNN 是一款强大的图像特征抽象和提取工具,常用于图像分类识别,并取得了较为理想的效果。我们通过 MATLAB 可以方便地设计不同结构、不同深度的 CNN 进行图像分类,最后一层一般设置为分类层(ClassificationLayer)进行类别标签的输出。如果我们将最后一层设计为回归层(RegressionLayer),则可以将其应用于对连续数据的预测,这对于曲线拟合、预测分析都有重要的意义。% 自定义 CNN 回归网络结构layers = [% 输入% 卷积% 池化% 池化% 卷积。

在职AI算法工程师,擅长计算机视觉,YOLO目标检测、分割等,擅长web、pyqt界面可视化,好内容持续更新中,来这里跟大家一起学习,共同进步 675

Delphi VCL 的消息处理机制(1)

开始学习 Delphi VCL 的消息处理机制。自从我写下《Delphi的对象机制浅探》,至今正好一个星期,我也基本上把 Delphi VCL 的消息处理框架读完了。我的学习方法就是阅读源代码,一开始比较艰苦,后来线索逐渐清晰起来。   我在分析 VCL 消息机制的过程中,基本上只考查了三个类 TObject、TControl 和 TWinControl。     推荐阅读:     《De

流年~~ 2225

数学建模模型总结

这是本人在两年内准备参加数学建模竞赛搜集到的模型资料,已经经过了本人的筛选和整理,希望能够对准备参加数学建模竞赛的学弟学妹们提供一些帮助!

Delphi语言的VCL框架

因此,main 函数的作用是初始化应用程序,并启动消息循环,而 TApplication 组件负责处理消息循环并转发消息。除了 TApplication 和 TWinControl 组件外,VCL 还提供了一些其他的组件来处理特定类型的消息,如 TTimer 组件用于处理定时器消息,TMessage 组件用于处理自定义消息等等。在 Delphi 应用程序中,TApplication 组件负责处理应用程序的消息循环,但它并不直接处理应用程序的 main 函数入口。

zhangzhechun的专栏 2284

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

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

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

Delphi VCL消息处理机制(2)

=============================================================================== ⊙ VCL 的消息处理从 TWinControl.MainWndProc 开始 =========================================================================

流年~~ 1677

Data-Structures-and-Algorithm-Analysis-in-Java.pdf

作者: Weiss, Mark A. 出版社: Addison Wesley Data Structures and Algorithm Analysis in Java is an “advanced algorithms” book that fits between traditional CS2 and Algorithms Analysis courses. In the old ACM Curriculum Guidelines, this course was known as CS7. This text is for readers who want to learn good programming and algorithm analysis skills simultaneously so that they can develop such programs with the maximum amo...

上一篇: BroadcastSystemMessage
下一篇: 由VCL中的代码理解VCL中的消息处理机制
Dcdu
博客等级 码龄21年 44粉丝 33原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值