MIDP2.0中Alert的新特性

M.2 SSD接口详解 一开始,B key的只能插在b key(Socket 2)的接口中,m key的只能插在m key(Socket 3)的接口中,但是随着m key接口的普及,越来越多电脑主板只有m key 接口,b key的ssd根本插不上去,于是厂商们又设计了一个b&m key接口的ssd。常见的M.2接口为Key A、Key B、Key E和Key M. 不同的key类型表示此m2接口支持的信号,见下表。Key B、Key M多用于硬盘,Key A、Key E多用于无线网卡,当然也有各种转接模块。 阅读详情
 Alert类继承自Screen,它的作用是通知用户发生异常信息。在高级用户界面API中有三个类是不能有父容器的,他们必须要占据屏幕,其中一个就是Alert,另外两个是List和TextBox。在MIDP1.0中,Alert的灵活性比较差,表示的信息比较死板。在MIDP2.0中添加了一个重要的特性就是能够在Alert上添加指示器,因此可以和Guage结合起来使用。

    和Alert结合使用的Guage有以下要求1.必须是非交互性的,2.不能同时在其他的容器内,3.Guage的label必须为null,4.Guage不能和Command和CommandListener关联。比如按照如下方式创建一个Guage实例
 int max = ... // maximum value
 int initial = ... // initial value
 Gauge gauge = new Gauge( null, false, max, initial );
通过调用方法setIndicator()可以把Alert和Guage结合起来
 Alert a = new Alert( "My alert" );
 a.setIndicator( gauge );
由于MIDP的用户界面类都是线程安全的,因此你可以在其他的线程内改变guage的值,Alert会自动的重新绘制屏幕来更新guage的当前值。

    在MIDP2.0中,我们可以显式的对Alert添加Command,当然如果你还要实现CommandListener的commandAction()方法来告诉系统当Command被按下的时候该做什么。在MIDP1.0中,有个默认的Command和Alert关联在一起的,如果我们在Alert中显式的添加了Command的话,那么这个默认的Command就被取代,如果添加的Command被删除,默认的Command会自动恢复和Alert的关联。如果我们在Alert上添加了两个以上的Command,那么它的Timeout会自动设置为FOREVER。

    下面的应用程序很好的说明了如何使用不同的Alert表示不同的信息

 

 

 

 

 

 

 





 

 


import javax.microedition.lcdui.*;
import javax.microedition.midlet.*;

// A simple MIDlet for testing various alerts.

public class AlertTest extends MIDlet implements CommandListener
{

    // An abstract class for our alert tests.

    public abstract class AlertRunner
    {
        protected static final int ONE_SECOND = 1000;
        protected static final int FIVE_SECONDS = 5000;

        public AlertRunner(String title)
        {
            _title = title;
        }

        public abstract Alert doAlert();

        public String getTitle()
        {
            return _title;
        }

        public String toString()
        {
            return getTitle();
        }

        private String _title;
    }

    // An alert test for a simple timed alert.

    public class TimedAlert extends AlertRunner
    {
        public TimedAlert(String title)
        {
            super(title);
        }

        public Alert doAlert()
        {
            Alert a = new Alert(getTitle());
            a.setString("Times out after 5 seconds...");
            a.setTimeout(FIVE_SECONDS);

            showAlert(a);

            return a;
        }
    }

    // An alert test for a simple modal alert.

    public class ModalAlert extends AlertRunner
    {
        public ModalAlert(String title)
        {
            super(title);
        }

        public Alert doAlert()
        {
            Alert a = new Alert(getTitle());
            a.setString("Waits to be dismissed");
            a.setTimeout(Alert.FOREVER);

            showAlert(a);

            return a;
        }
    }

    // An alert test that displays an alert with
    // a gauge whose value is increased every second.
    // The alert can be dismissed only after the gauge
    // reaches its maximum value.

    public class ProgressAlert extends AlertRunner implements CommandListener,
            Runnable
    {

        private static final int MAX = 10;

        public ProgressAlert(String title)
        {
            super(title);
        }

        public Alert doAlert()
        {
            _gauge = new Gauge(null, false, MAX, 0);
            _gauge.setValue(0);
            _done = false;

            _alert = new Alert(getTitle());
            _alert.setString("Counts to " + MAX
                    + " and then lets you dismiss it");
            _alert.setCommandListener(this);
            _alert.setIndicator(_gauge);

            // Set a _very_ long timeout
            _alert.setTimeout(ONE_SECOND * 3600);

            showAlert(_alert);
            new Thread(this).start();

            return _alert;
        }

        public void commandAction(Command c, Displayable d)
        {
            if (_done || _gauge.getValue() >= MAX)
            {
                showList();
            }
        }

        private void done()
        {
            _alert.addCommand(new Command("Done", Command.OK, 1));
            _done = true;
        }

        // A thread that bumps the value of the counter
        // every second.

        public void run()
        {
            int val = _gauge.getValue();
          
            try
            {
                while (val < MAX)
                {
                    Thread.sleep(ONE_SECOND);
                    _gauge.setValue(++val);
                }
            } catch (InterruptedException e)
            {
            }

            done();
        }

        private Alert _alert;
        private int _counter;
        private boolean _done;
        private Gauge _gauge;
    }

