自定义Annotation

转录组非负矩阵分解(NMF)/一致性聚类(ConsensusClusterPlus) 输入的数据矩阵。通常行代表样本,列代表特征或变量。是进行聚类分析的基础数据。该参数表示聚类分析时测试的最大簇数 (K)。通常设定一个合适的范围,比如2到10,以确定数据的最佳聚类数。重复聚类的次数。默认值为 100。增加重复次数可以提高一致性评估的准确性。在这里,设为500表示每个K值的聚类过程将重复500次。每次子采样时抽取样本的比例。默认值为 0.8。用于创建子样本来评估聚类的稳定性。pItem = 0.8表示每次采样80%的样本。每次子采样时抽取特征(变量)的比例。默认值为 1。 阅读详情


上图显示的内容包括:

1. 在界面显示一副地图;

2. 在地图上显示一个“笑脸”图标,笑脸所在的位置就是你的当前位置,或者你自己任意设定的地理位置;

3. 点击“笑脸”图标之后,会弹出一个类似标签(Annotation)的东西,标签上有三种内容:左边一副蝙蝠侠的图片,中间文字内容,以及最右边的按钮。

其中2和3都是属于自定义地图Annotation。

下面我们就一步步来实现上图的效果吧。

===显示地图===

第一步:

首先在你的工程的frameworks下面加入Mapkit.framework。至于如何加入一个framework,请参考之前的一篇文章。

加入Mapkit.framework之后,在需要用到地图的类的头文件中加入“#import <MapKit/MapKit.h>”。这时候便可以使用所有关于地图的功能了。

显示地图十分简单,只要在xib文件里面,将一个MKMapView拖进容纳这幅地图的View当中即可。这时候进行调试,将出现一个全球的地图。原因是因为你没有给地图一个显示的地理信息,所以初始化的地图只能显示一个全球的范围。

那么下一步便是将地图跳转到你需要显示的地理位置。加入你通过之前文章的阅读,已经获取到了当前位置,保存到checkinLocation(一个CLLocation的指针)当中了。

第二步:

在需要显示地图的View类中定义一个mapView:IBOutlet MKMapView *mapView。并且在xib中将之前拖进来的MKMapView和这个mapView成员变量建立outlets的关系(什么?不懂?那就从头学一下xcode吧)。

在类的实现文件(.m)中加入以下代码(方法名自己起吧,我这里起的是initMapView):

  1. - (void) initMapView {  
  2.     MKCoordinateSpan theSpan;  
  3.     //设置地图的范围,越小越精确  
  4.     theSpan.latitudeDelta = 0.02;  
  5.     theSpan.longitudeDelta = 0.02;  
  6.     MKCoordinateRegion theRegion;  
  7.     theRegion.center = [checkinLocation coordinate]; //让地图跳到之前获取到的当前位置checkinLocation  
  8.     theRegion.span = theSpan;  
  9.     [mapView setRegion:theRegion];  
  10. }  

然后,你在显示这个View的时候(比如在viewDidLoad函数中)调用initMapView,地图便可以跳到你要显示的位置了。这里关键的函数是setRegion,已经被MKMapView类封装好了。

至此,你的应用就可以显示地图,并且跳到你设定的任何位置了。是不是特简单?简直简单到我在怀疑我是否有写这篇文章的需要了。不过,废话少说。下面还是来看看如何自定义Annotation吧。

===自定义Annotation===

如果不采取自定义的Annotation,ios默认的是一个图钉的形状,如下图(一个紫色的图钉):


当然,千里执行始于足下,我们还是首先来看看如何在特定的位置显示以上的默认的小图钉吧。

第一步:

先定义一个自己的Annotation的类:

  1. @interface MyMapAnnotation : NSObject<MKAnnotation> {  
  2.     CLLocationCoordinate2D location;  
  3.     NSString *title;  
  4.     NSString *subtitle;  
  5.     NSString *headImage;  
  6. }  
  7.   
  8. @property CLLocationCoordinate2D location;  
  9. @property (nonatomic, copy) NSString *title;  
  10. @property (nonatomic, copy) NSString *subtitle;  
  11. @property (nonatomic, copy) NSString *headImage;  
  12.   
  13. @end  
从上面代码可以看到,MyMapAnnotation类继承于MKAnnotation。里面包含四个成员变量。其中location保存要显示这个Annotation的位置。其他三个变量对应我们之前那个效果图的几点内容:头像、文字内容。

