课后测试(2)_opt

合集下载

西瓜书课后习题——第二章

西瓜书课后习题——第二章

西⽠书课后习题——第⼆章2.1数据集包含500正例和500反例,按照70%的⽐例划分训练集和验证集,则验证集需要有150个正例、150个反例,则共有C1505002种划分⽅式。

2.2数据集包含100个样本,10折交叉验证时,每个训练集应该有45正例、45反例,验证集应该有5正例、5反例,由于训练集中正例、反例⽐例为1:1,则按照题⽬的预测算法,预测时会进⾏随机预测(因为训练样本数⽐例相同),所以错误率的期望为50%留⼀法时,留下来做验证集的样本有两种情况:正例、反例。

当留下来的是正例时,训练集中反例⽐正例多⼀个,按照题⽬的算法会将验证集预测为反例,预测错误;留下来的是反例时同理,会将验证集预测为正例。

所以错误率的期望为100%2.3F1的⼤⼩与BEP的⼤⼩没有明确的关系。

根据公式F1=2∗P∗RP+R,⽽BEP是查准率和查全率相等的点,即BEP=P=R,带⼊前式有F1=2∗P∗RP+R=2∗P∗PP+P=P=BEP,可以认为F1=BEP吗?显然不可以。

可以构造反例进⾏验证,容易构造BEP相同的两个分类器的F1值并不相同,分类器将所有训练样本按⾃⼰认为是正例的概率排序,排在越前⾯分类器更可能将它判断为正例。

按顺序逐个把样本标记为正,当查准率与查全率相等时,BEP=P=R。

当然分类器的真实输出是在这个序列中的选择⼀个位置,前⾯的标记为正,后⾯的标记为负,这时的查准率与查全率⽤来计算F1值。

可以看出有同样的BEP值的两个分类器在不同位置截断可能有不同的F1值,F1的⼤⼩与BEP的⼤⼩没有明确的关系。

2.4查全率:真正的正例被预测为正例的⽐率真正例率:真正的正例被预测为正例的⽐率显然查全率=真正例率查准率:预测的正例中真正的正例所占的⽐率假正例率:真正的反例被预测为正例的⽐率查准率与假正例率没有数值上的关系2.52.6ROC2.7参考图2.5由定义可以知道TPR与FPR都是由0上升到1,那么FNR则是由1下降到0。

Python核心编程第三版课后习题解答(第二章)

Python核心编程第三版课后习题解答(第二章)

Python核心编程第三版课后习题解答——第二章2-1.面向连接的套接字和无连接的套接字之间的区别是什么?面向连接的:通信之前必须先建立起一个连接,提供序列化的,可靠的和不重复的数据交付,而没有边界记录。

无连接的:在通信开始之前并不需要建立连接,在数据传输过程中并无法保证它的顺序性,可靠性或重复性。

2-2.用自己的话描述客户端/服务器架构的意思。

服务器就是一系列硬件或软件,为一个或多个客户端(服务的用户)提供所需的“服务”。

它存在唯一目的就是等待客户端的请求,并响应它们(提供服务),然后等待更多的请求。

客户端因特定的请求而联系服务器,并发送必要的数据,然后等待服务器的回应,最后完成请求或给出故障的原因。

2-3.TCP和UDP之中,哪种类型的服务器接受连接,并将它们转换到独立的套接字进行客户端通信?TCP。

2-4.客户端。

更新Tcp和Udp客户端,以使得服务器名称无需硬编码到应用程序中。

此外,应该允许用户指定主机名和端口号,且如果二者中任何一个或者全部参数丢失,那么应该使用默认值。

[python]view plain copy1.<span style="font-family:'Comic Sans MS';font-size:18px;">from socket import *2.3.DefaultHOST = 'localhost'4.DefaultPORT = 12365.BUFSIZ = 10246.def GetAddr():7. Host = raw_input("Please input host:")8. Port = raw_input("Please input port:")9.return Host, int(Port)10.11.Host, Port = GetAddr()12.13.if not Host:14. Host = DefaultHOST15.if not Port:16. Port = DefaultPORT17.18.ADDR = (Host, Port)19.20.tcpCliSock = socket(AF_INET, SOCK_STREAM)21.tcpCliSock.connect(ADDR)22.23.while True:24. data = raw_input('> ')25.if not data:26.break27. tcpCliSock.send(data)28. data = tcpCliSock.recv(BUFSIZ)29.print data30.31.tcpCliSock.close()</span><span style="font-family:'Microsoft YaHei';font-size:24px;"><strong>32.</strong></span>2-5.网络互接和套接字。

第5章课后习题

第5章课后习题

第5章课后习题2.假设一条指令的执行过程分为"取指令"、"分析"和"执行"三段,每一段的时间分别为Dt、2Dt和3Dt。

在下列各种情况下,分别写出连续执行n条指令所需要的时间表达式。

(1) 顺序执行方式。

(2) 仅"取指令"和"执行"重叠。

(3) "取指令"、"分析"和"执行"重叠。

3.用一条5个功能段的浮点加法器流水线计算F=。

每个功能段的延迟时间均相等,流水线的输出端与输入端之间有直接数据通路,而且设置有足够的缓冲寄存器。

要求用尽可能短的时间完成计算,画出流水线时空图,计算流水线的实际吞吐率、加速比和效率。