    // An alert test that displays a continuously
    // running gauge before automatically timing out.

    public class BusyAlert extends AlertRunner
    {
        public BusyAlert(String title)
        {
            super(title);
        }

        public Alert doAlert()
        {
            _gauge = new Gauge(null, false, Gauge.INDEFINITE,
                    Gauge.CONTINUOUS_RUNNING);

            _alert = new Alert(getTitle());
            _alert.setString("Runs for 5 seconds and "
                    + "times out automatically");
            _alert.setIndicator(_gauge);
            _alert.setTimeout(FIVE_SECONDS);

            showAlert(_alert);

            return _alert;
        }

        private Alert _alert;
        private Gauge _gauge;
    }

    // Standard MIDlet code. Displays a list of
    // available alert tests and runs the test once
    // it's been chosen.

    private Display display;

    public static final Command exitCommand = new Command("Exit", Command.EXIT,
            1);

    public AlertTest()
    {
    }

    public void commandAction(Command c, Displayable d)
    {
        if (c == exitCommand)
        {
            exitMIDlet();
        } else if (c == List.SELECT_COMMAND)
        {
            int index = _alertList.getSelectedIndex();
            _alertRunners[index].doAlert();
        }
    }

    protected void destroyApp(boolean unconditional)
            throws MIDletStateChangeException
    {
        exitMIDlet();
    }

    public void exitMIDlet()
    {
        notifyDestroyed();
    }

    public Display getDisplay()
    {
        return display;
    }

    protected void initMIDlet()
    {

        // The list of alert tests....

        _alertRunners = new AlertRunner[] { new TimedAlert("Timed alert"),
                new ModalAlert("Modal alert"),
                new ProgressAlert("Progress alert"),
                new BusyAlert("Busy alert") };

        _alertList = new List("Alert Testing", List.IMPLICIT);
        _alertList.setCommandListener(this);

        for (int i = 0; i < _alertRunners.length; ++i)
        {
            _alertList.append(_alertRunners[i].toString(), null);
        }

        showList();
    }

    protected void pauseApp()
    {
    }

    private void showAlert(Alert a)
    {
        getDisplay().setCurrent(a, _alertList);
    }

    private void showList()
    {
        getDisplay().setCurrent(_alertList);
    }

    protected void startApp() throws MIDletStateChangeException
    {
        if (display == null)
        {
            display = Display.getDisplay(this);
            initMIDlet();
        }
    }

    private List _alertList;
    private AlertRunner[] _alertRunners;
}

 

MIDP的界面类(javax.microedition.lcdui)体系详解  由于在MIDP手机编程中,没有控制台的概念,所以所有的MIDP手机软件都必须有自己的界面,下面就熟悉一下MIDP的界面类体系。首先说明的是,MIDP的标准界面类都位于javax.microedition.lcdui包中,使用时一定要记得引入。在界面体系中,所以可以直接显示的界面类都继承自同一个父类——Displayable。根据是否能直接操作屏幕,以及是否和屏幕尺寸相关,MIDP 阅读详情

相关推荐

Java游戏项目实战:MIDP 2.0开发教程与实例

Java作为一种广泛使用的编程语言,其在游戏开发领域也具有不可忽视的地位。其跨平台的特性使得Java编写的游戏可以在多种设备上运行,无论是在桌面系统、移动设备还是嵌入式系统上。开发者可以利用Java语言的特性,例如面向对象、垃圾回收机制以及强大的标准库,来构建丰富多样的游戏应用。J2ME(Java 2 Platform, Micro Edition)是Java平台针对消费类电子设备和嵌入式设备(如手机、PDA)的一个特别配置版本。

weixin_36078669的博客 658

MIDP 2.0 开发J2ME游戏起步之一

<!--google_ad_client = "pub-2947489232296736";/* 728x15, 创建于 08-4-23MSDN */google_ad_slot = "3624277373";google_ad_width = 728;google_ad_height = 15;//--><script type="text/javascript"

zgqtxwd的专栏 515

ASF(Alert Standard Format Specification)标准2.0

