鸿蒙5.0开发进阶:@ohos.app.ability.Want (Want)

鸿蒙NEXT开发:Stage模型能力的接口-@ohos.app.ability.AbilityConstant (AbilityConstant) AbilityConstant提供UIAbility相关的枚举........ 阅读详情

往期鸿蒙全套实战文章必看:(文中附带全栈鸿蒙学习资料)


@ohos.app.ability.Want (Want)

Want是对象间信息传递的载体,可以用于应用组件间的信息传递。Want的使用场景之一是作为startAbility的参数,其包含了指定的启动目标,以及启动时需携带的相关数据,例如bundleName和abilityName字段分别指明目标Ability所在应用的包名以及对应包内的Ability名称。当UIAbilityA需要启动UIAbilityB并传入一些数据时,可使用Want作为载体将这些数据传递给UIAbilityB。

说明

本模块首批接口从API version 9 开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。

导入模块

import { Want } from '@kit.AbilityKit';

属性

元服务API: 从API version 11开始,该接口支持在元服务中使用。

系统能力:SystemCapability.Ability.AbilityBase

名称类型必填说明
deviceIdstring否表示运行指定Ability的设备ID。如果未设置该字段,则表明指定本设备。
bundleNamestring否表示待启动Ability所在的应用Bundle名称。
moduleNamestring否表示待启动的Ability所属的模块名称。
abilityNamestring否表示待启动Ability名称。如果在Want中该字段同时指定了BundleName和AbilityName,则Want可以直接匹配到指定的Ability。AbilityName需要在一个应用的范围内保证唯一。
actionstring否表示要执行的通用操作(如:查看、分享、应用详情)。在隐式Want中,您可以定义该字段,配合uri或parameters来表示对数据要执行的操作。
entitiesArray<string>否表示目标Ability额外的类别信息(如:浏览器、视频播放器)。在隐式Want中是对action字段的补充。在隐式Want中,您可以定义该字段,来过滤匹配Ability类型。
uristring否表示携带的数据,一般配合type使用,指明待处理的数据类型。如果在Want中指定了uri,则Want将匹配指定的Uri信息,包括scheme、schemeSpecificPart、authority和path信息。
typestring否表示MIME type类型描述,打开文件的类型,主要用于文管打开文件。比如:'text/xml' 、 'image/*'等,MIME定义请参见https://www.iana.org/assignments/media-types/media-types.xhtml?utm_source=ld246.com。
parametersRecord<string, Object>否

表示WantParams描述。

一、以下Key均由系统赋值,开发者手动修改也不会生效,系统在数据传递时会自动修改为实际值。

- ohos.aafwk.param.callerPid:表示拉起方的pid,值为字符串类型。

- ohos.aafwk.param.callerBundleName:表示拉起方的BundleName,值为字符串类型。

- ohos.aafwk.param.callerAbilityName:表示拉起方的AbilityName,值为字符串类型。

- ohos.aafwk.param.callerNativeName:表示native调用时拉起方的进程名,值为字符串类型。

- ohos.aafwk.param.callerAppId:表示拉起应用的AppId信息,值为字符串类型。

- ohos.aafwk.param.callerAppIdentifier:表示拉起应用的AppIdentifier信息,值为字符串类型。

- ohos.aafwk.param.callerToken:表示拉起方的token,值为字符串类型。

- ohos.aafwk.param.callerUid:表示BundleInfo中的uid,应用包里应用程序的uid,值为数值类型。

- component.startup.newRules:表示是否启用新的管控规则,值为布尔类型。

- moduleName:表示拉起方的moduleName,值为字符串类型。

- ability.params.backToOtherMissionStack:表示是否支持跨任务链返回,值为布尔类型。

- ohos.ability.params.abilityRecoveryRestart:表示当前Ability是否发生了故障恢复重启,值为布尔类型。

- ohos.extra.param.key.contentTitle:表示元服务支持分享的标题,值为字符串类型。

