ios 创建圆形布局

ios 圆形旋转菜单_iOS 圆环菜单 前言之前的一个项目,没有使用TabBar,而是选择用圆环作为用户点击的菜单,加上深蓝的冷色调,APP看着还蛮高大上,先看下效果图:demo.gif效果图分析1.类似地球的是一张Image,其余的都是Button,每个button都是可以点击,点击回调至VC你可以处理一些事.2.项目中的需求是旋转圆盘后自动会停止,停止时布局还是和最开始的一样(只不过可能不是原来的按钮),点击某个按钮,这个按钮就在最... 阅读详情

创建圆形布局

    圆形布局是一种醒目的排版方式,他会将试图里的内容绕着某个中心区域来排布,这种布局方式很好的演示了如何在创建条目和删除条目的时候,把操作过程以动画形式展现出来。


    通过collectionViewContentSize方法把视图内容的尺寸设为固定值。由于它明确的创建了一块固定不变的排版区域,所以集合视图不会再滚动了。代码还会在prepareLayout方法中进行计算,以便进一步向内缩小排版区域。屏幕的高度与屏幕的宽度之中较小的值,决定了圆的半径。无论屏幕方向如何改变,圆的半径总保持不变。

@implementation CircleLayout
{
    NSInteger numberOfItems;
    CGPoint centerPoint;
    CGFloat radius;
    
    NSMutableArray *insertedIndexPaths;
    NSMutableArray * deletedIndexPaths;
}

- (void)prepareLayout
{
    [super prepareLayout];
    CGSize size = self.collectionView.frame.size;
    numberOfItems = [self.collectionView numberOfItemsInSection:0];
    centerPoint = CGPointMake(size.width / 2, size.height / 2);
    radius = MIN(size.width, size.height) / 3;
    insertedIndexPaths = [NSMutableArray array];
    deletedIndexPaths = [NSMutableArray array];
}

- (CGSize)collectionViewContentSize
{
    return self.collectionView.frame.size;
}

- (UICollectionViewLayoutAttributes *)layoutAttributesForItemAtIndexPath:(NSIndexPath *)indexPath
{
    UICollectionViewLayoutAttributes *attributes = [UICollectionViewLayoutAttributes layoutAttributesForCellWithIndexPath:indexPath];
    
    CGFloat progress = (float)indexPath.item / (float)numberOfItems;
    CGFloat theta = 2 * M_PI * progress;
    CGFloat xPosition = centerPoint.x + radius * cos(theta);
    CGFloat yPosition = centerPoint.y + radius * sin(theta);
    attributes.size = [self itemSize];
    attributes.center = CGPointMake(xPosition, yPosition);
    return attributes;
}

- (NSArray<UICollectionViewLayoutAttributes *> *)layoutAttributesForElementsInRect:(CGRect)rect
{
    NSMutableArray *attributes = [NSMutableArray array];
    for (NSInteger index = 0; index < numberOfItems; index ++) {
        NSIndexPath *path = [NSIndexPath indexPathForItem:index inSection:0];
        [attributes addObject:[self layoutAttributesForItemAtIndexPath:path]];
    }
    return attributes;
}

- (void)prepareForCollectionViewUpdates:(NSArray<UICollectionViewUpdateItem *> *)updateItems
{
    [super prepareForCollectionViewUpdates:updateItems];
    for (UICollectionViewUpdateItem *updateItem in updateItems) {
        if (updateItem.updateAction == UICollectionUpdateActionInsert) {
            [insertedIndexPaths addObject:updateItem.indexPathAfterUpdate];
        }else if (updateItem.updateAction == UICollectionUpdateActionDelete){
            [deletedIndexPaths addObject:updateItem.indexPathBeforeUpdate];
        }
    }
}

- (UICollectionViewLayoutAttributes *)insertionAttributesForItemAtIndexPath:(NSIndexPath *)itemIndexPath
{
    UICollectionViewLayoutAttributes *attributes = [self layoutAttributesForItemAtIndexPath:itemIndexPath];
    attributes.alpha = 0;
    attributes.center = centerPoint;
    return attributes;
}

- (UICollectionViewLayoutAttributes *)deletionAttributesForItemAtIndexPath:(NSIndexPath *)itemIndexPath
{
    UICollectionViewLayoutAttributes *attributes = [self layoutAttributesForItemAtIndexPath:itemIndexPath];
    attributes.alpha = 0;
    attributes.center = centerPoint;
    attributes.transform3D = CATransform3DMakeScale(0.1, 0.1, 1);
    return attributes;
}