这个类的实现文件(.m)文件很简单,就定义好dealloc和init方法就好,这里不再赘述。

第二步:

在要显示地图的View类中实现MKMapViewDelegate,并实现viewForAnnotation函数,代码如下:

  1. - (MKAnnotationView *)mapView:(MKMapView *)theMapView viewForAnnotation:(id <MKAnnotation>)annotation {  
  2.     if ([annotation isKindOfClass:[MKUserLocation class]])  
  3.         return nil;  
  4.     // 处理我们自定义的Annotation  
  5.     if ([annotation isKindOfClass:[MyMapAnnotation class]]) {    
  6.         static NSString* travellerAnnotationIdentifier = @"TravellerAnnotationIdentifier";  
  7.         MKPinAnnotationView* pinView = (MKPinAnnotationView *)  
  8.         [mapView dequeueReusableAnnotationViewWithIdentifier:travellerAnnotationIdentifier];  
  9.         if (!pinView)  
  10.         {  
  11.             // if an existing pin view was not available, create one  
  12.             MKAnnotationView* customPinView = [[[MKAnnotationView alloc]  
  13.                                                 initWithAnnotation:annotation reuseIdentifier:travellerAnnotationIdentifier] autorelease];  
  14.             customPinView.pinColor = MKPinAnnotationColorPurple;  
  15.             customPinView.animatesDrop = YES;  //如果不需要这个从天而降的效果,设置为NO即可。  
  16.             customPinView.canShowCallout = NO;  
  17.             return customPinView;  
  18.         }  
  19.         else  
  20.         {  
  21.             pinView.annotation = annotation;  
  22.         }  
  23.         return pinView;  
  24.     }  
  25.     return nil;  
  26. }  

这段代码将实现默认的一个图钉的效果。

细心地你会发现,上面的代码似乎没有涉及到地理位置,那么地图将怎么知道将这个Annotation放到合适的位置呢?稍安勿躁,稍候将会介绍如何设置Annotation的位置,同时设置Annotation的其他内容(还记得Annotation的定义里面有位置信息,还有几项内容信息吧)。

如果我不喜欢图钉,我想把它换成之前效果图中的笑脸呢?那就把上述代码改成如下:

  1. - (MKAnnotationView *)mapView:(MKMapView *)theMapView viewForAnnotation:(id <MKAnnotation>)annotation {  
  2.     if ([annotation isKindOfClass:[MKUserLocation class]])  
  3.         return nil;  
  4.     if ([annotation isKindOfClass:[TravellerMapAnnotation class]]) {     
  5.         static NSString* travellerAnnotationIdentifier = @"TravellerAnnotationIdentifier";  
  6.         MKPinAnnotationView* pinView = (MKPinAnnotationView *)  
  7.         [mapView dequeueReusableAnnotationViewWithIdentifier:travellerAnnotationIdentifier];  
  8.         if (!pinView)  
  9.         {  
  10.             // if an existing pin view was not available, create one  
  11.             MKAnnotationView* customPinView = [[[MKAnnotationView alloc]  
  12.                                                 initWithAnnotation:annotation reuseIdentifier:travellerAnnotationIdentifier] autorelease];   
  13.             UIImage *image = [UIImage imageNamed:@"smileFace.png"];  
  14.             customPinView.image = image;  //将图钉变成笑脸。  
  15.             [image release];  
  16.             return customPinView;  
  17.         }  
  18.         else  
  19.         {  
  20.             pinView.annotation = annotation;  
  21.         }  
  22.         return pinView;  
  23.     }  
  24.     return nil;  
  25. }  


从上述代码看出,也就是将定义pinColor的代码段去掉,换成设置image的代码:customPinView.image = image.

同样很简单吧。哎,我还有没有写下去的必要呢。(画外音:废话少说!!!)

第三步:

正如之前的疑问,哪里定义Annotation的地理位置以及其他内容呢?不仅仅如此,还有,怎么让用户点击笑脸(或者图钉)之后,弹出一个标签,显示定义好的内容呢。下面我们先看看最后一个问题,怎么让用户点击笑脸(或者图钉)之后,弹出一个标签,显示定义好的内容呢?