4.设有一个15000条指令的程序在一台时钟速率为25MHz的线性流水线处理机上执行。

假设该指令流水线有5段,并且每个时钟周期发射一条指令。

忽略由于转移指令和无序执行造成的损失。

(1) 用该流水线执行这一程序,并用流过延迟与其相等的一个等效非流水线处理机执行同一程序,将两者加以比较,并计算其加速比。

(2) 该流水线处理机的效率是多少?(3) 计算该流水线的吞吐率。

5.设有5段流水线处理机的预约表如下:(1) 列出禁止等待时间和冲突向量集。

(2) 画出状态转换图,说明不引起流水线冲突的所有可能的启动序列(循环)。

(3) 根据状态图列出所有简单循环。

(4) 从简单循环中找出迫切循环。

(5) 此流水线的最小平均等待时间(MAL)是多少?(6) 使用此流水线时,列出可允许的最小恒定循环。

(7) 该流水线的最大吞吐率是多少?(8) 如果使用最小恒定循环,则吞吐率是多少?1 2 3 4 5 6S1 X XS2 X XS3 XS4 XS5 X X6.下列汇编代码在一台3段流水线处理机上执行,每一段都有冒险(相关)检测和分解。

这三段是取指令、取操作数(根据要求取一个或者多个)和执行(包括写回操作)。

OPT 常问问题

OPT 常问问题