- (UICollectionViewLayoutAttributes *)initialLayoutAttributesForAppearingItemAtIndexPath:(NSIndexPath *)itemIndexPath
{
    return [insertedIndexPaths containsObject:itemIndexPath] ? [self insertionAttributesForItemAtIndexPath:itemIndexPath] : [super initialLayoutAttributesForAppearingItemAtIndexPath:itemIndexPath];
}

- (UICollectionViewLayoutAttributes *)finalLayoutAttributesForDisappearingItemAtIndexPath:(NSIndexPath *)itemIndexPath
{
    return [deletedIndexPaths containsObject:itemIndexPath] ? [self deletionAttributesForItemAtIndexPath:itemIndexPath] : [super finalLayoutAttributesForDisappearingItemAtIndexPath:itemIndexPath];
}
@end

    布局对象会根据每个条目的索引路径来计算他的位置。这个例子采用的布局方式只使用了一个区段,每个条目在该区段内的顺序决定了它在圆周上的位置:

 CGFloat progress = (float)indexPath.item / (float)numberOfItems;
    CGFloat theta = 2 * M_PI * progress;

    上述计算方式也适用于其他图形或其他形式的索引路径,只要各条目在索引路径中的位置都能调整到[0.0,1.0]这个范围内就行。对于圆形来说,此范围可以和从0至2π的弧度对应起来,而对于螺旋形的布局来说,此范围则可以和从0到3π、4π到5π的弧度对应起来。如果想按照贝塞尔曲线来布局,那么开发者需要遍历能够决定曲线形状的各个控制点,并要根据情况在其中插入其他的点。

    

1、实现创建条目与删除条目时的动画效果

    在例子中有几个方法值得关注,他们分别制定了新插入的条目所具备的初始属性,以及刚删除的条目所应具备的最后属性。这些属性使得集合视图在添加新条目及删除现有条目的时候,能够以动画效果来表示该操作执行前后的布局变化过程。

    这个例子的动画效果与苹果公司的原始范例代码一样:新添加的条目一开始会以全透明的形态出现在圆圈正中,然后会移动到它应有的位置上,在移动过程中它将逐渐淡入。而刚删除的条目则会从目前的位置移向圆心,并在此过程中逐渐缩小、淡出。运行范例代码的时候能看到这些效果了。

    开发文档中的initialLayoutAttributesForAppearingItemAtIndexPath及finalLayoutAttributesForDisappearingItemAtIndexPath方法,名字起得很令人困惑,从表面上看,这些方法似乎只会针对刚插入或删除的条目来调用。但实际上,系统会向每一个条目询问它的起始属性和最终属性,而不仅仅向刚添加或删除的条目询问。所以,在添加条目和删除条目的时候,会把所添加条目及所删条目的索引路径分别记录到两个数字里面。这样的话,我们就可以只针对当前要添加或删除的条目来定制其属性了。

该机制所提供的这种方法,能够把视图中全部条目的布局属性都以动画形式表现出来,使得开发者可以按照需要添加额外的动画效果。比方说,如果有新的条目插入第三行,那么该行末尾的条目就应该移动到第四行的开头。在默认的情况下,末尾的条目会按照斜线方向移动到下一行开头,但有了这套方式之后,我们就可以把第三行末尾的单元格向右移出屏幕,然后再将其从第四行左侧移入屏幕。

2、增强圆形布局的实用性

用户可以选定某个条目,然后可以把该条目删掉,也可以把新的条目添加到他的后面:
- (void)delete
{
    if (!count) {
        return;
    }
    count --;
    
    NSArray *selectedItems = [self.collectionView indexPathsForSelectedItems];
    NSInteger itemNumber = selectedItems.count ? ((NSIndexPath *)selectedItems[0]).item : 0;
    NSIndexPath *itemPath = [NSIndexPath indexPathForItem:itemNumber inSection:0];
    self.itemsInSection --;
    [self.collectionView performBatchUpdates:^{
        [self.collectionView deleteItemsAtIndexPaths:@[itemPath]];
        
        
    } completion:^(BOOL finished) {
        if (count) {
            [self.collectionView selectItemAtIndexPath:[NSIndexPath indexPathForItem:MAX(0, itemNumber - 1) inSection:0] animated:NO scrollPosition:UICollectionViewScrollPositionNone];
        }
        
        self.navigationItem.rightBarButtonItem.enabled = (count > 0);
        self.navigationItem.leftBarButtonItem.enabled = (count < 12);
        
    }];
}
- (void)add
{
    NSInteger itemNumber = self.itemsInSection ;
    NSIndexPath *itemPath = [NSIndexPath indexPathForItem:itemNumber inSection:0];
    self.itemsInSection ++;
    count ++;
    [self.collectionView performBatchUpdates:^{
        [self.collectionView insertItemsAtIndexPaths:@[itemPath]];
    } completion:^(BOOL finished) {
        self.navigationItem.rightBarButtonItem.enabled = (count > 0);
        self.navigationItem.leftBarButtonItem.enabled = (count < 12);
        
    }];
}