- ohos.extra.param.key.shareAbstract:表示元服务支持分享的内容,值为字符串类型。

- ohos.extra.param.key.shareUrl:表示元服务支持分享的链接,值为字符串类型。

- ohos.extra.param.key.supportContinuePageStack:表示在跨端迁移过程中是否迁移页面栈信息,值为布尔类型,默认值为true,自动迁移页面栈信息。

- ohos.extra.param.key.supportContinueSourceExit:表示跨端迁移源端应用是否退出,值为布尔类型,默认值为true,源端应用自动退出。

- ohos.extra.param.key.showMode:表示拉起元服务的展示模式,值为枚举类型wantConstant.ShowMode。

- ohos.dlp.params.sandbox:表示数据防泄漏(DLP)文件才会涉及。仅系统应用涉及。

- ohos.dlp.params.bundleName:表示数据防泄漏(DLP)的BundleName,值为字符串类型。仅系统应用涉及。

- ohos.dlp.params.moduleName:表示数据防泄漏(DLP)的moduleName,值为字符串类型。仅系统应用涉及。

- ohos.dlp.params.abilityName:表示数据防泄漏(DLP)的AbilityName,值为字符串类型。仅系统应用涉及。

- ohos.dlp.params.index:表示数据防泄漏(DLP)的索引,值为数值类型。仅系统应用涉及。

- ohos.ability.params.asssertFaultSessionId:表示AssertFault的会话ID,值为字符串类型。仅系统应用涉及。

二、以下是由系统定义、开发者按需赋值的Key。

- ability.params.stream:指示携带的文件URI要授权给目标方,值为string类型的文件URI数组。

- ohos.extra.param.key.appCloneIndex:指示分身应用索引。

三、除了上述两种情况,应用间还可以相互约定传入的键值对。

说明:

want的Params操作的常量的具体信息请参考wantConstant。

需注意,WantParams支持传输的最大数据量为200KB。当数据量超过200KB时,请使用WriteRawDataBuffer或uri的方式进行数据传输。

parameters的Value值仅支持基本数据类型:String、Number、Boolean、Object、undefined和null,不支持传递Object内部的function。

flagsnumber否

表示处理Want的方式。默认传数字。

例如通过wantConstant.Flags.FLAG_ABILITY_CONTINUATION表示是否以设备间迁移方式启动Ability。