Office of CommunicationsQuestions and Answers April 4, 2008USCIS ANNOUNCES NEW RULE ALLOWING EXTENSION OF OPTIONAL TRAINING PROGRAM FOR QUALIFIED STUDENTSRule Expands “Cap-Gap” Relief for Students with Pending H-1B PetitionsPRIOR F-1 REGULATIONS RELATING TO PRACTICAL TRAINING:What is optional practical training?Optional Practical Training (OPT) is temporary employment that is directly related to an F-1 student’s major area of study. Under existing rules, an F-1 student may be authorized to receive up to 12 months of practical training either pre- and/or post- completion of studies.•Pre-completion OPT:An F-1 student may be authorized to participate in pre-completion OPT after he/she has been enrolled for one full academic year. The pre-completion OPT must be directly related to the student’s course of study.Students authorized to participate in pre-completion OPT must work part-time while school is in session.They may work full time when school is not in session.•Post-completion OPT:An F-1 student may be authorized to participate in post-completion OPT upon completion of studies. The post-completion OPT must be directly related to the student’s course of study.What is the application process to participate in pre- or post-completion OPT?•Students must initiate a request by having their Designated School Official (DSO) recommend the OPT by endorsing Form I-20 and by making the appropriate notation in SEVIS, the system used to track F-1academic students.•Students then file Form I-765, Application for Employment Authorization Document (EAD), with USCIS. If approved, the student will be issued an EAD.•The student may begin engaging in pre- or post-completion OPT once an application has been approved and an EAD has been issued.How many students stand to benefit from today’s announcement?•There are approximately 26,000 students on OPT that have earned a bachelor's, master's, or doctorate in a STEM field. ICE and USCIS estimate that approximately 12,000 will take advantage of the STEMextension. Some of these students will be selected for an H-1B to start October 2009. Others may choose to continue their education, while some will depart the United States.•We estimate another 10,000 students will benefit from the automatic "cap gap" extension.What is the maximum duration of post-completion OPT?•Under the new rule, certain students will be eligible to receive a 17 month STEM extension of post-completion OPT.Do the periods of pre-completion OPT count against the available periods of post-completion OPT?•Yes. All periods of pre-completion OPT are deducted from the available periods of post-completion OPT.Are there fees associated with filing for extended OPT?•Yes. USCIS charges $380.00 when an applicant files an I-765 for optional practical training. CURRENT H-1B/CAP GAP REGULATIONS FOR F-1 ACADEMIC STUDENTS:What is the H-1B cap?•The cap is the Congressionally-mandated limit on the number of individuals who may be granted H-1B status during each fiscal year. For FY08, the cap is 65,000.What is the cap-gap?•Cap-gap occurs when an F-1 student’s status and work authorization expire in the current fiscal year, before they can start their approved H-1B employment in the next fiscal year beginning on October 1. An F-1 student in a cap-gap situation would have to leave the United States and return at the time his or her H-1B status becomes effective at the beginning of the next fiscal year.How does cap gap occur?•Many employers file H-1B petitions on behalf of F-1 students after their post-completion OPT expires.An employer can not file, and USCIS could not approve, an H-1B petition submitted earlier than sixmonths in advance of the date of actual need for the beneficiary’s services or training.As a result, the earliest date that an employer can file an H-1B petition for consideration under the next fiscal year cap is April 1, for an October 1 employment start date. If that H-1B petition and theaccompanying change of status request are approved, the earliest date that the student may start approved H-1B employment is October 1.Consequently, F-1 students who are the beneficiaries of approved H-1B petitions, but whose periods of authorized stay (including authorized periods of post-completion OPT and the subsequent 60-daydeparture preparation period) expire before October 1, must leave the United States, apply for an H-1B visa at a consular post abroad, and then seek readmission to the United States in H-1B status.What are the current cap-gap regulations?•Current regulations address the cap gap by authorizing an extension of the student’s authorized stay, but they do not extend the student’s employment authorization. This extension was not automatic, whichmeant that a notice had to be published in the Federal Register announcing the extension.•When this Federal Register notice was published, the student’s authorized stay was extended, but not the employment authorization. This means the student can remain in the United States until October 1, when the approved H-1B employment can begin, but cannot work until then.•If a Federal Register notice is not published, the student must leave the United States, apply for an H-1B visa, and seek readmission to the United States in H-1B status.How is the cap-gap situation changed under the interim final rule?•F-1 academic students on post-completion OPT maintain valid F-1 status until the expiration of their OPT. Once that OPT has ended, they are authorized to remain in the United States for up to 60 days to prepare for departure.•This cap-gap extension automatically becomes effective when the H-1B cap has been reached and the student has an H-1B petition filed on his/her behalf during the acceptance period.•If the H-1B petition filed on behalf of the student is not selected during the acceptance period, the automatic extension terminates when USCIS announces completion of the random selection on its public web site.•If the H-1B petition filed on behalf of the student is selected during the acceptance period, the student may remain in the United States and continue working until the October 1 start date indicated on theapproved H-1B petition. The student may benefit from this provision only if he/she has not violatedhis/her status.What is covered and clarified under the interim OPT Rule?•F-1 academic students may now apply for post-completion OPT 90 days before their academic programs end and no later than 60 days after their academic programs end.•This allows F-1 students seeking post-completion OPT to apply during their 60-day departure preparation periods, in the same way that they are allowed to apply for H-1B status during their departure preparation periods.•This allows students to ensure that they meet graduation requirements before applying for post-completion OPT.Is there additional post-completion OPT available to students in the high-tech industry?•F-1 academic students who receive science, technology, engineering, and mathematics (STEM) degrees and who receive an initial grant of post-completion OPT, may apply for a 17-month extension for amaximum of 29 months of post-completion OPT.•This gives U.S. businesses two chances recruit these highly desirable graduates through the H-1B process. Who is responsible for the development of the designated list of STEM degrees?•The STEM Designated Degree Program List is based on the "Classification of Instructional Programs"developed by the U.S. Department of Education's National Center for Education Statistics.What are the eligible STEM degrees?•To be eligible for the 17-month OPT extension, a student must have received a degree in one of the following fields:•Computer Science Applications •Life Sciences•Actuarial Science •Mathematics•Engineering •Military Technologies•Engineering Technologies •Physical Sciences.•The STEM degree list is posted on /sevis.What are the eligibility requirements for the 17-month extension of post-completion OPT?•The student must have a bachelor’s, master’s or doctorate degree in a STEM field.•The employer must be enrolled in E-Verify.•The student must apply on time (at least 90 days before the current post-completion OPT expires).What is the E-Verify program?•The E-Verify program is an internet-based system operated by USCIS, in partnership with the Social Security Administration (SSA).•The E-Verify program currently is the best means available for employers to determine employment eligibility of new hires and the validity of their Social Security Numbers.•E-Verify electronically compares information contained on the Employment Eligibility Verification Form I-9 with records contained in SSA and DHS databases to help employers verify identity and employment eligibility of newly-hired employees.Is there a cost associated with employers participating in the E-Verify program?•No, E-Verify is a free, easy to use web-based system available to employers and in all 50 states, the District of Columbia, Puerto Rico, Guam, and the U.S. Virgin Islands.What is the application process for the 17-month STEM extension?•The student files Form I-765 with USCIS, Form I-20 endorsed by the DSO, a copy of the STEM degree, and the required application fee.•Form I-765 is being amended to require the student to indicate the degree and provide the employer’s E-Verify information.•Students who timely file their STEM extension applications with USCIS may continue working while their applications are pending for 180 days or the date of the decision, whichever date is earlier.•This interim extension minimizes disruption in the student’s employment and also ensures that employers will conduct the necessary employment eligibility re-verification.What must a student do after being granted the 17-month STEM extension?•The student must report to his or her DSO (by email, within 10 days) any change in:-Legal name;-Residential and mailing address;-E-mail address;-Employer name;-Employer address;-Job title or position;-Supervisor name and contact information;-Employment start-date; and-Employment end-date•The student must also report to his or her DSO every six months (by email), confirming the information listed above; even if there have been no changes.•The requirement to report continues if the student’s 17-month STEM extension is extended further by the automatic cap-gap extension.– USCIS –。

opt页面置换算法例题详解(一)

opt页面置换算法例题详解(一)

opt页面置换算法例题详解(一)OPT页面置换算法例题解析1. 引言页面置换算法是操作系统中用于管理虚拟内存的重要算法之一。

OPT(Optimal)算法是一种最佳的页面置换算法,它通过预测未来的访问情况,选择未来最长时间不会被访问的页面进行置换。

本文将通过一个例题来详细解释OPT算法的工作原理。

2. 例题描述假设一个进程的虚拟内存中有5个页面,分别编号为1、2、3、4、5。

设进程的页面访问序列为1、2、1、4、5、1、2、4、3、5。

物理内存中的页面数为3,初始时物理内存为空。

3. 解题步骤Step 1: 遍历页面访问序列,将每个页面的下一次访问时间记录下来。