还是上面那段代,将它进一步改成:

  1. - (MKAnnotationView *)mapView:(MKMapView *)theMapView viewForAnnotation:(id <MKAnnotation>)annotation {  
  2.     if ([annotation isKindOfClass:[MKUserLocation class]])  
  3.         return nil;  
  4.     if ([annotation isKindOfClass:[TravellerMapAnnotation class]]) {   
  5.         // try to dequeue an existing pin view first  
  6.         static NSString* travellerAnnotationIdentifier = @"TravellerAnnotationIdentifier";  
  7.         MKPinAnnotationView* pinView = (MKPinAnnotationView *)  
  8.         [mapView dequeueReusableAnnotationViewWithIdentifier:travellerAnnotationIdentifier];  
  9.         if (!pinView)  
  10.         {  
  11.             // if an existing pin view was not available, create one  
  12.             MKAnnotationView* customPinView = [[[MKAnnotationView alloc]  
  13.                                                 initWithAnnotation:annotation reuseIdentifier:travellerAnnotationIdentifier] autorelease];  
  14.             customPinView.canShowCallout = YES;  //很重要,运行点击弹出标签  
  15.             UIButton* rightButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];  
  16.             [rightButton addTarget:self  
  17.                             action:@selector(showDetails:)  //点击右边的按钮之后,显示另外一个页面  
  18.                             forControlEvents:UIControlEventTouchUpInside];  
  19.             customPinView.rightCalloutAccessoryView = rightButton;  
  20.             MyMapAnnotation *travellerAnnotation = (TravellerMapAnnotation *)annotation;  
  21.             UIImageView *headImage = [[UIImageView alloc] initWithImage:[UIImage imageNamed:travellerAnnotation.headImage]];  
  22.             customPinView.leftCalloutAccessoryView = headImage; //设置最左边的头像  
  23.             [headImage release];  
  24.             UIImage *image = [UIImage imageNamed:@"smileFace.png"];  
  25.             customPinView.image = image;  
  26.             customPinView.opaque = YES;  
  27.             [travellerImage release];  
  28.             return customPinView;  
  29.         }  
  30.         else  
  31.         {  
  32.             pinView.annotation = annotation;  
  33.         }  
  34.         return pinView;  
  35.     }  
  36.     return nil;  
  37. }  
上面的代码很容易理解(加上我的注释之后),有点objective-C以及cocoa基础的朋友都会看懂。如果你看不懂,拜托,我这里不负责扫盲啊。

也许你有个疑问,似乎没见到设置文字信息呀。其实,之前自定义的MyMapAnnotation继承自MKAnnotation,所以只要你给一个MyMapAnnotation对象的title和subtitle填上内容之后,它会自动显示,不需要你手动让它显示。

下面我们就来看看如何添加MyMapAnnotation的内容吧。

其实这也十分简单,就是创建一个新的MyMapAnnotation,然后往里面添加内容即可。比如:

  1. TravellerMapAnnotation *travellerAnnotation = [[TravellerMapAnnotation alloc] init];  
  2. travellerAnnotation.location = checkinlocation.coordinate;  
  3. travellerAnnotation.title = [travellerNames objectAtIndex:i];  
  4. travellerAnnotation.subtitle = [scores objectAtIndex:i];  
  5. travellerAnnotation.headImage = [headImages objectAtIndex:i];  

现在还残留的一个问题是(这是历史遗留的问题,由于某种原因,我们暂时忽略了它。。。!跑题了吧,大叔。。。):

如何将创建好的一个或者多个甚至成千上万个MyMapAnnotation加入地图并显示它呢。

这个问题更加简单。加入建立了100个MyMapAnnotations,并且全部存进了一个NSArray中,MyMapAnnotationsArray,那么我们需要做的就十分简单了:

mapView addAnnotations:MyMapAnnotationsArray

也就是调用MKMapView的addAnnotations方法将所有创建好的Annotations加进来即可。


Java的自定义注解——Annotation的使用 Annotation——自定义注解 Java中提供了 Annotation 功能,该功能可用于类,构造方法,成员变量,方法。参数等的声明中。该功能不会影响程序的运行,但是会对编译器警告等辅助工具产生影响。 定义 Annotation 类型 在定义 Annotation 类型时,需要用到用来定义接口的 interface 关键字,但需要在 interface 关键字前面加一个 “ @ ” 符号,即定... 阅读详情

相关推荐

补课了,30分钟让你学会java自定义annotation

自定义Annotation概念篇 来看一个最简单的annotation package com.cts.elt.annotation; import java.lang.annotation.Documented; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; import

打造全国最全的AI Agent开发知识领域的博客 2万+

iPhone地图应用开发以及自定义Annotation