示例:

  • 基础用法:在UIAbility对象中调用,示例中的context的获取方式请参见获取UIAbility的上下文信息。

    import { common, Want } from '@kit.AbilityKit';
    import { BusinessError } from '@kit.BasicServicesKit';
    
    let context = getContext(this) as common.UIAbilityContext; // UIAbilityContext
    let want: Want = {
      deviceId: '', // deviceId为空表示本设备
      bundleName: 'com.example.myapplication',
      abilityName: 'FuncAbility',
      moduleName: 'entry' // moduleName非必选
    };
    
    context.startAbility(want, (err: BusinessError) => {
      if (err.code) {
        // 显式拉起Ability,通过bundleName、abilityName和moduleName可以唯一确定一个Ability
        console.error(`Failed to startAbility. Code: ${err.code}, message: ${err.message}`);
      }
    });
  • 目前支持的数据类型有:字符串、数字、布尔、对象、数组和文件描述符等。

    • 字符串(String)

      import { common, Want } from '@kit.AbilityKit';
      import { BusinessError } from '@kit.BasicServicesKit';
      
      let context = getContext(this) as common.UIAbilityContext; // UIAbilityContext
      let want: Want = {
        bundleName: 'com.example.myapplication',
        abilityName: 'FuncAbility',
        parameters: {
          keyForString: 'str',
        },
      };
      
      context.startAbility(want, (err: BusinessError) => {
        if (err.code) {
          console.error(`Failed to startAbility. Code: ${err.code}, message: ${err.message}`);
        }
      });
    • 数字(Number)

      import { common, Want } from '@kit.AbilityKit';
      
      let context = getContext(this) as common.UIAbilityContext; // UIAbilityContext
      let want: Want = {
        bundleName: 'com.example.myapplication',
        abilityName: 'FuncAbility',
        parameters: {
          keyForInt: 100,
          keyForDouble: 99.99,
        },
      };
      
      context.startAbility(want, (err) => {
        if (err.code) {
          console.error(`Failed to startAbility. Code: ${err.code}, message: ${err.message}`);
        }
      });
    • 布尔(Boolean)

      import { common, Want } from '@kit.AbilityKit';
      import { BusinessError } from '@kit.BasicServicesKit';
      
      let context = getContext(this) as common.UIAbilityContext; // UIAbilityContext
      let want: Want = {
        bundleName: 'com.example.myapplication',
        abilityName: 'FuncAbility',
        parameters: {
          keyForBool: true,
        },
      };
      
      context.startAbility(want, (err: BusinessError) => {
        if (err.code) {
          console.error(`Failed to startAbility. Code: ${err.code}, message: ${err.message}`);
        }
      });
    • 对象(Object)

      import { common, Want } from '@kit.AbilityKit';
      import { BusinessError } from '@kit.BasicServicesKit';
      
      let context = getContext(this) as common.UIAbilityContext; // UIAbilityContext
      let want: Want = {
        bundleName: 'com.example.myapplication',
        abilityName: 'FuncAbility',
        parameters: {
          keyForObject: {
            keyForObjectString: 'str',
            keyForObjectInt: -200,
            keyForObjectDouble: 35.5,
            keyForObjectBool: false,
          },
        },
      };
      
      context.startAbility(want, (err: BusinessError) => {
        if (err.code) {
          console.error(`Failed to startAbility. Code: ${err.code}, message: ${err.message}`);
        }
      });
    • 数组(Array)

      import { common, Want } from '@kit.AbilityKit';
      import { BusinessError } from '@kit.BasicServicesKit';
      
      let context = getContext(this) as common.UIAbilityContext; // UIAbilityContext
      let want: Want = {
        bundleName: 'com.example.myapplication',
        abilityName: 'FuncAbility',
        parameters: {
          keyForArrayString: ['str1', 'str2', 'str3'],
          keyForArrayInt: [100, 200, 300, 400],
          keyForArrayDouble: [0.1, 0.2],
          keyForArrayObject: [{ obj1: 'aaa' }, { obj2: 100 }],
        },
      };
      
      context.startAbility(want, (err: BusinessError) => {
        if (err.code) {
          console.error(`Failed to startAbility. Code: ${err.code}, message: ${err.message}`);
        }
      });
    • 文件描述符(FD)

      import { fileIo } from '@kit.CoreFileKit';
      import { common, Want } from '@kit.AbilityKit';
      import { BusinessError } from '@kit.BasicServicesKit';
      
      let context = getContext(this) as common.UIAbilityContext; // UIAbilityContext
      let fd: number = 0;
      
      try {
        fd = fileIo.openSync('/data/storage/el2/base/haps/pic.png').fd;
      } catch(err) {
        let code = (err as BusinessError).code;
        let message = (err as BusinessError).message;
        console.error(`Failed to openSync. Code: ${code}, message: ${message}`);
      }
      let want: Want = {
        deviceId: '', // deviceId为空表示本设备
        bundleName: 'com.example.myapplication',
        abilityName: 'FuncAbility',
        moduleName: 'entry', // moduleName非必选
        parameters: {
          'keyFd': { 'type': 'FD', 'value': fd } // {'type':'FD', 'value':fd}是固定用法,用于表示该数据是FD
        }
      };
      
      context.startAbility(want, (err: BusinessError) => {
        if (err.code) {
          console.error(`Failed to startAbility. Code: ${err.code}, message: ${err.message}`);
        }
      });
    • parameter参数用法:parameter携带开发者自定义参数,由UIAbilityA传递给UIAbilityB,并在UIAbilityB中进行获取。

      // (1) UIAbilityA通过startability启动UIAbilityB
      import { common, Want } from '@kit.AbilityKit';
      import { BusinessError } from '@kit.BasicServicesKit';
      
      let context = getContext(this) as common.UIAbilityContext; // UIAbilityContext
      let want: Want = {
        bundleName: 'com.example.myapplication',
        abilityName: 'UIAbilityB',
        parameters: {
          developerParameters: 'parameters',
        },
      };
      
      context.startAbility(want, (err: BusinessError) => {
        if (err.code) {
          console.error(`Failed to startAbility. Code: ${err.code}, message: ${err.message}`);
        }
      });
      // (2) 以UIAbilityB实例首次启动为例,会进入到UIAbilityB的onCreate生命周期
      import { UIAbility, Want, AbilityConstant } from '@kit.AbilityKit';
      
      class UIAbilityB extends UIAbility {
      onCreate(want: Want, launchParam: AbilityConstant.LaunchParam) {
      console.log(`onCreate, want parameters: ${want.parameters?.developerParameters}`);
      }
      }
    • parameter参数中wantConstant的Key的使用方法。

      import { common, Want, wantConstant } from '@kit.AbilityKit';
      import { BusinessError } from '@kit.BasicServicesKit';
      
      let context = getContext(this) as common.UIAbilityContext; // UIAbilityContext
      let want: Want = {
        bundleName: 'com.example.myapplication',
        abilityName: 'FuncAbility',
        parameters: {
          [wantConstant.Params.CONTENT_TITLE_KEY]: 'contentTitle',
        },
      };
      
      context.startAbility(want, (err: BusinessError) => {
        if (err.code) {
          console.error(`Failed to startAbility. Code: ${err.code}, message: ${err.message}`);
        }
      });

