团体程序设计天梯赛-练习集 L2-012 关于堆的判断(25分)

L2-012 关于堆的判断 (25分) 将一系列给定数字顺序插入一个初始为空的小顶堆H[]。随后判断一系列相关命题是否为真。命题分下列几种: x is the root:x是根结点; x and y are siblings:x和y是兄弟结点; x is the parent of y:x是y的父结点; x is a child of y:x是y的一个子结点。 输入格式: 每组测试第1行包含2个正整数N(≤ 1000)和M(≤ 20),... 阅读详情


原题如下:

L2-012. 关于堆的判断

时间限制
400 ms
内存限制
65536 kB
代码长度限制
8000 B
判题程序
Standard
作者
陈越

将一系列给定数字顺序插入一个初始为空的小顶堆H[]。随后判断一系列相关命题是否为真。命题分下列几种:

  • “x is the root”:x是根结点;
  • “x and y are siblings”:x和y是兄弟结点;
  • “x is the parent of y”:x是y的父结点;
  • “x is a child of y”:x是y的一个子结点。

输入格式:

每组测试第1行包含2个正整数N(<= 1000)和M(<= 20),分别是插入元素的个数、以及需要判断的命题数。下一行给出区间[-10000, 10000]内的N个要被插入一个初始为空的小顶堆的整数。之后M行,每行给出一个命题。题目保证命题中的结点键值都是存在的。

输出格式:

对输入的每个命题,如果其为真,则在一行中输出“T”,否则输出“F”。

输入样例:
5 4
46 23 26 24 10
24 is the root
26 and 23 are siblings
46 is the parent of 23
23 is a child of 10
输出样例:
F
T
F
T
看分值25分,应该属于较为简单的题,这题出的很朴素,并没有什么需要注意的边界值,笔者给出代码如下:

#include <bits/stdc++.h>
using namespace std;
int minheap[1005]= {0};
void makeheap(int i)         //建最小堆
{
  int temp;
  while(i>1)
    {
      if(minheap[i]<minheap[i/2])
        {
          temp=minheap[i];
          minheap[i]=minheap[i/2];
          minheap[i/2]=temp;

        }
      i/=2;
    }

}
int main()
{
  int n,m,i,j;
  string s;
  scanf("%d %d",&n,&m);
  scanf("%d",&minheap[1]);
  for(i=2; i<n+1; i++)
    {
      scanf("%d",&minheap[i]);
      makeheap(i);
    }
  int temp1,temp2;
  for(i=0; i<m; i++)
    {
      cin>>temp1>>s;
      if(s=="and")
        {
          cin>>temp2>>s>>s;
          for(j=1; j<n+1; j++)
            {
              if(minheap[j]==temp1)
                {
                  if(j%2==0)
                    {
                      if(minheap[j+1]==temp2)
                        cout<<"T"<<endl;
                      else
                        cout<<"F"<<endl;
                                            break;
                    }
                  else
                    {
                      if(minheap[j-1]==temp2)
                        cout<<"T"<<endl;
                      else
                        cout<<"F"<<endl;
                                            break;
                    }
                }
            }
        }
      else
        {
          cin>>s;
          if(s=="a")
            {
              cin>>s>>s>>temp2;
              for(j=1; j<n+1; j++)
                {
                  if(minheap[j]==temp1)
                    {
                      if(minheap[j/2]==temp2)
                        cout<<"T"<<endl;
                      else
                        cout<<"F"<<endl;
                    }
                }
            }
          else
            {
              cin>>s;
              if(s=="root")
                {
                  if(temp1==minheap[1])
                    cout<<"T"<<endl;
                  else
                    cout<<"F"<<endl;
                }
              else
                {
                  cin>>s>>temp2;
                  for(j=1; j<n+1; j++)
                    {
                      if(minheap[j]==temp2)
                        {
                          if(minheap[j/2]==temp1)
                            cout<<"T"<<endl;
                          else
                            cout<<"F"<<endl;
                        }

                    }
                }
            }
        }
    }
}



L2-012 关于堆的判断(建堆的不同方法) 两种方法,调整完都为小根堆,但是结构可能不一样(左右儿子可能不同)。接下来,判断是否为根结点,字符串中提取到对应的数字直接和数组的第一个位置比较即可。方法1. 完全二叉树从上到下,从左往右依次编号分别和数组的每一个位置对应。),逐个扫描所有的结点,向下调整,直到以当前为根结点的子树符合堆的特性。兄弟结点的父亲的编号是一致的。父结点和子结点可以通过之间编号的关系判断。,表示分别是插入元素的个数、以及需要判断的命题数。题目保证命题中的结点键值都是存在的。个要被插入一个初始为空的小顶堆的整数。 阅读详情