(推荐本人创建的一个iOS开源代码收集网站 Code4app.com) 之前写了一篇关于获取当前位置的文章。现在这篇文章将探讨一下,如何用地图显示地理信息,以及我们怎么自定义地图的Annotation,也就是地图图钉。 接下来的叙述都是为了实现下面的效果: 上图显示的内容包括: 1. 在界面显示一副地图; 2. 在地图上显示一个“笑脸”图标,笑脸所在的位置就是你的当前位置,或者你

1万+

leaflet-地图文字标注

可以在leaflet地图上添加文字标注,可以自己设置样式,有背景色或者无背景色

iOS地图的注释(Annotation)

1. 添加到map view的子视图不会随地图的移动而移动,map view会固定其子视图的位置。如果要添加随着地图移动的子视图,可以使用annotations和overlays。annotation用来显示由一个经纬度定义的位置,而overlay则是由多个点所定义或者包含了许多连续的图形。  2.在地图上显示annotation,需要提供两个对象  annotation object)

黑菜妞妞的专栏 943

基于Leaflet.CanvasLabel 矢量文本标注参数使用源代码

在Leaflet中Leaflet.CanvasLabel 矢量文本标注参数使用源代码,详细的说明了其参数是如何使用的,包括字体设置、放大缩小、方向设置、颜色设置,同时还展示了如何进行事件的绑定,以及通过事件的绑定实现标注颜色的修改。最后还分享了如何解决在地图初始化时,标注文本被截断的问题,参考博客地址:https://blog.youkuaiyun.com/yelangkingwuzuhu/article/details/139569706

RocketMq面板访问异常 com.alibaba.fastjson.JSONException: not close json text, token : string

rocketmq JSONException: not close json text, token : string 问题解决

qq_21067307的博客 5573

leaflet添加Marker和文字标注

leaflet添加Marker和文字标注

qq_41425267的博客 1万+

ISO7816协议深度解析-简单易懂协议详解(一)-- 复位,字符帧,及ATR

1. 摘要 IC卡必须支持T=0或T=1的协议,但不是同时支持这两种协议,而终端则必须同时支持T=0和T=1的协议。 • T=0通讯协议是异步半双工字符传输协议; • T=1通讯协议是异步半双工块传输协议; 在ISO7816-3标准中,具体规定了这两种协议:T0和T1。 IC卡所用的协议在TD1中指定,如果在复位应答信息中没有TD1,则表示用T=0的协议进行通讯。在复位应答后,IC卡和终端之间即用IC卡指定的协议进行通讯。 2. 硬件接口 1)VCC:电源输入(A类:5V, B类:3V) 2)GND:地 3

代码打工人的博客 4万+

LeaFlet学习之地图文字标注

在地图上进行一些文字的标注有些场景我们会用到,在这里我们文字标注用到了DivICon图标,通过与mark相结合,将mark的图标设置为DivICon图标,进行文字标注,放张图看看效果: 一、全部代码 <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> &lt...

weixin_30716725的博客 2574

光学设计进阶:Zemax中的坐标断点与离轴系统优化

本文深入解析了Zemax中坐标断点的核心原理与实战应用,它是实现离轴光学系统设计的关键。文章通过比喻和实例,详细阐述了如何利用坐标断点作为“方向盘”来精确控制光学元件的偏心和倾斜,实现“前断后接”的局部坐标系变换,从而构建并优化无中心遮拦的离轴反射系统,避免光线失控。

3a9bq4r8t2y的博客 525

5G核心技术:N3与N4接口深度解析

5G网络中,N3和N4接口是实现用户数据传输的核心。N3接口是gNB与UPF之间的用户面通道,采用GTP-U协议封装数据,通过UDP/IP传输,确保低时延和业务隔离。N4接口是SMF与UPF之间的控制面链路,基于PFCP协议下发转发规则(FAR/TDR/QER/URR),实现精细化流量控制。二者协同工作:N4下发策略(如QoS、计费规则),N3执行数据转发,共同支持5G三大场景(eMBB/uRLLC/mMTC),体现控制与转发分离(CUPS)架构优势。

Qinti_mm的博客 1632

Java自定义Annotation,通过反射解析Annotation

Java自定义Annotation,通过反射解析Annotation 创建一个自定义的Annotation import java.lang.annotation.*; import java.lang.reflect.Method; @Documented @Target(ElementType.METHOD) @Retention(RetentionPolicy.RUNTIME) p...

三三两两的博客 269

Python中的串口通信库pyserial(基础)