别再乱点U盘里的.exe了!手把手教你清除‘Usb Disk.exe’病毒并恢复隐藏文件 本文详细介绍了如何识别和清除U盘病毒(如Usb Disk.exe),并提供从终止病毒进程到恢复隐藏文件的完整步骤。通过禁用自动播放、清理注册表和使用命令行工具,帮助用户彻底清除病毒并预防未来感染,确保数据安全。 阅读详情

相关推荐

一种导弹追踪算法的MATLAB仿真实现

以下是一个用于模拟机动变轨导弹和防空导弹追踪过程的 MATLAB 代码,同时会提供 3D 效果展示。你可以运行这段代码,从而观察机动变轨导弹和防空导弹的速度与位置变化。

SmartGridequation的博客 937

【愚公系列】2023年12月 HarmonyOS教学课程 051-Stage模型(信息传递载体Want)

应用中的信息传递是为了实现各种功能和交互。信息传递可以帮助用户和应用之间进行有效的沟通和交流。通过信息传递,应用可以向用户传递重要的消息、通知和提示,以提供及时的反馈和指导。同时,用户也可以通过信息传递向应用发送指令、请求和反馈,以实现个性化的需求和操作。信息传递还可以帮助应用之间实现数据的共享和交互。通过信息传递,不同应用可以实现数据的互通,以实现更多的功能和服务。例如,一个购物应用可以通过信息传递与支付应用进行数据交互,以实现支付功能;

愚公智库 8万+

用户消费行为分析(MapReduce实现,Hive分析)

一、题目要求 数据来自CDNow网站的一份用户购买CD明细,本数据集共有 6 万条 左右数据,数据为 CDNow 网站 1997年1月至1998年6月的用户行为 数据

紫烟的博客 3014

鸿蒙API14开发【@ohos.app.ability.wantConstant (wantConstant)】应用框架api

wantConstant模块提供want中操作want常数和解释Flags说明的能力。

bbq的博客 326

PWM调节DCDC参数计算原理