•页面1的下一次访问时间是2•页面2的下一次访问时间是7•页面3的下一次访问时间是8•页面4的下一次访问时间是4•页面5的下一次访问时间是9Step 2: 依次访问页面,并进行页面置换。

•访问页面1,物理内存为空,将页面1放入物理内存。

•访问页面2,物理内存中只有页面1,将页面2放入物理内存。

•访问页面1,物理内存中已有页面1和页面2,无需置换。

•访问页面4,物理内存中已有页面1和页面2,将页面4放入物理内存,并移除最长时间不会被访问的页面。

•访问页面5,物理内存中已有页面1、2和4,将页面5放入物理内存,并移除最长时间不会被访问的页面。

•访问页面1,物理内存中已有页面2、4和5,无需置换。

•访问页面2,物理内存中已有页面2、4和5,无需置换。

•访问页面4,物理内存中已有页面2、4和5,无需置换。

•访问页面3,物理内存中已有页面2、4和5,将页面3放入物理内存,并移除最长时间不会被访问的页面。

•访问页面5,物理内存中已有页面4、3和5,无需置换。

4. 结果分析根据以上步骤,使用OPT算法得到的页面置换序列为:1、2、X、4、5、X、X、X、3、X,其中X表示发生页面置换。

经过计算,OPT算法的页面命中次数为6次,缺页次数为4次。

OPT(最佳)页面置换算法是一种理论上的最优算法,可以最大程度地减少缺页次数。

2024年Python性能测试习题及答案整理,针对测试开发工程师的面试题集锦

2024年Python性能测试习题及答案整理,针对测试开发工程师的面试题集锦

Python性能测试_习题及答案解析(答案见尾页)一、选择题1. 性能测试的定义是什么?A. 性能测试是评估软件系统在特定负载下的响应速度和稳定性B. 性能测试是在正常负载下评估软件系统的响应速度和稳定性C. 性能测试是在高负载下评估软件系统的响应速度和稳定性D. 性能测试是在特定环境下评估软件系统的响应速度和稳定性2. Python 中常用的性能测试工具有哪些?A. timeit, cProfile, coverageB. timeit, memory-profiler, pytestC. timeit, cProfile, pytestD. timeit, memory-profiler, coverage3. 在进行性能测试时,以下哪种行为有助于找到性能瓶颈?A. 对代码进行详细的检查和分析B. 增加更多的代码以增加负载C. 监控系统的运行状况并收集日志D. 直接修改代码以提升性能4. 内存泄漏的定义是什么?A. 内存泄漏是指程序在运行过程中分配的内存无法被回收B. 内存泄漏是指程序在运行过程中释放的内存被重新分配C. 内存泄漏是指程序在运行过程中使用的内存超过预期D. 内存泄漏是指程序在运行过程中未分配的内存5. 以下哪个方法可以用来监控CPU的性能?A. timeitB. cProfileC. memory-profiler6. 下列哪种操作会导致磁盘IO性能下降?A. 将大量数据存储在内存中B. 将大量数据存储在磁盘上C. 使用磁盘缓存D. 将数据多次读取到内存中7. 以下哪种方法可以用来检测网络性能问题?A. timeitB. cProfileC. pytestD. netcat8. 下列哪种技术可以用来优化数据库性能?A. 索引B. 缓存C. 分库分表D. all of the above9. 在进行性能测试时,以下哪种行为可能会影响测试结果的准确性?A. 测试环境的配置相同B. 测试数据的规模较小C. 测试数据的规模较大D. 测试环境的配置不同10. 下列哪种方法可以通过检查代码执行的路径来定位性能瓶颈?A. timeitB. cProfileC. coverageD. pytest11. 下列哪个操作可以用来查看Python进程的内存使用情况?B. ctopC. topD. htop12. 在Python中,可以通过什么方法来检测内存泄漏?A. 使用局部变量B. 使用全局变量C. 使用collections库中的namedtupleD. 遍历所有变量并进行检查13. 下列哪种磁盘IO操作可以提高性能?A. 随机读写B. 顺序读写C. 大量连续读写D. 小文件随机读写14. 下列哪种情况下,应该对数据库进行优化?A. 数据库连接数较少B. 数据库表结构复杂C. 数据库查询语句简单D. 数据库数据量较小15. 下列哪种方法可以用来诊断CPU性能瓶颈?A. 只查看CPU使用率B. 查看CPU的使用情况分布C. 监控系统负载D. 分析内存占用情况16. 下列哪些操作可以帮助减少代码中的内存泄漏?A. 及时释放不再使用的对象B. 使用局部变量而非全局变量C. 使用字典而非列表D. 避免使用循环17. 在Python中,如何提高网络性能?A. 增加网络带宽B. 减少网络延迟C. 优化代码中的网络IO操作D. 所有上述方法18. 下列哪种情况下,应该对操作系统内核参数进行调整?A. 系统资源丰富B. 系统资源紧张C. 系统运行稳定D. 没有明显影响19. 下列哪些操作可以帮助优化数据库查询性能?A. 对数据库表进行索引B. 使用连接池管理数据库连接C. 减少数据库表数据量D. 分析并优化数据库查询语句20. 下列哪种情况下,可以考虑使用异步编程来提高程序性能?A. 需要频繁访问数据库B. 计算密集型任务较多C. 网络IO操作较为复杂D. 所有上述情况21. 性能优化的基本目标是提高系统的()。