相关推荐

【天梯赛】L2-012 关于堆的判断

主要考察的就是一个建堆的过程,小根堆比较简单,插入一个元素到树的末端,每次与他的父节点比较,如果插入的元素更小就swap该元素和父节点,再对更新后的父节点进行同样的操作直至递归到根节点,这个操作由up函数完成。 #include <bits/stdc++.h> using namespace std; const int N = 1010; int n, m; int tr[N]; unordered_map<int, int> mp; void up(int u) {

Ybibabo__的博客 328

团体天梯 L2-012 关于堆的判断 (25 分)(简易五十行结构)

L2-012关于堆的判断(25 分) 将一系列给定数字顺序插入一个初始为空的小顶堆H[]。随后判断一系列相关命题是否为真。命题分下列几种: x is the root:x是根结点; x and y are siblings:x和y是兄弟结点; x is the parent of y:x是y的父结点; x is a child of y:x是y的一个子结点。 输入格式: 每组测试第...

ItaLink 734

团体程序设计天梯赛-练习集 01

L1-001 Hello World L1-002打印沙漏 L1-003个位数统计 L1-004计算摄氏温度 L1-005考试座位号 L1-006连续因子 L1-007念数字 L1-008求整数段和 L1-009 N个数求和 L1-010比较大小 L1-011 A-B L1-012计算指数

Obliviate的博客 1808

7-11 关于堆的判断 (25 分)

  将一系列给定数字顺序插入一个初始为空的小顶堆 H[]。随后判断一系列相关命题是否为真。命题分下列几种: x is the root:x是根结点; x and y are siblings:x和y是兄弟结点; x is the parent of y:x是y的父结点; x is a child of y:x是y的一个子结点。 输入格式:   每组测试第1行包含2个正整数 N(≤ 1000)和 M(≤ 20),分别是插入元素的个数、以及需要判断的命题数。下一行给出区间[−10000,10000]内的 N

Foolishman的博客 816

团体程序设计天梯赛L1-2

本题就请你编写一个监测程序,随时监测四轮的胎压,并给出正确的报警信息。是个11位数,其中有3个2,并且是负数,也是偶数,ht则它的犯二程度计算为:3/11×1.5×2×100%,约为81.82%。如果调整后的犯二程度对应的整数是偶数(即,该整数的最后一位是0、2、4、6、8),则犯二的程度再增加1倍。也就是说,犯二的程度变成了原来的2倍。(这题也还有其他写法如下)在一行中输出这个整数对应的拼音,每个数字的拼音之间用空格分开,行末没有最后的空格。的所有整数,每5个数字占一行,每个数字占5个字符宽度,向右对齐。

lj2325822047的博客 1920

【团体程序设计天梯赛】L1~L2实战反思合集(C++)

New:最后那两个长字符串测试点的处理,不要在一开始就将违禁词替换成“<censored>”,而是先替换成“-_-”这样的比较短的字符串,否则违禁词多的时候,不断地改成长替换词,会加重下一次查找操作的负担。此时,我们只要保证生成的过程是“单方向的”,也就是通过递归函数中for的单方向给每个元素赋值,就保证了生成矩阵的唯一性。从而:跑通的次数 = 矩阵的种类数。// 从中序找到根节点,根节点左边就是左子树的中序遍历,得到其长度len,则后序中前len个刚好就是左子树的后序遍历,由此调整区间,重复操作。

H13420972436的博客 1780

PTA 团体程序设计天梯赛-练习集 L2-012 关于堆的判断 (25分)