SOC芯片的核电压、GPU电压、NPU电压、GPU电压等,都会根据性能和实际应用场景来进行电压和频率的调整。 即动态电压频率调整DVFS(Dynamic Voltage and Frequency scaling),优化性能和功耗。

电子绿洲的博客 3167

STM32HAL库 基于外部Flash+FatFs模拟U盘方式进行固件拷贝升级(详解)

STM32HAL库 基于外部Flash+FatFs模拟U盘方式进行固件拷贝升级

qq_36075612的博客 1万+

HarmonyOS/OpenHarmony应用开发-stage使用显示Want启动Ability

HarmonyOS/OpenHarmony应用开发-stage使用显示Want启动Ability

weixin_69135651的博客 927

单粒子翻转对FPGA的影响及解决方法

单粒子翻转对FPGA的影响及解决方法

航天领域资深码农,型号经验丰富,一线干货分享 2446

鸿蒙开发:【信息传递载体Want】

Want]是一种对象,用于在应用组件之间传递信息。其中,一种常见的使用场景是作为[]方法的参数。例如,当UIAbilityA需要启动UIAbilityB并向UIAbilityB传递一些数据时,可以使用Want作为一个载体,将数据传递给UIAbilityB。Want用法示意。

鸿蒙的技术博客 1179

2、欧洲期权的赫斯顿模型

本文详细介绍了赫斯顿随机波动率模型在欧洲期权定价中的应用。模型通过引入随机方差过程,克服了布莱克-斯科尔斯模型中波动率恒定的局限性,更贴近市场实际。文章阐述了模型的动态结构、风险中性转换、期权定价公式及其半封闭解的计算方法,并提供了基于VBA的数值实现方案。通过梯形法则与高斯积分等数值方法对比,分析了不同积分策略的精度与效率。同时验证了当波动率为零时,赫斯顿模型退化为布莱克-斯科尔斯模型的一致性。最后讨论了模型的优势、挑战及实际应用建议,强调了数值积分稳定性和参数估计的重要性。

tequila的博客 350

抑制电磁干扰(EMI)的实用电路技术

抑制电磁干扰(EMI)的实用电路技术 qtFK_EMC_EMI 【导读】本系列文章的第 1 部分至第 4 部分详细介绍了开关电源稳压器引起的传导发射和辐射发射,包括噪声产生机制、测量要求、频率范围、适用的测试限值、传播模式和寄生效应。在第 5 部分中,我将基于这一理论基础介绍抑制电磁干扰 (EMI) 的实用电路技术。 一般来说,电路原理图和印刷电路板 (PCB) 对于实现出色的 EMI 性能至关重要。第 3 部分重点强调通过谨慎的元器件选型和 PCB 布局尽量减小“功率回路”寄生电感的重要性。电源转换

学海无涯的专栏 1196

HarmonyOS Want意图传递机制深度解析

Want是HarmonyOS中用于传递组件间通信意图的对象。它封装了目标组件的信息以及需要传递的数据,系统根据Want的描述来启动相应的Ability或执行特定操作。// Want基本结构示例deviceId?: string;// 目标设备IDbundleName?: string;// 目标应用包名: string;// 目标Ability名称uri?: string;// 统一资源标识符type?: string;// MIME类型flags?: number;// 启动标志。

不懂先生的博客 656

180.在 Vue3 中使用 OpenLayers 实现多个多边形的绘制、编辑、删除与清空

【摘要】本文介绍如何在Vue3+TypeScript环境下使用OpenLayers实现多边形地图交互功能。通过Composition API封装核心逻辑,实现了多边形绘制、编辑、删除及清空等操作。关键技术包括:使用VectorLayer管理图形数据,Draw/Modify/Select交互控制,以及通过ref()管理交互状态。文中提供了完整代码示例,并解决了交互对象叠加问题,为开发GIS应用提供了基础模块。该方案支持扩展为数据库存储、后端交互等高级功能。