ASF(Alert Standard Format Specification)标准,报警标准格式标准。 分布式管理工作小组 (Distributed Management Task Force - DMTF) 已发布报警标准格式 (Alert Standard Format - ASF) 2.0 规范, 该规范对报警和远程控制接口进行了定义,用以在没有操作系统的情况下对网络计算机进行管理。

MIDP v2.0规范简介

二 J2ME 架构:Java自1995年发明以来以发生了很大的变化,从最早的为基于溜览器中运行的Applet的编程,到Servlet/EJB的Server编程,再到现在的MIDlet为无线信息设备的编程。它已发展成为为开发者提供一端到端编程开发的平台,即我们常说的 J2SE/J2EE/J2ME,Java的三个平台(fig1)。由于无线编程有其完全不同于传统编程的特殊性,比如:运行设备的多样性,

mobilechannel的专栏 2066

深入MIDP2.0(2) - CLDC与MIDP工具类别

深入MIDP2.0(2) - CLDC与MIDP工具类别

MIDP2.0 稀有资源 与你分享

midp-20-src-windows-i686-J2ME-MobileInformationDeviceProfile-MIDP2.0

MIDP高级图形用户界面详解

一、MIDP图形用户界面(UI)简介图形用户界面编程在程序开发中非常重要,因为这是程序和用户之间交互的桥梁。在J2SE中我们可以通过AWT/Swing开发图形用户界面,也可以使用SWT,AWT/Swing主要是针对桌面应用程序而设计。但由于移动设备的显示屏幕和键盘实是种类太多了,几乎每个厂家都多多少少有所不同,设备的性能也比较有限,因此没有采用AWT/Swing作为MIDP的图形用户界面库,而建立

wwy25525761的专栏 844

JavaMIDP2.0教程

一点点MIDP2.0开发的教程

J2ME:Alert的使用

 import java.io.IOException;import javax.microedition.lcdui.Alert;import javax.microedition.lcdui.AlertType;import javax.microedition.lcdui.Command;import javax.microedition.lcdui.CommandListener;im

Smart coding space 745

R语言绘图进阶:五大工具高效组合多图(cowplot、patchwork、layout、par、gridExtra)

本文详细介绍了R语言中五大高效组合多图的工具:cowplot、patchwork、layout、par和gridExtra。针对不同场景提供了实用指南,帮助数据分析师解决图表排版难题,提升报告专业度。特别推荐cowplot用于ggplot2图形组合,patchwork提供最简洁语法,layout则支持完全自定义布局。

weixin_42544663的博客 289

ubuntu20.04安装UE4+Airsim环境

版本UE4.27+Airsim1.81

玖茸的博客 3380

MIDP图形用户界面结构

        图形用户界面编程在程序开发中非常重要,因为这是程序和用户之间交互的桥梁。很难想象一个应用程序没有用户界面。在J2SE中我们可以通过AWT/Swing开发图形用户界面,也可以使用近期备受关注的SWT。在J2ME专家组织定MIDP中的图形用户界面的时候,考虑到设备的性能比较有限,AWT/Swing主要是针对桌面应用程序而设计的原因,最终没有采用AWT/Swing作为MIDP的图形用户界

862

NAT反向代理技术的实现(外网访问内网)

NAT反向代理技术的实现(外网访问内网)(版权所有,引用 请联系作者,注明出处) NAT技术是网络中的重要应用之一。当有一个场景:内网搭建了服务器,需要外网访问时,可以借助NAT映射来实现。如:单位建立了一个Web服务器,我们希望在员工回家之后,依然可以访问到它,那怎么实现呢? 下面的拓扑图,就用来示范这个应用反面场景的实现过程。 一、题目要求: 地址配置如图。使用静态路由: 1、配置右侧交换机2950T,实现单臂路由; 2、配置路由使网络连通; 3、配置NAT访问,实现外网对风网服务器的

joyousmime的博客 8489

J2ME中文教程 3 MIDP高级UI 的使用

作者:stone111  文章来源:http://www.j2medev.com/Article/ShowArticle.asp?ArticleID=2763.1    概述我们在这一节要介绍一下整个LCDUI包的结构,让读者对我们整个UI的学习的有个大致的了解。下图为我们展示了整个LCDUI包的体系:     Screen类属于高级图形用户界面组件,就是我们这一章要着重介绍的内容,Canvas是

mobilechannel的专栏 1182

常用的集成TTL门电路

本篇主要分析了常用的逻辑门电路与非门,详细分析了电源原理。值得收藏。

ManagerUser的博客 5088