将一系列给定数字顺序插入一个初始为空的小顶堆H[]。随后判断一系列相关命题是否为真。命题分下列几种: x is the root:x是根结点; x and y are siblings:x和y是兄弟结点; x is the parent of y:x是y的父结点; x is a child of y:x是y的一个子结点。 输入格式: 每组测试第1行包含2个正整数N(≤1000)和M(≤...

weixin_41514525的博客 628

中国高校计算机大赛团体程序设计天梯赛考点内容总结(15分以上题)

L1: L1-002 打印沙漏 (20 分) 字符模拟 L1-003 个位数统计 (15 分) 字符模拟 L1-005 考试座位号 (15 分) 模拟 L1-006 连续因子 (20 分) 数学因数分解 L1-009 N个数求和 (20 分) 数学gcd,lcm L1-011 A-B (20 分) 字符串模拟 L1-015 跟奥巴马一起画方块 (15 分) 模拟 L1-016 查验身份证 (15 分) 数组模拟 L1-017 到底有多二 (15 分) 数学计算 L1-019 谁先倒 (15 分) 模拟 L

qq_38140952的博客 6860

团体程序设计天梯赛-练习集 L2-012 关于堆的判断 (25分) 堆的建立+坑点分析

L2-012 关于堆的判断 (25分) 将一系列给定数字顺序插入一个初始为空的小顶堆H[]。随后判断一系列相关命题是否为真。命题分下列几种: x is the root:x是根结点; x and y are siblings:x和y是兄弟结点; x is the parent of y:x是y的父结点; x is a child of y:x是y的一个子结点。 输入格式: 每组测试第1行包含2个正整数N(≤ 1000)和M(≤ 20),分别是插入元素的个数、以及需要判断的命题数。下一行给出区间[−10000

秀岩的博客 1428

PAT团体程序设计天梯赛L1习题集(建议收藏)

PAT团体程序设计天梯赛L1习题集(建议收藏) 5分题 L1-001 Hello World (5分) L1-004 计算摄氏温度 (5分) L1-012 计算指数 (5分) L1-014 简单题 (5分) L1-021 重要的话说三遍 (5分) L1-024 后天 (5分) L1-026 I Love GPLT (5分) L1-029 是不是太胖了 (5分) L1-036 A乘以B (5分)...

信小海 1584

十五天学会Autodesk Inventor,看完这一系列就够了(七),工程图纸

不管哪种绘图软件,二维或三维绘图,最终均需要转换成工程图纸,才能交给现场人员进行制作,这是任一产品图都要经历的过程。那本章开始,我们一起看一下Inventor是如何实现工程图纸?

Crazydoubao的博客 4937

团体程序设计天梯赛-练习集 - L2-012 关于堆的判断(25 分)

题目链接:点击打开链接 题目大意:略。 解题思路:此题为边插入边建堆,而不是先按层序遍历建好树再调整成堆;注意兄弟结点的判断条件(小偶大奇且(奇 - 偶==1))。 AC 代码 #include&lt;bits/stdc++.h&gt; #include&lt;cmath&gt; #define mem(a,b) memset(a,b,sizeof a) #defin...

848

Vision-Language Navigation - Windows环境下编译安装Matterport3D Simulator仿真器(三)

目录1 编译 Matterport3D Simulator 源码1.1 源码下载1.2 编译 1 编译 Matterport3D Simulator 源码   在 Windows 下编译 Matterport3D Simulator 稍微有些不方便,需要对 CMakeLists.txt 进行一些修改,如果有更好的方法欢迎大家评论。 1.1 源码下载   还是直接在 Github 上搜索 Matterport3D Simulator 的 repo,下载源码。如果用 zip 方式,那么直接在下即可。如果使用

weixin_44110393的博客 4852

团体程序设计天梯赛 L2 题目合集

目前 L1 的题目已经刷完,打算在赛前刷完 L2 的题目。本来想 L2 的题目都写个相对详细的题解的,但是由于时间已经很紧张了,就只能像来记录 L1题目的形式来 L2 的题解了,让我们都好好加油吧。

Veggie的博客 1万+

Windows 11安装 SQLServer 2008 R2 失败问题处理

Windows 11安装SQL Server 2008 R2失败解决方案 由于Windows 11移除了对PowerShell 2.0的支持,导致SQL Server 2008 R2安装失败。经过多次尝试,最终通过**方案六(修改注册表模拟PowerShell 2.0环境)**成功安装。其他可行方案包括: 使用SP3集成版安装包 通过命令行跳过检查(/SUPPRESSPOWERShellCHECK参数) 创建特殊配置文件 替代方案建议: 使用Docker容器运行 在虚拟机中安装 升级到新版SQL Serve

oDengWei的博客 7399

chatgpt赋能python:Python入侵摄像头:实现简单且危险

本文由chatgpt生成,文章没有在chatgpt生成的基础上进行任何的修改。以上只是chatgpt能力的冰山一角。作为通用的Aigc大模型,只是展现它原本的实力。对于颠覆工作方式的ChatGPT,应该选择拥抱而不是抗拒,未来属于“会用”AI的人。🧡AI职场汇报智能办公文案写作效率提升教程 🧡专注于AI+职场+办公方向。下图是课程的整体大纲下图是AI职场汇报智能办公文案写作效率提升教程中用到的ai工具。

axuhsssssco的博客 3024

团体程序设计天梯赛练习集题解整合

一年一度的 团体程序设计天梯赛 即将开始,PTA的练习集是必不可少的备赛必刷题单,这里为大家整理一份。写在前面,关于 团体程序设计天梯赛-练习集 题解整合。预计十天内更新完L1题。题解(内有题目描述)

qq_58362465的博客 2403

以太网PHY寄存器

并且,值得注意的是,由于目前很多百兆的PHY芯片其MAC接口主流的都是SMII/S3MII,8个端口的接口是相互关联的,一个端口设置Isolate可能会影响其他端口的正常使用,因此在使用中注意不要随意更改bit10的状态。Bit10和bit11的区别是,bit11的配置在强制情况下生效,PHY只能工做与bit11指定的工作模式,而bit10的配置在非强制配置情况下生效,仅仅控制PHY在AN时候的优先级,偏向于Maser或者Slave,但是最终的工作模式看协商的结果,不一定和优先级配置的结果一致。

mangofu的博客 301

PTA|团体程序设计天梯赛-练习题目题解锦集(C/C++)(持续更新中……)

PTA|团体程序设计天梯赛-练习题目题解锦集(持续更新中) 实现语言:C/C++;      欢迎各位看官交流讨论、指导题解错误;或者分享更快的方法!! 题目链接:https://pintia.cn/problem-sets/994805046380707840/problems 目录 (点击对应题目即可进入相应题解……小声BB……) L1-001 Hello World (5 分) ...

lesileqin的博客 3万+

少儿学编程系列--使用递归画出龙形曲线DragonCurve

龙形曲线(Dragon Curve) 龙形曲线(Dragon Curve)又叫分形龙,是一种自相似碎形曲线的统称,因形似龙的蜿蜒盘曲而得名 使用黄金比例画龙形曲线 根据黄金比例画一条龙曲线。每次递归,第一步向左转32.89度,移动0.74倍原距离;第二个递归步骤向右转46.99度,移动原来距离的0.55倍。请查看这个网页(https://larryriddle.agnesscott.org/ifs/heighway/goldenDragon.htm)了解关于龙形黄线数学的细节 龙形曲线效果 .

penriver的博客 2314

MAX30102心率血氧传感器原理图设计,已量产(e-Health传感器)

在最近的便携健康监测设备项目中,我们采用了集成算法的 MAX30102 心率血氧模块 —— 这类带内置 MCU 算法的传感器能直接输出心率 / 血氧数值,大幅降低了主控资源占用。但硬件电路的稳定性直接决定了 PPG 信号的采集精度,下面结合实际项目里的原理图,拆解下这个模块的设计细节。

不脱发的程序猿 1306

PTA团体程序设计天梯赛-练习集L1(Python3实现)

目录L1-001 Hello WorldL1-002 打印沙漏L1-003 个位数统计L1-004 计算摄氏温度L1-005 考试座位号L1-006 连续因子L1-007 念数字L1-008 求整数段和L1-009 N个数求和L1-010 比较大小L1-011 A-BL1-012 计算指数L1-013 计算阶乘和L1-014 简单题L1-015 跟奥巴马一起画方块L1-016 查验身份证L1-017 到底有多二L1-018 大笨钟L1-019 谁先倒L1-020 帅到没朋友L1-021 重要的话说三遍L1-

wasd233666的博客 5483

claude code desktop中出现Doesn‘t look like an Anthropic model - expected a gateway model route 解决方案

本文主要介绍了claude code desktop中出现Doesn’t look like an Anthropic model - expected a gateway model route referencing an Anthropic model和Server is busy. Retrying的解决方案,希望能对使用claude code desktop的同学们有所帮助。 文章目录 1. 问题描述 2. 解决方案

weixin_43178406的博客 10万+

团体程序设计天梯赛-练习集-java

团体程序设计天梯赛-练习集-java版本 博客提供题目解析,解题思路,ac代码。 对于无法ac的代码提供相应ac的C++代码

谢谢 啊sir的博客 6126

OV9734 DATASHEET,完整规格书

OV9734完整规格书,包括电气参数,尺寸规格,寄存器配置表等

怀旧版电脑GBC模拟器

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

团体程序设计天梯赛-L2组

团体程序设计天梯赛-L2组

weixin_41801682的博客 2129

假人有限元模型

假人模型,车辆碰撞假人有限元模型,适合做乘员安全的研究者利用

团体程序设计天梯赛 L1 题目合集

发现自己还能再参加一次天梯赛,在高兴之余,决定把在赛前将所有的天梯赛真题过一遍,希望自己可以取得理想的成绩。但是由于时间问题,而 L1 的题目相对比较简单,没有必要每一题都写详细的题解,就以文本来记录 L1 的题解吧。

Veggie的博客 2万+

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

上一篇: PAT (Basic Level) Practise (中文) 1020 月饼 (25)
下一篇: 团体程序设计天梯赛-练习集 L2-015 互评成绩
muyangren907
博客等级 码龄14年 34粉丝 46原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值