otsu计算题

otsu计算题
以下是使用OTSU算法进行阈值处理的计算题:
题目:假设有一幅图像,像素灰度值范围是0-255,灰度级数为256,像素值是按照灰度值进行量化得到的。

现在我们需要使用OTSU算法来计算最佳阈值,将图像二值化。

解题步骤:
1.统计灰度级中每个像素在整幅图像中的个数,得到每个像素值的概率分布P(i),其中i表示灰度值,P(i)表示灰度值为i的像素在图像中出现的概率。

2.遍历所有可能的阈值T(从0到255),将像素值小于T的像素归为前景类,像素值大于T的像素归为背景类。

3.计算当前阈值T下前景类和背景类的平均灰度值。

前景类的平均灰度值为Σ(i<T)*P(i)/N1,背景类的平均灰度值为Σ(i>=T)*P(i)/N2,其中N1和N2分别为前景类和背景类的像素个数。

4.计算当前阈值T下前景类和背景类的方差。

前景类的方差为Σ((i<T)*P(i)-(μ1)^2),背景类的方差为Σ((i>=T)*P(i)-(μ2)^2),其中μ1和μ2分别为前景类和背景类的平均灰度值。

5.计算类间方差。

类间方差为N1*N2*(μ1-μ2)^2,即前景类和背景类的方差之和。

6.遍历所有可能的阈值T,找到使类间方差最大的阈值T0,
即为最佳阈值。

7.根据最佳阈值T0,将像素值小于T0的像素归为前景类,像素值大于T0的像素归为背景类,从而实现图像的二值化。

Python程序设计课后习题答案第二单元

Python程序设计课后习题答案第二单元习题1:题目:实现一个计算器,能够进行加、减、乘、除四则运算。

答案:```pythondef calculator(num1, num2, operator):if operator == '+':return num1 + num2elif operator == '-':return num1 - num2elif operator == '*':return num1 * num2elif operator == '/':return num1 / num2else:return "Invalid operator"num1 = float(input("请输入第一个数:"))num2 = float(input("请输入第二个数:"))operator = input("请输入运算符(+、-、*、/):")result = calculator(num1, num2, operator)print("结果为:", result)```习题2:题目:编写一个函数,接受一个列表作为参数,将列表中的元素按照从小到大的顺序排列,并返回排好序的列表。

答案:```pythondef sort_list(lst):lst.sort()return lstlst = [5, 2, 8, 1, 9]sorted_lst = sort_list(lst)print("排好序的列表:", sorted_lst)```习题3:题目:设计一个程序,实现石头、剪刀、布的游戏,并能显示每次游戏的结果。

```pythonimport randomdef rock_paper_scissors(user_choice):choices = ['石头', '剪刀', '布']computer_choice = random.choice(choices)if user_choice == computer_choice:return '平局'elif (user_choice == '石头' and computer_choice == '剪刀') or \ (user_choice == '剪刀' and computer_choice == '布') or \ (user_choice == '布' and computer_choice == '石头'):return '用户胜利'else:return '电脑胜利'user_choice = input("请出拳(石头、剪刀、布):")result = rock_paper_scissors(user_choice)print("结果:", result)```题目:编写一个函数,能够计算出指定范围内所有偶数的和。

Python性能测试与优化习题及答案解析,面向高级Python自动化测试开放工程师的进阶习题