在真实的应用程序中很少需要添加或删除一些彼此之间没有区别的视图,不过,有的时候却需要添加或删除一些含义各不相同的视图。因此,这个例子所做的改动使得这个范例变得更加实用了。


IOS 使用自定义View实现圆形布局(Swift) 前面写过用安卓实现,还是同个需求,只不过现在需要做苹果版本。网上搜到了类似的案列点击打开链接只不过他的是用UICollectionView。跟我的需求有点不符合。没有搜到完全符合的案例。没办法自己写个,记录一下,也给有同种需求的童鞋填个坑。一、创建自定义view创建CircleView继承自UIView,重写draw方法。swift必须重写required init?(coder aDecoder... 阅读详情

相关推荐

Swift中如何创建自定义的UI控件

在这个例子中,我们使用了Auto Layout来设置子视图的布局。本文将详细介绍如何在Swift中创建自定义的UI控件,从基本的继承UIView开始,到更复杂的自定义绘制、布局和交互处理。layoutSubviews方法会在视图的布局发生变化时被调用,因此在这个方法中设置子视图的frame可以确保子视图能够正确地显示在父视图中。UIView是所有视图控件的基类,它提供了一些基本的属性和方法,如frame(位置和大小)、bounds(自身坐标系中的位置和大小)以及drawRect(绘制方法)等。

AdolphMacDonald的博客 739

iOS流布局UICollectionView系列五——圆环布局的实现

iOS流布局UICollectionView系列五——圆环布局的实现 一、引言 前边的几篇博客,我们了解了UICollectionView的基本用法以及一些扩展,在不定高的瀑布流布局中,我们发现,可以通过设置具体的布局属性类UICollectionViewLayoutAttributes来设置设置每个item的具体位置,我们可以再扩展...

weixin_33849942的博客 339

VMware ubuntu虚拟机(或Centos7)与主机共享文件夹

系统环境 Windows 10 Vmware Workstation 15 Pro Ubuntu 20.04.1 LTS centos7 1.Ubuntu配置共享文件 1.1安装VMware-tools 更新最新VMware-tools组件 编辑->首选项->更新->立即下载所有组件 安装VMware-tools 虚拟机->安装VMware-tools 安装后ubuntu会加载一个虚拟光驱,解压文件,在解压的文件目录下执行以下命令进行安装 sudo vmware-instal

weixin_38924500的博客 2160

一分钟学会collectionView自定义layout(二、圆形布局)

圆形布局很简单,主要的是实现layoutAttributesForItemAtIndexPath,在这方法里面计算cell的位置大小。第一步:因为不是流水布局,需继承自UICollectionViewLayout。 再写prepareLayout-(void)prepareLayout{ [super prepareLayout]; [self.attrsArray removeAl

写bug的打字员 1796

9 海康视觉平台VisionMaster 上手系列:典型案例之螺丝机案例

海康视觉平台VisionMaster 上手系列:典型案例之螺丝机案例 快速入门 工业机器视觉 机器视觉

HuangGong2022的博客 7166

对冲策略与马丁结合ea的编程实践(五)核心是把两个品种合成一个新品种

在外汇、数字货币、期货交易甚至赌博中,马丁策略、网格策略是最常用的策略,也是最容易被理解的策略,但是如何克服单边行情、极端行情,是使用马丁策略最为头疼的事情,如加大间距、加大资金量,只能缓解,并不能根本解决这样的情况,所以使用时大部分时候都心里没底。 有没有一种正确的思路,让行情控制在震荡范围以内呢,这是今天我要向大家分享的一个思路,那就是对冲。大家看下图: 大家可以看到欧美(EURUSD)和镑美(GBPUSD),这两个品种,大部分时候走势是一致的,那么我们有没有可能把他们两个品种进行一下合成,比如买0.

omidsky的博客 3738

iOS使用UICollectionView实现可旋转菜单

先来张效果图:之前项目中利用UICollectionView实现了一个圆环形分布的菜单,但不能随着手势进行旋转,正好这两天放假,参考一些大神的文章,捣鼓出了可以进行旋转的菜单。下面说一下代码实现。1.由于UICollectionVIew是依赖于UICollectionViewFlowLayout进行布局,而UICollectionViewFlowLayout 继承自 UICollectionVie...

HuberyYang 4405

C#调用Halcon程序三种方法

C#调用Halcon程序三种方法 1.halcon导出C#文件,在C#里面调用 2.在C#里面使用Halcon引擎调用Halcon程序 3.在C#里面使用Halcon引擎调用.hdev下本地函数或者.hdvp外部函数 Halcon引擎手册:C:/Program Files/MVTec/HALCON-21.11-Progress/doc_en_US/html/manuals/programmers_guide/programmers_guide_0120.html 1.导出C#(代码我只给出类,需要调用)

A541925504的博客 1万+

探索Windows安装程序本地化:揭秘Inno Setup中文翻译解决方案

你是否曾为Windows软件安装界面全是英文而头疼?当用户面对陌生的安装向导时,那种不知所措的感觉,往往成为软件体验的第一道门槛。今天,让我们一同探索Inno Setup中文简体翻译项目,看看这个开源解决方案如何让安装程序说用户熟悉的语言。 ## 当安装界面遇到语言障碍时,本地化成为刚需 想象这样一个场景:你的软件需要面向中文用户发布,但安装程序却显示着密密麻麻的英文选项。用户需要选择安装路径

gitblog_00092的博客 408

拓扑优化背后的科学:ANSYS Workbench中的算法与原理

本文深入解析了ANSYS Workbench中拓扑优化的科学原理与算法实现,重点介绍了密度法(SIMP)和灵敏度分析等核心算法。通过分层架构解析和参数调优实战,展示如何有效进行模型验证与多物理场耦合优化,帮助工程师提升结构设计效率与性能。

weixin_29250403的博客 417

Vertx之Grpc消息发送

介绍 Vert.x gRPC 模块,它将 Google gRPC 的编程风格与 Vert.x 风格保持一致. gRPC 是一个高性能、开源、通用的RPC框架,是一种进程间通讯技术,由Google推出,基于HTTP2协议标准设计开发,默认采用Protocol Buffers数据序列化协议,支持多种开发语言。gRPC提供了一种简单的方法来精确的定义服务,并且为客户端和服务端自动生成可靠的功能库。 在gRPC客户端可以直接调用不同服务器上的远程程序,使用姿势看起来就像调用本地程序一样,轻松的实现远端服务的连接、

Lance 1188

iOS 实现步骤进度条

Linux编程点击右侧关注,免费入门到精通!作者丨独木舟的木https://www.jianshu.com/p/fb471ca68a1b步骤进度条效果参考iOS UIKi...

iOS_开发 1834

SystemVerilog新手实战指南:iverilog与VScode的完美组合

本文为SystemVerilog新手提供了一套高效入门方案,详细介绍了如何利用开源编译器iverilog与轻量编辑器VScode搭建学习环境。内容涵盖十分钟快速安装配置、首个工程从编码到查看波形的完整流程,并演示了动态数组和队列等SystemVerilog新特性的使用,旨在帮助初学者避开复杂商业工具,快速掌握数字电路设计与验证的核心技能。

f6g7h8i9j的博客 513

iOS 编写与圆有关的控件

最近在做一个有关圆形的控件,发现有关圆形控件里面的布局涉及一些简单的算法,我这个人记性不太好,所以总结一下,怕时间长了,到时候忘了,又要从头开始研究。一、理解坐标系1、左手坐标系与右手坐标系在我们数学中的坐标系一般采用的是右手坐标系,在 iOS开发中,存在多种坐标系。首先我们看一张图,来理解一下左手坐标系和右手坐标系:2、UIView坐标系在iOS的UIView中,统一使用左手坐标系,也就是坐标原点

长沙火山 899

运行openclaw gateway install时出现Gateway install failed: Error: schtasks create failed的解决方案

本文主要介绍了运行openclaw gateway install时出现Gateway install failed: Error: schtasks create failed的解决方案,希望能对学习和使用openclaw的同学们有所帮助。 文章目录 1. 问题描述 2. 解决方案

weixin_43178406的博客 10万+

ssm框架搭建

这个是一个在idea上成功跑起来的ssm框架项目,保存在这里方便以后使用直接下载

iOS AutoLayout

- (void)viewDidLoad {     UIButton *btnSubmit=[UIButton buttonWithType:UIButtonTypeRoundedRect];     [btnSubmit setTitle:@"Submit" forState:UIControlStateNormal];     [btnSubmit setTranslat

CDUT100的专栏 606

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

Donut 项目推荐

Donut 项目推荐 项目基础介绍和主要编程语言 Donut 是一个用于将视图以圆形排列的开源库,主要使用 Swift 编程语言开发。该项目旨在简化在 iOS 应用中创建圆形视图布局的过程,使得开发者能够轻松实现类似甜甜圈的视图排列效果。 项目核心功能 Donut 项目提供了以下核心功能: 圆形视图排列:支持将多个视图以圆形排列,类似于甜甜圈的布局。 动画支持:提供动画效果,使得视图在选择和切换...

gitblog_00756的博客 290

复分析 阿尔福斯(Ahlfors) 第三版答案 英文

答案分为十章,有部分习题没有答案,全英文复分析阿尔福斯(Ahlfors) 第三版答案

廖雪峰Python教程[完整版]

廖雪峰的python教程整理的,已经排好版了,而且还是完整的,适合小白

swift使用NSLayoutConstraint进行控件布局

摘抄部分概念 该函数有如下参数: 第一个参数 view1: 要设置的视图; 第二个参数 attr1: view1要设置的属性,稍后详解; 第三个参数 relation: 视图view1和view2的指定属性之间的关系,稍后详解; 第四个参数 view2: 参照的视图; 第五个参数 attr2: 参照视图view2的属性,稍后详解; 第六个参数 multiplier: 视图view1的指定属性是参...

路漫漫其修远 347

Apache Beam 的 AvroIO 读写指南:从 Python、Java 到 Go 与 TypeScript 的跨语言 Avro 文件处理

本指南以 Apache Beam 对 Apache Avro 格式的官方支持为线索,系统讲解 `ReadFromAvro` / `WriteToAvro` 等核心 Transform 在 Python、Java、Go、TypeScript 四种 SDK 中的使用方式与底层实现。读完本文,你将掌握如何在 Beam 管道中读取和写出 Avro 文件、如何配置 schema 与压缩 codec、如何利用

gitblog_00579的博客 874

iOS 7:漫谈集合视图(CollectionView)

iOS 7:漫谈集合视图(CollectionView)   (2014-01-23 23:06:32) 转载▼ 标签:  it   什么是UICollectionView UICollectionView是一种新的数据展示方式,简单来说可以把他理解成多列的UITableView(请一定注意这是UICollection

kangli的专栏 641

iOS User Defined Runtime Attributes to define the key path

Next, add a button to the top right of each view controller. For both buttons, double-click and press backspace to set the button title to an empty string. Also set each button’s background color to

沐风 1829

IOS气泡实现

WPBadgeView.h // //WPBadgeView.h //draw // //Createdbywupengon15/9/18. //Copyright(c)2015年wupeng.Allrightsreserved. // #import...

chenyu881115的博客 854

iOS开发系列之Swift_UI_ImgVIew And UIView

self.leftImgView = UIImageView.init() self.leftImgView.frame = CGRectMake(20, self.middleTextField.frame.origin.y + 40, 100, 100) self.leftImgView.image = UIImage(named: "108") ...

afnc52340的博客 127

UICollectionView

UICollectionView 首先回顾一下Collection View的构成,我们能看到的有三个部分: Cells Supplementary Views 追加视图 (类似Header或者Footer) Decoration Views 装饰视图 (用作背景展示) 而在表面下,由两个方面对UICollectionView进行支持。其中之一和tableView一样,即

kunpengapple的博客 298

仿支付宝手势密码头部小九宫格绘制

#pragma mark -绘制头部九宫格 -(void)drawRect:(CGRect)rect{       //获取上下文     CGContextRef ctx = UIGraphicsGetCurrentContext();          //设置属性     CGContextSetLineWidth(ctx, CoreLockAr

qq_25864521的博客 427

iOS AutoLayout(1)

- (void)viewDidLoad {     UIButton *btnSubmit=[UIButtonbuttonWithType:UIButtonTypeRoundedRect];     [btnSubmit setTitle:@"Submit"forState:UIControlStateNormal];     [btnSubmit setTranslatesAu

洛阳如是 345
上一篇: ios UICollectionViewController集合视图(四)
下一篇: ios 动态字体
评论 1
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值