【图像去噪】论文复现:Mamba没Out!MaIR的Pytorch源码复现,跑通全流程,轻松解决环境配置问题,图文结合,明确MaIR创新点,与MambaIR对比,示意图与源码对应,清晰易懂,注释详细!

论文题目:MaIR: A Locality- and Continuity-Preserving Mamba for Image Restoration —— MaIR:用于图像恢复的局部性和连续性保持 Mamba【图像去噪】论文精读:MaIR: A Locality- and Continuity-Preserving Mamba for Image Restoration【图像去噪】论文复现:Man!

主要更新底层视觉(去噪、超分等)相关的科研内容,形式为【论文精读】+【论文复现】 1115

深入理解MIDP的界面类体系

深入理解MIDP的界面类体系 作者:陈跃峰 Email:cqucyf@gmail.com 因为在MIDP手机编程中,没有控制台的概念,所以所有的MIDP手机软件都必须有自己的界面,下面就熟悉一下MIDP的界面类体系。 首先说明的是,MIDP的标准界面类都位于javax.microedition.lcdui包中,使用时一定要记得引入。 在界面体系中,所以可以直接显示的界面类都继承自同一个父类...

iteye_8557的博客 112

【AIGC】大模型面试高频考点09-大模型Agent框架

聚焦AIGC专业技术分享

一个内容严谨、方向前沿、极具实践价值的AI大模型技术分享站 1967

java 对话框 是 否_Java ME中的是/否对话框

你需要一个Alert:An alert is a screen that shows data to the user and waits for a certain period of time before proceeding to the next Displayable. An alert can contain a text string and an image. The inten...

weixin_30814737的博客 302

基于SAHI算法优化YOLOv8的小目标检测性能研究

SAHI(SliceAwareHyperInference)是一种推理优化算法,通过将大图切片为小块并分别推理的方式,实现更精细的小目标检测。提升小目标检测精度:切片后的小目标在每个小块中占比更大,模型能够更好地聚焦。兼容性强:可直接集成到现有目标检测框架中(如YOLO系列、Detectron2等)。支持大分辨率图片和视频推理:减少硬件对大图推理的限制。本文详细探讨了如何通过SAHI(切片辅助超推理算法)结合YOLOv8模型,有效提升小目标检测性能,尤其是在高分辨率图片和视频场景中表现优异。

博客 2373

从零开始:使用Verilog在FPGA上实现8051微控制器的完整指南

8051微控制器是一种8位微控制器,由Intel在1980年代初推出。它包括一个CPU、一些RAM和ROM、I/O端口、定时器和串行通信接口。由于其简单的架构和强大的功能,8051已经成为了嵌入式系统设计的首选。FPGA是一种集成电路,设计师可以按照自己的需求进行编程。与传统的ASIC(应用特定集成电路)相比,FPGA提供了更高的灵活性,允许在硬件级别进行快速原型设计和迭代。这里,我们定义了一些基本的输入/输出端口,如时钟clk、复位reset、数据输入/输出和地址输入/输出。

qq_38334677的博客 1332

有效利用UI部件(1)-----转

有效利用UI部件(1)    今天我们将通过应用程序来介绍有效利用MIDP2.0的UI部件的方法。   什么是UI部件啊?  

482

锂电池充电器电路设计 里面有电路

锂电池充电器电路设计 里面有电路 3.7V升压到5V电路设计。

Motorola的J2ME界面扩展——LWT介绍

Motorola的J2ME界面扩展——LWT介绍作者:陈跃峰出自:http://blog.csdn.net/mailbomb        LWT(Lightweight Window Toolkit)是Motorola公司对MIDP的javax.microedition.lcdui界面包的一个扩展,可以在Motorola系列的手机中象使用MIDP界面一样来进行使用,解决了MIDP界面不能通过屏幕

爪哇米工作室陈跃峰的移动开发博客 2694

老版QQ原生表情gif动态

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

IEM模型,地表粗糙度模拟

利用微波反演土壤水分时候,利用IEM模型可以实现对随机地表的模拟

J2ME学习笔记(七)

    做手机的程序开发,肯定就会涉及到图形处理方面的问题咯。与事务处理一样,MIDP将图形介面处理也分成了高级图形介面处理与低级图形介面处理。同样,高级图形介面处理方法是可以方便移值的,但是功能有限,低级图形介面功能强大,但是再移值以后可能会需要更改部分代码。高级图形介面都需要继承Screen,而低级图形介面则继承Canvas,并大量使用Graphics所定义的图形处理方法。MIDP

北漂的鱼 1281

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

上一篇: 理解JTWI的具体内容和作用
下一篇: 实例论证J2ME的事件传输机制
mingjava
博客等级 码龄24年 68粉丝 114原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值