Python性能测试与优化习题及答案解析(答案见尾页)一、选择题1. 以下哪种工具可以用来进行性能测试?A. Python内置模块B. 第三方性能测试工具C. Java内置模块D. C++编写库2. 在进行性能测试时,下列哪个指标是用来衡量CPU性能的?A. 内存使用率B. 硬盘读写速度C. CPU利用率D. 网络带宽3. 在Python中,可以使用哪种方法来获取系统的CPU占用率?A. psutil库B. cpuinfo库C. time库D. os库4. 要对Python程序进行性能分析,首先需要做的是?A. 编写测试代码B. 运行测试代码C. 使用分析器对结果进行分析D. 优化代码5. 以下哪种方法不是常用的内存性能分析工具?A. top命令B. htop命令C. psutil库D. matplotlib库6. 要对磁盘性能进行测试,可以使用Python中的哪个库?A. psutil库B. cpuinfo库C. diskio库D. numpy库7. 以下哪个工具可以用来监控Python程序的性能?A. psutil库B. cpuinfo库C. time库D. os库8. 在Python中,如何计算进程的CPU利用率?A. 获取进程的PIDB. 获取进程的内存使用率C. 获取进程的CPU利用率D. 获取进程的内存使用率9. 如何使用Python来优化一个函数的性能?A. 减少循环次数B. 使用列表推导式替换for循环C. 将大数运算拆分成小数运算D. 使用多线程或多进程10. 在Python中,如何进行进程间通信(IPC)?A. 使用管道B. 使用队列C. 使用信号D. 使用共享内存11. 以下哪种算法对于查找排序来说效率最低?A. 快速排序B. 归并排序C. 插入排序D. 冒泡排序12. 在Python中,如何对字符串进行去重?A. 使用集合B. 使用列表推导式C. 使用循环D. 使用函数13. 以下哪种数据结构不支持随机访问?A. 链表B. 二叉树C. 散列表D. 数组14. Python中的列表和元组有什么区别?A. 列表是可变的,元组是不可变的B. 列表是用方括号[]表示,元组是用圆括号()表示C. 列表的长度可以动态调整,元组的长度固定D. 列表可以用append()方法添加元素,元组不能15. 以下哪种方法在Python中用来判断两个字符串是否相等?A. ==B. !=C. >D. <16. 以下哪个函数在Python中用于求和?A. sum()B. len()C. max()D. min()17. 在Python中,如何实现多线程编程?A. 使用threading模块B. 使用multiprocessing模块C. 使用asyncio模块D. 使用queue模块18. Python中的字典 key 和 value 分别是什么?A. 一个存储key的变量和一个存储value的变量B. 一个存储value的变量和一个存储key的变量C. 一个包含key的列表和一个包含value的列表D. 一个使用key作为索引的dict对象19. 以下哪种方法在Python中用于排序?A. sorted()B. sorted() functionC. sort()D. sorted20. 以下哪种方法在Python中用于查找最大值?A. max()B. max() functionC. max() methodD. max21. 性能优化的基本策略包括哪些?A. 仅关注CPU性能B. 关注CPU、内存和磁盘性能C. 忽略网络性能D. 只优化CPU,不考虑其他22. 如何通过分析内存使用情况来找出程序中的内存泄漏?A. 使用内存 profiler工具B. 使用CPU profiler工具C. 使用日志文件D. 直接查看变量使用情况23. Python中常用的性能监控工具有哪些?A. timeitB. cProfileC. Py-SpyD. pyprof2calltree24. 在Python中,如何实现CPU性能监控?A. 使用timeit模块B. 使用cProfile模块C. 使用Py-Spy模块D. 使用pyprof2calltree模块25. 如何优化Python网络性能?A. 减少网络请求次数B. 调整网络请求速度C. 使用更高效的网络库D. 所有上述方法26. 如何检测Python程序中的性能瓶颈?A. 通过分析程序代码B. 使用性能监控工具C. 通过运行多个测试用例D. 直接观察程序运行结果27. 如何提高Python程序的执行效率?A. 减少程序代码数量B. 使用缓存机制C. 使用并发编程D. 所有上述方法28. 如何使用Python进行内存性能优化?A. 减少全局变量的使用B. 使用内存池C. 对大对象进行切片D. 直接使用内置函数29. 如何通过性能测试找出程序中的性能问题?A. 运行多个测试用例B. 使用性能监控工具C. 手动观察程序运行结果D. 直接查看程序代码30. 如何优化Python程序的I/O操作性能?A. 使用异步I/OB. 使用非阻塞I/OC. 减少I/O操作次数D. 直接使用内置函数31. 调试工具中,Python 中常用的性能分析工具是:A. timeitB. cProfileC. pyprof2calltreeD. line_profiler32. 在 Python 中,可以使用 os 模块来监控哪个系统的资源使用情况?A. CPUB. 内存C. 磁盘D. 网络33. 在 Python 中,使用 multiprocessing 模块可以实现多进程并发执行,关于multiprocessing 模块的错误处理,以下哪项是正确的?A. 可以使用 try-except 语句捕获进程异常B. 可以使用 pool 对象创建多个进程C. 可以使用 join() 方法等待子进程执行完毕D. 以上都是34. 在 Python 中,使用 time 模块进行性能测试时,应该使用哪种方式来记录开始和结束时间?A. time()B. timeit()C. profile()D. cProfile()35. 下面哪个函数不是 Python 的内置函数?A. time()B. os.getpid()C. sys.pathD. exec()36. 下面哪个命令可以用来监控 Python 进程的内存使用情况?A. psutilB. topC. htopD. pmap37. 在 Python 中,使用 requests 库进行 HTTP 请求时,以下哪个选项可以指定超时时间?A. timeoutB. connect_timeoutC. read_timeoutD. all of the above38. 在 Python 中,使用 threading 模块创建线程时,以下哪个选项是正确的?A. start()B. join()C. exit()D. pthread39. 在 Python 中,使用 PySpy 库进行 Process 监控时,以下哪个选项是正确的?A. pySPY.process.Process.start()B. pySPY.process.Process.stop()C. pySPY.process.Process.join()D. pySPY.process.Process.terminate()40. 在 Python 中,使用 psutil 库监控系统资源使用情况时,以下哪个函数可以获取 CPU 占用率?A. percent_cpuB. memory_percentC. disk_percentD. network_io二、问答题1. 什么是性能测试?2. 为什么需要对软件进行性能测试?3. 如何选择合适的性能测试工具?4. 什么是内存性能测试?5. 如何提高程序的执行效率?6. 什么是I/O性能测试?7. 如何优化磁盘性能?8. 什么是网络性能测试?9. 如何解决性能问题?10. 什么是性能调优?参考答案选择题:1. B2. C3. A4. C5. D6. A7. A8. C9. D 10. B11. D 12. A 13. B 14. A 15. A 16. A 17. A 18. A 19. A 20. A21. B 22. A 23. ABD 24. B 25. D 26. B 27. D 28. AB 29. B 30. AB31. B 32. D 33. D 34. A 35. D 36. A 37. D 38. A 39. C 40. A问答题:1. 什么是性能测试?性能测试是评估软件或系统在特定工作负载下性能表现的过程。