pyserial是一个跨平台的库,可以在多个操作系统上使用,包括Windows、Linux和MacOS。:flushInput方法用于清除输入缓冲区中的所有数据,flushOutput方法用于清除输出缓冲区中的所有待发送数据。:PySerial允许在创建Serial对象后,通过修改对象的属性来设置串口参数,如波特率、数据位、校验位和停止位。同时,也提供了方法或属性来检查串口的状态,如是否已打开。:sendBreak方法用于向串口发送一个BREAK信号,这可以用于向连接的设备发送一个中断或重置信号。

weixin_44217158的博客 1万+

Java:自定义Annotation

一、自定义Annotation步骤  使用@interface关键字定义新的Annotation  //定义一个简单的Annotation类型 public @interface Test{ }  用于修饰程序的类、方法、变量、接口等定义  //使用@Test修饰类定义 @Test public class MyClass{ }

1024工场 2534

Openclaw 错误分析 与 解决方案 之:Selected model is at capacity. Try a different model, or wait and retry.

Openclaw 错误分析 与 解决方案 :Selected model is at capacity. Try a different model, or wait and retry.

多媒体编程、网络编程、系统编程、网络安全编程、驱动编程 6413

【R语言】基于Biomod2集成平台探究物种分布区的构建流程(SDMs)

我为什么想要写这个内容呢?其实我已经想了很久了,但是一直没有把所有的代码给理清楚,此外这将是我之后研究的主要方向。本博客讲述了如何基于Biomod2集成平台构建物种分布模型的全流程,以及我在使用该模型时的一些心得,同时还有我提供的一些小福利(一键处理代码),可以十分快捷的帮助你完成SDMs的构建,写出你的中英文论文。

amyniez的博客,欢迎交流讨论 3889

java自定义Annotation

相信在使用java编程的过程中,大家对于Annotation已经见怪不怪了,常见的有@Override、@Deprecated和一些开源框架(例如spring、hibernate等)中定义的Annotation。 Annotation可以用来修饰类、属性、方法,其不影响程序的运行,通过它来标识代码,能够起到代码分析、编译检查的作用。 下面通过一个例子来实现自定义Annotation的实现:...

yao891203的博客 171

matlab 点云可视化(1)——pcshow()函数可视化单个点云

matlab可视化单个点云常用方法汇总。

点云侠的博客 5357

Java自定义Annotation注解开发详解

Java自定义Annotation注解开发详解,包含Annotation Processor的使用介绍

DevCampsite的博客 2205

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

SIMATIC S7-1200, S7-1500 PID 控制[手册]

SIMATIC S7-1200, S7-1500 PID 控制[手册]

30分钟让你学会java自定义annotation

自定义Annotation概念篇 来看一个最简单的annotation Source code     package com.jianbage.java.annotation;   import java.lang.annotation.Documented;   import java.lang.annotation.ElementTyp

djun100的专栏 992

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...

Annotation之自定义

Annotation之自定义 定义Annotation的语法: Public @interface Annotation的名称{} 如:public @interface Override public @interface MyAnnotation { } 任何一个自定的Anntation都是继承了java.lang.annotation.Annotat...

weixin_33670713的博客 132

jre9下载 jdk9

(Java SE Runtime Environment 9.0) 9.0u175 官方最新版 【x86|x64】

Spring AOP自定义Annotation搭配log4j做日志

概况: 项目框架:Spring4,Hibernate4,SpringMVC 项目结构:使用了最常用的model,dao,service,controller 我的项目是在service层控件事务,运行日志也加在service层。 aop作用的是xml配置 涉及到的点: 1、自定义Annotation 2、使用SpringAOP 3、AOP通知参数 步骤: 1、自定义Annota

carlos1992的专栏 2359

自定义Annotation以及通过反射技术获取程序元素上的Annotation注解信息

Anonotation的含义:中文翻译为"注解",实际上表示的是一种注释的语法,这种注释和代码的注释是不一样的,代码的注释如单行注释使用双斜杠"//",或多行注释使用"/*...*/"等是给程序员看的,其主要是为了增加代码的可读性,便于代码的后期维护。而Annotation主要是服务于编译器,属于一种配置信息。在本质上,Annotation提供了一种与程序元素关联任何信息或任何元数据的方式。Ann...

qq_43648299的博客 452
上一篇: 常见的内存泄露情况
下一篇: 改变MKAnnotationView的大小,使之随MKMapView的缩放而缩放
focusjava
博客等级 码龄14年 127粉丝 528原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值