美国留学生关于Python机器学习自动梯度计算等的作业与答案

Python海龟宝典含200多个原创的用turtle模块制作的创意程序,原名《Python趣味编程200例》。准备参加全国创意编程与智能设计大赛的同学们可以用来做参考。

下面是一些文字叙述

ML in a nutshell

Optimization, and machine learning, are intimately connected. At a very coarse level, ML works as follows.

First, you come up somehow with a very complicated model 𝑦̂ =𝑀(𝑥,𝜃)y^=M(x,θ), which computes an output 𝑦̂ y^ as a function of an input 𝑥x and of a vector of parameters 𝜃θ. In general, 𝑥x𝑦y, and 𝜃θ are vectors, as the model has multiple inputs, multiple outputs, and several parameters. The model 𝑀M needs to be complicated, because only complicated models can represent complicated phenomena; for instance, 𝑀M can be a multi-layer neural net with parameters 𝜃=[𝜃1,,𝜃𝑘]θ=[θ1,…,θk], where 𝑘k is the number of parameters of the model.

Second, you come up with a notion of loss 𝐿L, that is, how badly the model is doing. For instance, if you have a list of inputs 𝑥1,,𝑥𝑛x1,…,xn, and a set of desired outputs 𝑦1,,𝑦𝑚y1,…,ym, you can use as loss:

𝐿(𝜃)=𝑖=1𝑛||𝑦𝑖𝑦̂ 𝑖||=𝑖=1𝑛||𝑦𝑖𝑀(𝑥𝑖,𝜃)||.L(θ)=∑i=1n||yi−y^i||=∑i=1n||yi−M(xi,θ)||.

Here, we wrote 𝐿(𝜃)L(θ) because, once the inputs 𝑥1,,𝑥𝑛x1,…,xn and the desired outputs 𝑦1,,𝑦𝑛y1,…,yn are chosen, the loss 𝐿L depends only on 𝜃θ.

Once the loss is chosen, you decrease it, by computing its gradient with respect to 𝜃θ. Remembering that 𝜃=[𝜃1,,𝜃𝑘]θ=[θ1,…,θk],

𝜃𝐿=[𝐿𝜃1,,𝐿𝜃𝑘].∇θL=[∂L∂θ1,…,∂L∂θk].

The gradient is a vector that indicates how to tweak 𝜃θ to decrease the loss. You then choose a small step size 𝛿δ, and you update 𝜃θ via 𝜃:=𝜃𝛿𝜃𝐿θ:=θ−δ∇θL. This makes the loss a little bit smaller, and the model a little bit better. If you repeat this step many times, the model will hopefully get (a good bit) better.

Autogradient

The key to pleasant ML is to focus on building the model 𝑀M in a way that is sufficiently expressive, and on choosing a loss 𝐿L that is helpful in guiding the optimization. The computation of the gradient is done automatically for you. This capability, called autogradient, is implemented in ML frameworks such as TensorflowKeras, and PyTorch.

It is possible to use these advanced ML libraries without ever knowing what is under the hood, and how autogradient works. Here, we will insted dive in, and implement autogradient.

Building a model 𝑀M corresponds to building an expression with inputs 𝑥x𝜃θ. We will provide a representaton for expressions that enables both the calculation of the expression value, and the differentiation with respect to any of the inputs. This will enable us to implement autogradient. On the basis of this, we will be able to implement a simple ML framework.

We say we, but we mean you. You will implement it; we will just provide guidance.

下面是要完成的问题,第一个是编写自动梯度计算的函数。本人已完成所有作业,需要答案的请联系本人。

Question 1 With these clarifications, we ask you to implement the compute_gradient method, which again must:
Question 2: Rounding up the implementation
Question 3: Implementation of the fit function

 

本站所有作品,教程等皆为原创,版权所有。只供个人及单位内部研究使用,对外展示或传播必需经本站同意,且注明来自本站。培训机构等用本站资源培训学生,需经本站授权。一旦付款,表示同意本站知识付费原则:数字商品,不支持退款。亦可直接向微信号scratch8付款购买。入住QQ群:225792826 和爱好者共同交流,并且能下载免费提供的Python资源(需提供真实姓名才可入群)
李兴球的博客_Python创意编程技术前沿_pygame » 美国留学生关于Python机器学习自动梯度计算等的作业与答案

李兴球Python微信公众号文章列表

Python编程家长会花絮_萍乡中小学Python家长会现场

火星路上等着你_少儿从小学什么最好呢?

国家大力整顿教育培训机构,Scratch或Python少儿编程还有得教吗?

鸿蒙系统支持Python开发_可视化编程特别兴趣小组

Scratch作品转Python作品_小猴接桃

python海龟数据可视化。第七次全国人口普查历年数据图表

你的孩子Python编程学到哪个阶段了?给孩子报编程的家长,务必仔细一读。

五一神女来对话,看看她们聊什么?赠Python教案等。

五一快乐有大礼,告诉大家我是如何上Python课的。

Python名堂多,趣味到处有,劈开机械手,帧帧是图片。速算达人之猫狮大战正在进行。 逐字动画不独享,自动生成皆有它。2行代码自动生成字幕gif动画。 Python之潮来临,我在安源区教师科技创新能力的Python讲座

小心你的Python程序,它会是你的一面镜子。小方块闯迷宫.py源代码简析。送Scratch算法集。?

铃儿响钉铛_音效怎能忘_Python配音之Pygame混音器

人面桃花相映红_winsound模块简介

《Python昨晚我想你了》_开源的游戏海龟模块实例案例浅析

《八猫联动初体验》_来自游戏海龟模块的问候

喜爱春天的人儿啊 心地纯洁的人_Python逐行像素显示

旋转之三叶炫彩扇_蟒蛇与海龟的表演

彩虹欢迎字幕_三模合体滚图形

《Python海龟宝典》简介

100%错误的算法还在用,明明没有错别字,说我有11个错别字

奇怪的Python代码,谁能帮我解释一下??

人造地球系统让人类文明充满整个宇宙之Python32768版

深夜,是什么把你的大脑搞成一团浆糊!再谈少儿编程!

5线城市萍乡的少儿Python寒假班学的是什么内容?

关于纯少儿编程课程进化的自然选择

Python海龟画图经典作品_国庆中秋双重喜庆源代码免费下载

海龟为什么要自杀!turtle制作游戏秘籍之一

朋友,你是否知道我在仰望着你_Python神笔马良案例集

酷酷的爆炸效果_Python海龟画图不仅仅是画图

虫子满屏爬_三bug多线程示例程序浅析 少儿Python视频课程A级简介

给的gif图片加文字水印_拆帧与合帧(免费下载180个Python创意源码

用Python制作酷炫图形之如意金箍棒_颜色增加模块应用

简单的用Python做酷炫图形与动画

sb3转exe,sb3素材提取器,编程小子apk, 未公开的pygame游戏集/scratch/python少儿编程免费下载集合

夜幕下的霓虹

学本领,探索更大的世界!

李兴球博客 风火轮编程主页