吴恩达深度学习第二课课后测验(docx版)

Practical aspects of deep learning1.If you have 10,000,000 examples, how would you split the train/dev/test set?☐33% train, 33% dev, 33% test☐60% train, 20% dev, 20% test☐98% train, 1% dev, 1% test2.The dev and test set should:☐Come from the same distribution☐Come from different distribution☐Be identical to each other (same (x,y) pairs)☐Have the same number of examples3.If your Neural Network model seems to have high bias, what of the following would bepromising things to try? (Check all that apply.)☐Add regularization☐Get more test data☐Increase the number of units in each hidden layer☐Make the Neural Network deeper☐Get more training data4.You are working on an automated check-out kiosk for a supermarket, and are building aclassifier for apples, bananas and oranges. Suppose your classifier obtains a training set error of 0.5%, and a dev set error of 7%. Which of the following are promising things to try to improve your classifier? (Check all that apply.)☐Increase the regularization parameter lambda☐Decrease the regularization parameter lambda☐Get more training data☐Use a bigger neural network5.What is weight decay?☐ A regularization technique (such as L2 regularization) that results in gradient decent shrinking the weights on every iteration.☐The process of gradually decreasing the learning rate during training.☐Gradual corruption of the weights in the neural network if it is trained on noisy data.☐ A technique to avoid vanishing gradient by imposing a ceiling on the values of the weights.6.What happens when you increase the regularization hyperparameter lambda?☐Weights are pushed toward becoming smaller (closer to 0)☐Weights are pushed toward becoming bigger (further from 0)☐Doubling lambda should roughly result in doubling the weights☐Gradient descent taking bigger steps with each iteration (proportional to lambda)7.With the inverted dropout technique, at test time:☐You apply dropout (randomly eliminating units) and do not keep the 1/keep_prob factor in the calculations used in training☐You apply dropout (randomly eliminating units) but keep the 1/keep_prob factor in the calculations used in training.☐You do not apply dropout ( do not randomly eliminating units), but keep the 1/keep_prob factor in the calculations used in training.☐You do not apply dropout (do not randomly eliminating units) and do not keep the 1/keep_prob factor in the calculations used in training.8.Increasing the parameter keep_prob from (say) 0.5 to 0.6 will likely cause the following:(Check the two that apply)☐Increasing the regularization effect☐Reducing the regularization effect☐Causing the neural network to end up with a higher training set error☐Causing the neural network to end up with a lower training set error9.Which of these techniques are useful for reducing variance (reducing overfitting)? (Check allthat apply.)☐Xavier initialization☐Data augmentation☐Gradient Checking☐Exploding gradient☐L2 regularization☐Vanishing gradient☐Dropout10.Why do we normalize the inputs x?☐It makes the parameter initialization faster☐It makes the cost function faster to optimize☐Normalization is another word for regularization—It helps to reduce variance☐It makes it easier to visualize the dataOptimization algorithms1.Which notation would you use to denote the 3rd layer’s activation when the inputs is the 7thexample from the 8th minibatch?☐a[8]{3}(7)☐a[8]{7}(3)☐a[3]{8}(7)☐a[3]{7}(8)2.Which of these statements about mini-batch gradient descent do you agree with ?☐One iteration of mini-batch gradient decent (computing on a single mini-batch) is faster than one iteration of batch gradient decent.☐You should implement mini-batch gradient descent without an explicit for loop over different mini-batches, so that the algorithm processes all mini-batches at the same time (vectorization).☐Training one epoch (one pass through the training set) using mini-batch gradient descent is faster than training one epoch using batch gradient descent.3.Why is the best mini-batch size usually not 1 and not m, but instead something in-between?☐If the mini-batch size is m, you end up with stochastic gradient descent, which is usually slower than mini-batch gradient descent.☐If the mini-batch size is m, you end up with batch gradient descent, which has to process the whole training set before making progress.☐If the mini-batch size is 1, you lose the benefits of vectorization across examples in the mini-batch.☐If the mini-batch size is 1, you end up having to process the entire training set before making any progress.4.Suppose your learning algorithm’s cost J, plotted as a function of the number of iterations,looks like this:Which of the following do you agree with?☐Whether you’re using batch gradient decent or mini-batch gradient decent, something is wrong.☐Whether you’re using batch gradient decent of mini-batch gradient descent, this looks acceptable.☐If you’re using mini-batch gradient descent, something is wrong. But if you’re using batch gradient descent, this looks acceptable.☐If you’re using mini-batch gradient descent, this looks acceptable. But if you’re using batch gradient decent, something is wrong.5.Suppose the temperature in Casablanca over the first three days of January are the same:Jan 1st: θ1=100CJan 2nd: θ2=100C(We used Fahrenheit in lecture, so will use Celsius here in honor of the metric world.)Say you use an exponentially weighted average with β=0.5 to track the temperature:v0=0, v t=βv t-1+(1-β)θt. If v2 is the value computed after day 2 without bias correction, and v2corrected is the value you compute with bias correction. What are these values? (You might be able to do this without a calculator, but don’t actually need one. Remember what is bias correction doing.)☐v2=7.5, v2corrected=10☐v2=10, v2corrected=7.5☐v2=7.5, v2corrected=7.5☐v2=10, v2corrected=106.Which of these is NOT a good learning rate decay scheme? Here, t is the epoch number.☐α=1α01+2∗t☐α=e tα0☐α=0.95tα0☐α=α0√t7.You use an exponentially weighted average on the London temperature dataset. You use thefollowing to track the temperature: v t=βv t-1+(1-β)θt. The red line below was computed using β=0.9. What would happen to your red curve as you vary β? (Check the two that apply)☐Decreasing βwill shift the red line slightly to the right☐Increasing βwill shift the red line slightly to the right☐Decreasing βwill create more oscillation within the red line.☐Increasing βwill create more oscillation within the red line.8.Consider this figure:These plots were generated with gradient descent; with gradient descent momentum (β=0.5) and gradient descent with momentum (β=0). Which curve corresponds to whichalgorithm?☐(1) is gradient descent with moment (small β). (2) is gradient descent. (3) is gradient descent with momentum (large β)☐(1) is gradient descent. (2) is gradient descent with momentum (small β). (3) is gradient descent with momentum (large β)☐(1) is gradient descent. (2) is gradient descent with momentum (large β). (3) is gradient descent with momentum (small β)☐(1) is gradient descent with momentum (small β). (2) is gradient descent with momentum (small β). (3) is gradient descent.9.Suppose batch gradient descent in a deep network is taking excessively long to find a value ofthe parameters that achieves a small value for the cost function J(W[1],b[1],……,W[L],b[L]).Which of the following techniques could help find parameter values that attain a small value for J? (check all that apply)☐Try tuning the learning rate α☐Try initializing all the weights to zero☐Try better random initialization for the weights☐Try mini-batch gradient descent☐Try using Adam10.Which of the following statements about Adam is False?☐Adam combines the advantages of RMSProp and momentum☐Adam should be used with batch gradient computations, not with mini-batches.☐The learning rate hyperparameter αin Adam usually needs to be tuned.☐We usually use “default” values for the hyperparameter β1, β2 andεin Adam (β=0.9, β2=0.999, ε=10-8)1Hyperparameter tuning, Batch Normalization, Programming Frameworks1.If searching among a large number of number of hyperparameters, you should try values in agrid rather than random values, so that you can carry out the search more systematically and not rely on chance. True or False?☐True☐False2.Every hyperparameters, if set poorly, can have a huge negative impact on training, and so allhyperparameters are about equally important to tune well. True or False?☐True☐False3.During hyperparameters serch, whether you try to babysit one model (“Panda” strategy) ortrain a lot of models in parallel (“Caviar”) is largely determined by:☐Whether you use batch or mini-batch optimization☐The presence of local minima (and saddle points) in your neural network☐The amount of computational power you can access☐The number of hyperparameters you have to tune4.If you think β(hyperparameter for momentum) is between on 0.9 and 0.99, which of thefollowing is the recommended way to sample a value for beta?☐ 1 r = np.random.rand()2 beta = r*0.09+0.09☐ 1 r = np.random.rand()2 beta = 1-10**(-r-1)☐ 1 r = np.random.rand()2 beta = 1-10**(-r+1)☐ 1 r = np.random.rand()2 beta = r*0.9+0.095.Finding good hyperparameter values is very time-consuming. So typically you should to itonce at the start of the project, and try to find very good hyperparameters so that you don’t ever have to revisit tuning them again. True or False?☐True☐False6.In batch normalization as presented in the video, if you apply it on the l th layer of you neuralnetwork, what are you normalizing?☐B [l ] ☐a [l ] ☐Z [l ] ☐W [l ]7. In the normalization formula z norm (i)=(i)√σ2+ε, why do we use epsilon?☐To speed up convergence ☐To avoid division by zero ☐To have a more accurate normalization ☐In case μ is too small8. Which of the following statements about γ and β in Batch Norm are true?☐ There is one global value of γ∈R and one global value of β∈R for each layer, andapplies to all the hidden units in that layer.☐ They can be learned using Adam, Gradient descent with momentum, or RMSprop, notjust with gradient descent.☐ The optimal values are γ=√σ2+ϵ, and β=μ.☐ β and γ are hyperparameters of the algorithm, which we tune via random sampling. ☐ They set the mean and variance of the linear variable z [l] of a given layer.9. After training a neural network with Batch Norm, at test time, to evaluate the neural networkon a new example you should:☐ Perform the needed normalization, use μ and σ2 estimated using an exponentiallyweighted average across mini-batches seen during training.☐ Skip the step where you normalize using μ and σ2 since a single test example cannotbe normalized☐ Use the most recent mini-batch ’s value of μ and σ2 to perform the needednormalizations.☐ If you implemented Batch Norm on mini-batches of (say) 256 examples, then toevaluate on one test example, duplicate that example 256 time so that you ’re working with a mini-batch the same size as during training.10. Which of these statements about deep learning programming frameworks are true? (Checkall that apply)☐ A programming frameworks allows you to code up deep learning algorithms withtypically fewer lines of code than a lower-level language such as Python.☐ Even if a project is currently open source, good governance of the project helps ensurethat the it remains open even in the long term, rather than become closed or modified to benefit only one company.Deep learning programming frameworks require cloud-based machines to run.。

  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
相关文档
最新文档