小彭的博客 771

鸿蒙5.0开发进阶:@ohos.app.ability.wantConstant (wantConstant)

wantConstant模块提供want中操作want常数和解释Flags说明的能力。

Androidbye的博客 1105

怀旧版电脑GBC模拟器

再现原版GBC掌机的界面,电脑运行连游戏界面都一样大小,很怀旧,很真实,(英文版)强烈推荐,很小的文件,很难才找到的。

Statistics and Machine Learning Toolbox

Statistics and Machine Learning Toolbox(带书签),MATLAB统计学习工具

【华为鸿蒙系统学习】- 如何利用鸿蒙系统进行App项目开发|自学篇

创建鸿蒙App项目|运行Hello World| 认识基本工程目录|项目开发过程错误总结 --- Previewer虚拟机构建失败解决方案,鸿蒙虚拟机黑屏解决方案

“路漫漫其修远兮,吾将上下求索。” 9646

Camera2Demo

在Camera2 的基础上进行封装,使得Camera2一堆初始化逻辑与Activity分离,降低耦合度,完成预览拍照并保存的操作

鸿蒙NEXT开发:FA模型能力的接口-@ohos.app.ability.Want (Want)

Want是对象间信息传递的载体,可以用于应用组件间的信息传递。

ZPYQAQ的博客 886

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

鸿蒙5.0开发进阶:@ohos.app.ability.Configuration (Configuration)

定义环境变化信息。Configuration是接口定义,仅做字段声明。

Androidbye的博客 768

鸿蒙5.0开发进阶:Stage模型-@ohos.app.ability.AbilityConstant (AbilityConstant)

AbilityConstant提供UIAbility相关的枚举,包括设置初次启动原因、上次退出原因、迁移结果、窗口类型等。

Androidbye的博客 965

鸿蒙5.0开发进阶:@ohos.app.ability.wantAgent (WantAgent模块)

app.ability.WantAgent是一个封装了Want对象的类,允许应用程序能够在未来的某个时间点执行该Want。

Androidbye的博客 1216

鸿蒙5.0开发进阶:Stage模型-@ohos.app.ability.common (应用上下文Context)

开发者可以通过该模块引用Ability公共模块类。

Androidbye的博客 936

鸿蒙5.0开发进阶:@ohos.app.ability.appManager (appManager)

appManager模块提供App管理的能力,包括查询当前是否处于稳定性测试场景、查询是否为ram受限设备、获取应用程序的内存大小、获取有关运行进程的信息等。

Androidbye的博客 1055

鸿蒙5.0开发进阶:Stage模型-@ohos.app.ability.StartOptions (StartOptions)

StartOptions可以作为startAbility()的入参,用于指定目标Ability的窗口模式。

Androidbye的博客 999

【华为鸿蒙系统学习】- 如何利用鸿蒙系统进行App项目开发 自学篇_鸿蒙app开发(1)

**

2301_76225520的博客 1146

鸿蒙5.0开发进阶:@ohos.app.ability.appRecovery (appRecovery)

appRecovery模块提供了应用在故障状态下的恢复能力。

Androidbye的博客 870

鸿蒙5.0开发进阶:Stage模型-@ohos.app.ability.contextConstant (ContextConstant)

ContextConstant提供Context相关的枚举,当前仅包含数据加密等级的枚举。

Androidbye的博客 848

鸿蒙5.0开发进阶:Stage模型-@ohos.app.ability.Ability (Ability基类)

UIAbility和ExtensionAbility的基类,提供系统配置更新回调和系统内存调整回调。

Androidbye的博客 604
上一篇: 鸿蒙5.0开发进阶:@ohos.app.ability.errorManager (ErrorManager)
下一篇: 鸿蒙5.0开发进阶:@ohos.app.ability.wantAgent (WantAgent模块)
懂你的大海
博客等级 码龄6年 9049粉丝 1381原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值