<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Math &#8211; 编码无悔 /  Intent &amp; Focused</title>
	<atom:link href="https://www.codelast.com/category/math/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.codelast.com</link>
	<description>最优化之路</description>
	<lastBuildDate>Wed, 24 May 2023 09:36:14 +0000</lastBuildDate>
	<language>zh-Hans</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.4</generator>
	<item>
		<title>[原创] 推荐一款编写数学公式的国产神器：AxMath，可与LATEX双向转换</title>
		<link>https://www.codelast.com/%e5%8e%9f%e5%88%9b-%e6%8e%a8%e8%8d%90%e4%b8%80%e6%ac%be%e7%bc%96%e5%86%99%e6%95%b0%e5%ad%a6%e5%85%ac%e5%bc%8f%e7%9a%84%e5%9b%bd%e4%ba%a7%e7%a5%9e%e5%99%a8%ef%bc%9aaxmath%ef%bc%8c%e5%8f%af%e4%b8%8ela/</link>
					<comments>https://www.codelast.com/%e5%8e%9f%e5%88%9b-%e6%8e%a8%e8%8d%90%e4%b8%80%e6%ac%be%e7%bc%96%e5%86%99%e6%95%b0%e5%ad%a6%e5%85%ac%e5%bc%8f%e7%9a%84%e5%9b%bd%e4%ba%a7%e7%a5%9e%e5%99%a8%ef%bc%9aaxmath%ef%bc%8c%e5%8f%af%e4%b8%8ela/#respond</comments>
		
		<dc:creator><![CDATA[learnhard]]></dc:creator>
		<pubDate>Sun, 25 Oct 2020 00:31:32 +0000</pubDate>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Mac]]></category>
		<category><![CDATA[Math]]></category>
		<category><![CDATA[原创]]></category>
		<category><![CDATA[AxMath]]></category>
		<category><![CDATA[LaTeX]]></category>
		<category><![CDATA[MathType]]></category>
		<category><![CDATA[数学公式]]></category>
		<guid isPermaLink="false">https://www.codelast.com/?p=13059</guid>

					<description><![CDATA[<div>
	<img decoding="async" alt="latex" src="https://www.codelast.com/wp-content/uploads/2020/10/latex.png" style="width: 300px; height: 144px;" /></div>
<p>我一直都很佩服那些可以直接用LATEX语法打出各种复杂数学公式的人，反正我是记不住，而且也真的不想去记LATEX语法。<br />
比如这个公式：<br />
<img decoding="async" alt="cauchy's inequality" src="https://www.codelast.com/wp-content/uploads/2020/10/cauchy_inequality.png" style="width: 500px; height: 91px;" /></p>
<p>有的人能直接用LATEX手写出来：<br />
<span style="color:#0000ff;">\left( \sum_{i=1}^n{a_ib_i} \right) ^2\leqslant \left( \sum_{i=1}^n{a_{i}^{2}} \right) \left( \sum_{i=1}^n{b_{i}^{2}} \right) , a_i,b_i\in \mathbb{R}</span><br />
这还算简单的了，更复杂的公式大神们都可以直接手写LATEX。<br />
就问你服不服。<br />
在下自愧脑容量不足。<br />
所以当我要输入数学公式的时候，MathType这个功能强大的可视化数学公式编辑器就是我认为最方便易用的软件。<br />
<span id="more-13059"></span></p>
<div>
	<img decoding="async" alt="mathtype" src="https://www.codelast.com/wp-content/uploads/2020/10/mathtype_logo.png" style="width: 225px; height: 225px;" /></div>
<p><span style="color: rgb(0, 0, 255);">▶</span>&#160;MathType的方便之处<br />
MathType可以直接在复制图形界面的公式的时候，就把公式自动转换成LATEX语法再复制到内存里，粘贴的时候直接粘贴出来LATEX。比如我的网站里面的数学公式，在后台的文字编辑界面里大部分都是LATEX，但它们并不是我用手输的，而是用软件转换成LATEX再粘贴上来的（参考<a href="https://www.codelast.com/?p=6199" rel="noopener noreferrer" target="_blank"><span style="background-color:#ffa07a;">这个</span></a>链接）。<br />
<img decoding="async" alt="mathtype convert latex" src="http://www.codelast.com/wp-content/uploads/ckfinder/images/mathtype_setting_convert.png" style="width: 285px; height: 255px;" /><br />
<span style="color: rgb(0, 0, 255);">▶</span>&#160;MathType的缺点<br />
但它有个缺点就是：贵。正版的单用户授权要300～400元。这个价格对大多数人来说都是要割肉的。<br />
<span style="color: rgb(0, 0, 255);">▶</span>&#160;MathType官方的雷人开发效率<br />
而且当前最新版的MathType 7在当前最新版的<span style="color:#800080;">MacOS Catalina</span>系统上无法运行（官方通告<a href="https://lp.wiris.com/catalina/" rel="noopener noreferrer" target="_blank"><span style="background-color:#ffa07a;">在此</span></a>）。官方说会在2020年发布新版MathType解决此问题，一个导致产品完全无法使用的P0级问题出现那么久了，开发商还没有解决问题，其效率之低，令人侧目。仗着自己是世界范围内同类软件的老大，可以无视用户对吧？<br />
<!--more--><br />
<span style="color: rgb(0, 0, 255);">▶</span>&#160;MathType有什么替代软件吗？<br />
首先是你能搜到很多&#8220;网页版&#8221;的数学公式编辑器，但我得说，我也用过很多个，一个真●能打的都没有，它们比MathType用起来麻烦多了，而且功能弱。</p>
<p>直到我遇到了<a href="https://www.amyxun.com/" rel="noopener noreferrer" target="_blank"><span style="background-color:#ffa07a;">AxMath</span></a>，一款国产的&#8220;仿MathType&#8221;软件(但在很多方面已经超越了MathType)，我才知道原来这种国产软件也可以做得这么精良，而且单用户单机正版授权才30多块钱，童叟无欺，一顿饭的钱就能买这么强大的正版软件，你买不了吃亏买不了上当！<br />
<img decoding="async" alt="axmath" src="https://www.codelast.com/wp-content/uploads/2020/10/axmath_logo.png" style="width: 300px; height: 244px;" /><br />
如果不买正版授权也是可以试用的，不过不能复制粘贴你输入的公式。<br />
<span style="color: rgb(255, 255, 255);">文章来源：</span><a href="https://www.codelast.com/" rel="noopener noreferrer" target="_blank"><span style="color: rgb(255, 255, 255);">https://www.codelast.com/</span></a>&#8230; <a href="https://www.codelast.com/%e5%8e%9f%e5%88%9b-%e6%8e%a8%e8%8d%90%e4%b8%80%e6%ac%be%e7%bc%96%e5%86%99%e6%95%b0%e5%ad%a6%e5%85%ac%e5%bc%8f%e7%9a%84%e5%9b%bd%e4%ba%a7%e7%a5%9e%e5%99%a8%ef%bc%9aaxmath%ef%bc%8c%e5%8f%af%e4%b8%8ela/" class="read-more">Read More </a></p>]]></description>
										<content:encoded><![CDATA[<div>
	<img decoding="async" alt="latex" src="https://www.codelast.com/wp-content/uploads/2020/10/latex.png" style="width: 300px; height: 144px;" /></div>
<p>我一直都很佩服那些可以直接用LATEX语法打出各种复杂数学公式的人，反正我是记不住，而且也真的不想去记LATEX语法。<br />
比如这个公式：<br />
<img decoding="async" alt="cauchy's inequality" src="https://www.codelast.com/wp-content/uploads/2020/10/cauchy_inequality.png" style="width: 500px; height: 91px;" /></p>
<p>有的人能直接用LATEX手写出来：<br />
<span style="color:#0000ff;">\left( \sum_{i=1}^n{a_ib_i} \right) ^2\leqslant \left( \sum_{i=1}^n{a_{i}^{2}} \right) \left( \sum_{i=1}^n{b_{i}^{2}} \right) , a_i,b_i\in \mathbb{R}</span><br />
这还算简单的了，更复杂的公式大神们都可以直接手写LATEX。<br />
就问你服不服。<br />
在下自愧脑容量不足。<br />
所以当我要输入数学公式的时候，MathType这个功能强大的可视化数学公式编辑器就是我认为最方便易用的软件。<br />
<span id="more-13059"></span></p>
<div>
	<img decoding="async" alt="mathtype" src="https://www.codelast.com/wp-content/uploads/2020/10/mathtype_logo.png" style="width: 225px; height: 225px;" /></div>
<p><span style="color: rgb(0, 0, 255);"><img src="https://s.w.org/images/core/emoji/17.0.2/72x72/25b6.png" alt="▶" class="wp-smiley" style="height: 1em; max-height: 1em;" /></span>&nbsp;MathType的方便之处<br />
MathType可以直接在复制图形界面的公式的时候，就把公式自动转换成LATEX语法再复制到内存里，粘贴的时候直接粘贴出来LATEX。比如我的网站里面的数学公式，在后台的文字编辑界面里大部分都是LATEX，但它们并不是我用手输的，而是用软件转换成LATEX再粘贴上来的（参考<a href="https://www.codelast.com/?p=6199" rel="noopener noreferrer" target="_blank"><span style="background-color:#ffa07a;">这个</span></a>链接）。<br />
<img decoding="async" alt="mathtype convert latex" src="http://www.codelast.com/wp-content/uploads/ckfinder/images/mathtype_setting_convert.png" style="width: 285px; height: 255px;" /><br />
<span style="color: rgb(0, 0, 255);"><img src="https://s.w.org/images/core/emoji/17.0.2/72x72/25b6.png" alt="▶" class="wp-smiley" style="height: 1em; max-height: 1em;" /></span>&nbsp;MathType的缺点<br />
但它有个缺点就是：贵。正版的单用户授权要300～400元。这个价格对大多数人来说都是要割肉的。<br />
<span style="color: rgb(0, 0, 255);"><img src="https://s.w.org/images/core/emoji/17.0.2/72x72/25b6.png" alt="▶" class="wp-smiley" style="height: 1em; max-height: 1em;" /></span>&nbsp;MathType官方的雷人开发效率<br />
而且当前最新版的MathType 7在当前最新版的<span style="color:#800080;">MacOS Catalina</span>系统上无法运行（官方通告<a href="https://lp.wiris.com/catalina/" rel="noopener noreferrer" target="_blank"><span style="background-color:#ffa07a;">在此</span></a>）。官方说会在2020年发布新版MathType解决此问题，一个导致产品完全无法使用的P0级问题出现那么久了，开发商还没有解决问题，其效率之低，令人侧目。仗着自己是世界范围内同类软件的老大，可以无视用户对吧？<br />
<!--more--><br />
<span style="color: rgb(0, 0, 255);"><img src="https://s.w.org/images/core/emoji/17.0.2/72x72/25b6.png" alt="▶" class="wp-smiley" style="height: 1em; max-height: 1em;" /></span>&nbsp;MathType有什么替代软件吗？<br />
首先是你能搜到很多&ldquo;网页版&rdquo;的数学公式编辑器，但我得说，我也用过很多个，一个真●能打的都没有，它们比MathType用起来麻烦多了，而且功能弱。</p>
<p>直到我遇到了<a href="https://www.amyxun.com/" rel="noopener noreferrer" target="_blank"><span style="background-color:#ffa07a;">AxMath</span></a>，一款国产的&ldquo;仿MathType&rdquo;软件(但在很多方面已经超越了MathType)，我才知道原来这种国产软件也可以做得这么精良，而且单用户单机正版授权才30多块钱，童叟无欺，一顿饭的钱就能买这么强大的正版软件，你买不了吃亏买不了上当！<br />
<img decoding="async" alt="axmath" src="https://www.codelast.com/wp-content/uploads/2020/10/axmath_logo.png" style="width: 300px; height: 244px;" /><br />
如果不买正版授权也是可以试用的，不过不能复制粘贴你输入的公式。<br />
<span style="color: rgb(255, 255, 255);">文章来源：</span><a href="https://www.codelast.com/" rel="noopener noreferrer" target="_blank"><span style="color: rgb(255, 255, 255);">https://www.codelast.com/</span></a><br />
<span style="color: rgb(0, 0, 255);"><img src="https://s.w.org/images/core/emoji/17.0.2/72x72/25b6.png" alt="▶" class="wp-smiley" style="height: 1em; max-height: 1em;" /></span>&nbsp;AxMath的局限性<br />
只支持Windows系统（不像MathType有Mac版的）。不过这也还好，如果电脑是Mac/Linux的话，大不了在Windows虚拟机里运行AxMath，或者用<a href="https://www.codeweavers.com/crossover" rel="noopener noreferrer" target="_blank"><span style="background-color:#ffa07a;">CrossOver</span></a>跑AxMath（亲测可用）。</p>
<p><span style="color: rgb(0, 0, 255);"><img src="https://s.w.org/images/core/emoji/17.0.2/72x72/25b6.png" alt="▶" class="wp-smiley" style="height: 1em; max-height: 1em;" /></span>&nbsp;AxMath的华丽功能<br />
当你第一眼看到AxMath界面的时候，一定会被它的华丽外观给迷到，简直比MathType高级到不知道到哪里去了！<br />
<img decoding="async" alt="axmath ui" src="https://www.codelast.com/wp-content/uploads/2020/10/axmath_ui_1.png" style="width: 600px; height: 761px;" /><br />
看看它支持输入的数学符号有多少种，简直多到像满天星。<br />
官网上的那些强大功能介绍我就不粘贴过来了，我只说几个我肤浅使用了之后感觉特别好的地方。<br />
<span style="color: rgb(255, 255, 255);">文章来源：</span><a href="https://www.codelast.com/" rel="noopener noreferrer" target="_blank"><span style="color: rgb(255, 255, 255);">https://www.codelast.com/</span></a><br />
<span style="color:#b22222;"><img src="https://s.w.org/images/core/emoji/17.0.2/72x72/2714.png" alt="✔" class="wp-smiley" style="height: 1em; max-height: 1em;" /></span>&nbsp;可以自定义复制出来的LATEX的起始、结束符号<br />
举个例子。<br />
在MatyType里，复制一个数学公式 <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_3a8d8ec90ca2d552f7f63b3627032a7b.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="y=ax+b" /></span><script type='math/tex'>y=ax+b</script> ，再粘贴到任意文本编辑器里，得到的内容如下：<br />
<span style="color:#0000ff;">\ [y=ax+b\ ]</span><br />
开头、结尾的 <span style="color:#ff0000;">\ [</span> 和 <span style="color:#ff0000;">\ ]&nbsp;</span>是不能在MathType中自定义的。当我在网站后台编辑器里用LATEX写数学公式时，这两个开头、结尾的符号要人工修改成 <span style="color:#ff0000;">\ (</span>&nbsp;和 <span style="color:#ff0000;">\ )</span>（&rarr;我特意在这些标成红色的符号之间都多加了一个空格以避免它们显示为数学公式），否则就会被LaTeX for WordPress插件解释成&ldquo;换行居中&rdquo;的式样，从而导致文章排版有问题，我在<a href="https://www.codelast.com/?p=6199" rel="noopener noreferrer" target="_blank"><span style="background-color:#ffa07a;">这篇文章</span></a>里已经做了详细的解释。<br />
每次在MathType里复制公式时，都要做这个重复的人工活，心累。<br />
AxMath就没有这种问题，因为它可以设置&ldquo;<span style="color:#0000ff;">语法定界符</span>&rdquo;，也就是上面说的LATEX开头、结尾的符号。设置成&nbsp;<span style="color: rgb(255, 0, 0);">\ (</span>&nbsp;和&nbsp;<span style="color: rgb(255, 0, 0);">\ )&nbsp;</span>就解决问题啦！<br />
<img decoding="async" alt="axmath settings" src="https://www.codelast.com/wp-content/uploads/2020/10/axmath_settings.jpg" style="width: 476px; height: 475px;" /><br />
<span style="color: rgb(255, 255, 255);">文章来源：</span><a href="https://www.codelast.com/" rel="noopener noreferrer" target="_blank"><span style="color: rgb(255, 255, 255);">https://www.codelast.com/</span></a><br />
<span style="color: rgb(178, 34, 34);"><img src="https://s.w.org/images/core/emoji/17.0.2/72x72/2714.png" alt="✔" class="wp-smiley" style="height: 1em; max-height: 1em;" /></span>&nbsp;没有MathType经常&ldquo;多生成一个空格&rdquo;的问题<br />
举个例子。<br />
在MathType中用图形界面输入以下公式：<br />
<img decoding="async" alt="math function" src="https://www.codelast.com/wp-content/uploads/2020/10/math_function_1.png" style="width: 657px; height: 92px;" /><br />
复制，粘贴到文本编辑器中，变成了：<br />
<span style="color:#0000ff;">\ [{V_\pi }(s) = {E_{{s^{(1)}}, \cdots }}\left( {\sum\limits_{t = 0}^\infty&nbsp; {{\gamma ^t}R({s^{(t)}},\pi ({s^{(t)}}),{s^{(t + 1)}})\left| {{s^{(0)}} = s;\pi } \right.} } \right) \ ]</span><br />
注意：<span style="color:#b22222;">为了让上面的LATEX显示为纯文本，而不是被我网站里的LaTeX for WordPress插件渲染成数学公式展现出来，我特意在开头的&nbsp;</span><span style="color: rgb(0, 0, 255);">\</span><span style="color:#b22222;">&nbsp;符号后面、以及结尾的&nbsp;</span><span style="color: rgb(0, 0, 255);">]</span><span style="color:#b22222;">&nbsp;符号前面分别都加了一个空格（实际上复制出来的LATEX是没有这两个空格的）</span>。<br />
这个LATEX被我网站里的LaTeX for WordPress插件渲染成了这样：<br />
<img decoding="async" alt="math function" src="https://www.codelast.com/wp-content/uploads/2020/10/math_function_1_with_problem.png" style="width: 535px; height: 79px;" /><br />
注意看中间有一个奇怪的问号，是个什么鬼？<br />
这就是MathType的一个缺陷了（不知道算不算bug）。原因是在  <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_334de1ea38b615839e4ee6b65ee1b103.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="\gamma " /></span><script type='math/tex'>\gamma </script>  字母的前面，MathType生成了两个空格（&nbsp;<span style="color: rgb(0, 0, 255);">infty&nbsp; {{\gamma&nbsp;</span>），而不是正确的一个空格。<br />
注意看这个小细节。在我的使用过程中，MathType经常犯这样的错误，导致我不得不对复制出来的LATEX做人工修正，很烦很烦。<br />
而AxMath就没有这个问题。</p>
<p><span style="color: rgb(0, 0, 255);"><img src="https://s.w.org/images/core/emoji/17.0.2/72x72/25b6.png" alt="▶" class="wp-smiley" style="height: 1em; max-height: 1em;" /></span>&nbsp;结语<br />
AxMath，你值得拥有！</p>
<p><span style="color: rgb(255, 255, 255);">文章来源：</span><a href="https://www.codelast.com/" rel="noopener noreferrer" target="_blank"><span style="color: rgb(255, 255, 255);">https://www.codelast.com/</span></a><br />
<span style="color: rgb(255, 0, 0);">➤➤</span>&nbsp;版权声明&nbsp;<span style="color: rgb(255, 0, 0);">➤➤</span>&nbsp;<br />
转载需注明出处：<u><a href="https://www.codelast.com/" rel="noopener noreferrer" target="_blank"><em><span style="color: rgb(0, 0, 255);"><strong style="font-size: 16px;"><span style="font-family: arial, helvetica, sans-serif;">codelast.com</span></strong></span></em></a></u>&nbsp;<br />
感谢关注我的微信公众号（微信扫一扫）：</p>
<p style="border: 0px; font-size: 13px; margin: 0px 0px 9px; outline: 0px; padding: 0px; color: rgb(77, 77, 77);">
	<img decoding="async" alt="wechat qrcode of codelast" src="https://www.codelast.com/codelast_wechat_qr_code.jpg" style="width: 200px; height: 200px;" /></p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.codelast.com/%e5%8e%9f%e5%88%9b-%e6%8e%a8%e8%8d%90%e4%b8%80%e6%ac%be%e7%bc%96%e5%86%99%e6%95%b0%e5%ad%a6%e5%85%ac%e5%bc%8f%e7%9a%84%e5%9b%bd%e4%ba%a7%e7%a5%9e%e5%99%a8%ef%bc%9aaxmath%ef%bc%8c%e5%8f%af%e4%b8%8ela/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>[原创] 重要性采样／Importance Sampling</title>
		<link>https://www.codelast.com/%e5%8e%9f%e5%88%9b-%e9%87%8d%e8%a6%81%e6%80%a7%e9%87%87%e6%a0%b7%ef%bc%8fimportance-sampling/</link>
					<comments>https://www.codelast.com/%e5%8e%9f%e5%88%9b-%e9%87%8d%e8%a6%81%e6%80%a7%e9%87%87%e6%a0%b7%ef%bc%8fimportance-sampling/#respond</comments>
		
		<dc:creator><![CDATA[learnhard]]></dc:creator>
		<pubDate>Thu, 11 Jul 2019 12:17:07 +0000</pubDate>
				<category><![CDATA[Algorithm]]></category>
		<category><![CDATA[Math]]></category>
		<category><![CDATA[原创]]></category>
		<category><![CDATA[Monte Carlo method]]></category>
		<category><![CDATA[蒙特卡洛方法]]></category>
		<category><![CDATA[蒙特卡罗方法]]></category>
		<guid isPermaLink="false">https://www.codelast.com/?p=10022</guid>

					<description><![CDATA[<p>
查看本系列文章合集，请点击<a href="https://www.codelast.com/?p=9951" rel="noopener noreferrer" target="_blank"><span style="background-color: rgb(255, 160, 122);">这里</span></a>。</p>
<p>在前面的文章中，我们看到，随机采样是一个蒙特卡罗方法中很关键的步骤。而采样是需要技巧的，单纯地增加采样次数太没有效率了，比如说，如果随机采样一亿次，你可以把结果计算得特别精确，但是采样一亿次需要的时间非常长，长得远远超过了我们能接受的范围，这又有什么意义呢？<br />
人们发现，有一些方法可以让随机采的样本&#8220;特别好&#8221;。那么什么算&#8220;特别好&#8221;呢？比如说，本来使用没有任何原则的采样方法，需要采样1万个点，才能让计算出来的结果很接近真实值；现在使用一个&#8220;特别好&#8221;的采样方法，可以让我们只需要采样100个点，就可以让计算出来的结果很接近真实值了，这样就极大地减少了计算量。<br />
<span id="more-10022"></span><br />
而<span style="color:#0000ff;">重要性采样</span>（Importance Sampling），就是人们发现的、可以实现这个目的手段之一。</p>
<ul>
<li>
		<span style="background-color:#00ff00;">定义</span></li>
</ul>
<blockquote>
<p>
		重要性采样（Importance Sampling）是统计学中估计某一分布性质时使用的一种方法。该方法从与原分布不同的另一个分布中采样，而对原先分布的性质进行估计。</p>
</blockquote>
<p>乍一看，这句话可能有点抽象，别急，往后看你就理解了。</p>
<ul>
<li>
		<span style="background-color:#00ff00;">实例&#8212;&#8212;蒙特卡罗平均值法计算定积分</span></li>
</ul>
<p>在之前的文章中，我们已经见识过了用蒙特卡罗<span style="color:#0000ff;">投点法</span>计算定积分的过程，这里有另一个叫作&#8220;平均值法&#8221;的方法，由于它也是随机化的算法，因此，它也属于一种蒙特卡罗方法。<br />
<span style="color: rgb(255, 255, 255);">文章来源：</span><a href="https://www.codelast.com/" rel="noopener noreferrer" target="_blank"><span style="color: rgb(255, 255, 255);">https://www.codelast.com/</span></a><br />
我们来看看来自<a href="https://www.scratchapixel.com/lessons/mathematics-physics-for-computer-graphics/monte-carlo-methods-in-practice/monte-carlo-integration" rel="noopener noreferrer" target="_blank"><span style="background-color:#ffa07a;">scratchapixel.com</span></a>的一幅图：<br />
<span style="text-align: center; height: 212px;"><img decoding="async" alt="monte carlo calculate definite integral" src="https://www.codelast.com/wp-content/uploads/2017/12/monte_carlo_importance_sampling_integration_1.png" style="width: 670px; height: 212px;" /></span></p>
<p>这幅图表明了什么意思呢？我们知道，计算[a,b]内的定积分就是求曲线 f(x)、直线 x=a,x=b以及x轴围成的形状的面积，因此，如果我们在曲线上随机地选取N个点，计算如图所示的粉红色长方形面积之和，再求个平均，其实就得到了定积分的近似值。点的数量取得越多，这个平均值就越逼近定积分的真实值。<br />
用公式写出来就是：<br />
 <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_6729ad9b16ef416b8e9a493de61ad802.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="\frac{1}{N}\left[ {(b - a) \times f({X_1}) + (b - a) \times f({X_2}) + \cdots + (b - a) \times f({X_N})} \right] = \frac{{b - a}}{N}\sum\limits_{i = 1}^N {f({X_i})} " /></span><script type='math/tex'>\frac{1}{N}\left[ {(b - a) \times f({X_1}) + (b - a) \times f({X_2}) + \cdots + (b - a) \times f({X_N})} \right] = \frac{{b - a}}{N}\sum\limits_{i = 1}^N {f({X_i})} </script> <br />
<span style="color: rgb(255, 255, 255);">文章来源：</span><a href="https://www.codelast.com/" rel="noopener noreferrer" target="_blank"><span style="color: rgb(255, 255, 255);">https://www.codelast.com/</span></a>&#8230; <a href="https://www.codelast.com/%e5%8e%9f%e5%88%9b-%e9%87%8d%e8%a6%81%e6%80%a7%e9%87%87%e6%a0%b7%ef%bc%8fimportance-sampling/" class="read-more">Read More </a></p>]]></description>
										<content:encoded><![CDATA[<p>
查看本系列文章合集，请点击<a href="https://www.codelast.com/?p=9951" rel="noopener noreferrer" target="_blank"><span style="background-color: rgb(255, 160, 122);">这里</span></a>。</p>
<p>在前面的文章中，我们看到，随机采样是一个蒙特卡罗方法中很关键的步骤。而采样是需要技巧的，单纯地增加采样次数太没有效率了，比如说，如果随机采样一亿次，你可以把结果计算得特别精确，但是采样一亿次需要的时间非常长，长得远远超过了我们能接受的范围，这又有什么意义呢？<br />
人们发现，有一些方法可以让随机采的样本&ldquo;特别好&rdquo;。那么什么算&ldquo;特别好&rdquo;呢？比如说，本来使用没有任何原则的采样方法，需要采样1万个点，才能让计算出来的结果很接近真实值；现在使用一个&ldquo;特别好&rdquo;的采样方法，可以让我们只需要采样100个点，就可以让计算出来的结果很接近真实值了，这样就极大地减少了计算量。<br />
<span id="more-10022"></span><br />
而<span style="color:#0000ff;">重要性采样</span>（Importance Sampling），就是人们发现的、可以实现这个目的手段之一。</p>
<ul>
<li>
		<span style="background-color:#00ff00;">定义</span></li>
</ul>
<blockquote>
<p>
		重要性采样（Importance Sampling）是统计学中估计某一分布性质时使用的一种方法。该方法从与原分布不同的另一个分布中采样，而对原先分布的性质进行估计。</p>
</blockquote>
<p>乍一看，这句话可能有点抽象，别急，往后看你就理解了。</p>
<ul>
<li>
		<span style="background-color:#00ff00;">实例&mdash;&mdash;蒙特卡罗平均值法计算定积分</span></li>
</ul>
<p>在之前的文章中，我们已经见识过了用蒙特卡罗<span style="color:#0000ff;">投点法</span>计算定积分的过程，这里有另一个叫作&ldquo;平均值法&rdquo;的方法，由于它也是随机化的算法，因此，它也属于一种蒙特卡罗方法。<br />
<span style="color: rgb(255, 255, 255);">文章来源：</span><a href="https://www.codelast.com/" rel="noopener noreferrer" target="_blank"><span style="color: rgb(255, 255, 255);">https://www.codelast.com/</span></a><br />
我们来看看来自<a href="https://www.scratchapixel.com/lessons/mathematics-physics-for-computer-graphics/monte-carlo-methods-in-practice/monte-carlo-integration" rel="noopener noreferrer" target="_blank"><span style="background-color:#ffa07a;">scratchapixel.com</span></a>的一幅图：<br />
<span style="text-align: center; height: 212px;"><img decoding="async" alt="monte carlo calculate definite integral" src="https://www.codelast.com/wp-content/uploads/2017/12/monte_carlo_importance_sampling_integration_1.png" style="width: 670px; height: 212px;" /></span></p>
<p>这幅图表明了什么意思呢？我们知道，计算[a,b]内的定积分就是求曲线 f(x)、直线 x=a,x=b以及x轴围成的形状的面积，因此，如果我们在曲线上随机地选取N个点，计算如图所示的粉红色长方形面积之和，再求个平均，其实就得到了定积分的近似值。点的数量取得越多，这个平均值就越逼近定积分的真实值。<br />
用公式写出来就是：<br />
 <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_6729ad9b16ef416b8e9a493de61ad802.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="\frac{1}{N}\left[ {(b - a) \times f({X_1}) + (b - a) \times f({X_2}) + \cdots + (b - a) \times f({X_N})} \right] = \frac{{b - a}}{N}\sum\limits_{i = 1}^N {f({X_i})} " /></span><script type='math/tex'>\frac{1}{N}\left[ {(b - a) \times f({X_1}) + (b - a) \times f({X_2}) + \cdots + (b - a) \times f({X_N})} \right] = \frac{{b - a}}{N}\sum\limits_{i = 1}^N {f({X_i})} </script> <br />
<span style="color: rgb(255, 255, 255);">文章来源：</span><a href="https://www.codelast.com/" rel="noopener noreferrer" target="_blank"><span style="color: rgb(255, 255, 255);">https://www.codelast.com/</span></a><br />
现在来看一下蒙特卡罗积分的表达式：<br />
 <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_ca4826a1e89d7dcf370577224b5a94c8.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="{F^N} = \frac{1}{N}\sum\limits_{i = 1}^N {\frac{{f({X_i})}}{{p({X_i})}}} " /></span><script type='math/tex'>{F^N} = \frac{1}{N}\sum\limits_{i = 1}^N {\frac{{f({X_i})}}{{p({X_i})}}} </script> <br />
这个式子没有积分符号 <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_d4dfe9e9553b338ea11840e57f6345cd.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="\int {} " /></span><script type='math/tex'>\int {} </script> ，但是它却叫做&ldquo;积分&rdquo;公式，这是因为这个式子求的是积分的近似值&mdash;&mdash;当N越大的时候，计算出的值就越接近定积分的真实值。<br />
在公式中，有一个奇怪的东西，就是 <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_eddcdfcc218117c455e65c9d0d947b17.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="{p({X_i})}" /></span><script type='math/tex'>{p({X_i})}</script> ，它表示 <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_2af46b114c169c94ea9a86ca7b36758b.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="{{X_i}}" /></span><script type='math/tex'>{{X_i}}</script> 这个点，在某个分布下取 <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_2af46b114c169c94ea9a86ca7b36758b.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="{{X_i}}" /></span><script type='math/tex'>{{X_i}}</script> 这个值的概率。那么这个分布是什么呢？比如说，它能不能是简单的均匀分布？后面我们会看到，这个分布是我们自己选取的。<br />
既然是要随机采样N个点，那么是不是随便用什么样的策略去采样，都可以达到同样的效果呢？这里用一幅图来说明，采样也是要讲究策略的，否则效果会很差：<br />
<img decoding="async" alt="monte carlo calculate definite integral" src="https://www.codelast.com/wp-content/uploads/2017/12/monte_carlo_importance_sampling_integration_2.png" style="text-align: center; width: 580px; height: 401px;" /><br />
由于定积分值就是曲线下的面积，显然，如果我们采样的点恰巧大部分处于圆圈内，那么这些点下的面积之和必然比较小，此时，我们按前面所说的计算矩形面积的方法算得的积分值，是远远不能反映积分的真实值的。也就是说，圆圈处的点，对积分值的贡献小，靠近&nbsp; <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_118337530070f44bdf9c7cdeb8e35f9a.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="x = a" /></span><script type='math/tex'>x = a</script>  处的曲线上的点，对积分值的贡献大。<br />
所以，在实际采样的时候，靠近圆圈处的点应该少采一些，非圆圈处的点应该多采一些。<br />
这就是重要性采样（Importance Sampling）的概念由来了&mdash;&mdash;采样要按&ldquo;重要性&rdquo;来进行，不应该&ldquo;平等对待&rdquo;。<br />
如果采样恰到好处的话，可能只需要进行很少的采样（计算若干个点的函数值），就可以求出误差很小的积分值。</p>
<ul>
<li>
		<span style="background-color: rgb(0, 255, 0);">参考文献</span></li>
</ul>
<p>►&nbsp;<a href="https://zh.wikipedia.org/wiki/%E9%87%8D%E8%A6%81%E6%80%A7%E9%87%87%E6%A0%B7" rel="noopener noreferrer" target="_blank">维基百科：重要性采样</a><br />
►&nbsp;<a href="https://www.scratchapixel.com/lessons/mathematics-physics-for-computer-graphics/monte-carlo-methods-in-practice/monte-carlo-integration" rel="noopener noreferrer" target="_blank">scratchapixel.com：Monte Carlo Methods in Practice</a></p>
<p><span style="color: rgb(255, 255, 255);">文章来源：</span><a href="https://www.codelast.com/" rel="noopener noreferrer" target="_blank"><span style="color: rgb(255, 255, 255);">https://www.codelast.com/</span></a><br />
<span style="color: rgb(255, 0, 0);">➤➤</span>&nbsp;版权声明&nbsp;<span style="color: rgb(255, 0, 0);">➤➤</span>&nbsp;<br />
转载需注明出处：<u><a href="https://www.codelast.com/" rel="noopener noreferrer" target="_blank"><em><span style="color: rgb(0, 0, 255);"><strong style="font-size: 16px;"><span style="font-family: arial, helvetica, sans-serif;">codelast.com</span></strong></span></em></a></u>&nbsp;<br />
感谢关注我的微信公众号（微信扫一扫）：</p>
<p style="border: 0px; font-size: 13px; margin: 0px 0px 9px; outline: 0px; padding: 0px; color: rgb(77, 77, 77);">
	<img decoding="async" alt="wechat qrcode of codelast" src="https://www.codelast.com/codelast_wechat_qr_code.jpg" style="width: 200px; height: 200px;" /></p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.codelast.com/%e5%8e%9f%e5%88%9b-%e9%87%8d%e8%a6%81%e6%80%a7%e9%87%87%e6%a0%b7%ef%bc%8fimportance-sampling/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>[原创] 蒙特卡罗算法 对比 拉斯维加斯算法</title>
		<link>https://www.codelast.com/%e5%8e%9f%e5%88%9b-%e8%92%99%e7%89%b9%e5%8d%a1%e7%bd%97%e7%ae%97%e6%b3%95-%e5%af%b9%e6%af%94-%e6%8b%89%e6%96%af%e7%bb%b4%e5%8a%a0%e6%96%af%e7%ae%97%e6%b3%95/</link>
					<comments>https://www.codelast.com/%e5%8e%9f%e5%88%9b-%e8%92%99%e7%89%b9%e5%8d%a1%e7%bd%97%e7%ae%97%e6%b3%95-%e5%af%b9%e6%af%94-%e6%8b%89%e6%96%af%e7%bb%b4%e5%8a%a0%e6%96%af%e7%ae%97%e6%b3%95/#respond</comments>
		
		<dc:creator><![CDATA[learnhard]]></dc:creator>
		<pubDate>Thu, 11 Jul 2019 12:15:53 +0000</pubDate>
				<category><![CDATA[Algorithm]]></category>
		<category><![CDATA[Math]]></category>
		<category><![CDATA[原创]]></category>
		<category><![CDATA[Monte Carlo method]]></category>
		<category><![CDATA[蒙特卡洛方法]]></category>
		<category><![CDATA[蒙特卡罗方法]]></category>
		<guid isPermaLink="false">https://www.codelast.com/?p=10017</guid>

					<description><![CDATA[<p>
查看本系列文章合集，请点击<a href="https://www.codelast.com/?p=9951" rel="noopener noreferrer" target="_blank"><span style="background-color: rgb(255, 160, 122);">这里</span></a>。</p>
<ul>
<li>
		<span style="background-color:#00ff00;">区别</span></li>
</ul>
<p>讲到这里，稍微提一下，随机算法可以分为两类：蒙特卡洛算法 &#38; 拉斯维加斯算法。<br />
对蒙特卡洛算法来说，采样越多，越<span style="color:#0000ff;">近似最优解</span>。<br />
对拉斯维加斯算法来说，它永远给出正确解的随机化算法，总是给出正确结果，或是返回失败。<br />
<span id="more-10017"></span><br />
在固定的计算资源下，蒙特卡洛一定可以得到一个解，但拉斯维加斯不一定。<br />
<span style="color: rgb(255, 255, 255);">文章来源：</span><a href="https://www.codelast.com/" rel="noopener noreferrer" target="_blank"><span style="color: rgb(255, 255, 255);">https://www.codelast.com/</span></a></p>
<ul>
<li>
		<span style="background-color:#00ff00;">拉斯维加斯算法实例</span></li>
</ul>
<p>这里有一个很无趣的拉斯维加斯算法的例子：有10把钥匙，每次随机地取一把钥匙来开门，直到把门打开。如果只给你5次尝试的机会（在固定的计算资源下），那么可能能打开门（给出正确结果），也可能无法打开门（返回失败）。</p>
<p>当然，这个例子可能不能拿来套在蒙特卡罗算法身上，但这并不妨碍我们理解拉斯维加斯算法。</p>
<ul>
<li>
		<span style="background-color: rgb(0, 255, 0);">参考文献</span></li>
</ul>
<p>►&#160;<a href="https://zh.wikipedia.org/zh-hans/%E6%8B%89%E6%96%AF%E7%BB%B4%E5%8A%A0%E6%96%AF%E7%AE%97%E6%B3%95" rel="noopener noreferrer" target="_blank">维基百科：拉斯维加斯算法</a></p>
<p><span style="color: rgb(255, 255, 255);">文章来源：</span><a href="https://www.codelast.com/" rel="noopener noreferrer" target="_blank"><span style="color: rgb(255, 255, 255);">https://www.codelast.com/</span></a><br />
<span style="color: rgb(255, 0, 0);">➤➤</span>&#160;版权声明&#160;<span style="color: rgb(255, 0, 0);">➤➤</span>&#160;<br />
转载需注明出处：<u><a href="https://www.codelast.com/" rel="noopener noreferrer" target="_blank"><em><span style="color: rgb(0, 0, 255);"><strong style="font-size: 16px;"><span style="font-family: arial, helvetica, sans-serif;">codelast.com</span></strong></span></em></a></u>&#160;<br />
感谢关注我的微信公众号（微信扫一扫）：</p>
<p style="border: 0px; font-size: 13px; margin: 0px 0px 9px; outline: 0px; padding: 0px; color: rgb(77, 77, 77);">
	<img decoding="async" alt="wechat qrcode of codelast" src="https://www.codelast.com/codelast_wechat_qr_code.jpg" style="width: 200px; height: 200px;" />&#8230; <a href="https://www.codelast.com/%e5%8e%9f%e5%88%9b-%e8%92%99%e7%89%b9%e5%8d%a1%e7%bd%97%e7%ae%97%e6%b3%95-%e5%af%b9%e6%af%94-%e6%8b%89%e6%96%af%e7%bb%b4%e5%8a%a0%e6%96%af%e7%ae%97%e6%b3%95/" class="read-more">Read More </a></p>]]></description>
										<content:encoded><![CDATA[<p>
查看本系列文章合集，请点击<a href="https://www.codelast.com/?p=9951" rel="noopener noreferrer" target="_blank"><span style="background-color: rgb(255, 160, 122);">这里</span></a>。</p>
<ul>
<li>
		<span style="background-color:#00ff00;">区别</span></li>
</ul>
<p>讲到这里，稍微提一下，随机算法可以分为两类：蒙特卡洛算法 &amp; 拉斯维加斯算法。<br />
对蒙特卡洛算法来说，采样越多，越<span style="color:#0000ff;">近似最优解</span>。<br />
对拉斯维加斯算法来说，它永远给出正确解的随机化算法，总是给出正确结果，或是返回失败。<br />
<span id="more-10017"></span><br />
在固定的计算资源下，蒙特卡洛一定可以得到一个解，但拉斯维加斯不一定。<br />
<span style="color: rgb(255, 255, 255);">文章来源：</span><a href="https://www.codelast.com/" rel="noopener noreferrer" target="_blank"><span style="color: rgb(255, 255, 255);">https://www.codelast.com/</span></a></p>
<ul>
<li>
		<span style="background-color:#00ff00;">拉斯维加斯算法实例</span></li>
</ul>
<p>这里有一个很无趣的拉斯维加斯算法的例子：有10把钥匙，每次随机地取一把钥匙来开门，直到把门打开。如果只给你5次尝试的机会（在固定的计算资源下），那么可能能打开门（给出正确结果），也可能无法打开门（返回失败）。</p>
<p>当然，这个例子可能不能拿来套在蒙特卡罗算法身上，但这并不妨碍我们理解拉斯维加斯算法。</p>
<ul>
<li>
		<span style="background-color: rgb(0, 255, 0);">参考文献</span></li>
</ul>
<p>►&nbsp;<a href="https://zh.wikipedia.org/zh-hans/%E6%8B%89%E6%96%AF%E7%BB%B4%E5%8A%A0%E6%96%AF%E7%AE%97%E6%B3%95" rel="noopener noreferrer" target="_blank">维基百科：拉斯维加斯算法</a></p>
<p><span style="color: rgb(255, 255, 255);">文章来源：</span><a href="https://www.codelast.com/" rel="noopener noreferrer" target="_blank"><span style="color: rgb(255, 255, 255);">https://www.codelast.com/</span></a><br />
<span style="color: rgb(255, 0, 0);">➤➤</span>&nbsp;版权声明&nbsp;<span style="color: rgb(255, 0, 0);">➤➤</span>&nbsp;<br />
转载需注明出处：<u><a href="https://www.codelast.com/" rel="noopener noreferrer" target="_blank"><em><span style="color: rgb(0, 0, 255);"><strong style="font-size: 16px;"><span style="font-family: arial, helvetica, sans-serif;">codelast.com</span></strong></span></em></a></u>&nbsp;<br />
感谢关注我的微信公众号（微信扫一扫）：</p>
<p style="border: 0px; font-size: 13px; margin: 0px 0px 9px; outline: 0px; padding: 0px; color: rgb(77, 77, 77);">
	<img decoding="async" alt="wechat qrcode of codelast" src="https://www.codelast.com/codelast_wechat_qr_code.jpg" style="width: 200px; height: 200px;" /></p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.codelast.com/%e5%8e%9f%e5%88%9b-%e8%92%99%e7%89%b9%e5%8d%a1%e7%bd%97%e7%ae%97%e6%b3%95-%e5%af%b9%e6%af%94-%e6%8b%89%e6%96%af%e7%bb%b4%e5%8a%a0%e6%96%af%e7%ae%97%e6%b3%95/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>[原创] 蒙特卡罗方法的实例2：计算定积分</title>
		<link>https://www.codelast.com/%e5%8e%9f%e5%88%9b-%e8%92%99%e7%89%b9%e5%8d%a1%e7%bd%97%e6%96%b9%e6%b3%95%e7%9a%84%e5%ae%9e%e4%be%8b2%ef%bc%9a%e8%ae%a1%e7%ae%97%e5%ae%9a%e7%a7%af%e5%88%86/</link>
					<comments>https://www.codelast.com/%e5%8e%9f%e5%88%9b-%e8%92%99%e7%89%b9%e5%8d%a1%e7%bd%97%e6%96%b9%e6%b3%95%e7%9a%84%e5%ae%9e%e4%be%8b2%ef%bc%9a%e8%ae%a1%e7%ae%97%e5%ae%9a%e7%a7%af%e5%88%86/#respond</comments>
		
		<dc:creator><![CDATA[learnhard]]></dc:creator>
		<pubDate>Thu, 11 Jul 2019 12:14:19 +0000</pubDate>
				<category><![CDATA[Algorithm]]></category>
		<category><![CDATA[Math]]></category>
		<category><![CDATA[原创]]></category>
		<category><![CDATA[Monte Carlo method]]></category>
		<category><![CDATA[蒙特卡洛方法]]></category>
		<category><![CDATA[蒙特卡罗方法]]></category>
		<guid isPermaLink="false">https://www.codelast.com/?p=10003</guid>

					<description><![CDATA[<p>
查看本系列文章合集，请点击<a href="https://www.codelast.com/?p=9951" rel="noopener noreferrer" target="_blank"><span style="background-color: rgb(255, 160, 122);">这里</span></a>。</p>
<p>为了对蒙特卡罗方法有一个直观的印象，本文再举一个实例（计算定积分），以说明蒙特卡罗方法的用途。</p>
<ul>
<li>
		<span style="background-color:#00ff00;">什么是定积分</span></li>
</ul>
<blockquote>
<p>
		对于一个给定的正实值函数 <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_50bbd36e1fd2333108437a2ca378be62.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="f(x)" /></span><script type='math/tex'>f(x)</script> ，它在一个实数区间 [a,b]上的定积分 <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_950c163edd420ea5410013869ef03ca6.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="\int_a^b {f(x)dx} " /></span><script type='math/tex'>\int_a^b {f(x)dx} </script> 可以理解为在 OXY 坐标平面上，由曲线 (x,f(x))、直线 x=a,x=b以及x轴围成的曲边梯形的面积值。</p>
</blockquote>
<p><span id="more-10003"></span>如下图所示：<br />
<a href="https://www.codelast.com" rel="noopener noreferrer" style="text-align: center;" target="_blank"><img decoding="async" alt="monte carlo calculate definite integral" src="https://www.codelast.com/wp-content/uploads/2017/11/monte_carlo_example_calculate_definite_integral_1.png" style="width: 399px; height: 417px;" /></a><br />
<span style="color: rgb(255, 255, 255);">文章来源：</span><a href="https://www.codelast.com/" rel="noopener noreferrer" target="_blank"><span style="color: rgb(255, 255, 255);">https://www.codelast.com/</span></a></p>
<ul>
<li>
		<span style="background-color:#00ff00;">非蒙特卡罗方法</span></li>
</ul>
<p>其中一个计算定积分的方法就是用上面定积分的定义来求它：把面积均分成N个小矩形/梯形，求矩形/梯形面积之和。至于要分到多细才能良好地逼近定积分的真实值，我就不知道是否有什么理论上的说法了。</p>
<ul>
<li>
		<span style="background-color:#00ff00;">蒙特卡罗方法</span></li>
</ul>
<p>用蒙特卡罗方法来计算定积分，又分成好几种方法&#8212;&#8212;毕竟，蒙特卡罗方法是一类方法的统称，而不是指一种特定的方法。其中一种求定积分的蒙特卡罗方法，可以称之为<span style="color:#0000ff;">投点法</span>。和之前的文章中计算圆周率的做法类似，我们这里也用一个实际的函数  <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_990d8846cdb8bfba65b16bf6252a7dd6.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="y = {x^2}" /></span><script type='math/tex'>y = {x^2}</script>  来说明问题：<br />
<a href="https://www.codelast.com" rel="noopener noreferrer" style="text-align: center;" target="_blank"><img decoding="async" alt="monte carlo calculate definite integral" src="https://www.codelast.com/wp-content/uploads/2017/11/monte_carlo_example_calculate_definite_integral_2.png" style="width: 475px; height: 370px;" /></a><br />
<span style="color: rgb(255, 255, 255);">文章来源：</span><a href="https://www.codelast.com/" rel="noopener noreferrer" target="_blank"><span style="color: rgb(255, 255, 255);">https://www.codelast.com/</span></a><br />
假设要计算函数在在[0, 1]区间的积分，也就是求红色部分的面积。<br />
然后，在1x1的正方形里生成大量随机点（m个），计算出在红色区域内的点的个数n&#8212;&#8212;判断条件： <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_e799055323eb79d077c822461d7628ff.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="y < {x^2}" /></span><script type='math/tex'>y < {x^2}</script> <br />
最后，n/m 即为红色部分的面积，也就是所求的积分值。<br />
投点法只是其中一种计算定积分的蒙特卡罗方法，当然也是一种很简单的蒙特卡罗方法，另外还有更麻烦的<span style="color:#0000ff;">平均值法</span>求定积分&#8212;&#8212;可以利用特殊的<span style="color:#0000ff;">采样</span>技巧来提高计算效率，在后面的文章中会讲到。<br />
在后面的文章中， 还会解释采样和蒙特卡罗方法有什么关系，先不要急。</p>
<ul>
<li>
		<span style="background-color: rgb(0, 255, 0);">参考文献</span></li>
</ul>
<p>►&#160;<a href="https://zh.wikipedia.org/wiki/%E7%A7%AF%E5%88%86" rel="noopener noreferrer" target="_blank">维基百科：积分</a><br />
►&#160;<a href="http://www.ruanyifeng.com/blog/2015/07/monte-carlo-method.html" rel="noopener noreferrer" target="_blank">蒙特卡罗方法入门</a></p>
<p><span style="color: rgb(255, 255, 255);">文章来源：</span><a href="https://www.codelast.com/" rel="noopener noreferrer" target="_blank"><span style="color: rgb(255, 255, 255);">https://www.codelast.com/</span></a>&#8230; <a href="https://www.codelast.com/%e5%8e%9f%e5%88%9b-%e8%92%99%e7%89%b9%e5%8d%a1%e7%bd%97%e6%96%b9%e6%b3%95%e7%9a%84%e5%ae%9e%e4%be%8b2%ef%bc%9a%e8%ae%a1%e7%ae%97%e5%ae%9a%e7%a7%af%e5%88%86/" class="read-more">Read More </a></p>]]></description>
										<content:encoded><![CDATA[<p>
查看本系列文章合集，请点击<a href="https://www.codelast.com/?p=9951" rel="noopener noreferrer" target="_blank"><span style="background-color: rgb(255, 160, 122);">这里</span></a>。</p>
<p>为了对蒙特卡罗方法有一个直观的印象，本文再举一个实例（计算定积分），以说明蒙特卡罗方法的用途。</p>
<ul>
<li>
		<span style="background-color:#00ff00;">什么是定积分</span></li>
</ul>
<blockquote>
<p>
		对于一个给定的正实值函数 <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_50bbd36e1fd2333108437a2ca378be62.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="f(x)" /></span><script type='math/tex'>f(x)</script> ，它在一个实数区间 [a,b]上的定积分 <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_950c163edd420ea5410013869ef03ca6.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="\int_a^b {f(x)dx} " /></span><script type='math/tex'>\int_a^b {f(x)dx} </script> 可以理解为在 OXY 坐标平面上，由曲线 (x,f(x))、直线 x=a,x=b以及x轴围成的曲边梯形的面积值。</p>
</blockquote>
<p><span id="more-10003"></span>如下图所示：<br />
<a href="https://www.codelast.com" rel="noopener noreferrer" style="text-align: center;" target="_blank"><img decoding="async" alt="monte carlo calculate definite integral" src="https://www.codelast.com/wp-content/uploads/2017/11/monte_carlo_example_calculate_definite_integral_1.png" style="width: 399px; height: 417px;" /></a><br />
<span style="color: rgb(255, 255, 255);">文章来源：</span><a href="https://www.codelast.com/" rel="noopener noreferrer" target="_blank"><span style="color: rgb(255, 255, 255);">https://www.codelast.com/</span></a></p>
<ul>
<li>
		<span style="background-color:#00ff00;">非蒙特卡罗方法</span></li>
</ul>
<p>其中一个计算定积分的方法就是用上面定积分的定义来求它：把面积均分成N个小矩形/梯形，求矩形/梯形面积之和。至于要分到多细才能良好地逼近定积分的真实值，我就不知道是否有什么理论上的说法了。</p>
<ul>
<li>
		<span style="background-color:#00ff00;">蒙特卡罗方法</span></li>
</ul>
<p>用蒙特卡罗方法来计算定积分，又分成好几种方法&mdash;&mdash;毕竟，蒙特卡罗方法是一类方法的统称，而不是指一种特定的方法。其中一种求定积分的蒙特卡罗方法，可以称之为<span style="color:#0000ff;">投点法</span>。和之前的文章中计算圆周率的做法类似，我们这里也用一个实际的函数  <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_990d8846cdb8bfba65b16bf6252a7dd6.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="y = {x^2}" /></span><script type='math/tex'>y = {x^2}</script>  来说明问题：<br />
<a href="https://www.codelast.com" rel="noopener noreferrer" style="text-align: center;" target="_blank"><img decoding="async" alt="monte carlo calculate definite integral" src="https://www.codelast.com/wp-content/uploads/2017/11/monte_carlo_example_calculate_definite_integral_2.png" style="width: 475px; height: 370px;" /></a><br />
<span style="color: rgb(255, 255, 255);">文章来源：</span><a href="https://www.codelast.com/" rel="noopener noreferrer" target="_blank"><span style="color: rgb(255, 255, 255);">https://www.codelast.com/</span></a><br />
假设要计算函数在在[0, 1]区间的积分，也就是求红色部分的面积。<br />
然后，在1x1的正方形里生成大量随机点（m个），计算出在红色区域内的点的个数n&mdash;&mdash;判断条件： <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_e799055323eb79d077c822461d7628ff.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="y < {x^2}" /></span><script type='math/tex'>y < {x^2}</script> <br />
最后，n/m 即为红色部分的面积，也就是所求的积分值。<br />
投点法只是其中一种计算定积分的蒙特卡罗方法，当然也是一种很简单的蒙特卡罗方法，另外还有更麻烦的<span style="color:#0000ff;">平均值法</span>求定积分&mdash;&mdash;可以利用特殊的<span style="color:#0000ff;">采样</span>技巧来提高计算效率，在后面的文章中会讲到。<br />
在后面的文章中， 还会解释采样和蒙特卡罗方法有什么关系，先不要急。</p>
<ul>
<li>
		<span style="background-color: rgb(0, 255, 0);">参考文献</span></li>
</ul>
<p>►&nbsp;<a href="https://zh.wikipedia.org/wiki/%E7%A7%AF%E5%88%86" rel="noopener noreferrer" target="_blank">维基百科：积分</a><br />
►&nbsp;<a href="http://www.ruanyifeng.com/blog/2015/07/monte-carlo-method.html" rel="noopener noreferrer" target="_blank">蒙特卡罗方法入门</a></p>
<p><span style="color: rgb(255, 255, 255);">文章来源：</span><a href="https://www.codelast.com/" rel="noopener noreferrer" target="_blank"><span style="color: rgb(255, 255, 255);">https://www.codelast.com/</span></a><br />
<span style="color: rgb(255, 0, 0);">➤➤</span>&nbsp;版权声明&nbsp;<span style="color: rgb(255, 0, 0);">➤➤</span>&nbsp;<br />
转载需注明出处：<u><a href="https://www.codelast.com/" rel="noopener noreferrer" target="_blank"><em><span style="color: rgb(0, 0, 255);"><strong style="font-size: 16px;"><span style="font-family: arial, helvetica, sans-serif;">codelast.com</span></strong></span></em></a></u>&nbsp;<br />
感谢关注我的微信公众号（微信扫一扫）：</p>
<p style="border: 0px; font-size: 13px; margin: 0px 0px 9px; outline: 0px; padding: 0px; color: rgb(77, 77, 77);">
	<img decoding="async" alt="wechat qrcode of codelast" src="https://www.codelast.com/codelast_wechat_qr_code.jpg" style="width: 200px; height: 200px;" /></p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.codelast.com/%e5%8e%9f%e5%88%9b-%e8%92%99%e7%89%b9%e5%8d%a1%e7%bd%97%e6%96%b9%e6%b3%95%e7%9a%84%e5%ae%9e%e4%be%8b2%ef%bc%9a%e8%ae%a1%e7%ae%97%e5%ae%9a%e7%a7%af%e5%88%86/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>[原创] 蒙特卡罗方法的定义、历史以及存在意义</title>
		<link>https://www.codelast.com/%e5%8e%9f%e5%88%9b-%e8%92%99%e7%89%b9%e5%8d%a1%e7%bd%97%e6%96%b9%e6%b3%95%e7%9a%84%e5%ae%9a%e4%b9%89%e3%80%81%e5%8e%86%e5%8f%b2%e4%bb%a5%e5%8f%8a%e5%ad%98%e5%9c%a8%e6%84%8f%e4%b9%89/</link>
					<comments>https://www.codelast.com/%e5%8e%9f%e5%88%9b-%e8%92%99%e7%89%b9%e5%8d%a1%e7%bd%97%e6%96%b9%e6%b3%95%e7%9a%84%e5%ae%9a%e4%b9%89%e3%80%81%e5%8e%86%e5%8f%b2%e4%bb%a5%e5%8f%8a%e5%ad%98%e5%9c%a8%e6%84%8f%e4%b9%89/#respond</comments>
		
		<dc:creator><![CDATA[learnhard]]></dc:creator>
		<pubDate>Thu, 11 Jul 2019 12:06:23 +0000</pubDate>
				<category><![CDATA[Algorithm]]></category>
		<category><![CDATA[Math]]></category>
		<category><![CDATA[原创]]></category>
		<category><![CDATA[Monte Carlo method]]></category>
		<category><![CDATA[蒙特卡洛方法]]></category>
		<category><![CDATA[蒙特卡罗方法]]></category>
		<guid isPermaLink="false">https://www.codelast.com/?p=9963</guid>

					<description><![CDATA[<p>
查看本系列文章合集，请点击<a href="https://www.codelast.com/?p=9951" rel="noopener noreferrer" target="_blank"><span style="background-color:#ffa07a;">这里</span></a>。</p>
<ul>
<li>
		<span style="background-color:#00ff00;">定义</span></li>
</ul>
<p>来自维基百科：</p>
<blockquote>
<p>
		蒙特卡罗（洛）方法（Monte Carlo method），也称统计模拟方法，是1940年代中期由于科学技术的发展和电子计算机的发明，而提出的一种以概率统计理论为指导的数值计算方法。是指使用随机数来解决很多计算问题的方法。</p>
</blockquote>
<p>也就是说，蒙特卡罗方法并不是指一种特定的算法，而是一类算法的总称，这种算法主要利用了&#8220;随机&#8221;来实现。<span id="more-9963"></span></p>
<ul>
<li>
		<span style="background-color:#00ff00;">历史</span></li>
</ul>
<p>说到蒙特卡罗，这个名字是不是似曾相识？其实，它是摩纳哥大公国的一座城市，以蒙特卡洛大赌场闻名全球，始建于1858年。</p>
<div style="text-align: center;">
	<a href="https://www.codelast.com" rel="noopener noreferrer" target="_blank"><img decoding="async" alt="monte carlo casino" src="https://www.codelast.com/wp-content/uploads/2017/11/monte_carlo_casino_night_view.jpg" style="width: 646px; height: 358px;" /></a></div>
<div style="text-align: center;">
	(蒙特卡罗大赌场)</div>
<p><span style="color: rgb(255, 255, 255);">文章来源：</span><a href="https://www.codelast.com/" rel="noopener noreferrer" target="_blank"><span style="color: rgb(255, 255, 255);">https://www.codelast.com/</span></a><br />
摩纳哥大公国是一个位于欧洲的城邦国家，它也是世界上面积第二小的国家。<br />
这个国家比较神奇的一点是，本地的摩纳哥人在他们自己的国家是&#8220;少数派&#8221;&#8212;&#8212;人口最多的是法国人，占32%，本地的摩纳哥人只占19%。<br />
摩纳哥还有很多与众不同的特点：不需要缴纳个人收入所得税，它是世界上最富裕最文明的国家（之一？），全世界很多富人都生活在这里。<br />
<span style="color: rgb(255, 255, 255);">文章来源：</span><a href="https://www.codelast.com/" rel="noopener noreferrer" target="_blank"><span style="color: rgb(255, 255, 255);">https://www.codelast.com/</span></a><br />
回到主题，蒙特卡罗方法和摩纳哥的蒙特卡罗这座城市有什么关系？<br />
说到这个，就不得不提蒙特卡罗方法的发明人&#8212;&#8212;冯&#183;诺伊曼、斯塔尼斯拉夫&#183;乌拉姆（数学家）、尼古拉斯&#183;梅特罗波利斯（物理学家），一般认为是这3人在194x年发明了蒙特卡罗方法。其中，乌拉姆的叔叔经常在蒙特卡洛赌场输钱，而蒙特卡洛方法正是以概率为基础的方法，因此得名。</p>
<ul>
<li>
		<span style="background-color:#00ff00;">意义</span></li>
</ul>
<div>
	蒙特卡罗方法的现实意义在于，很多问题计算量太大，难以遍历所有可能性来求解，通过采样，我们可以在短时间内求得近似解。<br />
	&#160;</div>
<ul>
<li>
		<span style="background-color:#00ff00;">参考文献</span></li>
</ul>
<p>► <a href="https://zh.wikipedia.org/wiki/%E8%92%99%E5%9C%B0%E5%8D%A1%E7%BE%85%E6%96%B9%E6%B3%95" rel="noopener noreferrer" target="_blank">维基百科：蒙特卡罗方法</a><br />
► <a href="https://zh.wikipedia.org/wiki/%E6%91%A9%E7%BA%B3%E5%93%A5" rel="noopener noreferrer" target="_blank">维基百科：摩纳哥</a></p>
<p><span style="color: rgb(255, 255, 255);">文章来源：</span><a href="https://www.codelast.com/" rel="noopener noreferrer" target="_blank"><span style="color: rgb(255, 255, 255);">https://www.codelast.com/</span></a><br />
<span style="color: rgb(255, 0, 0);">➤➤</span>&#160;版权声明&#160;<span style="color: rgb(255, 0, 0);">➤➤</span>&#160;<br />
转载需注明出处：<u><a href="https://www.codelast.com/" rel="noopener noreferrer" target="_blank"><em><span style="color: rgb(0, 0, 255);"><strong style="font-size: 16px;"><span style="font-family: arial, helvetica, sans-serif;">codelast.com</span></strong></span></em></a></u>&#160;<br />
感谢关注我的微信公众号（微信扫一扫）：</p>
<p style="border: 0px; font-size: 13px; margin: 0px 0px 9px; outline: 0px; padding: 0px; color: rgb(77, 77, 77);">
	<img decoding="async" alt="wechat qrcode of codelast" src="https://www.codelast.com/codelast_wechat_qr_code.jpg" style="width: 200px; height: 200px;" />&#8230; <a href="https://www.codelast.com/%e5%8e%9f%e5%88%9b-%e8%92%99%e7%89%b9%e5%8d%a1%e7%bd%97%e6%96%b9%e6%b3%95%e7%9a%84%e5%ae%9a%e4%b9%89%e3%80%81%e5%8e%86%e5%8f%b2%e4%bb%a5%e5%8f%8a%e5%ad%98%e5%9c%a8%e6%84%8f%e4%b9%89/" class="read-more">Read More </a></p>]]></description>
										<content:encoded><![CDATA[<p>
查看本系列文章合集，请点击<a href="https://www.codelast.com/?p=9951" rel="noopener noreferrer" target="_blank"><span style="background-color:#ffa07a;">这里</span></a>。</p>
<ul>
<li>
		<span style="background-color:#00ff00;">定义</span></li>
</ul>
<p>来自维基百科：</p>
<blockquote>
<p>
		蒙特卡罗（洛）方法（Monte Carlo method），也称统计模拟方法，是1940年代中期由于科学技术的发展和电子计算机的发明，而提出的一种以概率统计理论为指导的数值计算方法。是指使用随机数来解决很多计算问题的方法。</p>
</blockquote>
<p>也就是说，蒙特卡罗方法并不是指一种特定的算法，而是一类算法的总称，这种算法主要利用了&ldquo;随机&rdquo;来实现。<span id="more-9963"></span></p>
<ul>
<li>
		<span style="background-color:#00ff00;">历史</span></li>
</ul>
<p>说到蒙特卡罗，这个名字是不是似曾相识？其实，它是摩纳哥大公国的一座城市，以蒙特卡洛大赌场闻名全球，始建于1858年。</p>
<div style="text-align: center;">
	<a href="https://www.codelast.com" rel="noopener noreferrer" target="_blank"><img decoding="async" alt="monte carlo casino" src="https://www.codelast.com/wp-content/uploads/2017/11/monte_carlo_casino_night_view.jpg" style="width: 646px; height: 358px;" /></a></div>
<div style="text-align: center;">
	(蒙特卡罗大赌场)</div>
<p><span style="color: rgb(255, 255, 255);">文章来源：</span><a href="https://www.codelast.com/" rel="noopener noreferrer" target="_blank"><span style="color: rgb(255, 255, 255);">https://www.codelast.com/</span></a><br />
摩纳哥大公国是一个位于欧洲的城邦国家，它也是世界上面积第二小的国家。<br />
这个国家比较神奇的一点是，本地的摩纳哥人在他们自己的国家是&ldquo;少数派&rdquo;&mdash;&mdash;人口最多的是法国人，占32%，本地的摩纳哥人只占19%。<br />
摩纳哥还有很多与众不同的特点：不需要缴纳个人收入所得税，它是世界上最富裕最文明的国家（之一？），全世界很多富人都生活在这里。<br />
<span style="color: rgb(255, 255, 255);">文章来源：</span><a href="https://www.codelast.com/" rel="noopener noreferrer" target="_blank"><span style="color: rgb(255, 255, 255);">https://www.codelast.com/</span></a><br />
回到主题，蒙特卡罗方法和摩纳哥的蒙特卡罗这座城市有什么关系？<br />
说到这个，就不得不提蒙特卡罗方法的发明人&mdash;&mdash;冯&middot;诺伊曼、斯塔尼斯拉夫&middot;乌拉姆（数学家）、尼古拉斯&middot;梅特罗波利斯（物理学家），一般认为是这3人在194x年发明了蒙特卡罗方法。其中，乌拉姆的叔叔经常在蒙特卡洛赌场输钱，而蒙特卡洛方法正是以概率为基础的方法，因此得名。</p>
<ul>
<li>
		<span style="background-color:#00ff00;">意义</span></li>
</ul>
<div>
	蒙特卡罗方法的现实意义在于，很多问题计算量太大，难以遍历所有可能性来求解，通过采样，我们可以在短时间内求得近似解。<br />
	&nbsp;</div>
<ul>
<li>
		<span style="background-color:#00ff00;">参考文献</span></li>
</ul>
<p>► <a href="https://zh.wikipedia.org/wiki/%E8%92%99%E5%9C%B0%E5%8D%A1%E7%BE%85%E6%96%B9%E6%B3%95" rel="noopener noreferrer" target="_blank">维基百科：蒙特卡罗方法</a><br />
► <a href="https://zh.wikipedia.org/wiki/%E6%91%A9%E7%BA%B3%E5%93%A5" rel="noopener noreferrer" target="_blank">维基百科：摩纳哥</a></p>
<p><span style="color: rgb(255, 255, 255);">文章来源：</span><a href="https://www.codelast.com/" rel="noopener noreferrer" target="_blank"><span style="color: rgb(255, 255, 255);">https://www.codelast.com/</span></a><br />
<span style="color: rgb(255, 0, 0);">➤➤</span>&nbsp;版权声明&nbsp;<span style="color: rgb(255, 0, 0);">➤➤</span>&nbsp;<br />
转载需注明出处：<u><a href="https://www.codelast.com/" rel="noopener noreferrer" target="_blank"><em><span style="color: rgb(0, 0, 255);"><strong style="font-size: 16px;"><span style="font-family: arial, helvetica, sans-serif;">codelast.com</span></strong></span></em></a></u>&nbsp;<br />
感谢关注我的微信公众号（微信扫一扫）：</p>
<p style="border: 0px; font-size: 13px; margin: 0px 0px 9px; outline: 0px; padding: 0px; color: rgb(77, 77, 77);">
	<img decoding="async" alt="wechat qrcode of codelast" src="https://www.codelast.com/codelast_wechat_qr_code.jpg" style="width: 200px; height: 200px;" /></p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.codelast.com/%e5%8e%9f%e5%88%9b-%e8%92%99%e7%89%b9%e5%8d%a1%e7%bd%97%e6%96%b9%e6%b3%95%e7%9a%84%e5%ae%9a%e4%b9%89%e3%80%81%e5%8e%86%e5%8f%b2%e4%bb%a5%e5%8f%8a%e5%ad%98%e5%9c%a8%e6%84%8f%e4%b9%89/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>[原创] 用人话解释蒙特卡罗方法/Monte Carlo method(文章合集)</title>
		<link>https://www.codelast.com/%e5%8e%9f%e5%88%9b-%e7%94%a8%e4%ba%ba%e8%af%9d%e8%a7%a3%e9%87%8a%e8%92%99%e7%89%b9%e5%8d%a1%e7%bd%97%e6%96%b9%e6%b3%95-monte-carlo-method%e6%96%87%e7%ab%a0%e5%90%88%e9%9b%86/</link>
					<comments>https://www.codelast.com/%e5%8e%9f%e5%88%9b-%e7%94%a8%e4%ba%ba%e8%af%9d%e8%a7%a3%e9%87%8a%e8%92%99%e7%89%b9%e5%8d%a1%e7%bd%97%e6%96%b9%e6%b3%95-monte-carlo-method%e6%96%87%e7%ab%a0%e5%90%88%e9%9b%86/#respond</comments>
		
		<dc:creator><![CDATA[learnhard]]></dc:creator>
		<pubDate>Thu, 11 Jul 2019 12:03:56 +0000</pubDate>
				<category><![CDATA[Algorithm]]></category>
		<category><![CDATA[Math]]></category>
		<category><![CDATA[原创]]></category>
		<category><![CDATA[Monte Carlo method]]></category>
		<category><![CDATA[蒙特卡洛方法]]></category>
		<category><![CDATA[蒙特卡罗方法]]></category>
		<guid isPermaLink="false">https://www.codelast.com/?p=9951</guid>

					<description><![CDATA[<p>
蒙特卡罗(洛)方法（Monte Carlo method），也称统计模拟方法，是1940年代中期由于科学技术的发展和电子计算机的发明，而提出的一种以概率统计理论为指导的数值计算方法。是指使用随机数来解决很多计算问题的方法。<br />
<span id="more-9951"></span><br />
下面的系列文章是《Deep Learning Book》一书第17章的部分肤浅读书笔记。由于本人理论水平有限，我认为满是公式、基本没有实例的《Deep Learning Book》第17章&#8220;很难看&#8221;、不利于学习。因此，我根据第17章的章节结构，自己去查阅了一些其他资料，找到了很多实例来写成了这些文章，我认为对初学者来说，它们可以让人更容易看懂。<br />
不过，还是需要事先声明，这些文章中的某些陈述，是我个人的理解，本人水平有限，难免会有各种错误，请自行辨别。</p>
<p><span style="background-color: rgb(0, 255, 0);">➤&#160;</span><a href="https://www.codelast.com/?p=9963" target="_blank" rel="noopener noreferrer">蒙特卡罗方法的定义、历史以及存在意义</a></p>
<p><span style="background-color: rgb(0, 255, 0);">➤&#160;</span><a href="https://www.codelast.com/?p=9983" target="_blank" rel="noopener noreferrer">蒙特卡罗方法的实例1：计算圆周率</a></p>
<p><span style="background-color: rgb(0, 255, 0);">➤&#160;</span><a href="https://www.codelast.com/?p=10003" target="_blank" rel="noopener noreferrer">蒙特卡罗方法的实例2：计算定积分</a></p>
<p><span style="background-color: rgb(0, 255, 0);">➤&#160;</span><a href="https://www.codelast.com/?p=10017" target="_blank" rel="noopener noreferrer">蒙特卡罗算法 对比 拉斯维加斯算法</a></p>
<p><span style="background-color: rgb(0, 255, 0);">➤&#160;</span><a href="https://www.codelast.com/?p=10022" target="_blank" rel="noopener noreferrer">重要性采样／Importance Sampling</a></p>
<p><span style="background-color: rgb(0, 255, 0);">➤&#160;</span>马尔科夫链蒙特卡罗／Markov chain Monte Carlo, MCMC</p>
<p><span style="background-color: rgb(0, 255, 0);">➤&#160;</span>马尔科夫链／Markov chain</p>
<p><span style="background-color: rgb(0, 255, 0);">➤&#160;</span>马尔科夫链的平稳分布</p>
<div>
	<span style="background-color: rgb(0, 255, 0);">➤&#160;</span>马尔科夫链的细致平稳条件／Detailed Balance
<p>	<span style="background-color: rgb(0, 255, 0);">➤&#160;</span>马尔科夫链的接受率／Acceptance Probability</p>
<p>	<span style="background-color: rgb(0, 255, 0);">➤&#160;</span>标准MCMC算法实现及其存在的问题</p>
<p>	<span style="background-color: rgb(0, 255, 0);">➤&#160;</span>Metropolis Hastings MCMC算法</p>
<p>	<span style="background-color: rgb(0, 255, 0);">➤&#160;</span>吉布斯采样／Gibbs Sampling</p></div>
<div>
	<br />
	<span style="color: rgb(255, 255, 255);">文章来源：</span><a href="https://www.codelast.com/" rel="noopener noreferrer" target="_blank"><span style="color: rgb(255, 255, 255);">https://www.codelast.com/</span></a></div>&#8230; <a href="https://www.codelast.com/%e5%8e%9f%e5%88%9b-%e7%94%a8%e4%ba%ba%e8%af%9d%e8%a7%a3%e9%87%8a%e8%92%99%e7%89%b9%e5%8d%a1%e7%bd%97%e6%96%b9%e6%b3%95-monte-carlo-method%e6%96%87%e7%ab%a0%e5%90%88%e9%9b%86/" class="read-more">Read More </a>]]></description>
										<content:encoded><![CDATA[<p>
蒙特卡罗(洛)方法（Monte Carlo method），也称统计模拟方法，是1940年代中期由于科学技术的发展和电子计算机的发明，而提出的一种以概率统计理论为指导的数值计算方法。是指使用随机数来解决很多计算问题的方法。<br />
<span id="more-9951"></span><br />
下面的系列文章是《Deep Learning Book》一书第17章的部分肤浅读书笔记。由于本人理论水平有限，我认为满是公式、基本没有实例的《Deep Learning Book》第17章&ldquo;很难看&rdquo;、不利于学习。因此，我根据第17章的章节结构，自己去查阅了一些其他资料，找到了很多实例来写成了这些文章，我认为对初学者来说，它们可以让人更容易看懂。<br />
不过，还是需要事先声明，这些文章中的某些陈述，是我个人的理解，本人水平有限，难免会有各种错误，请自行辨别。</p>
<p><span style="background-color: rgb(0, 255, 0);">➤&nbsp;</span><a href="https://www.codelast.com/?p=9963" target="_blank" rel="noopener noreferrer">蒙特卡罗方法的定义、历史以及存在意义</a></p>
<p><span style="background-color: rgb(0, 255, 0);">➤&nbsp;</span><a href="https://www.codelast.com/?p=9983" target="_blank" rel="noopener noreferrer">蒙特卡罗方法的实例1：计算圆周率</a></p>
<p><span style="background-color: rgb(0, 255, 0);">➤&nbsp;</span><a href="https://www.codelast.com/?p=10003" target="_blank" rel="noopener noreferrer">蒙特卡罗方法的实例2：计算定积分</a></p>
<p><span style="background-color: rgb(0, 255, 0);">➤&nbsp;</span><a href="https://www.codelast.com/?p=10017" target="_blank" rel="noopener noreferrer">蒙特卡罗算法 对比 拉斯维加斯算法</a></p>
<p><span style="background-color: rgb(0, 255, 0);">➤&nbsp;</span><a href="https://www.codelast.com/?p=10022" target="_blank" rel="noopener noreferrer">重要性采样／Importance Sampling</a></p>
<p><span style="background-color: rgb(0, 255, 0);">➤&nbsp;</span>马尔科夫链蒙特卡罗／Markov chain Monte Carlo, MCMC</p>
<p><span style="background-color: rgb(0, 255, 0);">➤&nbsp;</span>马尔科夫链／Markov chain</p>
<p><span style="background-color: rgb(0, 255, 0);">➤&nbsp;</span>马尔科夫链的平稳分布</p>
<div>
	<span style="background-color: rgb(0, 255, 0);">➤&nbsp;</span>马尔科夫链的细致平稳条件／Detailed Balance</p>
<p>	<span style="background-color: rgb(0, 255, 0);">➤&nbsp;</span>马尔科夫链的接受率／Acceptance Probability</p>
<p>	<span style="background-color: rgb(0, 255, 0);">➤&nbsp;</span>标准MCMC算法实现及其存在的问题</p>
<p>	<span style="background-color: rgb(0, 255, 0);">➤&nbsp;</span>Metropolis Hastings MCMC算法</p>
<p>	<span style="background-color: rgb(0, 255, 0);">➤&nbsp;</span>吉布斯采样／Gibbs Sampling</div>
<div>
	<br />
	<span style="color: rgb(255, 255, 255);">文章来源：</span><a href="https://www.codelast.com/" rel="noopener noreferrer" target="_blank"><span style="color: rgb(255, 255, 255);">https://www.codelast.com/</span></a><br />
	<span style="color: rgb(255, 0, 0);">➤➤</span>&nbsp;版权声明&nbsp;<span style="color: rgb(255, 0, 0);">➤➤</span>&nbsp;<br />
	转载需注明出处：<u><a href="https://www.codelast.com/" rel="noopener noreferrer" target="_blank"><em><span style="color: rgb(0, 0, 255);"><strong style="font-size: 16px;"><span style="font-family: arial, helvetica, sans-serif;">codelast.com</span></strong></span></em></a></u>&nbsp;<br />
	感谢关注我的微信公众号（微信扫一扫）：</p>
<p style="border: 0px; font-size: 13px; margin: 0px 0px 9px; outline: 0px; padding: 0px; color: rgb(77, 77, 77);">
		<img decoding="async" alt="wechat qrcode of codelast" src="https://www.codelast.com/codelast_wechat_qr_code.jpg" style="width: 200px; height: 200px;" /></p>
</div>
]]></content:encoded>
					
					<wfw:commentRss>https://www.codelast.com/%e5%8e%9f%e5%88%9b-%e7%94%a8%e4%ba%ba%e8%af%9d%e8%a7%a3%e9%87%8a%e8%92%99%e7%89%b9%e5%8d%a1%e7%bd%97%e6%96%b9%e6%b3%95-monte-carlo-method%e6%96%87%e7%ab%a0%e5%90%88%e9%9b%86/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>[原创] 蒙特卡罗方法的实例1：计算圆周率</title>
		<link>https://www.codelast.com/%e5%8e%9f%e5%88%9b-%e8%92%99%e7%89%b9%e5%8d%a1%e7%bd%97%e6%96%b9%e6%b3%95%e7%9a%84%e5%ae%9e%e4%be%8b1%ef%bc%9a%e8%ae%a1%e7%ae%97%e5%9c%86%e5%91%a8%e7%8e%87/</link>
					<comments>https://www.codelast.com/%e5%8e%9f%e5%88%9b-%e8%92%99%e7%89%b9%e5%8d%a1%e7%bd%97%e6%96%b9%e6%b3%95%e7%9a%84%e5%ae%9e%e4%be%8b1%ef%bc%9a%e8%ae%a1%e7%ae%97%e5%9c%86%e5%91%a8%e7%8e%87/#respond</comments>
		
		<dc:creator><![CDATA[learnhard]]></dc:creator>
		<pubDate>Wed, 22 Nov 2017 16:02:18 +0000</pubDate>
				<category><![CDATA[Algorithm]]></category>
		<category><![CDATA[Math]]></category>
		<category><![CDATA[原创]]></category>
		<category><![CDATA[Monte Carlo method]]></category>
		<category><![CDATA[蒙特卡洛方法]]></category>
		<category><![CDATA[蒙特卡罗方法]]></category>
		<guid isPermaLink="false">https://www.codelast.com/?p=9983</guid>

					<description><![CDATA[<p>
查看本系列文章合集，请点击<a href="https://www.codelast.com/?p=9951" rel="noopener noreferrer" target="_blank"><span style="background-color: rgb(255, 160, 122);">这里</span></a>。</p>
<p>为了对蒙特卡罗方法有一个直观的印象，我们先举一个实例（计算圆周率 <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_522359592d78569a9eac16498aa7a087.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="\pi " /></span><script type='math/tex'>\pi </script> ），让从来没有接触过蒙特卡罗方法的人产生&#8220;原来这就是Monte Carlo&#8221;的感觉，以减少刚开始学习的困惑。</p>
<ul>
<li>
		<span style="background-color:#00ff00;">非蒙特卡罗方法</span></li>
</ul>
<p>圆周率 <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_522359592d78569a9eac16498aa7a087.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="\pi " /></span><script type='math/tex'>\pi </script> 可以怎么计算？其中一个&#8220;常规&#8221;的方法就是利用 <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_522359592d78569a9eac16498aa7a087.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="\pi " /></span><script type='math/tex'>\pi </script> 的莱布尼茨公式：<br />
 <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_aef37fd61f243ce0d16aadd617fe03c7.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="\frac{\pi }{4} = \sum\limits_{n = 0}^\infty {\frac{{{{\left( { - 1} \right)}^n}}}{{2n + 1}}} = 1 - \frac{1}{3} + \frac{1}{5} - \frac{1}{7} + \frac{1}{9} - \cdots " /></span><script type='math/tex'>\frac{\pi }{4} = \sum\limits_{n = 0}^\infty {\frac{{{{\left( { - 1} \right)}^n}}}{{2n + 1}}} = 1 - \frac{1}{3} + \frac{1}{5} - \frac{1}{7} + \frac{1}{9} - \cdots </script> <br />
不断增大 <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_7b8b965ad4bca0e41ab51de7b31363a1.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="n" /></span><script type='math/tex'>n</script> 的值，就能越来越逼近 <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_9c05e99783ffbdc89e86bee35eb07484.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="\frac{\pi }{4}" /></span><script type='math/tex'>\frac{\pi }{4}</script> <span id="more-9983"></span><br />
当 <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_7b8b965ad4bca0e41ab51de7b31363a1.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="n" /></span><script type='math/tex'>n</script> 的最大值取30000时，可以计算得  <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_5ff097626c52b389d39054bca2cab608.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="\pi = 3.141559320256462" /></span><script type='math/tex'>\pi = 3.141559320256462</script> </p>
<ul>
<li>
		<span style="background-color:#00ff00;">蒙特卡罗方法</span></li>
</ul>
<p>相比之下，用蒙特卡罗方法来计算 <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_522359592d78569a9eac16498aa7a087.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="\pi " /></span><script type='math/tex'>\pi </script> ，可能就是一个比较&#8220;另类&#8221;的途径了。<br />
假设圆外部有一个相切的正方形，如下图所示：<br />
<a href="https://www.codelast.com" rel="noopener noreferrer" target="_blank"><img decoding="async" alt="monte carlo method calculate pi example" src="https://www.codelast.com/wp-content/uploads/2017/11/monte_carlo_example_calculate_pi_1.png" style="width: 255px; height: 210px;" /></a><br />
<span style="color: rgb(255, 255, 255);">文章来源：</span><a href="https://www.codelast.com/" rel="noopener noreferrer" target="_blank"><span style="color: rgb(255, 255, 255);">https://www.codelast.com/</span></a>&#8230; <a href="https://www.codelast.com/%e5%8e%9f%e5%88%9b-%e8%92%99%e7%89%b9%e5%8d%a1%e7%bd%97%e6%96%b9%e6%b3%95%e7%9a%84%e5%ae%9e%e4%be%8b1%ef%bc%9a%e8%ae%a1%e7%ae%97%e5%9c%86%e5%91%a8%e7%8e%87/" class="read-more">Read More </a></p>]]></description>
										<content:encoded><![CDATA[<p>
查看本系列文章合集，请点击<a href="https://www.codelast.com/?p=9951" rel="noopener noreferrer" target="_blank"><span style="background-color: rgb(255, 160, 122);">这里</span></a>。</p>
<p>为了对蒙特卡罗方法有一个直观的印象，我们先举一个实例（计算圆周率 <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_522359592d78569a9eac16498aa7a087.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="\pi " /></span><script type='math/tex'>\pi </script> ），让从来没有接触过蒙特卡罗方法的人产生&ldquo;原来这就是Monte Carlo&rdquo;的感觉，以减少刚开始学习的困惑。</p>
<ul>
<li>
		<span style="background-color:#00ff00;">非蒙特卡罗方法</span></li>
</ul>
<p>圆周率 <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_522359592d78569a9eac16498aa7a087.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="\pi " /></span><script type='math/tex'>\pi </script> 可以怎么计算？其中一个&ldquo;常规&rdquo;的方法就是利用 <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_522359592d78569a9eac16498aa7a087.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="\pi " /></span><script type='math/tex'>\pi </script> 的莱布尼茨公式：<br />
 <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_aef37fd61f243ce0d16aadd617fe03c7.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="\frac{\pi }{4} = \sum\limits_{n = 0}^\infty {\frac{{{{\left( { - 1} \right)}^n}}}{{2n + 1}}} = 1 - \frac{1}{3} + \frac{1}{5} - \frac{1}{7} + \frac{1}{9} - \cdots " /></span><script type='math/tex'>\frac{\pi }{4} = \sum\limits_{n = 0}^\infty {\frac{{{{\left( { - 1} \right)}^n}}}{{2n + 1}}} = 1 - \frac{1}{3} + \frac{1}{5} - \frac{1}{7} + \frac{1}{9} - \cdots </script> <br />
不断增大 <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_7b8b965ad4bca0e41ab51de7b31363a1.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="n" /></span><script type='math/tex'>n</script> 的值，就能越来越逼近 <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_9c05e99783ffbdc89e86bee35eb07484.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="\frac{\pi }{4}" /></span><script type='math/tex'>\frac{\pi }{4}</script> <span id="more-9983"></span><br />
当 <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_7b8b965ad4bca0e41ab51de7b31363a1.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="n" /></span><script type='math/tex'>n</script> 的最大值取30000时，可以计算得  <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_5ff097626c52b389d39054bca2cab608.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="\pi = 3.141559320256462" /></span><script type='math/tex'>\pi = 3.141559320256462</script> </p>
<ul>
<li>
		<span style="background-color:#00ff00;">蒙特卡罗方法</span></li>
</ul>
<p>相比之下，用蒙特卡罗方法来计算 <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_522359592d78569a9eac16498aa7a087.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="\pi " /></span><script type='math/tex'>\pi </script> ，可能就是一个比较&ldquo;另类&rdquo;的途径了。<br />
假设圆外部有一个相切的正方形，如下图所示：<br />
<a href="https://www.codelast.com" rel="noopener noreferrer" target="_blank"><img decoding="async" alt="monte carlo method calculate pi example" src="https://www.codelast.com/wp-content/uploads/2017/11/monte_carlo_example_calculate_pi_1.png" style="width: 255px; height: 210px;" /></a><br />
<span style="color: rgb(255, 255, 255);">文章来源：</span><a href="https://www.codelast.com/" rel="noopener noreferrer" target="_blank"><span style="color: rgb(255, 255, 255);">https://www.codelast.com/</span></a><br />
设圆面积为C，正方形面积为S，则利用面积公式可以轻易算得： <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_623c1f945c60bccf841dc43aa5c4e088.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="\frac{C}{S} = \frac{{\pi {r^2}}}{{{{(2r)}^2}}} = \frac{\pi }{4}" /></span><script type='math/tex'>\frac{C}{S} = \frac{{\pi {r^2}}}{{{{(2r)}^2}}} = \frac{\pi }{4}</script> <br />
然后，我们在正方形内随机生成30000个点（当然可以生成更多，这里只是用30000举个例子），分别计算这些点与圆心的距离，距离&lt;r 表示点在圆内部：<br />
<a href="https://www.codelast.com" rel="noopener noreferrer" target="_blank"><img decoding="async" alt="monte carlo method calculate pi example" src="https://www.codelast.com/wp-content/uploads/2017/11/monte_carlo_example_calculate_pi_2.png" style="width: 216px; height: 213px;" /></a><br />
<span style="color: rgb(255, 255, 255);">文章来源：</span><a href="https://www.codelast.com/" rel="noopener noreferrer" target="_blank"><span style="color: rgb(255, 255, 255);">https://www.codelast.com/</span></a><br />
从面积之比可知：如果点是均匀分布的，则圆内的点的数量应该占所有点数量的 <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_9c05e99783ffbdc89e86bee35eb07484.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="\frac{\pi }{4}" /></span><script type='math/tex'>\frac{\pi }{4}</script> ，计算数量之比，再乘以4，即可得圆周率。<br />
在某一次实验中，模拟30000个点， <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_522359592d78569a9eac16498aa7a087.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="\pi " /></span><script type='math/tex'>\pi </script> 的估算值与真实值相差0.07%<br />
所以，这里正是巧妙地利用了&ldquo;随机&rdquo;这个技术，来计算了圆周率，这种方法就属于蒙特卡罗方法。</p>
<ul>
<li>
		<span style="background-color:#00ff00;">参考文献</span></li>
</ul>
<p>► <a href="https://zh.wikipedia.org/wiki/%CE%A0%E7%9A%84%E8%8E%B1%E5%B8%83%E5%B0%BC%E8%8C%A8%E5%85%AC%E5%BC%8F" rel="noopener noreferrer" target="_blank">维基百科： <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_522359592d78569a9eac16498aa7a087.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="\pi " /></span><script type='math/tex'>\pi </script> 的莱布尼茨公式</a><br />
►&nbsp;<a href="http://www.ruanyifeng.com/blog/2015/07/monte-carlo-method.html" rel="noopener noreferrer" target="_blank">蒙特卡罗方法入门</a></p>
<p><span style="color: rgb(255, 255, 255);">文章来源：</span><a href="https://www.codelast.com/" rel="noopener noreferrer" target="_blank"><span style="color: rgb(255, 255, 255);">https://www.codelast.com/</span></a><br />
<span style="color: rgb(255, 0, 0);">➤➤</span>&nbsp;版权声明&nbsp;<span style="color: rgb(255, 0, 0);">➤➤</span>&nbsp;<br />
转载需注明出处：<u><a href="https://www.codelast.com/" rel="noopener noreferrer" target="_blank"><em><span style="color: rgb(0, 0, 255);"><strong style="font-size: 16px;"><span style="font-family: arial, helvetica, sans-serif;">codelast.com</span></strong></span></em></a></u>&nbsp;<br />
感谢关注我的微信公众号（微信扫一扫）：</p>
<p style="border: 0px; font-size: 13px; margin: 0px 0px 9px; outline: 0px; padding: 0px; color: rgb(77, 77, 77);">
	<img decoding="async" alt="wechat qrcode of codelast" src="https://www.codelast.com/codelast_wechat_qr_code.jpg" style="width: 200px; height: 200px;" /></p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.codelast.com/%e5%8e%9f%e5%88%9b-%e8%92%99%e7%89%b9%e5%8d%a1%e7%bd%97%e6%96%b9%e6%b3%95%e7%9a%84%e5%ae%9e%e4%be%8b1%ef%bc%9a%e8%ae%a1%e7%ae%97%e5%9c%86%e5%91%a8%e7%8e%87/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>[原创] 如何防止softmax函数上溢出(overflow)和下溢出(underflow)</title>
		<link>https://www.codelast.com/%e5%8e%9f%e5%88%9b-%e5%a6%82%e4%bd%95%e9%98%b2%e6%ad%a2softmax%e5%87%bd%e6%95%b0%e4%b8%8a%e6%ba%a2%e5%87%baoverflow%e5%92%8c%e4%b8%8b%e6%ba%a2%e5%87%baunderflow/</link>
					<comments>https://www.codelast.com/%e5%8e%9f%e5%88%9b-%e5%a6%82%e4%bd%95%e9%98%b2%e6%ad%a2softmax%e5%87%bd%e6%95%b0%e4%b8%8a%e6%ba%a2%e5%87%baoverflow%e5%92%8c%e4%b8%8b%e6%ba%a2%e5%87%baunderflow/#comments</comments>
		
		<dc:creator><![CDATA[learnhard]]></dc:creator>
		<pubDate>Sat, 11 Mar 2017 17:22:44 +0000</pubDate>
				<category><![CDATA[Algorithm]]></category>
		<category><![CDATA[Math]]></category>
		<category><![CDATA[原创]]></category>
		<category><![CDATA[overflow]]></category>
		<category><![CDATA[softmax]]></category>
		<category><![CDATA[underflow]]></category>
		<category><![CDATA[上溢出]]></category>
		<category><![CDATA[下溢出]]></category>
		<guid isPermaLink="false">http://www.codelast.com/?p=9211</guid>

					<description><![CDATA[<p>《<a href="http://www.deeplearningbook.org/" rel="noopener noreferrer" target="_blank">Deep Learning</a>》（Ian Goodfellow &#38; Yoshua Bengio &#38; Aaron Courville）第四章「数值计算」中，谈到了上溢出（overflow）和下溢出（underflow）对数值计算的影响，并以softmax函数和log softmax函数为例进行了讲解。这里我再详细地把它总结一下。<br />
<span id="more-9211"></span><br />
<span style="background-color:#00ff00;">『1』</span>什么是<span style="color: rgb(0, 0, 255);">下溢出</span>（underflow）和<span style="color: rgb(0, 0, 255);">上溢出</span>（overflow）<br />
实数在计算机内用二进制表示，所以不是一个精确值，当数值过小的时候，被四舍五入为0，这就是下溢出。此时如果对这个数再做某些运算（例如除以它）就会出问题。<br />
反之，当数值过大的时候，情况就变成了上溢出。</p>
<p><span style="background-color:#00ff00;">『2』</span>softmax函数是什么<br />
softmax函数如下：<br />
 <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_1506d61211b9a5466d9421954776fde3.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="f{(x)_i} = \frac{{{e^{{x_i}}}}}{{\sum\limits_{j = 1}^n {{e^{{x_j}}}} }},j = 1,2,...,n" /></span><script type='math/tex'>f{(x)_i} = \frac{{{e^{{x_i}}}}}{{\sum\limits_{j = 1}^n {{e^{{x_j}}}} }},j = 1,2,...,n</script> <br />
从公式上看含义不是特别清晰，所以借用<a href="https://www.zhihu.com/question/23765351" rel="noopener noreferrer" target="_blank"><span style="background-color:#ffa07a;">知乎上</span></a>的一幅图来说明（感谢原作者）：</p>
<p><a href="http://www.codelast.com" rel="noopener noreferrer" target="_blank"><img decoding="async" alt="softmax function" src="https://www.codelast.com/wp-content/uploads/ckfinder/images/softmax.jpg" style="width: 600px; height: 336px;" /></a></p>
<p>这幅图极其清晰地表明了softmax函数是什么，一图胜千言。<br />
<span style="color: rgb(255, 255, 255);">文章来源：</span><a href="https://www.codelast.com/" rel="noopener noreferrer" target="_blank"><span style="color: rgb(255, 255, 255);">https://www.codelast.com/</span></a><br />
<span style="background-color:#00ff00;">『2』</span>计算softmax函数值的问题<br />
通常情况下，计算softmax函数值不会出现什么问题，例如，当softmax函数表达式里的所有 x<sub>i</sub> 都是一个&#8220;一般大小&#8221;的数值 c 时&#8212;&#8212;也就是上图中， <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_9386b124bb9a0ea80843f97b974c387f.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="{z_1} = {z_2} = {z_3} = c" /></span><script type='math/tex'>{z_1} = {z_2} = {z_3} = c</script> &#160;时，那么，计算出来的函数值  <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_4719b045cf7e43b9e9c4ec40b1b0cfda.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="{y_1} = {y_2} = {y_3} = \frac{1}{3}" /></span><script type='math/tex'>{y_1} = {y_2} = {y_3} = \frac{1}{3}</script> 。<br />
但是，当某些情况发生时，计算函数值就出问题了：</p>
<ul>
<li>
		c 极其大，导致分子计算  <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_0b1e10e461ff30c53b0f45ab4ba9eb00.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="{e^c}" /></span><script type='math/tex'>{e^c}</script>  时上溢出</li>
<li>
		c 为负数，且&#160; <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_789cb215a4afd57b77d138cb09d2a0f7.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="\left&#124; c \right&#124;" /></span><script type='math/tex'>\left&#124; c \right&#124;</script>  很大，此时分母是一个极小的正数，有可能四舍五入为0，导致下溢出</li>
</ul>
<p><span style="color: rgb(255, 255, 255);">文章来源：</span><a href="https://www.codelast.com/" rel="noopener noreferrer" target="_blank"><span style="color: rgb(255, 255, 255);">https://www.codelast.com/</span></a>&#8230; <a href="https://www.codelast.com/%e5%8e%9f%e5%88%9b-%e5%a6%82%e4%bd%95%e9%98%b2%e6%ad%a2softmax%e5%87%bd%e6%95%b0%e4%b8%8a%e6%ba%a2%e5%87%baoverflow%e5%92%8c%e4%b8%8b%e6%ba%a2%e5%87%baunderflow/" class="read-more">Read More </a></p>]]></description>
										<content:encoded><![CDATA[<p>《<a href="http://www.deeplearningbook.org/" rel="noopener noreferrer" target="_blank">Deep Learning</a>》（Ian Goodfellow &amp; Yoshua Bengio &amp; Aaron Courville）第四章「数值计算」中，谈到了上溢出（overflow）和下溢出（underflow）对数值计算的影响，并以softmax函数和log softmax函数为例进行了讲解。这里我再详细地把它总结一下。<br />
<span id="more-9211"></span><br />
<span style="background-color:#00ff00;">『1』</span>什么是<span style="color: rgb(0, 0, 255);">下溢出</span>（underflow）和<span style="color: rgb(0, 0, 255);">上溢出</span>（overflow）<br />
实数在计算机内用二进制表示，所以不是一个精确值，当数值过小的时候，被四舍五入为0，这就是下溢出。此时如果对这个数再做某些运算（例如除以它）就会出问题。<br />
反之，当数值过大的时候，情况就变成了上溢出。</p>
<p><span style="background-color:#00ff00;">『2』</span>softmax函数是什么<br />
softmax函数如下：<br />
 <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_1506d61211b9a5466d9421954776fde3.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="f{(x)_i} = \frac{{{e^{{x_i}}}}}{{\sum\limits_{j = 1}^n {{e^{{x_j}}}} }},j = 1,2,...,n" /></span><script type='math/tex'>f{(x)_i} = \frac{{{e^{{x_i}}}}}{{\sum\limits_{j = 1}^n {{e^{{x_j}}}} }},j = 1,2,...,n</script> <br />
从公式上看含义不是特别清晰，所以借用<a href="https://www.zhihu.com/question/23765351" rel="noopener noreferrer" target="_blank"><span style="background-color:#ffa07a;">知乎上</span></a>的一幅图来说明（感谢原作者）：</p>
<p><a href="http://www.codelast.com" rel="noopener noreferrer" target="_blank"><img decoding="async" alt="softmax function" src="https://www.codelast.com/wp-content/uploads/ckfinder/images/softmax.jpg" style="width: 600px; height: 336px;" /></a></p>
<p>这幅图极其清晰地表明了softmax函数是什么，一图胜千言。<br />
<span style="color: rgb(255, 255, 255);">文章来源：</span><a href="https://www.codelast.com/" rel="noopener noreferrer" target="_blank"><span style="color: rgb(255, 255, 255);">https://www.codelast.com/</span></a><br />
<span style="background-color:#00ff00;">『2』</span>计算softmax函数值的问题<br />
通常情况下，计算softmax函数值不会出现什么问题，例如，当softmax函数表达式里的所有 x<sub>i</sub> 都是一个&ldquo;一般大小&rdquo;的数值 c 时&mdash;&mdash;也就是上图中， <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_9386b124bb9a0ea80843f97b974c387f.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="{z_1} = {z_2} = {z_3} = c" /></span><script type='math/tex'>{z_1} = {z_2} = {z_3} = c</script> &nbsp;时，那么，计算出来的函数值  <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_4719b045cf7e43b9e9c4ec40b1b0cfda.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="{y_1} = {y_2} = {y_3} = \frac{1}{3}" /></span><script type='math/tex'>{y_1} = {y_2} = {y_3} = \frac{1}{3}</script> 。<br />
但是，当某些情况发生时，计算函数值就出问题了：</p>
<ul>
<li>
		c 极其大，导致分子计算  <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_0b1e10e461ff30c53b0f45ab4ba9eb00.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="{e^c}" /></span><script type='math/tex'>{e^c}</script>  时上溢出</li>
<li>
		c 为负数，且&nbsp; <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_789cb215a4afd57b77d138cb09d2a0f7.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="\left| c \right|" /></span><script type='math/tex'>\left| c \right|</script>  很大，此时分母是一个极小的正数，有可能四舍五入为0，导致下溢出</li>
</ul>
<p><span style="color: rgb(255, 255, 255);">文章来源：</span><a href="https://www.codelast.com/" rel="noopener noreferrer" target="_blank"><span style="color: rgb(255, 255, 255);">https://www.codelast.com/</span></a><br />
<span style="background-color:#00ff00;">『3』</span>如何解决<br />
所以怎样规避这些问题呢？我们可以用同一个方法一口气解决俩：<br />
令&nbsp; <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_0d5a61c338abd8aff4445d1c25f572fc.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="M = \max ({x_i}),i = 1,2, \cdots ,n" /></span><script type='math/tex'>M = \max ({x_i}),i = 1,2, \cdots ,n</script> ，即 M 为所有  <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_9fc055e2c2e0857258028ea14586b4b2.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="{x_i}" /></span><script type='math/tex'>{x_i}</script>  中最大的值，那么我们只需要把计算  <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_182c3aad17e24f621a53493762cbab83.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="f{(x)_i}" /></span><script type='math/tex'>f{(x)_i}</script>  的值，改为计算&nbsp; <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_93907f78f842e2d2d8d9c0fce17d1c7c.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="f({x_i} - M)" /></span><script type='math/tex'>f({x_i} - M)</script>  的值，就可以解决上溢出、下溢出的问题了，并且，计算结果理论上仍然和  <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_182c3aad17e24f621a53493762cbab83.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="f{(x)_i}" /></span><script type='math/tex'>f{(x)_i}</script>  保持一致。<br />
<span style="color: rgb(255, 255, 255);">文章来源：</span><a href="https://www.codelast.com/" rel="noopener noreferrer" target="_blank"><span style="color: rgb(255, 255, 255);">https://www.codelast.com/</span></a><br />
举个实例：还是以前面的图为例，本来我们计算&nbsp; <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_97f45a0c17c2a4a6cb57514984dda5b6.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="f({z_2})" /></span><script type='math/tex'>f({z_2})</script> ，是用&ldquo;常规&rdquo;方法来算的：<br />
 <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_3ae3a1b3649531949433c41bb96344fc.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="\frac{{{e^{{z_2}}}}}{{{e^{{z_1}}} + {e^{{z_2}}} + {e^{{z_3}}}}} = \frac{{{e^1}}}{{{e^3} + {e^1} + {e^{ - 3}}}} = \frac{{2.7}}{{20 + 2.7 + 0.05}} \approx 0.12" /></span><script type='math/tex'>\frac{{{e^{{z_2}}}}}{{{e^{{z_1}}} + {e^{{z_2}}} + {e^{{z_3}}}}} = \frac{{{e^1}}}{{{e^3} + {e^1} + {e^{ - 3}}}} = \frac{{2.7}}{{20 + 2.7 + 0.05}} \approx 0.12</script> <br />
现在我们改成：<br />
 <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_9c2d838566cf61705acd0d094d09ca81.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="\frac{{{e^{({z_2} - M)}}}}{{{e^{({z_1} - M)}} + {e^{({z_2} - M)}} + {e^{({z_3} - M)}}}} = \frac{{{e^{(1 - 3)}}}}{{{e^{(3 - 3)}} + {e^{(1 - 3)}} + {e^{( - 3 - 3)}}}} \approx 0.12" /></span><script type='math/tex'>\frac{{{e^{({z_2} - M)}}}}{{{e^{({z_1} - M)}} + {e^{({z_2} - M)}} + {e^{({z_3} - M)}}}} = \frac{{{e^{(1 - 3)}}}}{{{e^{(3 - 3)}} + {e^{(1 - 3)}} + {e^{( - 3 - 3)}}}} \approx 0.12</script> <br />
其中， <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_a3769b09e6be65ab8971d2c1331435af.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="M = 3" /></span><script type='math/tex'>M = 3</script>  是&nbsp; <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_353cc7216665e636da2353e624e435b6.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="{z_1},{z_2},{z_3}" /></span><script type='math/tex'>{z_1},{z_2},{z_3}</script>  中的最大值。<br />
可见计算结果并未改变。<br />
<span style="color: rgb(255, 255, 255);">文章来源：</span><a href="https://www.codelast.com/" rel="noopener noreferrer" target="_blank"><span style="color: rgb(255, 255, 255);">https://www.codelast.com/</span></a><br />
这是怎么做到的呢？通过简单的代数运算就可以参透其中的&ldquo;秘密&rdquo;：<br />
 <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_c29567cfa01a4957042af2d8056e59f2.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="\frac{{{e^{{z_2}}}}}{{{e^{{z_1}}} + {e^{{z_2}}} + {e^{{z_3}}}}} = \frac{{\frac{{{e^{{z_2}}}}}{{{e^M}}}}}{{\frac{{{e^{{z_1}}} + {e^{{z_2}}} + {e^{{z_3}}}}}{{{e^M}}}}} = \frac{{\frac{{{e^{{z_2}}}}}{{{e^M}}}}}{{\frac{{{e^{{z_1}}}}}{{{e^M}}} + \frac{{{e^{{z_2}}}}}{{{e^M}}} + \frac{{{e^{{z_3}}}}}{{{e^M}}}}} = \frac{{{e^{\left( {{z_2} - M} \right)}}}}{{{e^{\left( {{z_1} - M} \right)}} + {e^{\left( {{z_2} - M} \right)}} + {e^{\left( {{z_3} - M} \right)}}}}" /></span><script type='math/tex'>\frac{{{e^{{z_2}}}}}{{{e^{{z_1}}} + {e^{{z_2}}} + {e^{{z_3}}}}} = \frac{{\frac{{{e^{{z_2}}}}}{{{e^M}}}}}{{\frac{{{e^{{z_1}}} + {e^{{z_2}}} + {e^{{z_3}}}}}{{{e^M}}}}} = \frac{{\frac{{{e^{{z_2}}}}}{{{e^M}}}}}{{\frac{{{e^{{z_1}}}}}{{{e^M}}} + \frac{{{e^{{z_2}}}}}{{{e^M}}} + \frac{{{e^{{z_3}}}}}{{{e^M}}}}} = \frac{{{e^{\left( {{z_2} - M} \right)}}}}{{{e^{\left( {{z_1} - M} \right)}} + {e^{\left( {{z_2} - M} \right)}} + {e^{\left( {{z_3} - M} \right)}}}}</script> <br />
通过这样的变换，对任何一个 x<sub>i</sub>，减去M之后，e 的指数的最大值为0，所以不会发生上溢出；同时，分母中也至少会包含一个值为1的项，所以分母也不会下溢出（四舍五入为0）。<br />
所以这个技巧没什么高级的技术含量。<br />
<span style="color: rgb(255, 255, 255);">文章来源：</span><a href="https://www.codelast.com/" rel="noopener noreferrer" target="_blank"><span style="color: rgb(255, 255, 255);">https://www.codelast.com/</span></a><br />
<span style="background-color:#00ff00;">『4』</span>延伸问题<br />
看似已经结案了，但仍然有一个问题：如果softmax函数中的分子发生下溢出，也就是前面所说的 c 为负数，且  <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_789cb215a4afd57b77d138cb09d2a0f7.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="\left| c \right|" /></span><script type='math/tex'>\left| c \right|</script>  很大，此时分母是一个极小的正数，有可能四舍五入为0的情况，此时，如果我们把softmax函数的计算结果再拿去计算 log，即 log softmax，其实就相当于计算&nbsp; <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_f28430e76ce080a889f0bdd64591d94a.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="\log (0)" /></span><script type='math/tex'>\log (0)</script> ，所以会得到  <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_8ce04232c352cfa94e22f923f71fa1dc.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt=" - \infty " /></span><script type='math/tex'> - \infty </script> ，但这实际上是错误的，因为它是由舍入误差造成的计算错误。<br />
所以，有没有一个方法，可以把这个问题也解决掉呢？<br />
答案还是采用和前面类似的策略来计算 log softmax 函数值：<br />
 <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_1ae2bb47902237d025410897d8644e12.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="\log [f({x_i})] = \log \left( {\frac{{{e^{{x_i}}}}}{{{e^{{x_1}}} + {e^{{x_2}}} + \cdots {e^{{x_n}}}}}} \right) = \log \left( {\frac{{\frac{{{e^{{x_i}}}}}{{{e^M}}}}}{{\frac{{{e^{{x_1}}}}}{{{e^M}}} + \frac{{{e^{{x_2}}}}}{{{e^M}}} + \cdots \frac{{{e^{{x_n}}}}}{{{e^M}}}}}} \right) = \log \left( {\frac{{{e^{\left( {{x_i} - M} \right)}}}}{{\sum\limits_j^n {{e^{\left( {{x_j} - M} \right)}}} }}} \right) = \log \left( {{e^{\left( {{x_i} - M} \right)}}} \right) - \log \left( {\sum\limits_j^n {{e^{\left( {{x_j} - M} \right)}}} } \right) = \left( {{x_i} - M} \right) - \log \left( {\sum\limits_j^n {{e^{\left( {{x_j} - M} \right)}}} } \right)" /></span><script type='math/tex'>\log [f({x_i})] = \log \left( {\frac{{{e^{{x_i}}}}}{{{e^{{x_1}}} + {e^{{x_2}}} + \cdots {e^{{x_n}}}}}} \right) = \log \left( {\frac{{\frac{{{e^{{x_i}}}}}{{{e^M}}}}}{{\frac{{{e^{{x_1}}}}}{{{e^M}}} + \frac{{{e^{{x_2}}}}}{{{e^M}}} + \cdots \frac{{{e^{{x_n}}}}}{{{e^M}}}}}} \right) = \log \left( {\frac{{{e^{\left( {{x_i} - M} \right)}}}}{{\sum\limits_j^n {{e^{\left( {{x_j} - M} \right)}}} }}} \right) = \log \left( {{e^{\left( {{x_i} - M} \right)}}} \right) - \log \left( {\sum\limits_j^n {{e^{\left( {{x_j} - M} \right)}}} } \right) = \left( {{x_i} - M} \right) - \log \left( {\sum\limits_j^n {{e^{\left( {{x_j} - M} \right)}}} } \right)</script> <br />
大家看到，在最后的表达式中，会产生下溢出的因素已经被消除掉了&mdash;&mdash;求和项中，至少有一项的值为1，这使得log后面的值不会下溢出，也就不会发生计算 log(0) 的悲剧。<br />
在很多数值计算的library中，都采用了此类方法来保持数值稳定。<br />
<span style="color: rgb(255, 255, 255);">文章来源：</span><a href="https://www.codelast.com/" rel="noopener noreferrer" target="_blank"><span style="color: rgb(255, 255, 255);">https://www.codelast.com/</span></a><br />
<span style="color: rgb(255, 0, 0);">➤➤</span>&nbsp;版权声明&nbsp;<span style="color: rgb(255, 0, 0);">➤➤</span>&nbsp;<br />
转载需注明出处：<u><a href="https://www.codelast.com/" rel="noopener noreferrer" target="_blank"><em><span style="color: rgb(0, 0, 255);"><strong style="font-size: 16px;"><span style="font-family: arial, helvetica, sans-serif;">codelast.com</span></strong></span></em></a></u>&nbsp;<br />
感谢关注我的微信公众号（微信扫一扫）：</p>
<p style="border: 0px; font-size: 13px; margin: 0px 0px 9px; outline: 0px; padding: 0px; color: rgb(77, 77, 77);">
	<img decoding="async" alt="wechat qrcode of codelast" src="https://www.codelast.com/codelast_wechat_qr_code.jpg" style="width: 200px; height: 200px;" /></p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.codelast.com/%e5%8e%9f%e5%88%9b-%e5%a6%82%e4%bd%95%e9%98%b2%e6%ad%a2softmax%e5%87%bd%e6%95%b0%e4%b8%8a%e6%ba%a2%e5%87%baoverflow%e5%92%8c%e4%b8%8b%e6%ba%a2%e5%87%baunderflow/feed/</wfw:commentRss>
			<slash:comments>5</slash:comments>
		
		
			</item>
		<item>
		<title>[原创]Machine Learning/机器学习 文章合集</title>
		<link>https://www.codelast.com/%e5%8e%9f%e5%88%9bmachine-learning%e6%9c%ba%e5%99%a8%e5%ad%a6%e4%b9%a0-%e6%96%87%e7%ab%a0%e5%90%88%e9%9b%86/</link>
					<comments>https://www.codelast.com/%e5%8e%9f%e5%88%9bmachine-learning%e6%9c%ba%e5%99%a8%e5%ad%a6%e4%b9%a0-%e6%96%87%e7%ab%a0%e5%90%88%e9%9b%86/#comments</comments>
		
		<dc:creator><![CDATA[learnhard]]></dc:creator>
		<pubDate>Sat, 21 Jan 2017 10:57:16 +0000</pubDate>
				<category><![CDATA[Algorithm]]></category>
		<category><![CDATA[Math]]></category>
		<category><![CDATA[原创]]></category>
		<category><![CDATA[machine learning]]></category>
		<category><![CDATA[机器学习]]></category>
		<guid isPermaLink="false">http://www.codelast.com/?p=9137</guid>

					<description><![CDATA[<p>注：带有 <span style="color:#ff0000;">♬♬♬♬♬</span>&#160;标志的是文章合集。</p>
<p>✍<a href="https://www.codelast.com/?p=10907" rel="noopener noreferrer" target="_blank">强化学习(Reinforcement Learning)文章合集</a>&#160;<span style="color: rgb(255, 0, 0);">♬♬♬♬♬</span></p>
<p>✍<a href="https://www.codelast.com/?p=8629" rel="noopener noreferrer" target="_blank">用人话解释机器学习中的Logistic Regression（逻辑回归）</a></p>
<p>✍<a href="https://www.codelast.com/?p=9211" rel="noopener noreferrer" target="_blank">如何防止softmax函数上溢出(overflow)和下溢出(underflow)</a></p>
<p>✍<a href="https://www.codelast.com/?p=9754" rel="noopener noreferrer" target="_blank">ELL（Embedded Learning Library，微软嵌入式学习库）文章合集</a>&#160;<span style="color: rgb(255, 0, 0);">♬♬♬♬♬</span><br />
<span id="more-9137"></span><br />
✍<a href="https://www.codelast.com/?p=9040" rel="noopener noreferrer" target="_blank">《Neural Networks and Deep Learning》读书笔记：最简单的识别MNIST的神经网络程序(1)</a></p>
<p>✍<a href="https://www.codelast.com/?p=9083" rel="noopener noreferrer" target="_blank">《Neural Networks and Deep Learning》读书笔记：最简单的识别MNIST的神经网络程序(2)</a></p>
<p>✍<a href="https://www.codelast.com/?p=9085" rel="noopener noreferrer" target="_blank">《Neural Networks and Deep Learning》读书笔记：反向传播的4个基本方程(1)</a></p>
<p>✍<a href="https://www.codelast.com/?p=9951" rel="noopener noreferrer" target="_blank">用人话解释蒙特卡罗方法/Monte Carlo method(文章合集)</a>&#160;<span style="color: rgb(255, 0, 0);">♬♬♬♬♬</span></p>
<p>✍<a href="https://www.codelast.com/?p=10475" rel="noopener noreferrer" target="_blank">一个简单的TensorFlow-Serving例子</a></p>
<p>✍<a href="https://www.codelast.com/?p=10520" rel="noopener noreferrer" target="_blank">tf.tile()</a>&#8230; <a href="https://www.codelast.com/%e5%8e%9f%e5%88%9bmachine-learning%e6%9c%ba%e5%99%a8%e5%ad%a6%e4%b9%a0-%e6%96%87%e7%ab%a0%e5%90%88%e9%9b%86/" class="read-more">Read More </a></p>]]></description>
										<content:encoded><![CDATA[<p>注：带有 <span style="color:#ff0000;">♬♬♬♬♬</span>&nbsp;标志的是文章合集。</p>
<p><img src="https://s.w.org/images/core/emoji/17.0.2/72x72/270d.png" alt="✍" class="wp-smiley" style="height: 1em; max-height: 1em;" /><a href="https://www.codelast.com/?p=10907" rel="noopener noreferrer" target="_blank">强化学习(Reinforcement Learning)文章合集</a>&nbsp;<span style="color: rgb(255, 0, 0);">♬♬♬♬♬</span></p>
<p><img src="https://s.w.org/images/core/emoji/17.0.2/72x72/270d.png" alt="✍" class="wp-smiley" style="height: 1em; max-height: 1em;" /><a href="https://www.codelast.com/?p=8629" rel="noopener noreferrer" target="_blank">用人话解释机器学习中的Logistic Regression（逻辑回归）</a></p>
<p><img src="https://s.w.org/images/core/emoji/17.0.2/72x72/270d.png" alt="✍" class="wp-smiley" style="height: 1em; max-height: 1em;" /><a href="https://www.codelast.com/?p=9211" rel="noopener noreferrer" target="_blank">如何防止softmax函数上溢出(overflow)和下溢出(underflow)</a></p>
<p><img src="https://s.w.org/images/core/emoji/17.0.2/72x72/270d.png" alt="✍" class="wp-smiley" style="height: 1em; max-height: 1em;" /><a href="https://www.codelast.com/?p=9754" rel="noopener noreferrer" target="_blank">ELL（Embedded Learning Library，微软嵌入式学习库）文章合集</a>&nbsp;<span style="color: rgb(255, 0, 0);">♬♬♬♬♬</span><br />
<span id="more-9137"></span><br />
<img src="https://s.w.org/images/core/emoji/17.0.2/72x72/270d.png" alt="✍" class="wp-smiley" style="height: 1em; max-height: 1em;" /><a href="https://www.codelast.com/?p=9040" rel="noopener noreferrer" target="_blank">《Neural Networks and Deep Learning》读书笔记：最简单的识别MNIST的神经网络程序(1)</a></p>
<p><img src="https://s.w.org/images/core/emoji/17.0.2/72x72/270d.png" alt="✍" class="wp-smiley" style="height: 1em; max-height: 1em;" /><a href="https://www.codelast.com/?p=9083" rel="noopener noreferrer" target="_blank">《Neural Networks and Deep Learning》读书笔记：最简单的识别MNIST的神经网络程序(2)</a></p>
<p><img src="https://s.w.org/images/core/emoji/17.0.2/72x72/270d.png" alt="✍" class="wp-smiley" style="height: 1em; max-height: 1em;" /><a href="https://www.codelast.com/?p=9085" rel="noopener noreferrer" target="_blank">《Neural Networks and Deep Learning》读书笔记：反向传播的4个基本方程(1)</a></p>
<p><img src="https://s.w.org/images/core/emoji/17.0.2/72x72/270d.png" alt="✍" class="wp-smiley" style="height: 1em; max-height: 1em;" /><a href="https://www.codelast.com/?p=9951" rel="noopener noreferrer" target="_blank">用人话解释蒙特卡罗方法/Monte Carlo method(文章合集)</a>&nbsp;<span style="color: rgb(255, 0, 0);">♬♬♬♬♬</span></p>
<p><img src="https://s.w.org/images/core/emoji/17.0.2/72x72/270d.png" alt="✍" class="wp-smiley" style="height: 1em; max-height: 1em;" /><a href="https://www.codelast.com/?p=10475" rel="noopener noreferrer" target="_blank">一个简单的TensorFlow-Serving例子</a></p>
<p><img src="https://s.w.org/images/core/emoji/17.0.2/72x72/270d.png" alt="✍" class="wp-smiley" style="height: 1em; max-height: 1em;" /><a href="https://www.codelast.com/?p=10520" rel="noopener noreferrer" target="_blank">tf.tile() 用法举例(TensorFlow)</a></p>
<p><img src="https://s.w.org/images/core/emoji/17.0.2/72x72/270d.png" alt="✍" class="wp-smiley" style="height: 1em; max-height: 1em;" /><a href="https://www.codelast.com/?p=10534">二维numpy数组保存到TFRecord并读取还原回来</a></p>
<p><img src="https://s.w.org/images/core/emoji/17.0.2/72x72/270d.png" alt="✍" class="wp-smiley" style="height: 1em; max-height: 1em;" /><a href="https://www.codelast.com/?p=10565" rel="noopener noreferrer" target="_blank">如何打印出TensorFlow保存的checkpoint里的参数名</a></p>
<p><img src="https://s.w.org/images/core/emoji/17.0.2/72x72/270d.png" alt="✍" class="wp-smiley" style="height: 1em; max-height: 1em;" /><a href="https://www.codelast.com/?p=10578" rel="noopener noreferrer" target="_blank">如何取出 tf.layers.dense 定义的全连接层的weight和bias参数值</a></p>
<p><img src="https://s.w.org/images/core/emoji/17.0.2/72x72/270d.png" alt="✍" class="wp-smiley" style="height: 1em; max-height: 1em;" /><a href="https://www.codelast.com/?p=10950" rel="noopener noreferrer" target="_blank">PyTorch模型 .pt，.pth，.pkl 的区别</a></p>
<p><img src="https://s.w.org/images/core/emoji/17.0.2/72x72/270d.png" alt="✍" class="wp-smiley" style="height: 1em; max-height: 1em;" /><a href="https://www.codelast.com/?p=10953" rel="noopener noreferrer" target="_blank">PyTorch模型的两种保存方法</a></p>
<p><img src="https://s.w.org/images/core/emoji/17.0.2/72x72/270d.png" alt="✍" class="wp-smiley" style="height: 1em; max-height: 1em;" /><a href="https://www.codelast.com/?p=12047" rel="noopener noreferrer" target="_blank">PyTorch做inference/prediction的时候如何使用GPU</a></p>
<p><img src="https://s.w.org/images/core/emoji/17.0.2/72x72/270d.png" alt="✍" class="wp-smiley" style="height: 1em; max-height: 1em;" /><a href="https://www.codelast.com/?p=12698" rel="noopener noreferrer" target="_blank">调戏了一番度娘&quot;最先进&quot;的PLATO-2预训练模型之后，我还是回到了和人类交谈...</a></p>
<p><img src="https://s.w.org/images/core/emoji/17.0.2/72x72/270d.png" alt="✍" class="wp-smiley" style="height: 1em; max-height: 1em;" /><a href="https://www.codelast.com/?p=12856" rel="noopener noreferrer" target="_blank">《使用 fastText 做中文文本分类》文章合集</a><span style="color: rgb(255, 0, 0);">♬♬♬♬♬</span></p>
<p><img src="https://s.w.org/images/core/emoji/17.0.2/72x72/270d.png" alt="✍" class="wp-smiley" style="height: 1em; max-height: 1em;" /><a href="https://www.codelast.com/?p=13912" rel="noopener noreferrer" target="_blank">怎样确认当前正在运行的TensorFlow model-serving服务加载的是哪个.pb模型</a></p>
<p><span style="color: rgb(255, 255, 255);">文章来源：</span><a href="https://www.codelast.com/" rel="noopener noreferrer" target="_blank"><span style="color: rgb(255, 255, 255);">https://www.codelast.com/</span></a><br />
<span style="color:#ff0000;">➤➤</span>&nbsp;版权声明&nbsp;<span style="color: rgb(255, 0, 0);">➤➤</span>&nbsp;<br />
转载需注明出处：<u><a href="https://www.codelast.com/" rel="noopener noreferrer" target="_blank"><em><span style="color: rgb(0, 0, 255);"><strong style="font-size: 16px;"><span style="font-family: arial, helvetica, sans-serif;">codelast.com</span></strong></span></em></a></u>&nbsp;<br />
感谢关注我的微信公众号（微信扫一扫）：</p>
<p style="border: 0px; font-size: 13px; margin: 0px 0px 9px; outline: 0px; padding: 0px; color: rgb(77, 77, 77);">
	<img decoding="async" alt="wechat qrcode of codelast" src="https://www.codelast.com/codelast_wechat_qr_code.jpg" style="width: 200px; height: 200px;" /></p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.codelast.com/%e5%8e%9f%e5%88%9bmachine-learning%e6%9c%ba%e5%99%a8%e5%ad%a6%e4%b9%a0-%e6%96%87%e7%ab%a0%e5%90%88%e9%9b%86/feed/</wfw:commentRss>
			<slash:comments>4</slash:comments>
		
		
			</item>
		<item>
		<title>[原创] 用人话解释机器学习中的Logistic Regression（逻辑回归）</title>
		<link>https://www.codelast.com/%e5%8e%9f%e5%88%9b-%e7%94%a8%e4%ba%ba%e8%af%9d%e8%a7%a3%e9%87%8a%e6%9c%ba%e5%99%a8%e5%ad%a6%e4%b9%a0%e4%b8%ad%e7%9a%84logistic-regression%ef%bc%88%e9%80%bb%e8%be%91%e5%9b%9e%e5%bd%92%ef%bc%89/</link>
					<comments>https://www.codelast.com/%e5%8e%9f%e5%88%9b-%e7%94%a8%e4%ba%ba%e8%af%9d%e8%a7%a3%e9%87%8a%e6%9c%ba%e5%99%a8%e5%ad%a6%e4%b9%a0%e4%b8%ad%e7%9a%84logistic-regression%ef%bc%88%e9%80%bb%e8%be%91%e5%9b%9e%e5%bd%92%ef%bc%89/#comments</comments>
		
		<dc:creator><![CDATA[learnhard]]></dc:creator>
		<pubDate>Fri, 19 Feb 2016 08:47:08 +0000</pubDate>
				<category><![CDATA[Algorithm]]></category>
		<category><![CDATA[Math]]></category>
		<category><![CDATA[原创]]></category>
		<category><![CDATA[cross entropy]]></category>
		<category><![CDATA[Logistic Regression]]></category>
		<category><![CDATA[Logit Regression]]></category>
		<category><![CDATA[machine learning]]></category>
		<category><![CDATA[optimization]]></category>
		<category><![CDATA[交叉熵]]></category>
		<category><![CDATA[最优化]]></category>
		<category><![CDATA[机器学习]]></category>
		<category><![CDATA[逻辑回归]]></category>
		<guid isPermaLink="false">http://www.codelast.com/?p=8629</guid>

					<description><![CDATA[<p>友情提示：如果觉得页面中的公式显示太小，可以放大页面查看（不会失真）。</p>
<p><span style="color:#0000ff;">Logistic Regression</span>（或<span style="color:#0000ff;">Logit Regression</span>），即<span style="color:#0000ff;">逻辑回归</span>，简记为<span style="color:#0000ff;">LR</span>，是机器学习领域的一种极为常用的算法／方法／模型。<br />
你能从网上搜到十万篇讲述Logistic Regression的文章，也不多我这一篇，但是，就像我写过的<a href="http://www.codelast.com/?p=7364" rel="noopener noreferrer" target="_blank"><span style="background-color:#ffa07a;">最优化系列文章</span></a>一样，我仍然试图用&#8220;人话&#8221;来再解释一遍&#8212;&#8212;可能不专业，但是容易看得懂。那些一上来就是几页数学公式什么的最讨厌了，不是吗？<br />
所以这篇文章是写给完全没听说过Logistic Regression的人看的，我相信看完这篇文章，你差不多可以从无到有，把逻辑回归应用到实践中去。<br />
<span id="more-8629"></span><br />
Logistic Regression是一种<span style="color:#0000ff;">分类</span>算法。分类，也就是把一个群体（或问题，或数据）分为几个类别，例如，男/女/人妖；爱她的人/不爱她的人；今天会下雨/今天不会下雨。<br />
Logistic Regression最常用于处理&#8220;<span style="color:#0000ff;">二分类</span>&#8221;问题，也就是说分类只有两个，像&#8220;爱她的人/不爱她的人&#8221;就是二分类，而&#8220;男/女/人妖&#8221;就不是二分类。当然，Logistic Regression也可以用于处理多分类问题，即所谓的&#8220;<span style="color:#800080;">多分类逻辑回归</span>&#8221;（<span style="color:#b22222;">Multiclass Logistic Regression</span>），但本文并不涉及这个方面。<br />
所以，说得简单点就是，给你一条数据，用Logistic Regression可以判断出这条数据应该被分到两个类别中的哪个中去。<br />
<span style="color: rgb(255, 255, 255);">文章来源：</span><a href="http://www.codelast.com/" rel="noopener noreferrer" target="_blank"><span style="color: rgb(255, 255, 255);">http://www.codelast.com/</span></a><br />
Logistic Regression在现实世界中非常有用。例如，可以用它来判断一个用户是否会点击一个广告（会点击／不会点击），可以用Logistic Regression来判断两类人是否会相爱（会相爱／不会相爱），等等。</p>
<p>机器学习的主旨就是通过对历史数据的计算（即&#8220;学习&#8221;），得到一些未知参数的值，从而可以推断出新数据会有什么结论。例如一个非常简单的函数： <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_0fdb61c8abfb7bfd67516c1f8c8055b2.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="y = ax + b" /></span><script type='math/tex'>y = ax + b</script> ，在已知几组  <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_90cbc22edf225adf8a68974f51227f05.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="(x,y)" /></span><script type='math/tex'>(x,y)</script>  历史数据的情况下：</p>
<div>
<blockquote>
<div>
			(1, 5.5)<br />
			(1.5, 7)<br />
			(2, 6.5)</div>
</blockquote>
<p>	我们怎样能够预测一个未知的自变量  <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_4c63f2fd29fec6c20010a36949e9752d.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="x = 3" /></span><script type='math/tex'>x = 3</script>  会对应什么样的因变量&#160; <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_415290769594460e2e485922904f345d.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="y" /></span><script type='math/tex'>y</script>  呢？也就是说， <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_4c63f2fd29fec6c20010a36949e9752d.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="x = 3" /></span><script type='math/tex'>x = 3</script>  时&#160; <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_232ec2a90bc0ab9fb1a405d8ffe47582.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="y = ?" /></span><script type='math/tex'>y = ?</script></p></div>&#8230; <a href="https://www.codelast.com/%e5%8e%9f%e5%88%9b-%e7%94%a8%e4%ba%ba%e8%af%9d%e8%a7%a3%e9%87%8a%e6%9c%ba%e5%99%a8%e5%ad%a6%e4%b9%a0%e4%b8%ad%e7%9a%84logistic-regression%ef%bc%88%e9%80%bb%e8%be%91%e5%9b%9e%e5%bd%92%ef%bc%89/" class="read-more">Read More </a>]]></description>
										<content:encoded><![CDATA[<p>友情提示：如果觉得页面中的公式显示太小，可以放大页面查看（不会失真）。</p>
<p><span style="color:#0000ff;">Logistic Regression</span>（或<span style="color:#0000ff;">Logit Regression</span>），即<span style="color:#0000ff;">逻辑回归</span>，简记为<span style="color:#0000ff;">LR</span>，是机器学习领域的一种极为常用的算法／方法／模型。<br />
你能从网上搜到十万篇讲述Logistic Regression的文章，也不多我这一篇，但是，就像我写过的<a href="http://www.codelast.com/?p=7364" rel="noopener noreferrer" target="_blank"><span style="background-color:#ffa07a;">最优化系列文章</span></a>一样，我仍然试图用&ldquo;人话&rdquo;来再解释一遍&mdash;&mdash;可能不专业，但是容易看得懂。那些一上来就是几页数学公式什么的最讨厌了，不是吗？<br />
所以这篇文章是写给完全没听说过Logistic Regression的人看的，我相信看完这篇文章，你差不多可以从无到有，把逻辑回归应用到实践中去。<br />
<span id="more-8629"></span><br />
Logistic Regression是一种<span style="color:#0000ff;">分类</span>算法。分类，也就是把一个群体（或问题，或数据）分为几个类别，例如，男/女/人妖；爱她的人/不爱她的人；今天会下雨/今天不会下雨。<br />
Logistic Regression最常用于处理&ldquo;<span style="color:#0000ff;">二分类</span>&rdquo;问题，也就是说分类只有两个，像&ldquo;爱她的人/不爱她的人&rdquo;就是二分类，而&ldquo;男/女/人妖&rdquo;就不是二分类。当然，Logistic Regression也可以用于处理多分类问题，即所谓的&ldquo;<span style="color:#800080;">多分类逻辑回归</span>&rdquo;（<span style="color:#b22222;">Multiclass Logistic Regression</span>），但本文并不涉及这个方面。<br />
所以，说得简单点就是，给你一条数据，用Logistic Regression可以判断出这条数据应该被分到两个类别中的哪个中去。<br />
<span style="color: rgb(255, 255, 255);">文章来源：</span><a href="http://www.codelast.com/" rel="noopener noreferrer" target="_blank"><span style="color: rgb(255, 255, 255);">http://www.codelast.com/</span></a><br />
Logistic Regression在现实世界中非常有用。例如，可以用它来判断一个用户是否会点击一个广告（会点击／不会点击），可以用Logistic Regression来判断两类人是否会相爱（会相爱／不会相爱），等等。</p>
<p>机器学习的主旨就是通过对历史数据的计算（即&ldquo;学习&rdquo;），得到一些未知参数的值，从而可以推断出新数据会有什么结论。例如一个非常简单的函数： <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_0fdb61c8abfb7bfd67516c1f8c8055b2.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="y = ax + b" /></span><script type='math/tex'>y = ax + b</script> ，在已知几组  <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_90cbc22edf225adf8a68974f51227f05.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="(x,y)" /></span><script type='math/tex'>(x,y)</script>  历史数据的情况下：</p>
<div>
<blockquote>
<div>
			(1, 5.5)<br />
			(1.5, 7)<br />
			(2, 6.5)</div>
</blockquote>
<p>	我们怎样能够预测一个未知的自变量  <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_4c63f2fd29fec6c20010a36949e9752d.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="x = 3" /></span><script type='math/tex'>x = 3</script>  会对应什么样的因变量&nbsp; <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_415290769594460e2e485922904f345d.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="y" /></span><script type='math/tex'>y</script>  呢？也就是说， <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_4c63f2fd29fec6c20010a36949e9752d.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="x = 3" /></span><script type='math/tex'>x = 3</script>  时&nbsp; <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_232ec2a90bc0ab9fb1a405d8ffe47582.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="y = ?" /></span><script type='math/tex'>y = ?</script> <br />
	显然我们的任务就是计算出两个未知参数&nbsp; <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_0cc175b9c0f1b6a831c399e269772661.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="a" /></span><script type='math/tex'>a</script>  和&nbsp; <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_92eb5ffee6ae2fec3ad71c777531578f.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="b" /></span><script type='math/tex'>b</script>  的值，有了这两个值，那么任意给定一个&nbsp; <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_9dd4e461268c8034f5c8564e155c67a6.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="x" /></span><script type='math/tex'>x</script> ，我们都能通过函数&nbsp; <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_0fdb61c8abfb7bfd67516c1f8c8055b2.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="y = ax + b" /></span><script type='math/tex'>y = ax + b</script>  计算出&nbsp; <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_415290769594460e2e485922904f345d.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="y" /></span><script type='math/tex'>y</script>  的值了，这就是所谓的&ldquo;预测&rdquo;。<br />
	<span style="color: rgb(255, 255, 255);">文章来源：</span><a href="http://www.codelast.com/" rel="noopener noreferrer" target="_blank"><span style="color: rgb(255, 255, 255);">http://www.codelast.com/</span></a><br />
	Logistic Regression也是类似，我们有一个函数  <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_d19546fa62d4242fb94dd1e54f1497ec.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="y = f(X)" /></span><script type='math/tex'>y = f(X)</script> ，里面包含若干个未知参数  <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_600c746b4b1e96f24bf5e68ffdd17c32.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="{\theta _0},{\theta _1},{\theta _2}, \cdots ,{\theta _n}" /></span><script type='math/tex'>{\theta _0},{\theta _1},{\theta _2}, \cdots ,{\theta _n}</script> 。<br />
	由于现实世界是复杂的，因变量&nbsp; <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_415290769594460e2e485922904f345d.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="y" /></span><script type='math/tex'>y</script>  通常会跟很多因素（自变量  <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_9dd4e461268c8034f5c8564e155c67a6.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="x" /></span><script type='math/tex'>x</script> ）有关系，即&nbsp; <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_51e1680e3df2c1a03394b225f5754880.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="{x_0},{x_1},{x_2}, \cdots ,{x_n}" /></span><script type='math/tex'>{x_0},{x_1},{x_2}, \cdots ,{x_n}</script> ，所以这里自变量是一个<span style="color:#0000ff;">向量</span>，这里用大写的  <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_02129bb861061d1a052c592e2dc6b383.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="X" /></span><script type='math/tex'>X</script>  来表示。同理，那一堆未知的参数也是一个向量，用一个字母  <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_50d91f80cbb8feda1d10e167107ad1ff.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="\theta " /></span><script type='math/tex'>\theta </script>  来表示。<br />
	现在给我们一堆 <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_90cbc22edf225adf8a68974f51227f05.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="(x,y)" /></span><script type='math/tex'>(x,y)</script> 的历史数据，我们要想办法计算出所有未知参数的值，然后就可以拿来预测新的&nbsp; <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_9dd4e461268c8034f5c8564e155c67a6.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="x" /></span><script type='math/tex'>x</script>  值所对应的&nbsp; <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_415290769594460e2e485922904f345d.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="y" /></span><script type='math/tex'>y</script>  值了。<br />
	但是这个函数是什么呢？如下：<br />
	<span style="color:#0000ff;"> <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_d75712642d3eb1dbfc0bc0718cdfb7cd.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="f(X) = \frac{1}{{1 + {e^{ - {\theta ^T}X}}}}{\rm{ }}" /></span><script type='math/tex'>f(X) = \frac{1}{{1 + {e^{ - {\theta ^T}X}}}}{\rm{ }}</script> </span> <span style="color:#ff0000;">&hellip;&hellip;（1）</span><br />
	其中， <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_50d91f80cbb8feda1d10e167107ad1ff.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="\theta " /></span><script type='math/tex'>\theta </script>  是参数向量， <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_02129bb861061d1a052c592e2dc6b383.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="X" /></span><script type='math/tex'>X</script>  是自变量（向量）。<br />
	<span style="color: rgb(255, 255, 255);">文章来源：</span><a href="http://www.codelast.com/" rel="noopener noreferrer" target="_blank"><span style="color: rgb(255, 255, 255);">http://www.codelast.com/</span></a><br />
	那么，这个略显奇怪的函数是怎么来的呢？<br />
	首先我们看  <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_7214334e01f01d7c5648efcd790e4631.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="{{\theta ^T}X}" /></span><script type='math/tex'>{{\theta ^T}X}</script>  这部分：这是参数向量与自变量（向量）的<a href="https://zh.wikipedia.org/wiki/%E6%95%B0%E9%87%8F%E7%A7%AF" rel="noopener noreferrer" target="_blank"><span style="background-color:#ffa07a;">点积</span></a>，这个式子想要表达的含义是：计算某个事件发生的可能性，可以把跟这个事件相关的所有特征加权求和。例如，要求今天下雨的可能性，可以把今天所有和下雨相关的概率加权求和，例如梅雨季节权重为9（每天都很可能下雨），有台风经过权重为6，等等，每一个因素都影响着&ldquo;下雨的可能性&rdquo;，即：<br />
	 <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_bbeb4b1d67260873773804370090ce01.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="s = \sum\limits_{i = 0}^n {{\theta _i}{x_i}} = {\theta _0}{x_0} + {\theta _1}{x_1} + \cdots + {\theta _n}{x_n} = {\theta ^T}X" /></span><script type='math/tex'>s = \sum\limits_{i = 0}^n {{\theta _i}{x_i}} = {\theta _0}{x_0} + {\theta _1}{x_1} + \cdots + {\theta _n}{x_n} = {\theta ^T}X</script> <br />
	但是这个加权求和的结果是在  <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_d0b6f29f7312261c6da8700518a6a27e.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="( - \infty , + \infty )" /></span><script type='math/tex'>( - \infty , + \infty )</script>  范围内的，为了能表示预测的概率，我们希望把输出值限制在  <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_b6dbc33006b907f2db1855810abfce98.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="(0,1)" /></span><script type='math/tex'>(0,1)</script>  之间，而不是&nbsp; <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_d0b6f29f7312261c6da8700518a6a27e.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="( - \infty , + \infty )" /></span><script type='math/tex'>( - \infty , + \infty )</script> 。所以，这时，<span style="color: rgb(0, 0, 255);">逻辑函数</span>就出场了。</div>
<div>
	<span style="color: rgb(255, 255, 255);">文章来源：</span><a href="http://www.codelast.com/" rel="noopener noreferrer" target="_blank"><span style="color: rgb(255, 255, 255);">http://www.codelast.com/</span></a><br />
	通过<a href="https://zh.wikipedia.org/wiki/%E9%82%8F%E8%BC%AF%E5%87%BD%E6%95%B8" rel="noopener noreferrer" target="_blank"><span style="background-color:#ffa07a;">这个WiKi页面</span></a>你可以知道，其实所谓的<span style="color:#0000ff;">逻辑函数</span>，就是这样的一个函数：<br />
	 <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_88b4cd1dcd65e1f12fe0d827ba791108.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="P(t) = \frac{1}{{1 + {e^{ - t}}}}" /></span><script type='math/tex'>P(t) = \frac{1}{{1 + {e^{ - t}}}}</script> <br />
	这个函数是由 Pierre Fran&ccedil;ois Verhulst（皮埃尔&middot;弗朗索瓦&middot;韦吕勒）在1844～1845年的时候给它起的名字。而我们上面的函数(1)，就是这个形式。<br />
	逻辑函数的图像是这个样子的：<br />
	<img decoding="async" alt="logistic function" src="https://www.codelast.com/wp-content/uploads/2016/01/logistic_function.png" style="width: 517px; height: 273px;" /><br />
	它的函数值刚好就是在(0,1)之间。<br />
	所以，我们通过逻辑函数，就可以计算出一个事件的概率了（(0,1)之间）。但是不要忘了，我们前面说要处理二分类问题，得到一个(0,1)之间的任意值并不能归到两个分类中的一个里去，所以还要把这个概率值&ldquo;归类&rdquo;。其实这里很简单，我们可以在&nbsp; <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_4b8d6a6375fd790e922b90da0ecd933d.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="f(X) > 0.5" /></span><script type='math/tex'>f(X) > 0.5</script> &nbsp;的时候，把它归到类别1中， <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_224bae9043a536776b0b33751b1b72b0.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="f(X) \le 0.5" /></span><script type='math/tex'>f(X) \le 0.5</script> &nbsp;的时候，把它归到类别2中就可以了（概率值的&ldquo;分水岭&rdquo;可以根据实际情况调整）。用数学公式来表达这段话的含义就是：</p>
<div>
		 <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_fd236b87dd9852ea434e65a277b2398c.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="y' = \left\{ {\begin{array}{*{20}{c}}{0,f(X) > 0.5}\\{1,f(X) \le 0.5}\end{array}} \right." /></span><script type='math/tex'>y' = \left\{ {\begin{array}{*{20}{c}}{0,f(X) > 0.5}\\{1,f(X) \le 0.5}\end{array}} \right.</script> </div>
<p>
	在各种机器学习的文章中，你都会看到，它们给了逻辑函数一个常用的名字：<span style="color:#0000ff;">Sigmoid函数</span>。sigmoid，意为&ldquo;S形的&rdquo;，这正符合其函数图像特点，所以大家记住就行了。<br />
	<span style="color: rgb(255, 255, 255);">文章来源：</span><a href="http://www.codelast.com/" rel="noopener noreferrer" target="_blank"><span style="color: rgb(255, 255, 255);">http://www.codelast.com/</span></a><br />
	现在，我们已经有了函数，下一步任务就是求出函数表达式中的未知参数向量  <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_50d91f80cbb8feda1d10e167107ad1ff.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="\theta " /></span><script type='math/tex'>\theta </script>  了。这个过程是机器学习中最为核心的计算步骤。<br />
	以前面讲过的函数  <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_0fdb61c8abfb7bfd67516c1f8c8055b2.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="y = ax + b" /></span><script type='math/tex'>y = ax + b</script> &nbsp;为例：<br />
	你会发现，当已知几组  <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_90cbc22edf225adf8a68974f51227f05.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="(x,y)" /></span><script type='math/tex'>(x,y)</script> &nbsp;数据的情况下：</p>
<blockquote><p>
		(1, 5.5)<br />
		(1.5, 7)<br />
		(2, 6.5)</p></blockquote>
<p>	你无论如何也不可能找到一对  <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_0cc175b9c0f1b6a831c399e269772661.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="a" /></span><script type='math/tex'>a</script>  和&nbsp; <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_92eb5ffee6ae2fec3ad71c777531578f.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="b" /></span><script type='math/tex'>b</script>  的值，使得以上3组数据能精确地满足方程&nbsp;&nbsp; <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_0fdb61c8abfb7bfd67516c1f8c8055b2.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="y = ax + b" /></span><script type='math/tex'>y = ax + b</script> ，正如下面的图像所示：<br />
	<img decoding="async" alt="logistic function" src="https://www.codelast.com/wp-content/uploads/2016/01/ax_b.png" style="width: 1010px; height: 234px;" /></p>
<p>	这条直线如果要精确地通过其中的两个点，那么就不能通过第三个点。所以，最终求出来的&nbsp; <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_0cc175b9c0f1b6a831c399e269772661.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="a" /></span><script type='math/tex'>a</script>  和&nbsp; <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_92eb5ffee6ae2fec3ad71c777531578f.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="b" /></span><script type='math/tex'>b</script>  的值，并不是方程的<a href="https://zh.wikipedia.org/wiki/%E8%A7%A3%E6%9E%90%E8%A7%A3" rel="noopener noreferrer" target="_blank"><span style="background-color:#ffa07a;">解析解</span></a>，而是&ldquo;<span style="color:#0000ff;">最优解</span>&rdquo;。<br />
	因此，问题在于，我们如何画一条直线，使得其是&ldquo;最优&rdquo;的？&ldquo;最优&rdquo;的评判标准是什么？<br />
	<span style="color: rgb(255, 255, 255);">文章来源：</span><a href="http://www.codelast.com/" rel="noopener noreferrer" target="_blank"><span style="color: rgb(255, 255, 255);">http://www.codelast.com/</span></a><br />
	为了理解&ldquo;最优&rdquo;，我们需要先了解一些概念。</p>
<ul>
<li>
			<span style="color:#0000ff;">损失函数</span>／<span style="color: rgb(0, 0, 255);">Loss Function</span>／<span style="color: rgb(0, 0, 255);">代价函数</span>／<span style="color: rgb(0, 0, 255);">Cost Function</span></li>
</ul>
</div>
<div>
	很多文章说，这几个名词的含义是一样的。但是也有文章说，Loss Function和Cost Function不是一回事，例如<a href="http://image.diku.dk/shark/sphinx_pages/build/html/rest_sources/tutorials/concepts/library_design/losses.html" rel="noopener noreferrer" target="_blank"><span style="background-color:#ffa07a;">这篇</span></a>文章。但通常认为，这二者是一回事。我觉得嘛，大家就按通常的概念来接受就好了。<br />
	按<a href="https://en.wikipedia.org/wiki/Loss_function" rel="noopener noreferrer" target="_blank"><span style="background-color:#ffa07a;">WiKi</span></a>的定义：</div>
<blockquote>
<div>
		In mathematical optimization, statistics, decision theory and machine learning, a loss function or cost function is a function that maps an event or values of one or more variables onto a real number intuitively representing some &quot;cost&quot; associated with the event. An optimization problem seeks to minimize a loss function.</div>
</blockquote>
<div>
	以及：</div>
<blockquote>
<div>
		The loss function quantifies the amount by which the prediction deviates from the actual values.</div>
</blockquote>
<div>
	我们可以知道，损失函数用于衡量预测值与实际值的偏离程度，如果预测是完全精确的，则损失函数值为0；如果损失函数值不为0，则其表示的是预测的错误有多糟糕。使得损失函数值最小的那些待求参数值，就是&ldquo;最优&rdquo;的参数值。<br />
	<span style="color: rgb(255, 255, 255);">文章来源：</span><a href="http://www.codelast.com/" rel="noopener noreferrer" target="_blank"><span style="color: rgb(255, 255, 255);">http://www.codelast.com/</span></a><br />
	所以现在问题来了，损失函数的表达式又是什么？<br />
	在探讨损失函数的表达式之前，我们先来看一下损失函数有哪些种类。<br />
	损失函数有很多种，例如下面几个：<br />
	<span style="background-color:#dda0dd;">（1）</span>0-1损失函数：可用于<span style="color:#0000ff;">分类</span>问题，即该函数用于衡量<span style="color:#0000ff;">分类错误</span>的数量，但由于此损失函数是非凸（non-convex）的，因此在做最优化计算时，难以求解，所以，正因为如此，0-1损失函数不是那么&ldquo;实用&rdquo;（如果这句话有误，请指正）。<br />
	<span style="background-color:#dda0dd;">（2）</span>平方损失函数（Square Loss）：常用于线性回归（Linear Regression）。<br />
	<span style="background-color:#dda0dd;">（3）</span>对数损失（Log Loss）函数：常用于其模型输出每一类概率的分类器（classifier），例如逻辑回归。<br />
	<span style="background-color:#dda0dd;">（4）</span>Hinge损失函数：常用于SVM（Support Vector Machine，支持向量机，一种机器学习算法）。中文名叫&ldquo;<span style="color:#0000ff;">合页</span>损失函数&rdquo;，因为hinge有&ldquo;合页&rdquo;之意。这个翻译虽然直白，但是你会发现，99％的文章都不会用它的中文名来称呼它，而是用&ldquo;Hinge损失&rdquo;之类的说法。</p>
<p>	这些都是人们的经验总结，当然，说每一种损失函数常用于什么机器学习算法，也都是有数学依据的。但是在这里，我们讲的是Logistic Regression，所以只看对数损失函数。对数损失函数通常用于衡量分类器（classifier）的精度，这里的&ldquo;分类器&rdquo;也就是指机器学习的模型，它对每一个类别输出一个概率值。从前面的文章中，我们已经知道了，逻辑回归就是这样一种分类器，所以才用对数损失函数来衡量其精度。<br />
	有时候，对数损失函数（Log Loss）也被叫作<span style="color:#0000ff;">交叉熵</span>损失函数（Cross-entropy Loss）。<a href="https://en.wikipedia.org/wiki/Cross_entropy" rel="noopener noreferrer" target="_blank"><span style="color:#0000ff;">交叉熵</span></a>这个名字比较拗口，在信息理论中，<span style="color:#0000ff;">熵</span>用于衡量某种事件的&ldquo;不可预测性&rdquo;，而<span style="color:#0000ff;">交叉熵</span>=事件的真实分布+不可预测性，所以交叉熵可以用于度量两个概率分布（真实分布&amp;预测分布）之间的差异性，即：交叉熵损失函数（对数损失函数）可以衡量一个模型对真实值带来的额外噪音，通过最小化交叉熵损失函数（对数损失函数），我们就可以最大化分类器（模型）的精度。<br />
	上面这一大段话试图用简单的描述让你相信，为什么要用Log Loss来衡量Logistic Regression的误差，但是没有给出证明。有人可能会说，为什么不能用其他的方法来衡量，例如用平方损失函数（Square Loss）。事实上，这是有数学依据的&mdash;&mdash;它会导致损失函数是一个关于参数向量 <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_50d91f80cbb8feda1d10e167107ad1ff.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="\theta " /></span><script type='math/tex'>\theta </script> 的<span style="color:#0000ff;">非</span><a href="https://zh.wikipedia.org/wiki/%E5%87%B8%E5%87%BD%E6%95%B0" rel="noopener noreferrer" target="_blank"><span style="background-color:#ffa07a;">凸函数</span></a>，而用对数损失函数就没有这种问题。凸函数的性质为我们后面求解参数向量 <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_50d91f80cbb8feda1d10e167107ad1ff.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="\theta " /></span><script type='math/tex'>\theta </script> 提供了极大便利，非凸函数有很多局部最优解，不利于求解 <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_50d91f80cbb8feda1d10e167107ad1ff.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="\theta " /></span><script type='math/tex'>\theta </script> 的计算过程。<br />
	<span style="color: rgb(255, 255, 255);">文章来源：</span><a href="http://www.codelast.com/" rel="noopener noreferrer" target="_blank"><span style="color: rgb(255, 255, 255);">http://www.codelast.com/</span></a><br />
	到这里为止，我们还是没有提到损失函数的数学表达式，但是如果要计算损失函数的值，我们是回避不了的，必须要知道。所以，这里用 L 来表示损失函数（取<span style="color: rgb(255, 0, 0);">L</span>oss之意），则对数损失函数的表达式为：<br />
	<span style="color:#0000ff;"> <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_276a829ddba9850126edcea1af119036.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="L = - \frac{1}{n}\sum\limits_{i = 1}^n {[{y_i}\log ({{\hat y}_i}) + (1 - {y_i})\log (1 - {{\hat y}_i})]} " /></span><script type='math/tex'>L = - \frac{1}{n}\sum\limits_{i = 1}^n {[{y_i}\log ({{\hat y}_i}) + (1 - {y_i})\log (1 - {{\hat y}_i})]} </script> </span> <span style="color:#ff0000;">......（2）</span><br />
	其中， <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_eb80f83e86467cf361778c55e850e5e0.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="{{y_i}}" /></span><script type='math/tex'>{{y_i}}</script> 是第i个真实值（ <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_64903c82c12bd5f8d201e975ac2c3101.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="{y_i} \in \{ 0,1\} " /></span><script type='math/tex'>{y_i} \in \{ 0,1\} </script> ）， <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_e466a7d704ae3cf2e5b7414bbae760ba.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="{{{\hat y}_i}}" /></span><script type='math/tex'>{{{\hat y}_i}}</script> 是第i个预测值。<br />
	这个对数损失函数的表达式中并没有出现我们要求解的参数&nbsp; <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_50d91f80cbb8feda1d10e167107ad1ff.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="\theta " /></span><script type='math/tex'>\theta </script> ，所以我们把&nbsp; <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_683296a9a6612653594c598476e669a8.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="\hat y = f(X) = \frac{1}{{1 + {e^{ - {\theta ^T}X}}}}" /></span><script type='math/tex'>\hat y = f(X) = \frac{1}{{1 + {e^{ - {\theta ^T}X}}}}</script>  代到（2）式中去：<br />
	 <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_961181b6fd923c712b21a4cb9334697a.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="L = - \frac{1}{N}\sum\limits_{i = 1}^n {\left[ {{y_i}\log \left( {\frac{1}{{1 + {e^{ - {\theta ^T}{X_i}}}}}} \right) + (1 - {y_i})\log \left( {1 - \frac{1}{{1 + {e^{ - {\theta ^T}{X_i}}}}}} \right)} \right]} " /></span><script type='math/tex'>L = - \frac{1}{N}\sum\limits_{i = 1}^n {\left[ {{y_i}\log \left( {\frac{1}{{1 + {e^{ - {\theta ^T}{X_i}}}}}} \right) + (1 - {y_i})\log \left( {1 - \frac{1}{{1 + {e^{ - {\theta ^T}{X_i}}}}}} \right)} \right]} </script> <br />
	再来仔细看一下这个式子：N 为数据集的条数（有多少组 <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_0340c3897ed6af331d4d59a20946c451.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="(X,y)" /></span><script type='math/tex'>(X,y)</script> ，N就是多少），已知； <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_eb80f83e86467cf361778c55e850e5e0.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="{{y_i}}" /></span><script type='math/tex'>{{y_i}}</script>  是真实值，已知； <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_2af46b114c169c94ea9a86ca7b36758b.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="{{X_i}}" /></span><script type='math/tex'>{{X_i}}</script> 是输入的向量，也已知。所以整个式子里只有 <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_50d91f80cbb8feda1d10e167107ad1ff.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="\theta " /></span><script type='math/tex'>\theta </script> 是未知的，可以记为 <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_bd346812a06f2d43be738a6f13cc17ee.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="L(\theta )" /></span><script type='math/tex'>L(\theta )</script> ，称之为<span style="color:#0000ff;">目标函数</span>：<br />
	 <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_ea3fb6a016e9c65dd4bae8aeb9ee1f68.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="L(\theta ) = - \frac{1}{N}\sum\limits_{i = 1}^n {\left[ {{y_i}\log \left( {\frac{1}{{1 + {e^{ - {\theta ^T}{X_i}}}}}} \right) + (1 - {y_i})\log \left( {1 - \frac{1}{{1 + {e^{ - {\theta ^T}{X_i}}}}}} \right)} \right]} " /></span><script type='math/tex'>L(\theta ) = - \frac{1}{N}\sum\limits_{i = 1}^n {\left[ {{y_i}\log \left( {\frac{1}{{1 + {e^{ - {\theta ^T}{X_i}}}}}} \right) + (1 - {y_i})\log \left( {1 - \frac{1}{{1 + {e^{ - {\theta ^T}{X_i}}}}}} \right)} \right]} </script> <br />
	因此，我们只要找到一个参数向量 <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_50d91f80cbb8feda1d10e167107ad1ff.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="\theta " /></span><script type='math/tex'>\theta </script> ，能使得此式的值最小，那么这个参数向量 <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_50d91f80cbb8feda1d10e167107ad1ff.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="\theta " /></span><script type='math/tex'>\theta </script> 就是&ldquo;最优&rdquo;的参数向量。<br />
	求得了这个最优的 <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_50d91f80cbb8feda1d10e167107ad1ff.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="\theta " /></span><script type='math/tex'>\theta </script> 之后，把它代入式（1），则对任一个未知的 <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_02129bb861061d1a052c592e2dc6b383.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="X" /></span><script type='math/tex'>X</script> ，我们都可以计算出 <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_41c2f2136110516f7d332adc5041b0fe.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="f(X)" /></span><script type='math/tex'>f(X)</script> 值，然后再根据一个阈值把它调整到 0 或 1，就得到了这个 <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_02129bb861061d1a052c592e2dc6b383.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="X" /></span><script type='math/tex'>X</script> 所属的分类，这样，我们就完成了一次&ldquo;预测&rdquo;的过程。<br />
	<span style="color: rgb(255, 255, 255);">文章来源：</span><a href="http://www.codelast.com/" rel="noopener noreferrer" target="_blank"><span style="color: rgb(255, 255, 255);">http://www.codelast.com/</span></a></div>
<ul>
<li>
		求解方法</li>
</ul>
<div>
	所以现在问题来了，这个&ldquo;最优&rdquo;的参数向量 <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_50d91f80cbb8feda1d10e167107ad1ff.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="\theta " /></span><script type='math/tex'>\theta </script> 怎么求解？<br />
	在大的方向上，你可以选择不使用搜索方向的算法（例如<a href="http://www.codelast.com/?p=7488" rel="noopener noreferrer" target="_blank"><span style="background-color:#ffa07a;">信赖域算法</span></a>），也可以选择众多使用搜索方向的算法（例如<a href="http://www.codelast.com/?p=8006" rel="noopener noreferrer" target="_blank"><span style="background-color:#ffa07a;">梯度下降法</span></a>）。<br />
	在是否计算<span style="color:#0000ff;">目标函数</span>的导数这个方面，你可以使用不用求目标函数导数的算法（例如<a href="http://www.codelast.com/?p=388" rel="noopener noreferrer" target="_blank"><span style="background-color:#ffa07a;">Powell共轭方向集方法</span></a>），也可以使用要求目标函数导数的算法（例如<span style="background-color: rgb(255, 160, 122);"><a href="http://www.codelast.com/?p=8006" rel="noopener noreferrer" target="_blank">梯度下降法</a></span>）。由于某些目标函数形式特别复杂，计算其导数特别麻烦，所以在这种时候，不用计算导数的算法可能大有帮助。</div>
<div>
	求解的过程就是一个<a href="http://www.codelast.com/?p=7364" rel="noopener noreferrer" target="_blank"><span style="background-color:#ffa07a;">最优化</span></a>的过程，本文无法用一两句话描述清楚，请大家移步链接进行阅读。</p>
<p>	事实上，在现在各种机器学习library百花齐放的今天，我们基本上不需要自己编写这些算法的具体实现，只需要调用它们即可。例如，通过Spark的Machine Learning Library (MLlib)，我们可以直接使用Stochastic gradient descent (SGD)，Limited-memory <a href="http://www.codelast.com/?p=2780" rel="noopener noreferrer" target="_blank"><span style="background-color:#ffa07a;">BFGS</span></a> (L-BFGS)等实现。但是对这背后的原理有所了解，对工作学习是有帮助的。<br />
	<span style="color: rgb(255, 255, 255);">文章来源：</span><a href="https://www.codelast.com/" rel="noopener noreferrer" target="_blank"><span style="color: rgb(255, 255, 255);">https://www.codelast.com/</span></a><br />
	<span style="color: rgb(255, 0, 0);">➤➤</span>&nbsp;版权声明&nbsp;<span style="color: rgb(255, 0, 0);">➤➤</span>&nbsp;<br />
	转载需注明出处：<u><a href="https://www.codelast.com/" rel="noopener noreferrer" target="_blank"><em><span style="color: rgb(0, 0, 255);"><strong style="font-size: 16px;"><span style="font-family: arial, helvetica, sans-serif;">codelast.com</span></strong></span></em></a></u>&nbsp;<br />
	感谢关注我的微信公众号（微信扫一扫）：</p>
<p style="border: 0px; font-size: 13px; margin: 0px 0px 9px; outline: 0px; padding: 0px; color: rgb(77, 77, 77);">
		<img decoding="async" alt="wechat qrcode of codelast" src="https://www.codelast.com/codelast_wechat_qr_code.jpg" style="width: 200px; height: 200px;" /></p>
</div>
]]></content:encoded>
					
					<wfw:commentRss>https://www.codelast.com/%e5%8e%9f%e5%88%9b-%e7%94%a8%e4%ba%ba%e8%af%9d%e8%a7%a3%e9%87%8a%e6%9c%ba%e5%99%a8%e5%ad%a6%e4%b9%a0%e4%b8%ad%e7%9a%84logistic-regression%ef%bc%88%e9%80%bb%e8%be%91%e5%9b%9e%e5%bd%92%ef%bc%89/feed/</wfw:commentRss>
			<slash:comments>19</slash:comments>
		
		
			</item>
		<item>
		<title>[原创] 再谈 共轭方向法/Conjugate Direction Method In Optimization</title>
		<link>https://www.codelast.com/%e5%8e%9f%e5%88%9b-%e5%86%8d%e8%b0%88-%e5%85%b1%e8%bd%ad%e6%96%b9%e5%90%91%e6%b3%95conjugate-direction-method-in-optimization/</link>
					<comments>https://www.codelast.com/%e5%8e%9f%e5%88%9b-%e5%86%8d%e8%b0%88-%e5%85%b1%e8%bd%ad%e6%96%b9%e5%90%91%e6%b3%95conjugate-direction-method-in-optimization/#comments</comments>
		
		<dc:creator><![CDATA[learnhard]]></dc:creator>
		<pubDate>Sat, 26 Apr 2014 16:13:12 +0000</pubDate>
				<category><![CDATA[Algorithm]]></category>
		<category><![CDATA[Math]]></category>
		<category><![CDATA[原创]]></category>
		<category><![CDATA[conjugate direction method]]></category>
		<category><![CDATA[optimization]]></category>
		<category><![CDATA[共轭方向法]]></category>
		<category><![CDATA[最优化]]></category>
		<guid isPermaLink="false">http://www.codelast.com/?p=8095</guid>

					<description><![CDATA[<p>
共轭方向法是介于<a href="http://www.codelast.com/?p=8006" target="_blank" rel="noopener noreferrer"><span style="background-color:#ffa07a;">最速下降法</span></a>和<a href="http://www.codelast.com/?p=8052" target="_blank" rel="noopener noreferrer"><span style="background-color:#ffa07a;">牛顿法</span></a>之间的一种存在&#8212;&#8212;它的收敛速度（二阶收敛）比最速下降法（线性收敛）快，同时它的计算量又比牛顿法要小，因此它的存在是有意义的。<br />
<span id="more-8095"></span><br />
需要注意，共轭方向法可以不使用目标函数的一阶导数信息（当然也可以使用）。所以，如果目标函数的一阶导数不容易求的话，共轭方向法可能就可以派上用场了。<br />
共轭方向法的显著特征就是：两次搜索方向之间是有关联的，这种关联就是&#8220;<span style="color:#0000ff;">共轭</span>&#8221;。<br />
<span style="color: rgb(255, 255, 255);">文章来源：</span><a href="http://www.codelast.com/" target="_blank" rel="noopener noreferrer"><span style="color: rgb(255, 255, 255);">http://www.codelast.com/</span></a><br />
<span style="background-color:#00ff00;">『1』</span>向量共轭<br />
先解释一下向量共轭的含义，你就明白共轭方向法的两次搜索方向之间的&#8220;共轭&#8221;是怎么回事了。<br />
设 <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_dfcf28d0734569a6a693bc8194de62bf.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="G" /></span><script type='math/tex'>G</script> 为对称正定矩阵，若 <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_37aa6fd50c9cd0ae84da344d3fea07a2.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="d_m^TG{d_n} = 0,\;\;m \ne n" /></span><script type='math/tex'>d_m^TG{d_n} = 0,\;\;m \ne n</script> ，则称 <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_fba7cefe2ae092ffa5b6b0427619538b.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="{d_m}" /></span><script type='math/tex'>{d_m}</script> 和 <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_bbc1f7226df689a8d60b4e3d69a468a6.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="{d_n}" /></span><script type='math/tex'>{d_n}</script> 为&#8220;G共轭&#8221;，共轭方向是&#8220;互不相关&#8221;的方向。</p>
<p><span style="background-color:#00ff00;">『2』</span>特性<br />
当目标函数是二次函数 <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_7b3308f8a3b2b34b5121ac917759d1ae.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="f(x) = \frac{1}{2}{x^T}Gx + {b^T}x + c" /></span><script type='math/tex'>f(x) = \frac{1}{2}{x^T}Gx + {b^T}x + c</script> 时，共轭方向法最多经过N步（N为向量维数）迭代，就可以到达极小值点&#8212;&#8212;这种特性叫作<span style="color:#0000ff;">二次收敛性</span>（<span style="color:#a52a2a;">Quadratic Convergence</span>）。<br />
假设沿着一系列的共轭方向做迭代（寻找极小值点），这些共轭方向组成的集合叫作共轭方向集，则沿共轭方向集的每个方向顺序做line search的时候，在每个方向上都不需要做重复搜索&#8212;&#8212;在任何一个方向上的移动，都不会影响到在另一个方向上已经找到的极小值。<br />
上面这段描述是什么意思呢？我们先不讨论这些共轭方向是怎么计算出来的，拿一个在水平面上走路的例子来做比喻：你在水平方向A上走了10米，然后再沿着与水平方向垂直的另一个方向B上又走了10米，那么，你在方向A上走动的时候，在方向B上的坐标是不变的；你在方向B上走动的时候，在方向A上的坐标也是不变的。因此，把方向A和方向B看作两个共轭方向，那么，你在这两个共轭方向中的任何一个方向上移动，都不会影响到另一个方向上已经走到的坐标（把它想像成在这个方向上的极小值）。<br />
<span style="color: rgb(255, 255, 255);">文章来源：</span><a href="http://www.codelast.com/" target="_blank" rel="noopener noreferrer"><span style="color: rgb(255, 255, 255);">http://www.codelast.com/</span></a>&#8230; <a href="https://www.codelast.com/%e5%8e%9f%e5%88%9b-%e5%86%8d%e8%b0%88-%e5%85%b1%e8%bd%ad%e6%96%b9%e5%90%91%e6%b3%95conjugate-direction-method-in-optimization/" class="read-more">Read More </a></p>]]></description>
										<content:encoded><![CDATA[<p>
共轭方向法是介于<a href="http://www.codelast.com/?p=8006" target="_blank" rel="noopener noreferrer"><span style="background-color:#ffa07a;">最速下降法</span></a>和<a href="http://www.codelast.com/?p=8052" target="_blank" rel="noopener noreferrer"><span style="background-color:#ffa07a;">牛顿法</span></a>之间的一种存在&mdash;&mdash;它的收敛速度（二阶收敛）比最速下降法（线性收敛）快，同时它的计算量又比牛顿法要小，因此它的存在是有意义的。<br />
<span id="more-8095"></span><br />
需要注意，共轭方向法可以不使用目标函数的一阶导数信息（当然也可以使用）。所以，如果目标函数的一阶导数不容易求的话，共轭方向法可能就可以派上用场了。<br />
共轭方向法的显著特征就是：两次搜索方向之间是有关联的，这种关联就是&ldquo;<span style="color:#0000ff;">共轭</span>&rdquo;。<br />
<span style="color: rgb(255, 255, 255);">文章来源：</span><a href="http://www.codelast.com/" target="_blank" rel="noopener noreferrer"><span style="color: rgb(255, 255, 255);">http://www.codelast.com/</span></a><br />
<span style="background-color:#00ff00;">『1』</span>向量共轭<br />
先解释一下向量共轭的含义，你就明白共轭方向法的两次搜索方向之间的&ldquo;共轭&rdquo;是怎么回事了。<br />
设 <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_dfcf28d0734569a6a693bc8194de62bf.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="G" /></span><script type='math/tex'>G</script> 为对称正定矩阵，若 <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_37aa6fd50c9cd0ae84da344d3fea07a2.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="d_m^TG{d_n} = 0,\;\;m \ne n" /></span><script type='math/tex'>d_m^TG{d_n} = 0,\;\;m \ne n</script> ，则称 <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_fba7cefe2ae092ffa5b6b0427619538b.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="{d_m}" /></span><script type='math/tex'>{d_m}</script> 和 <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_bbc1f7226df689a8d60b4e3d69a468a6.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="{d_n}" /></span><script type='math/tex'>{d_n}</script> 为&ldquo;G共轭&rdquo;，共轭方向是&ldquo;互不相关&rdquo;的方向。</p>
<p><span style="background-color:#00ff00;">『2』</span>特性<br />
当目标函数是二次函数 <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_7b3308f8a3b2b34b5121ac917759d1ae.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="f(x) = \frac{1}{2}{x^T}Gx + {b^T}x + c" /></span><script type='math/tex'>f(x) = \frac{1}{2}{x^T}Gx + {b^T}x + c</script> 时，共轭方向法最多经过N步（N为向量维数）迭代，就可以到达极小值点&mdash;&mdash;这种特性叫作<span style="color:#0000ff;">二次收敛性</span>（<span style="color:#a52a2a;">Quadratic Convergence</span>）。<br />
假设沿着一系列的共轭方向做迭代（寻找极小值点），这些共轭方向组成的集合叫作共轭方向集，则沿共轭方向集的每个方向顺序做line search的时候，在每个方向上都不需要做重复搜索&mdash;&mdash;在任何一个方向上的移动，都不会影响到在另一个方向上已经找到的极小值。<br />
上面这段描述是什么意思呢？我们先不讨论这些共轭方向是怎么计算出来的，拿一个在水平面上走路的例子来做比喻：你在水平方向A上走了10米，然后再沿着与水平方向垂直的另一个方向B上又走了10米，那么，你在方向A上走动的时候，在方向B上的坐标是不变的；你在方向B上走动的时候，在方向A上的坐标也是不变的。因此，把方向A和方向B看作两个共轭方向，那么，你在这两个共轭方向中的任何一个方向上移动，都不会影响到另一个方向上已经走到的坐标（把它想像成在这个方向上的极小值）。<br />
<span style="color: rgb(255, 255, 255);">文章来源：</span><a href="http://www.codelast.com/" target="_blank" rel="noopener noreferrer"><span style="color: rgb(255, 255, 255);">http://www.codelast.com/</span></a><br />
但是世界哪有那么美好？目标函数不是二次函数的时候多得去了！这个时候，共轭方向法不就废了吗？非也非也。<br />
<span style="color:#0000cd;">理论与实践证明，将二次收敛算法用于非二次的目标函数，也有很好的效果</span>。但是，这个时候，就不能保证N步迭代到达极小值点了。大家需要记住的是，很多函数都可以用二次函数很好地近似，这种近似在工程上是很重要。<br />
有人一定会问，哪些函数可以用二次函数很好地近似呢？请原谅我没在书中看到这个总结，你只能自己去挖掘了。</p>
<p><span style="background-color:#00ff00;">『3』</span>理论基础<br />
共轭方向法有一个重要的理论基础，它是一个神奇的定理，有了它，可以推导出很多结论（共轭梯度法的理论推导就依赖于此）。<br />
这里只把结论写上来，证明较长，不是本文关注的所以就不写了：<br />
<span style="color:#ff0000;">在精确line search的情况下，当前迭代点的梯度 <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_b2f5ff47436671b6e533d8dc3614845d.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="g" /></span><script type='math/tex'>g</script> 与前面所有的搜索方向 <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_8277e0910d750195b448797616e091ad.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="d" /></span><script type='math/tex'>d</script> 直交：<br />
 <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_9af80bf9ecd8ae0b0013c8f5c7c8412a.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="g_{i + 1}^T{d_j} = 0,\;\;j = 0,1, \cdots ,i" /></span><script type='math/tex'>g_{i + 1}^T{d_j} = 0,\;\;j = 0,1, \cdots ,i</script> </span><br />
这个结论在很多专业书中，都用了晦涩的描述来显示出教科书般的&ldquo;高端、大气、上档次&rdquo;，我看完之后只有一个感觉：看你们这些牛人写的书压力好大啊！<br />
上面的红字，是我认为可以精简成&ldquo;人话&rdquo;之后的描述，也许它不严谨，也许它有漏洞，但是它大概说的就是这么回事，简单不就是美吗？<br />
下面稍微解释一下定理中的一些概念：</p>
<div>
	<span style="color:#800080;">●</span> 为什么 <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_8d872f432d24ebbba8149cc6b8513904.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="g_{i + 1}^T{d_j} = 0" /></span><script type='math/tex'>g_{i + 1}^T{d_j} = 0</script> 表明两个向量&ldquo;直交&rdquo;？从两个向量的夹角的数学定义：</div>
<div style="text-align: center;">
	<img decoding="async" alt="vector angle" src="http://www.codelast.com/wp-content/uploads/ckfinder/images/vector_angle.png" style="width: 150px; height: 71px;" /></div>
<div>
	我们可知， <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_83ac542f846e9dcc6aea6534e5303b66.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="g_{i + 1}^T{d_j}" /></span><script type='math/tex'>g_{i + 1}^T{d_j}</script> 为0时，整个式子为零，从而 <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_f898dd39bd002624d891bc76fb86aa9f.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="\theta = \frac{\pi }{2}" /></span><script type='math/tex'>\theta = \frac{\pi }{2}</script> ，也就是说两个向量的夹角是 <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_e26d35e05970ddca7d236176d1db4d6d.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="\frac{\pi }{2}" /></span><script type='math/tex'>\frac{\pi }{2}</script> ，所以它们当然是&ldquo;直交&rdquo;的。</div>
<div>
	在 <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_8d872f432d24ebbba8149cc6b8513904.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="g_{i + 1}^T{d_j} = 0" /></span><script type='math/tex'>g_{i + 1}^T{d_j} = 0</script> 这个式子中，当 <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_b2f5ff47436671b6e533d8dc3614845d.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="g" /></span><script type='math/tex'>g</script> 的下标是 <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_14b8b90a04464597e4e220394a9e1416.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="{i + 1}" /></span><script type='math/tex'>{i + 1}</script> 时， <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_8277e0910d750195b448797616e091ad.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="d" /></span><script type='math/tex'>d</script> 的下标可以是 <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_9b99ea6244b508fa66267b802a9accf5.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="0,1,\cdots ,i" /></span><script type='math/tex'>0,1,\cdots ,i</script> ，例如， <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_2e6140194834b2ff066e6b6bc5bafd46.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="g_3^T{d_0} = 0,\;\;g_3^T{d_1} = 0,\;\;g_3^T{d_2} = 0" /></span><script type='math/tex'>g_3^T{d_0} = 0,\;\;g_3^T{d_1} = 0,\;\;g_3^T{d_2} = 0</script> ，这表明，当前迭代点的梯度 <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_d0720487a8b5bdbea3c08f5a9b9d3fef.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="{g_3}" /></span><script type='math/tex'>{g_3}</script> 与前面所有的搜索方向（ <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_808b726a7c1125dc98c805fd9e6951a2.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="{d_0},{d_1},{d_2}" /></span><script type='math/tex'>{d_0},{d_1},{d_2}</script> ）直交。</div>
<p><span style="color: rgb(255, 255, 255);">文章来源：</span><a href="http://www.codelast.com/" target="_blank" rel="noopener noreferrer"><span style="color: rgb(255, 255, 255);">http://www.codelast.com/</span></a><br />
现在我把某书中一段和上面的理论等价的描述摘录下来，让大家看看它描述得是不是很晦涩：<br />
<span style="color:#b22222;">共轭方向法在迭代过程中的每一个迭代点 <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_1ab026d0142e45d545714e7a32bc3258.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="{x_{i + 1}}" /></span><script type='math/tex'>{x_{i + 1}}</script> 都是目标函数 <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_50bbd36e1fd2333108437a2ca378be62.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="f(x)" /></span><script type='math/tex'>f(x)</script> 在 <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_892581f6aefecae90be73076e1aeee5c.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="{x_0}" /></span><script type='math/tex'>{x_0}</script> 和方向 <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_2a5196aebb115722e7689aa4492f5dc9.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="{d_0},{d_1}, \cdots ,{d_i}" /></span><script type='math/tex'>{d_0},{d_1}, \cdots ,{d_i}</script> 所张成的线性流形</span></p>
<div style="text-align: center;">
	<img decoding="async" alt="conjugate direction basic theory" src="http://www.codelast.com/wp-content/uploads/ckfinder/images/conjugate_direction_basic_theory.png" style="width: 330px; height: 94px;" /></div>
<p><span style="color:#b22222;">中的极小点。</span></p>
<div>
	其实这个晦涩的描述，是<a href="http://www.codelast.com/?p=7838" target="_blank" rel="noopener noreferrer"><span style="background-color:#ffa07a;">line search基础定理&mdash;&mdash;梯度与方向的点积为零</span></a>&mdash;&mdash;的另一种表述。例如，我们拿一个特例来说：</div>
<div>
	迭代点 <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_c1015f14836165504ccbb2a42b2c150b.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="{x_2}" /></span><script type='math/tex'>{x_2}</script> （此时 <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_5905475576a21ecdafdaab879ff45aff.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="i = 1" /></span><script type='math/tex'>i = 1</script> ）是目标函数 <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_50bbd36e1fd2333108437a2ca378be62.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="f(x)" /></span><script type='math/tex'>f(x)</script> 和方向 <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_f4aba82441fb27b51c794c3f12805550.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="{d_0},{d_1}" /></span><script type='math/tex'>{d_0},{d_1}</script> 所张成的线性流形 <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_567c97afc470e145244da0863bc2784a.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="\left\{ {\left. x \right|x = {x_0} + {\alpha _0}{d_0} + {\alpha _1}{d_1}} \right\}" /></span><script type='math/tex'>\left\{ {\left. x \right|x = {x_0} + {\alpha _0}{d_0} + {\alpha _1}{d_1}} \right\}</script> 的极小值点。</div>
<div>
	而 <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_af41c8e502055b5419bf4c6ea8922fa9.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="{x_0} + {\alpha _0}{d_0} + {\alpha _1}{d_1} = {x_1} + {\alpha _1}{d_1} = {x_2}" /></span><script type='math/tex'>{x_0} + {\alpha _0}{d_0} + {\alpha _1}{d_1} = {x_1} + {\alpha _1}{d_1} = {x_2}</script> ，所以这就说明了 <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_802914d74c5ec475b03d8e01114b4af4.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="{x_1}" /></span><script type='math/tex'>{x_1}</script> 是在 <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_8fec6c6a71936f2a9cd2d11877a06b26.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="{{d_0}}" /></span><script type='math/tex'>{{d_0}}</script> 方向上line search得到的极小值点， <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_c1015f14836165504ccbb2a42b2c150b.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="{x_2}" /></span><script type='math/tex'>{x_2}</script> 是在 <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_17fbe469667bc25c9dd11284cd8a5b48.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="{{d_1}}" /></span><script type='math/tex'>{{d_1}}</script> 方向上line search得到的极小值点。所以由基础定理可知，当前迭代点的梯度与前面所有方向的点积为零。</div>
<p>自己慢慢体会...<br />
<span style="color: rgb(255, 255, 255);">文章来源：</span><a href="http://www.codelast.com/" target="_blank" rel="noopener noreferrer"><span style="color: rgb(255, 255, 255);">http://www.codelast.com/</span></a><br />
<span style="background-color:#00ff00;">『4』</span>基本流程<br />
下面来看看，共轭方向法在迭代过程中是怎么做的。<br />
假设迭代已经进行到了第 <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_8ce4b16b22b58894aa86c421e8759df3.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="k" /></span><script type='math/tex'>k</script> 步，那么，下一步怎么走？</p>
<ul>
<li>
		确定一个搜索方向要满足： <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_c929b0bed7e38c6e5590cfd702e19c30.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="{g_{k + 1}}^T{d_{k + 1}} < 0" /></span><script type='math/tex'>{g_{k + 1}}^T{d_{k + 1}} < 0</script> &mdash;&mdash;这是为了满足目标函数值下降的条件（下降是最优化的目标），并且 <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_65e44e11f11bcc2ccfa8dbe199bd54b2.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="d_{k + 1}^TG{d_i} = 0,\;\;i = 1,2, \cdots ,k" /></span><script type='math/tex'>d_{k + 1}^TG{d_i} = 0,\;\;i = 1,2, \cdots ,k</script> &mdash;&mdash;这是为了满足搜索方向之间的&ldquo;共轭&rdquo;条件。</li>
<li>
		检验迭代终止条件，若未终止，则用line search求 <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_178488525cdfe1026fada662fa2c21f7.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="f({x_k} + {\alpha _k}{d_k}) = \mathop {\min }\limits_{\alpha \ge 0} f({x_k} + \alpha {d_k})" /></span><script type='math/tex'>f({x_k} + {\alpha _k}{d_k}) = \mathop {\min }\limits_{\alpha \ge 0} f({x_k} + \alpha {d_k})</script> &mdash;&mdash;在每一个搜索方向上，我们都要找到极小值点。</li>
<li>
		 <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_1a5b2864f2c2ad1481a919c59a5a793c.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="{x_{k + 1}} = {x_k} + {\alpha _k}{d_k}" /></span><script type='math/tex'>{x_{k + 1}} = {x_k} + {\alpha _k}{d_k}</script> ，继续迭代</li>
</ul>
<p>大家注意到，上面说确定一个搜索方向，要满足&ldquo;共轭&rdquo;的条件，问题是，共轭方向是如何获取的？光有愿望可不行啊。<br />
<span style="color: rgb(255, 255, 255);">文章来源：</span><a href="http://www.codelast.com/" target="_blank" rel="noopener noreferrer"><span style="color: rgb(255, 255, 255);">http://www.codelast.com/</span></a><br />
<span style="background-color:#00ff00;">『5』</span>创造共轭方向<br />
这里的关键是，如何构造出一个方向的集合，其N个方向线性无关、两两共轭？<br />
有一个经典的方案就是<span style="color:#ff0000;">Powell共轭方向集方法</span>。<br />
Powell是谁？</p>
<blockquote>
<p>
		<a href="http://mat.uc.pt/~zhang/powell.html" target="_blank" rel="noopener noreferrer">M.J.D. POWELL</a>，剑桥大学教授（已故），世界著名的最优化专家。他是袁亚湘的导师（袁亚湘，中国科学院数学与系统科学研究院研究员、博士生导师，美国数学学会首届会士（2012年），中国科学院院士）。</p>
</blockquote>
<p>Powell方法是一种不需要求目标函数导数的方法（<span style="color:#0000ff;">zero-order method</span>）。有一篇英文文章里说，如果你只需要知道一种zero-order method如何编程实现的话，那么一定是选Powell方法，可见Powell方法是有其重要地位的。<br />
关于Powell方法，可以参考一下<a href="http://www.codelast.com/?p=388" target="_blank" rel="noopener noreferrer"><span style="background-color:#ffa07a;">这篇文章</span></a>，本文不详述。<br />
<span style="color: rgb(255, 255, 255);">文章来源：</span><a href="http://www.codelast.com/" target="_blank" rel="noopener noreferrer"><span style="color: rgb(255, 255, 255);">http://www.codelast.com/</span></a><br />
<span style="background-color:#00ff00;">『6』</span>Powell方法的问题及改进<br />
Powell方法产生的共轭方向集可能会变得线性相关，这会导致最终我们求得的，是N维空间的一个子空间内的极小值，而不是整体的极小值，所以，人们对Powell方法研究出了一些改进方案，例如：</p>
<ul>
<li>
		N轮迭代后，方向集重置为基向量；</li>
<li>
		Brent（就是<a href="http://en.wikipedia.org/wiki/Brent's_method" target="_blank" rel="noopener noreferrer"><span style="background-color:#ffa07a;">Brent&#39;s method</span></a>的作者）提出，N轮迭代后，可以将方向集重置为任意<span style="color:#0000ff;">正交矩阵</span>（见下面的说明）的列向量；</li>
<li>
		放弃目标函数下降最大的方向，用一些好的方向代替N个必须共轭的方向；</li>
<li>
		...</li>
</ul>
<p>PS：什么是<span style="color:#0000ff;">正交矩阵</span>？<br />
一个实数正交矩阵是方块矩阵Q，它的转置矩阵是它的逆矩阵： <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_d289da4bbbfa230c42cbeebe685a9e05.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="{Q^T}Q = Q{Q^T} = E" /></span><script type='math/tex'>{Q^T}Q = Q{Q^T} = E</script> ，其中， <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_3a3ea00cfc35332cedf6e5e9a32e94da.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="E" /></span><script type='math/tex'>E</script> 为单位矩阵：<br />
<img decoding="async" alt="unit matrix" src="http://www.codelast.com/wp-content/uploads/ckfinder/images/unit_matrix.png" style="width: 130px; height: 140px;" /><br />
<span style="color: rgb(255, 255, 255);">文章来源：</span><a href="https://www.codelast.com/" rel="noopener noreferrer" target="_blank"><span style="color: rgb(255, 255, 255);">https://www.codelast.com/</span></a><br />
<span style="color: rgb(255, 0, 0);">➤➤</span>&nbsp;版权声明&nbsp;<span style="color: rgb(255, 0, 0);">➤➤</span>&nbsp;<br />
转载需注明出处：<u><a href="https://www.codelast.com/" rel="noopener noreferrer" target="_blank"><em><span style="color: rgb(0, 0, 255);"><strong style="font-size: 16px;"><span style="font-family: arial, helvetica, sans-serif;">codelast.com</span></strong></span></em></a></u>&nbsp;<br />
感谢关注我的微信公众号（微信扫一扫）：</p>
<p style="border: 0px; font-size: 13px; margin: 0px 0px 9px; outline: 0px; padding: 0px; color: rgb(77, 77, 77);">
	<img decoding="async" alt="wechat qrcode of codelast" src="https://www.codelast.com/codelast_wechat_qr_code.jpg" style="width: 200px; height: 200px;" /></p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.codelast.com/%e5%8e%9f%e5%88%9b-%e5%86%8d%e8%b0%88-%e5%85%b1%e8%bd%ad%e6%96%b9%e5%90%91%e6%b3%95conjugate-direction-method-in-optimization/feed/</wfw:commentRss>
			<slash:comments>2</slash:comments>
		
		
			</item>
		<item>
		<title>[原创] 再谈 牛顿法/Newton&#039;s Method In Optimization</title>
		<link>https://www.codelast.com/%e5%8e%9f%e5%88%9b-%e5%86%8d%e8%b0%88-%e7%89%9b%e9%a1%bf%e6%b3%95newtons-method-in-optimization/</link>
					<comments>https://www.codelast.com/%e5%8e%9f%e5%88%9b-%e5%86%8d%e8%b0%88-%e7%89%9b%e9%a1%bf%e6%b3%95newtons-method-in-optimization/#comments</comments>
		
		<dc:creator><![CDATA[learnhard]]></dc:creator>
		<pubDate>Sun, 06 Apr 2014 02:58:34 +0000</pubDate>
				<category><![CDATA[Algorithm]]></category>
		<category><![CDATA[Math]]></category>
		<category><![CDATA[原创]]></category>
		<category><![CDATA[Newton's method]]></category>
		<category><![CDATA[optimization]]></category>
		<category><![CDATA[最优化]]></category>
		<category><![CDATA[牛顿法]]></category>
		<guid isPermaLink="false">http://www.codelast.com/?p=8052</guid>

					<description><![CDATA[<p>
<a href="http://en.wikipedia.org/wiki/Newton's_method_in_optimization" target="_blank" rel="noopener noreferrer"><span style="background-color:#ffa07a;">牛顿法</span></a>是最优化领域的经典算法，它在寻优的过程中，使用了目标函数的二阶导数信息，具体说来就是：用迭代点的梯度和二阶导数对目标函数进行二次逼近，把二次函数的极小点作为新的迭代点，不断重复此过程，直到找到最优点。<br />
<span id="more-8052"></span><br />
<span style="background-color:#00ff00;">『1』</span>历史<br />
话说，牛顿法为什么叫牛顿法？这个近乎&#8220;废话&#8221;的问题，谁又真正查过？<br />
Wiki里是这样写的：牛顿法（Newton&#39;s method）是一种近似求解方程的方法，它使用函数f(x)的泰勒级数的前面几项来寻找方程f(x)=0的根。<br />
它最初由艾萨克&#8226;牛顿在《流数法》（Method of Fluxions，1671年完成，在牛顿死后的1736年公开发表）。<br />
按我的理解，起初牛顿法和最优化没什么关系（在那个年代应该还没有最优化这门学科分支），但是在最优化研究兴起后，人们把牛顿法的思想应用在最优化领域，于是也就叫它牛顿法了。</p>
<div>
	<span style="color: rgb(255, 255, 255);">文章来源：</span><a href="http://www.codelast.com/" target="_blank" rel="noopener noreferrer"><span style="color: rgb(255, 255, 255);">http://www.codelast.com/</span></a></div>
<p><span style="background-color:#00ff00;">『2』</span>原理<br />
下面我们就来推导一下牛顿法的实现。<br />
目标函数 <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_50bbd36e1fd2333108437a2ca378be62.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="f(x)" /></span><script type='math/tex'>f(x)</script> 在点 <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_550187f469eda08b9e5b55143f19c4ce.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="{x_k}" /></span><script type='math/tex'>{x_k}</script> 的泰勒展示式前三项为：<br />
 <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_1e6187e61977f3367ae2cfab3166bef4.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="{q_k}(x) = {q_k}({x_k} + x - {x_k}) = f({x_k}) + g_k^T(x - {x_k}) + \frac{1}{2}{(x - {x_k})^T}{G_k}(x - {x_k}) + o(x - {x_k})" /></span><script type='math/tex'>{q_k}(x) = {q_k}({x_k} + x - {x_k}) = f({x_k}) + g_k^T(x - {x_k}) + \frac{1}{2}{(x - {x_k})^T}{G_k}(x - {x_k}) + o(x - {x_k})</script> <br />
其中， <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_1cd5597a080292208723039cfd7bfd41.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="{g_k}" /></span><script type='math/tex'>{g_k}</script> 是一阶导数（梯度）， <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_8ac8fda2ed3a75d5af87815e87a3ebc7.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="{G_k}" /></span><script type='math/tex'>{G_k}</script> 是二阶导数。当然，最后一项（高阶无穷小）我们依然是不考虑的。<br />
<span style="color: rgb(255, 255, 255);">文章来源：</span><a href="http://www.codelast.com/" target="_blank" rel="noopener noreferrer"><span style="color: rgb(255, 255, 255);">http://www.codelast.com/</span></a>&#8230; <a href="https://www.codelast.com/%e5%8e%9f%e5%88%9b-%e5%86%8d%e8%b0%88-%e7%89%9b%e9%a1%bf%e6%b3%95newtons-method-in-optimization/" class="read-more">Read More </a></p>]]></description>
										<content:encoded><![CDATA[<p>
<a href="http://en.wikipedia.org/wiki/Newton's_method_in_optimization" target="_blank" rel="noopener noreferrer"><span style="background-color:#ffa07a;">牛顿法</span></a>是最优化领域的经典算法，它在寻优的过程中，使用了目标函数的二阶导数信息，具体说来就是：用迭代点的梯度和二阶导数对目标函数进行二次逼近，把二次函数的极小点作为新的迭代点，不断重复此过程，直到找到最优点。<br />
<span id="more-8052"></span><br />
<span style="background-color:#00ff00;">『1』</span>历史<br />
话说，牛顿法为什么叫牛顿法？这个近乎&ldquo;废话&rdquo;的问题，谁又真正查过？<br />
Wiki里是这样写的：牛顿法（Newton&#39;s method）是一种近似求解方程的方法，它使用函数f(x)的泰勒级数的前面几项来寻找方程f(x)=0的根。<br />
它最初由艾萨克&bull;牛顿在《流数法》（Method of Fluxions，1671年完成，在牛顿死后的1736年公开发表）。<br />
按我的理解，起初牛顿法和最优化没什么关系（在那个年代应该还没有最优化这门学科分支），但是在最优化研究兴起后，人们把牛顿法的思想应用在最优化领域，于是也就叫它牛顿法了。</p>
<div>
	<span style="color: rgb(255, 255, 255);">文章来源：</span><a href="http://www.codelast.com/" target="_blank" rel="noopener noreferrer"><span style="color: rgb(255, 255, 255);">http://www.codelast.com/</span></a></div>
<p><span style="background-color:#00ff00;">『2』</span>原理<br />
下面我们就来推导一下牛顿法的实现。<br />
目标函数 <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_50bbd36e1fd2333108437a2ca378be62.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="f(x)" /></span><script type='math/tex'>f(x)</script> 在点 <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_550187f469eda08b9e5b55143f19c4ce.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="{x_k}" /></span><script type='math/tex'>{x_k}</script> 的泰勒展示式前三项为：<br />
 <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_1e6187e61977f3367ae2cfab3166bef4.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="{q_k}(x) = {q_k}({x_k} + x - {x_k}) = f({x_k}) + g_k^T(x - {x_k}) + \frac{1}{2}{(x - {x_k})^T}{G_k}(x - {x_k}) + o(x - {x_k})" /></span><script type='math/tex'>{q_k}(x) = {q_k}({x_k} + x - {x_k}) = f({x_k}) + g_k^T(x - {x_k}) + \frac{1}{2}{(x - {x_k})^T}{G_k}(x - {x_k}) + o(x - {x_k})</script> <br />
其中， <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_1cd5597a080292208723039cfd7bfd41.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="{g_k}" /></span><script type='math/tex'>{g_k}</script> 是一阶导数（梯度）， <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_8ac8fda2ed3a75d5af87815e87a3ebc7.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="{G_k}" /></span><script type='math/tex'>{G_k}</script> 是二阶导数。当然，最后一项（高阶无穷小）我们依然是不考虑的。<br />
<span style="color: rgb(255, 255, 255);">文章来源：</span><a href="http://www.codelast.com/" target="_blank" rel="noopener noreferrer"><span style="color: rgb(255, 255, 255);">http://www.codelast.com/</span></a><br />
 <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_9dd4e461268c8034f5c8564e155c67a6.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="x" /></span><script type='math/tex'>x</script> 为极小值点的一阶必要条件是：<br />
 <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_d05c810b120192221a64b9c5b09c6137.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="\nabla {q_k}(x) = 0 = {g_k} + {G_k}(x - {x_k})" /></span><script type='math/tex'>\nabla {q_k}(x) = 0 = {g_k} + {G_k}(x - {x_k})</script> <br />
由此便可得到迭代公式： <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_8270e2e3b7d900af415458d0bfd0cefa.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="{x_{k + 1}} = {x_k} - {G_k}^{ - 1}{g_k}" /></span><script type='math/tex'>{x_{k + 1}} = {x_k} - {G_k}^{ - 1}{g_k}</script> <br />
在最优化line search的过程中，下一个点是由前一个点在一个方向d上移动得到的，因此，在牛顿法中，人们就顺其自然地称这个方向为&ldquo;<span style="color:#0000ff;">牛顿方向</span>&rdquo;，由上面的式子可知其等于： <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_70df409d5a96a374522d67b7ec6cb9d9.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="{d_k} = - {G_k}^{ - 1}{g_k}" /></span><script type='math/tex'>{d_k} = - {G_k}^{ - 1}{g_k}</script> </p>
<p><span style="background-color:#00ff00;">『3』</span>优缺点<br />
优点：充分接近极小点时，牛顿法具有二阶收敛速度&mdash;&mdash;挺好的，不是么。<br />
缺点：<br />
①牛顿法不是整体收敛的。<br />
②每次迭代计算 <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_8ac8fda2ed3a75d5af87815e87a3ebc7.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="{G_k}" /></span><script type='math/tex'>{G_k}</script> （的逆矩阵），计算量偏大。<br />
③线性方程组 <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_70df409d5a96a374522d67b7ec6cb9d9.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="{d_k} = - {G_k}^{ - 1}{g_k}" /></span><script type='math/tex'>{d_k} = - {G_k}^{ - 1}{g_k}</script> 可能是<span style="color:#0000ff;">病态</span>的，不好求解。<br />
（注：在代数方程中，有的多项式系数有微小扰动时其根变化很大，这种根对系数变化的敏感性称为不稳定性（instability），这种方程就是<span style="color:#0000ff;">病态</span>多项式方程）<br />
为了解决&ldquo;原始&rdquo;牛顿法的这些问题，人们想出了各种办法，于是就有了下面的各种改进方案，请听我一一道来。<br />
<span style="color: rgb(255, 255, 255);">文章来源：</span><a href="http://www.codelast.com/" target="_blank" rel="noopener noreferrer"><span style="color: rgb(255, 255, 255);">http://www.codelast.com/</span></a><br />
<span style="background-color:#00ff00;">『4』</span>牛顿法的改进１&mdash;&mdash;阻尼牛顿法<br />
前面说过了，牛顿法不是整体收敛的，在远离最优解时，牛顿方向 <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_70df409d5a96a374522d67b7ec6cb9d9.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="{d_k} = - {G_k}^{ - 1}{g_k}" /></span><script type='math/tex'>{d_k} = - {G_k}^{ - 1}{g_k}</script> 不一定是<span style="color:#0000ff;">下降方向</span>&mdash;&mdash;而目标函数值&ldquo;下降&rdquo;就是最优化努力的方向，因此，人们想到了，可以在牛顿法迭代的过程中加入一点&ldquo;阻力&rdquo;：<br />
 <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_1a5b2864f2c2ad1481a919c59a5a793c.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="{x_{k + 1}} = {x_k} + {\alpha _k}{d_k}" /></span><script type='math/tex'>{x_{k + 1}} = {x_k} + {\alpha _k}{d_k}</script> <br />
我觉得&ldquo;阻力&rdquo;这个词还是比较形象的&mdash;&mdash;原来只有一个 <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_66eea6bfeea7fcb327d435f627a2390b.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="{d_k}" /></span><script type='math/tex'>{d_k}</script> ，现在多了一个 <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_501cb8ba16bc463c7329e28f3ec226a7.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="{\alpha _k}" /></span><script type='math/tex'>{\alpha _k}</script> ，这就像是个阻碍啊。<br />
问题是， <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_501cb8ba16bc463c7329e28f3ec226a7.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="{\alpha _k}" /></span><script type='math/tex'>{\alpha _k}</script> 怎么求呢？<br />
可以在确定 <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_66eea6bfeea7fcb327d435f627a2390b.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="{d_k}" /></span><script type='math/tex'>{d_k}</script> 之后，利用line search技术，求出 <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_501cb8ba16bc463c7329e28f3ec226a7.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="{\alpha _k}" /></span><script type='math/tex'>{\alpha _k}</script> ，使之满足 <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_178488525cdfe1026fada662fa2c21f7.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="f({x_k} + {\alpha _k}{d_k}) = \mathop {\min }\limits_{\alpha \ge 0} f({x_k} + \alpha {d_k})" /></span><script type='math/tex'>f({x_k} + {\alpha _k}{d_k}) = \mathop {\min }\limits_{\alpha \ge 0} f({x_k} + \alpha {d_k})</script> （至于line search的算法，有太多太多了，<a href="http://www.codelast.com/?p=7364" target="_blank" rel="noopener noreferrer"><span style="background-color:#ffa07a;">这里</span></a>有几个可以参考一下）。<br />
满足了这个条件，会发生什么？<br />
大家还记得《<a href="http://www.codelast.com/?p=7514" target="_blank" rel="noopener noreferrer"><span style="background-color:#ffa07a;">使用一维搜索(line search)的算法的收敛性</span></a>》定理吗？仔细看里面的&ldquo;适用于使用精确line search技术的算法&rdquo;的收敛性定理，你就会发现，当满足了上面所说的条件时，（阻尼）牛顿法的整体收敛性就得到了保证。<br />
当然，满足上面所说的条件的前提，就是所有的 <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_8ac8fda2ed3a75d5af87815e87a3ebc7.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="{G_k}" /></span><script type='math/tex'>{G_k}</script> 都正定。因为如果 <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_8ac8fda2ed3a75d5af87815e87a3ebc7.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="{G_k}" /></span><script type='math/tex'>{G_k}</script> 不正定的话，就求不出 <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_66eea6bfeea7fcb327d435f627a2390b.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="{d_k}" /></span><script type='math/tex'>{d_k}</script> ；求不出 <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_66eea6bfeea7fcb327d435f627a2390b.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="{d_k}" /></span><script type='math/tex'>{d_k}</script> 的话，就求不出 <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_501cb8ba16bc463c7329e28f3ec226a7.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="{\alpha _k}" /></span><script type='math/tex'>{\alpha _k}</script> ；求不出 <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_501cb8ba16bc463c7329e28f3ec226a7.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="{\alpha _k}" /></span><script type='math/tex'>{\alpha _k}</script> 的话，就求不出 <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_63df53abbcadecae947de65a842e4f86.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="{x_{k + 1}}" /></span><script type='math/tex'>{x_{k + 1}}</script> ，因此就求不出迭代公式，寻优过程就无法进行。<br />
<span style="color: rgb(255, 255, 255);">文章来源：</span><a href="http://www.codelast.com/" target="_blank" rel="noopener noreferrer"><span style="color: rgb(255, 255, 255);">http://www.codelast.com/</span></a><br />
那么问题就来了：阻尼牛顿法确实offer了整体收敛性，但是它并没有解决一个问题： <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_8ac8fda2ed3a75d5af87815e87a3ebc7.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="{G_k}" /></span><script type='math/tex'>{G_k}</script> 不正定怎么办？此时迭代如何进行下去？因此，另一种改进方案应运而生，各位接着往下看。</p>
<p><span style="background-color:#00ff00;">『5』</span>Goldstein-Price修正<br />
首先，Goldstein和Price是两个人名，他们的具体生平事迹我没研究过。他们在1967年提出，如果 <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_8ac8fda2ed3a75d5af87815e87a3ebc7.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="{G_k}" /></span><script type='math/tex'>{G_k}</script> 不正定（此时难以解出 <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_70df409d5a96a374522d67b7ec6cb9d9.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="{d_k} = - {G_k}^{ - 1}{g_k}" /></span><script type='math/tex'>{d_k} = - {G_k}^{ - 1}{g_k}</script> ），就用&ldquo;<a href="http://www.codelast.com/?p=8006" target="_blank" rel="noopener noreferrer"><span style="background-color:#ffa07a;">最速下降方向</span></a>&rdquo;来作为搜索方向（看似已经&ldquo;过时&rdquo;的最速下降法还是能发挥余热的，这就体现出来了）：</p>
<div>
	<img decoding="async" alt="Newton's method Goldstein-Price" src="http://www.codelast.com/wp-content/uploads/ckfinder/images/newton_method_goldstein_price.png" style="width: 400px; height: 73px;" /><br />
	其中， <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_e6885dfcb4c4a8ddb730c59135ffe731.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="\delta \in (0,1)" /></span><script type='math/tex'>\delta \in (0,1)</script> <br />
	在这样的条件下，就使得 <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_66eea6bfeea7fcb327d435f627a2390b.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="{d_k}" /></span><script type='math/tex'>{d_k}</script> 总能满足 <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_f9d2500ba754546d742143e1e9f0230c.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="\cos ({d_k}, - {g_k}) \ge \delta " /></span><script type='math/tex'>\cos ({d_k}, - {g_k}) \ge \delta </script> ，从而也就满足了《<a href="http://www.codelast.com/?p=7514" target="_blank" rel="noopener noreferrer"><span style="background-color: rgb(255, 160, 122);">使用一维搜索(line search)的算法的收敛性</span></a>》定理中的&ldquo;搜索方向条件&rdquo;，从而（Goldstein-Price修正）牛顿法具有整体收敛性。<br />
	<span style="color: rgb(255, 255, 255);">文章来源：</span><a href="http://www.codelast.com/" target="_blank" rel="noopener noreferrer"><span style="color: rgb(255, 255, 255);">http://www.codelast.com/</span></a><br />
	<span style="background-color:#00ff00;">『6』</span>Goldfeld修正<br />
	与上面的Goldstein-Price修正的思路不同，Goldfeld在1966年也提出了一种方法，他的方法虽然还是在搜索方向 <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_66eea6bfeea7fcb327d435f627a2390b.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="{d_k}" /></span><script type='math/tex'>{d_k}</script> 上动手，但是当 <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_8ac8fda2ed3a75d5af87815e87a3ebc7.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="{G_k}" /></span><script type='math/tex'>{G_k}</script> 不正定时，他不是用最速下降方向 <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_be9976a20363f7c49bb370084b76dca7.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt=" - {g_k}" /></span><script type='math/tex'> - {g_k}</script> 来作为搜索方向，而是将 <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_66eea6bfeea7fcb327d435f627a2390b.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="{d_k}" /></span><script type='math/tex'>{d_k}</script> 修正成下降方向&mdash;&mdash;用下面的式子：<br />
	 <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_bd5579526a4aeccd9e6784566e80ea59.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="{d_k} = - B_k^{ - 1}{g_k}" /></span><script type='math/tex'>{d_k} = - B_k^{ - 1}{g_k}</script> <br />
	其中， <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_d6b197395545713e292f056543da88ce.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="{B_k} = {G_k} + {E_k}" /></span><script type='math/tex'>{B_k} = {G_k} + {E_k}</script> 是一个正定矩阵， <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_6117194d806ebd85685939d8d20e4de5.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="{E_k}" /></span><script type='math/tex'>{E_k}</script> 称为修正矩阵。在 <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_6117194d806ebd85685939d8d20e4de5.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="{E_k}" /></span><script type='math/tex'>{E_k}</script> <span style="color:#0000ff;">满足一定条件</span>的时候，（Goldfeld修正）牛顿法具有整体收敛性。<br />
	具体要满足什么条件呢？一个关于矩阵 <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_a8065340a6debc5139adfdd3265f2b07.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="{B_k}" /></span><script type='math/tex'>{B_k}</script> &ldquo;<a href="http://zh.wikipedia.org/zh/%E6%9D%A1%E4%BB%B6%E6%95%B0" target="_blank" rel="noopener noreferrer"><span style="background-color:#ffa07a;">条件数</span></a>&rdquo;的条件。说实在的我对这部分不了解，并且这也不是本文的重点，所以在这里我就不把书上的定理搬上来了。<br />
	Goldfeld修正没有解决的问题就是：难以给出选取 <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_6117194d806ebd85685939d8d20e4de5.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="{E_k}" /></span><script type='math/tex'>{E_k}</script> 的有效方法。这就像是我告诉你，你要去魔法森林，就需要用到魔棒，但是魔棒去哪找，我不告诉你。于是，有其他的学者提出了其他的改进方法，帮你找到这个&ldquo;魔棒&rdquo;，请接着往下看。<br />
	<span style="color: rgb(255, 255, 255);">文章来源：</span><a href="http://www.codelast.com/" target="_blank" rel="noopener noreferrer"><span style="color: rgb(255, 255, 255);">http://www.codelast.com/</span></a><br />
	<span style="background-color:#00ff00;">『7』</span>Gill-Murray的Cholesky分解法<br />
	看到这个小标题你可能就有点晕&mdash;&mdash;请尽情地晕吧，这里光是人名就有三个。最重要的就是Cholesky，这里我要补充一个小插曲，给大家说点轻松的知识（从网上复制来的，链接不记得了）：</div>
<blockquote>
<div>
		Cholesky是一个法国数学家，生于19世纪末。Cholesky分解是他在学术界最重要的贡献。后来，Cholesky参加了法国军队，不久在一战初始阵亡。<br />
		Cholesky分解是一种分解矩阵的方法, 在线性代数中有重要的应用。Cholesky分解把矩阵分解为一个下三角矩阵以及它的共轭转置矩阵的乘积（那实数界来类比的话，此分解就好像求平方根）。与一般的矩阵分解求解方程的方法比较，Cholesky分解效率很高。</div>
</blockquote>
<div>
	Cholesky真是英年早逝，以他对学术界的贡献来看，确实值得我们缅怀。<br />
	Gill和Murray这两个人，用Cholesky分解法实现了对牛顿法的改进，我个人觉得，他们的改进可以算是对Goldfeld修正的一种改进（或补充）吧，因为他们提供了求 <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_6117194d806ebd85685939d8d20e4de5.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="{E_k}" /></span><script type='math/tex'>{E_k}</script> 的方法。</p>
<p>	这里的Cholesky分解（牛顿法），是这么一回事：对 <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_8ac8fda2ed3a75d5af87815e87a3ebc7.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="{G_k}" /></span><script type='math/tex'>{G_k}</script> （即Hesse矩阵）进行Cholesky分解，在分解的过程中，对它进行一定的修正，最后得到近似的 <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_cbc036587240f187400a7665837a1611.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="\overline {{G_k}} " /></span><script type='math/tex'>\overline {{G_k}} </script> ，把这个 <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_cbc036587240f187400a7665837a1611.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="\overline {{G_k}} " /></span><script type='math/tex'>\overline {{G_k}} </script> 当作 <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_8ac8fda2ed3a75d5af87815e87a3ebc7.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="{G_k}" /></span><script type='math/tex'>{G_k}</script> ，用于解出 <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_66eea6bfeea7fcb327d435f627a2390b.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="{d_k}" /></span><script type='math/tex'>{d_k}</script> 。<br />
	<span style="color: rgb(255, 255, 255);">文章来源：</span><a href="http://www.codelast.com/" target="_blank" rel="noopener noreferrer"><span style="color: rgb(255, 255, 255);">http://www.codelast.com/</span></a><br />
	至于这个修正过程的具体做法，我只能说我不甚清楚，<span style="color:#800000;">我不想在这里误导大家，只想把我自己理解的写下来</span>：<br />
	若 <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_8ac8fda2ed3a75d5af87815e87a3ebc7.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="{G_k}" /></span><script type='math/tex'>{G_k}</script> 为正定矩阵，则它总能进行Cholesky分解，即&nbsp; <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_fb77d6c4e0828b5703126ee6c6b6069a.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="{G_k} = {L_k}{D_k}L_k^T" /></span><script type='math/tex'>{G_k} = {L_k}{D_k}L_k^T</script> ，其中 <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_a16319f7563602c7dbf5a2c5ca46ecc0.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="{L_k}" /></span><script type='math/tex'>{L_k}</script> 是一个单位下三角矩阵， <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_3961878be696f3864a17e9b34591e36e.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="{D_k}" /></span><script type='math/tex'>{D_k}</script> 是一个对角矩阵（diagonal matrix，除主对角线外的元素均为0的方阵）。<br />
	若 <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_8ac8fda2ed3a75d5af87815e87a3ebc7.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="{G_k}" /></span><script type='math/tex'>{G_k}</script> 不是个正定矩阵，那么就让Chokesky分解过程满足 <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_e55103a097cb5f563b30c1461ebe9cb1.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="\overline {{G_k}} = {L_k}{D_k}L_k^T = {G_k} + {E_k}" /></span><script type='math/tex'>\overline {{G_k}} = {L_k}{D_k}L_k^T = {G_k} + {E_k}</script> （ <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_6117194d806ebd85685939d8d20e4de5.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="{E_k}" /></span><script type='math/tex'>{E_k}</script> 是一个对角矩阵），并且在分解过中调整 <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_3961878be696f3864a17e9b34591e36e.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="{D_k}" /></span><script type='math/tex'>{D_k}</script> 对角线上的元素（人们总结出了一些调整方法，例如使这些元素&gt;某个正常数），使得Hesse矩阵正定&mdash;&mdash;这里说的Hesse矩阵，是指前面说的 <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_cbc036587240f187400a7665837a1611.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="\overline {{G_k}} " /></span><script type='math/tex'>\overline {{G_k}} </script> 。分解完成后，就可以用 <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_cbc036587240f187400a7665837a1611.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="\overline {{G_k}} " /></span><script type='math/tex'>\overline {{G_k}} </script> 来解出 <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_66eea6bfeea7fcb327d435f627a2390b.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="{d_k}" /></span><script type='math/tex'>{d_k}</script> 了。<br />
	如果 <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_8ac8fda2ed3a75d5af87815e87a3ebc7.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="{G_k}" /></span><script type='math/tex'>{G_k}</script> 是个<span style="color:#0000ff;">充分正定</span>（书上的名词，谁能给解释一下？）的矩阵，那么经过这个修正的过程， <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_cbc036587240f187400a7665837a1611.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="\overline {{G_k}} " /></span><script type='math/tex'>\overline {{G_k}} </script> 其实就是原来的 <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_8ac8fda2ed3a75d5af87815e87a3ebc7.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="{G_k}" /></span><script type='math/tex'>{G_k}</script> ， <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_6117194d806ebd85685939d8d20e4de5.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="{E_k}" /></span><script type='math/tex'>{E_k}</script> 其实也就不存在了&mdash;&mdash;这是个很好的特性。<br />
	我感觉上面的修正过程，用妹子来做一个比喻就是：一个妹子本来已经长得挺漂亮了，你为她化个妆（只要不是故意黑她），她还是那么漂亮。反之，如果一个妹子长得很搓，那么，你为她化妆，是有可能让她看上去变靓的。总之，都得到了我们想要的结果。<br />
	Cholesky分解算法我没看过，这里就没办法说了。</p>
<p>	有书上说，Gill-Murray的Cholesky分解牛顿法是&ldquo;对牛顿法改造得最彻底、最有实用价值的方法&rdquo;。<br />
	看来，有时候真的是：最复杂的就是最好的，没有捷径可走啊。<br />
	<span style="color: rgb(255, 255, 255);">文章来源：</span><a href="http://www.codelast.com/" target="_blank" rel="noopener noreferrer"><span style="color: rgb(255, 255, 255);">http://www.codelast.com/</span></a><br />
	<span style="background-color:#00ff00;">『8』</span>信赖域牛顿法<br />
	在<a href="http://www.codelast.com/?p=7488" target="_blank" rel="noopener noreferrer"><span style="background-color:#ffa07a;">这篇</span></a>解释信赖域算法的文章里，我们说过了，<span style="color:#0000ff;">信赖域算法具有整体收敛性</span>。利用这一点，可以将其与牛顿法&ldquo;合体&rdquo;，创造出具有整体收敛性的信赖域牛顿法，即，我们要求的问题是：</p>
<div>
		<img decoding="async" alt="Newton's method trust region" src="http://www.codelast.com/wp-content/uploads/ckfinder/images/newton_method_trust_region.png" style="width: 400px; height: 113px;" /><br />
		其中， <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_03c7c0ace395d80182db07ae2c30f034.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="s" /></span><script type='math/tex'>s</script> 为位移， <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_8ce4b16b22b58894aa86c421e8759df3.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="k" /></span><script type='math/tex'>k</script> 表示第k次迭代， <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_1cd5597a080292208723039cfd7bfd41.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="{g_k}" /></span><script type='math/tex'>{g_k}</script> 为梯度， <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_8ac8fda2ed3a75d5af87815e87a3ebc7.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="{G_k}" /></span><script type='math/tex'>{G_k}</script> 为Hesse矩阵（二阶导数矩阵）， <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_7897c8db80031ff84df5a87ff3761308.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="{h_k}" /></span><script type='math/tex'>{h_k}</script> 为第k次迭代时的信赖域上界（半径）。<br />
		为什么它叫信赖域牛顿法？首先，它没有line search，求的是位移s，所以是一种信赖域算法；其次，它在求解的时候用到了梯度和二阶导数，因此是一种牛顿法。所以整体上叫它信赖域牛顿法是讲得过去的。<br />
		信赖域牛顿法有一个特点是令人欣慰的：没有要求 <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_8ac8fda2ed3a75d5af87815e87a3ebc7.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="{G_k}" /></span><script type='math/tex'>{G_k}</script> （即Hesse矩阵）必须正定，这与前面各种算法与 <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_8ac8fda2ed3a75d5af87815e87a3ebc7.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="{G_k}" /></span><script type='math/tex'>{G_k}</script> 正定那些纠缠不清的关系有很大不同。<br />
		至于信赖域算法的具体求解步骤是怎样的，这里就不说了，还是请大家参考<a href="http://www.codelast.com/?p=7488" target="_blank" rel="noopener noreferrer"><span style="background-color:#ffa07a;">这篇</span></a>文章。<br />
		<span style="color: rgb(255, 255, 255);">文章来源：</span><a href="http://www.codelast.com/" target="_blank" rel="noopener noreferrer"><span style="color: rgb(255, 255, 255);">http://www.codelast.com/</span></a><br />
		<span style="background-color:#00ff00;">『9』</span>总结<br />
		对牛顿法及其众多改进的介绍就到这里结束了。大家会看到，里面有很多定理没给出证明，有些推导可能也不够严谨，但是它们的结论基本上是正确的，如果纠结于细节，那真的是要去做理论研究，而不是应用到工程实践了。所以，学习最优化的时候，我们可以在一定程度上&ldquo;着眼全局，忽略细节&rdquo;，这会极大地有助于理解。<br />
		<span style="color: rgb(255, 255, 255);">文章来源：</span><a href="https://www.codelast.com/" rel="noopener noreferrer" target="_blank"><span style="color: rgb(255, 255, 255);">https://www.codelast.com/</span></a><br />
		<span style="color: rgb(255, 0, 0);">➤➤</span>&nbsp;版权声明&nbsp;<span style="color: rgb(255, 0, 0);">➤➤</span>&nbsp;<br />
		转载需注明出处：<u><a href="https://www.codelast.com/" rel="noopener noreferrer" target="_blank"><em><span style="color: rgb(0, 0, 255);"><strong style="font-size: 16px;"><span style="font-family: arial, helvetica, sans-serif;">codelast.com</span></strong></span></em></a></u>&nbsp;<br />
		感谢关注我的微信公众号（微信扫一扫）：</p>
<p style="border: 0px; font-size: 13px; margin: 0px 0px 9px; outline: 0px; padding: 0px; color: rgb(77, 77, 77);">
			<img decoding="async" alt="wechat qrcode of codelast" src="https://www.codelast.com/codelast_wechat_qr_code.jpg" style="width: 200px; height: 200px;" /></p>
</p></div>
</div>
]]></content:encoded>
					
					<wfw:commentRss>https://www.codelast.com/%e5%8e%9f%e5%88%9b-%e5%86%8d%e8%b0%88-%e7%89%9b%e9%a1%bf%e6%b3%95newtons-method-in-optimization/feed/</wfw:commentRss>
			<slash:comments>4</slash:comments>
		
		
			</item>
		<item>
		<title>[原创] 再谈 梯度下降法/最速下降法/Gradient descent/Steepest Descent</title>
		<link>https://www.codelast.com/%e5%8e%9f%e5%88%9b-%e5%86%8d%e8%b0%88-%e6%9c%80%e9%80%9f%e4%b8%8b%e9%99%8d%e6%b3%95%e6%a2%af%e5%ba%a6%e6%b3%95steepest-descent/</link>
					<comments>https://www.codelast.com/%e5%8e%9f%e5%88%9b-%e5%86%8d%e8%b0%88-%e6%9c%80%e9%80%9f%e4%b8%8b%e9%99%8d%e6%b3%95%e6%a2%af%e5%ba%a6%e6%b3%95steepest-descent/#comments</comments>
		
		<dc:creator><![CDATA[learnhard]]></dc:creator>
		<pubDate>Wed, 02 Apr 2014 16:23:41 +0000</pubDate>
				<category><![CDATA[Algorithm]]></category>
		<category><![CDATA[Math]]></category>
		<category><![CDATA[原创]]></category>
		<category><![CDATA[gradient descent]]></category>
		<category><![CDATA[optimization]]></category>
		<category><![CDATA[steepest descent]]></category>
		<category><![CDATA[最优化]]></category>
		<category><![CDATA[最速下降法]]></category>
		<category><![CDATA[梯度下降法]]></category>
		<guid isPermaLink="false">http://www.codelast.com/?p=8006</guid>

					<description><![CDATA[<p>
当今世界，深度学习应用已经渗透到了我们生活的方方面面，深度学习技术背后的核心问题是最优化(Optimization)。最优化是应用数学的一个分支，它是研究在给定约束之下如何寻求某些因素(的量)，以使某一(或某些)指标达到最优的一些学科的总称。<br />
梯度下降法（Gradient descent，又称最速下降法/Steepest&#160;descent），是无约束<a href="http://zh.wikipedia.org/wiki/%E6%9C%80%E4%BC%98%E5%8C%96" rel="noopener noreferrer" target="_blank"><span style="background-color: rgb(255, 160, 122);">最优化</span></a>领域中历史最悠久、最简单的算法，单独就这种算法来看，属于早就&#8220;过时&#8221;了的一种算法。但是，它的理念是其他某些算法的组成部分，或者说在其他某些算法中，也有梯度下降法的&#8220;影子&#8221;。例如，各种深度学习库都会使用SGD（Stochastic Gradient Descent，随机梯度下降）或变种作为其优化算法。<br />
今天我们就再来回顾一下梯度下降法的基础知识。<br />
<span id="more-8006"></span><br />
<span style="background-color:#00ff00;">『1』</span>名字释义<br />
在很多机器学习算法中，我们通常会通过多轮的迭代计算，最小化一个损失函数(loss function)的值，这个损失函数，对应到最优化里就是所谓的&#8220;目标函数&#8221;。<br />
在寻找最优解的过程中，梯度下降法只使用目标函数的一阶导数信息&#8212;&#8212;从&#8220;梯度&#8221;这个名字也可见一斑。并且它的本意是取目标函数值&#8220;最快下降&#8221;的方向作为搜索方向，这也是&#8220;最速下降&#8221;这个名字的来源。<br />
于是自然而然地，我们就想知道一个问题的答案：沿什么方向，目标函数  <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_50bbd36e1fd2333108437a2ca378be62.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="f(x)" /></span><script type='math/tex'>f(x)</script>  的值下降最快呢？</p>
<p><span style="background-color:#00ff00;">『2』</span>函数值下降最快的方向是什么<br />
先说结论：沿负梯度方向&#160; <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_aaf665c8dc32efb0ed392432cb3091ef.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="d = - {g_k}" /></span><script type='math/tex'>d = - {g_k}</script> ，函数值下降最快。此处，我们用&#160; <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_8277e0910d750195b448797616e091ad.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="d" /></span><script type='math/tex'>d</script> &#160;表示方向(direction)，用&#160; <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_b2f5ff47436671b6e533d8dc3614845d.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="g" /></span><script type='math/tex'>g</script> &#160;表示梯度(gradient)。<br />
下面就来推导一下。<br />
将目标函数 <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_50bbd36e1fd2333108437a2ca378be62.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="f(x)" /></span><script type='math/tex'>f(x)</script> 在点 <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_550187f469eda08b9e5b55143f19c4ce.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="{x_k}" /></span><script type='math/tex'>{x_k}</script> 处泰勒展开（在最优化领域，这是一个常用的手段）：<br />
 <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_37ec8b5a5be749597c9ef1bb8e9b1d2d.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="f(x) = f({x_k}) + \alpha g_k^T{d_k} + o(\alpha )" /></span><script type='math/tex'>f(x) = f({x_k}) + \alpha g_k^T{d_k} + o(\alpha )</script> <br />
高阶无穷小 <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_c42304a467a6fa377fc950fcc6a5ccf9.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="o(\alpha )" /></span><script type='math/tex'>o(\alpha )</script> 可忽略，由于我们定义了步长 <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_7f54bc2116eb53e3231634d008c92d90.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="\alpha/> 0" /</span><script type='math/tex'>\alpha 0</script> （在ML领域，步长就是平常所说的learning rate），因此，当 <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_ead119a63ddef55ab91efbf5514e3609.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="g_k^T{d_k} < 0" /></span><script type='math/tex'>g_k^T{d_k} < 0</script> 时， <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_320ccfc2694ebec4aa2bccff656c7baa.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="f(x) < f({x_k})" /></span><script type='math/tex'>f(x) < f({x_k})</script> ，即函数值是<span style="color:#0000ff;">下降</span>的。此时 <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_66eea6bfeea7fcb327d435f627a2390b.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="{d_k}" /></span><script type='math/tex'>{d_k}</script> 就是一个下降方向。<br />
但是 <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_66eea6bfeea7fcb327d435f627a2390b.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="{d_k}" /></span><script type='math/tex'>{d_k}</script> 具体等于什么的时候，可使目标函数值下降最快呢？<br />
<span style="color: rgb(255, 255, 255);">文章来源：</span><a href="http://www.codelast.com/" rel="noopener noreferrer" target="_blank"><span style="color: rgb(255, 255, 255);">http://www.codelast.com/</span></a>&#8230; <a href="https://www.codelast.com/%e5%8e%9f%e5%88%9b-%e5%86%8d%e8%b0%88-%e6%9c%80%e9%80%9f%e4%b8%8b%e9%99%8d%e6%b3%95%e6%a2%af%e5%ba%a6%e6%b3%95steepest-descent/" class="read-more">Read More </a></p>]]></description>
										<content:encoded><![CDATA[<p>
当今世界，深度学习应用已经渗透到了我们生活的方方面面，深度学习技术背后的核心问题是最优化(Optimization)。最优化是应用数学的一个分支，它是研究在给定约束之下如何寻求某些因素(的量)，以使某一(或某些)指标达到最优的一些学科的总称。<br />
梯度下降法（Gradient descent，又称最速下降法/Steepest&nbsp;descent），是无约束<a href="http://zh.wikipedia.org/wiki/%E6%9C%80%E4%BC%98%E5%8C%96" rel="noopener noreferrer" target="_blank"><span style="background-color: rgb(255, 160, 122);">最优化</span></a>领域中历史最悠久、最简单的算法，单独就这种算法来看，属于早就&ldquo;过时&rdquo;了的一种算法。但是，它的理念是其他某些算法的组成部分，或者说在其他某些算法中，也有梯度下降法的&ldquo;影子&rdquo;。例如，各种深度学习库都会使用SGD（Stochastic Gradient Descent，随机梯度下降）或变种作为其优化算法。<br />
今天我们就再来回顾一下梯度下降法的基础知识。<br />
<span id="more-8006"></span><br />
<span style="background-color:#00ff00;">『1』</span>名字释义<br />
在很多机器学习算法中，我们通常会通过多轮的迭代计算，最小化一个损失函数(loss function)的值，这个损失函数，对应到最优化里就是所谓的&ldquo;目标函数&rdquo;。<br />
在寻找最优解的过程中，梯度下降法只使用目标函数的一阶导数信息&mdash;&mdash;从&ldquo;梯度&rdquo;这个名字也可见一斑。并且它的本意是取目标函数值&ldquo;最快下降&rdquo;的方向作为搜索方向，这也是&ldquo;最速下降&rdquo;这个名字的来源。<br />
于是自然而然地，我们就想知道一个问题的答案：沿什么方向，目标函数  <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_50bbd36e1fd2333108437a2ca378be62.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="f(x)" /></span><script type='math/tex'>f(x)</script>  的值下降最快呢？</p>
<p><span style="background-color:#00ff00;">『2』</span>函数值下降最快的方向是什么<br />
先说结论：沿负梯度方向&nbsp; <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_aaf665c8dc32efb0ed392432cb3091ef.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="d = - {g_k}" /></span><script type='math/tex'>d = - {g_k}</script> ，函数值下降最快。此处，我们用&nbsp; <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_8277e0910d750195b448797616e091ad.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="d" /></span><script type='math/tex'>d</script> &nbsp;表示方向(direction)，用&nbsp; <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_b2f5ff47436671b6e533d8dc3614845d.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="g" /></span><script type='math/tex'>g</script> &nbsp;表示梯度(gradient)。<br />
下面就来推导一下。<br />
将目标函数 <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_50bbd36e1fd2333108437a2ca378be62.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="f(x)" /></span><script type='math/tex'>f(x)</script> 在点 <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_550187f469eda08b9e5b55143f19c4ce.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="{x_k}" /></span><script type='math/tex'>{x_k}</script> 处泰勒展开（在最优化领域，这是一个常用的手段）：<br />
 <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_37ec8b5a5be749597c9ef1bb8e9b1d2d.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="f(x) = f({x_k}) + \alpha g_k^T{d_k} + o(\alpha )" /></span><script type='math/tex'>f(x) = f({x_k}) + \alpha g_k^T{d_k} + o(\alpha )</script> <br />
高阶无穷小 <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_c42304a467a6fa377fc950fcc6a5ccf9.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="o(\alpha )" /></span><script type='math/tex'>o(\alpha )</script> 可忽略，由于我们定义了步长 <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_7f54bc2116eb53e3231634d008c92d90.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="\alpha > 0" /></span><script type='math/tex'>\alpha > 0</script> （在ML领域，步长就是平常所说的learning rate），因此，当 <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_ead119a63ddef55ab91efbf5514e3609.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="g_k^T{d_k} < 0" /></span><script type='math/tex'>g_k^T{d_k} < 0</script> 时， <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_320ccfc2694ebec4aa2bccff656c7baa.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="f(x) < f({x_k})" /></span><script type='math/tex'>f(x) < f({x_k})</script> ，即函数值是<span style="color:#0000ff;">下降</span>的。此时 <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_66eea6bfeea7fcb327d435f627a2390b.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="{d_k}" /></span><script type='math/tex'>{d_k}</script> 就是一个下降方向。<br />
但是 <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_66eea6bfeea7fcb327d435f627a2390b.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="{d_k}" /></span><script type='math/tex'>{d_k}</script> 具体等于什么的时候，可使目标函数值下降最快呢？<br />
<span style="color: rgb(255, 255, 255);">文章来源：</span><a href="http://www.codelast.com/" rel="noopener noreferrer" target="_blank"><span style="color: rgb(255, 255, 255);">http://www.codelast.com/</span></a><br />
数学上，有一个非常著名的不等式：<a href="http://www.codelast.com/?p=8022" rel="noopener noreferrer" target="_blank"><span style="background-color:#ffa07a;">Cauchy-Schwartz不等式（柯西-许瓦兹不等式）</span></a><sup><span style="font-size: 13.3333px;">1</span></sup>，它是一个在很多场合都用得上的不等式：</p>
<div>
	<span style="color:#b22222;"> <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_2faef7bfff1303da60951a77f6c7d4d0.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="({a_1}{b_1} + {a_2}{b_2} + \cdots + {a_n}{b_n}) \le \sqrt {(a_1^2 + a_2^2 + \cdots + a_n^2)} \sqrt {(b_1^2 + b_2^2 + \cdots + b_n^2)} " /></span><script type='math/tex'>({a_1}{b_1} + {a_2}{b_2} + \cdots + {a_n}{b_n}) \le \sqrt {(a_1^2 + a_2^2 + \cdots + a_n^2)} \sqrt {(b_1^2 + b_2^2 + \cdots + b_n^2)} </script> </span></div>
<div>
	当且仅当：</div>
<div>
	<span style="color:#b22222;"> <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_6337b1fff757e26d559865b0f907b86f.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="\frac{{{a_1}}}{{{b_1}}} = \frac{{{a_2}}}{{{b_2}}} = \cdots = \frac{{{a_n}}}{{{b_n}}}" /></span><script type='math/tex'>\frac{{{a_1}}}{{{b_1}}} = \frac{{{a_2}}}{{{b_2}}} = \cdots = \frac{{{a_n}}}{{{b_n}}}</script> </span></div>
<div>
	时等号成立。<br />
	&nbsp;</div>
<p>由Cauchy-Schwartz不等式可知：<br />
 <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_0a0acce3485256ce4904d0abea1a4717.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="\left| {d_k^T{g_k}} \right| \le \left\| {{d_k}} \right\|\left\| {{g_k}} \right\|" /></span><script type='math/tex'>\left| {d_k^T{g_k}} \right| \le \left\| {{d_k}} \right\|\left\| {{g_k}} \right\|</script> <br />
当且仅当 <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_a7c9e705147a8c9a65808417da4ea36f.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="{d_k} = {g_k}" /></span><script type='math/tex'>{d_k} = {g_k}</script> 时，等号成立， <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_62f84a80c057c4892a5e22755b4976aa.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="d_k^T{g_k}" /></span><script type='math/tex'>d_k^T{g_k}</script> 最大（&gt;0）。<br />
所以 <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_6f02d7b4f8531090efdc877eb851f093.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="{d_k} = - {g_k}" /></span><script type='math/tex'>{d_k} = - {g_k}</script> 时， <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_62f84a80c057c4892a5e22755b4976aa.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="d_k^T{g_k}" /></span><script type='math/tex'>d_k^T{g_k}</script> 最小（&lt;0）， <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_50bbd36e1fd2333108437a2ca378be62.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="f(x)" /></span><script type='math/tex'>f(x)</script> 下降量最大。<br />
所以 <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_be9976a20363f7c49bb370084b76dca7.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt=" - {g_k}" /></span><script type='math/tex'> - {g_k}</script> 是<span style="color:#ff0000;">最</span>快<span style="color:#ff0000;">速</span>下降方向。</p>
<p><span style="background-color:#00ff00;">『3』</span>缺点<br />
它真的如它的名字所描述的，是&ldquo;最快速&rdquo;的吗？从很多经典的最优化书籍你会了解到：并不是。<br />
事实上，它只在局部范围内具有&ldquo;最速&rdquo;性质；对整体求最优解的过程而言，它让目标函数值下降非常缓慢。</p>
<p><span style="background-color:#00ff00;">『4』</span>感受一下它是如何&ldquo;慢&rdquo;的<br />
先来看一幅图<sup>2</sup>：</p>
<div style="text-align: center;">
	<img decoding="async" alt="" src="http://www.codelast.com/wp-content/uploads/ckfinder/images/Rosenbrock_function.png" style="width: 378px; height: 302px;" /></div>
<p><span style="color: rgb(255, 255, 255);">文章来源：</span><a href="http://www.codelast.com/" rel="noopener noreferrer" target="_blank"><span style="color: rgb(255, 255, 255);">http://www.codelast.com/</span></a><br />
这幅图表示的是对一个目标函数寻找最优解的过程，图中锯齿状的路线就是寻优路线在二维平面上的投影。从这幅图我们可以看到，锯齿一开始比较大（跨越的距离比较大），后来越来越小；这就像一个人走路迈的步子，一开始大，后来步子越迈越小。<br />
这个函数的表达式是这样的：<br />
 <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_4526ba6075c8c9c1d532166726779a6a.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="f({x_1},{x_2}) = {(1 - {x_1})^2} + 100 \cdot {({x_2} - {x_1}^2)^2}" /></span><script type='math/tex'>f({x_1},{x_2}) = {(1 - {x_1})^2} + 100 \cdot {({x_2} - {x_1}^2)^2}</script> <br />
它叫做<span style="color:#0000ff;">Rosenbrock function<sup>3</sup>（罗森布罗克函数）</span>，是个非凸函数，在最优化领域，它可以用作一个最优化算法的performance test函数。这个函数还有一个更好记也更滑稽的名字：banana function（香蕉函数）。<br />
我们来看一看它在三维空间中的图形：</p>
<div style="text-align: center;">
	<img decoding="async" alt="Rosenbrock function 3D" src="http://www.codelast.com/wp-content/uploads/ckfinder/images/Rosenbrock_function_3d.jpg" style="width: 450px; height: 338px;" /></div>
<div>
	<span style="color: rgb(255, 255, 255);">文章来源：</span><a href="http://www.codelast.com/" rel="noopener noreferrer" target="_blank"><span style="color: rgb(255, 255, 255);">http://www.codelast.com/</span></a><br />
	它的全局最优点位于一个长长的、狭窄的、抛物线形状的、扁平的&ldquo;山谷&rdquo;中。</div>
<div>
	找到&ldquo;山谷&rdquo;并不难，难的是收敛到全局最优解（在 (1,1) 处）。</div>
<div>
	正所谓：<span style="color:#800000;">世界上最遥远的距离，不是你离我千山万水，而是你就在我眼前，我却要跨越千万步，才能找到你</span>。</div>
<div>
	<span style="color: rgb(255, 255, 255);">文章来源：</span><a href="http://www.codelast.com/" rel="noopener noreferrer" target="_blank"><span style="color: rgb(255, 255, 255);">http://www.codelast.com/</span></a><br />
	我们再来看另一个目标函数 <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_8befafb138a9640e761679a0f15f30bb.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="f(x,y) = \sin \left( {\frac{1}{2}{x^2} - \frac{1}{4}{y^2} + 3} \right)\cos \left( {2x + 1 - {e^y}} \right)" /></span><script type='math/tex'>f(x,y) = \sin \left( {\frac{1}{2}{x^2} - \frac{1}{4}{y^2} + 3} \right)\cos \left( {2x + 1 - {e^y}} \right)</script> 的寻优过程<sup>4</sup>：</div>
<div style="text-align: center;">
	<img decoding="async" alt="" src="http://www.codelast.com/wp-content/uploads/ckfinder/images/function_find_opt_process.jpg" style="width: 310px; height: 309px;" /></div>
<div>
	和前面的Rosenbrock function一样，它的寻优过程也是&ldquo;锯齿状&rdquo;的。<br />
	它在三维空间中的图形是这样的：</div>
<div style="text-align: center;">
	<img decoding="async" alt="" src="http://www.codelast.com/wp-content/uploads/ckfinder/images/function_find_opt_process_3d.jpg" style="width: 365px; height: 300px;" /></div>
<div>
	总而言之就是：当目标函数的等值线接近于圆(球)时，下降较快；等值线类似于扁长的椭球时，一开始快，后来很慢。</div>
<div>
	<span style="color: rgb(255, 255, 255);">文章来源：</span><a href="http://www.codelast.com/" rel="noopener noreferrer" target="_blank"><span style="color: rgb(255, 255, 255);">http://www.codelast.com/</span></a><br />
	<span style="background-color:#00ff00;">『5』</span>为什么&ldquo;慢&rdquo;<br />
	从上面花花绿绿的图，我们看到了寻找最优解的过程有多么&ldquo;艰辛&rdquo;，但不能光看热闹，还要分析一下原因。<br />
	在最优化算法中，精确的line search满足一个<a href="http://www.codelast.com/?p=7838" rel="noopener noreferrer" target="_blank"><span style="background-color:#ffa07a;">一阶必要条件</span></a>，即：梯度与方向的点积为零（当前点在 <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_66eea6bfeea7fcb327d435f627a2390b.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="{d_k}" /></span><script type='math/tex'>{d_k}</script> 方向上移动到的那一点（ <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_dfce03f6c63c6112ec0a9e19d3390177.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="{x_k} + {\alpha _k}{d_k}" /></span><script type='math/tex'>{x_k} + {\alpha _k}{d_k}</script> ）处的梯度，与当前点的搜索方向 <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_66eea6bfeea7fcb327d435f627a2390b.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="{d_k}" /></span><script type='math/tex'>{d_k}</script> 的点积为零）。<br />
	由此得知：<br />
	 <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_79c40a2ebc114054140981fdaed79c9f.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="\nabla f{({x_k} + {\alpha _k}{d_k})^T}{d_k} = 0" /></span><script type='math/tex'>\nabla f{({x_k} + {\alpha _k}{d_k})^T}{d_k} = 0</script> ，即 <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_2b4eb83bd55e78edd9cda00404acfeb0.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="g_{k + 1}^T{d_k} = 0" /></span><script type='math/tex'>g_{k + 1}^T{d_k} = 0</script> <br />
	故由梯度下降法的 <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_6f02d7b4f8531090efdc877eb851f093.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="{d_k} = - {g_k}" /></span><script type='math/tex'>{d_k} = - {g_k}</script> 得：<br />
	 <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_03f082fe728fefc7e4909366635af3e9.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="g_{k + 1}^T{d_k} = g_{k + 1}^T( - {g_k}) = - g_{k + 1}^T{g_k} = - d_{k + 1}^T{d_k} = 0 \Rightarrow " /></span><script type='math/tex'>g_{k + 1}^T{d_k} = g_{k + 1}^T( - {g_k}) = - g_{k + 1}^T{g_k} = - d_{k + 1}^T{d_k} = 0 \Rightarrow </script> <span style="color:#ff0000;"> <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_fb24eac9024e19c63ae8e21214df893f.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="d_{k + 1}^T{d_k} = 0" /></span><script type='math/tex'>d_{k + 1}^T{d_k} = 0</script> </span><br />
	即：相邻两次的搜索方向是相互直交的（投影到二维平面上，就是锯齿形状了）。<br />
	<span style="color: rgb(255, 255, 255);">文章来源：</span><a href="http://www.codelast.com/" rel="noopener noreferrer" target="_blank"><span style="color: rgb(255, 255, 255);">http://www.codelast.com/</span></a><br />
	如果你非要问，为什么 <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_fb24eac9024e19c63ae8e21214df893f.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="d_{k + 1}^T{d_k} = 0" /></span><script type='math/tex'>d_{k + 1}^T{d_k} = 0</script> 就表明这两个向量是相互直交的？那是因为，由两向量夹角的公式：<br />
	 <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_162dccc3552556d48c0bb57f60aaebc4.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="\cos \theta = \frac{{{d_k}^T{d_k}}}{{\left\| {{d_k}} \right\|\left\| {{d_k}} \right\|}} = \frac{0}{{\left\| {{d_k}} \right\|\left\| {{d_k}} \right\|}} = 0\;" /></span><script type='math/tex'>\cos \theta = \frac{{{d_k}^T{d_k}}}{{\left\| {{d_k}} \right\|\left\| {{d_k}} \right\|}} = \frac{0}{{\left\| {{d_k}} \right\|\left\| {{d_k}} \right\|}} = 0\;</script> <br />
	=&gt;<span style="color:#ff0000;">  <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_f898dd39bd002624d891bc76fb86aa9f.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="\theta = \frac{\pi }{2}" /></span><script type='math/tex'>\theta = \frac{\pi }{2}</script> </span><br />
	可知两向量夹角为90度，因此它们直交。</p>
<p>	<span style="background-color:#00ff00;">『6』</span>优点<br />
	这个被我们说得一无是处的方法真的就那么糟糕吗？其实它还是有优点的：程序简单，计算量小；并且对初始点没有特别的要求；此外，许多算法的初始/再开始方向都是最速下降方向（即负梯度方向）。<br />
	<span style="color: rgb(255, 255, 255);">文章来源：</span><a href="http://www.codelast.com/" rel="noopener noreferrer" target="_blank"><span style="color: rgb(255, 255, 255);">http://www.codelast.com/</span></a><br />
	<span style="background-color:#00ff00;">『7』</span>收敛性及收敛速度<br />
	梯度下降法具有整体收敛性&mdash;&mdash;对初始点没有特殊要求。<br />
	采用<a href="http://www.codelast.com/?p=2348" rel="noopener noreferrer" target="_blank"><span style="background-color:#ffa07a;">精确的line search</span></a>的梯度下降法的收敛速度：线性。<br />
	&nbsp;</div>
<ul>
<li>
		引用</li>
</ul>
<div>
	（1）https://en.wikipedia.org/wiki/Cauchy%E2%80%93Schwarz_inequality<br />
	（2）https://en.wikipedia.org/wiki/Gradient_descent<br />
	（3）https://en.wikipedia.org/wiki/Rosenbrock_function<br />
	（4）https://en.wikipedia.org/wiki/Gradient_descent</p>
<p>	<span style="color: rgb(255, 255, 255);">文章来源：</span><a href="https://www.codelast.com/" rel="noopener noreferrer" target="_blank"><span style="color: rgb(255, 255, 255);">https://www.codelast.com/</span></a><br />
	<span style="color: rgb(255, 0, 0);">➤➤</span>&nbsp;版权声明&nbsp;<span style="color: rgb(255, 0, 0);">➤➤</span>&nbsp;<br />
	转载需注明出处：<u><a href="https://www.codelast.com/" rel="noopener noreferrer" target="_blank"><em><span style="color: rgb(0, 0, 255);"><strong style="font-size: 16px;"><span style="font-family: arial, helvetica, sans-serif;">codelast.com</span></strong></span></em></a></u>&nbsp;<br />
	感谢关注我的微信公众号（微信扫一扫）：</p>
<p style="border: 0px; font-size: 13px; margin: 0px 0px 9px; outline: 0px; padding: 0px; color: rgb(77, 77, 77);">
		<img decoding="async" alt="wechat qrcode of codelast" src="https://www.codelast.com/codelast_wechat_qr_code.jpg" style="width: 200px; height: 200px;" /></p>
</div>
]]></content:encoded>
					
					<wfw:commentRss>https://www.codelast.com/%e5%8e%9f%e5%88%9b-%e5%86%8d%e8%b0%88-%e6%9c%80%e9%80%9f%e4%b8%8b%e9%99%8d%e6%b3%95%e6%a2%af%e5%ba%a6%e6%b3%95steepest-descent/feed/</wfw:commentRss>
			<slash:comments>9</slash:comments>
		
		
			</item>
		<item>
		<title>[原创] line search中的重要定理 - 梯度与方向的点积为零</title>
		<link>https://www.codelast.com/%e5%8e%9f%e5%88%9b-line-search%e4%b8%ad%e7%9a%84%e9%87%8d%e8%a6%81%e5%ae%9a%e7%90%86-%e6%a2%af%e5%ba%a6%e4%b8%8e%e6%96%b9%e5%90%91%e7%9a%84%e7%82%b9%e7%a7%af%e4%b8%ba%e9%9b%b6/</link>
					<comments>https://www.codelast.com/%e5%8e%9f%e5%88%9b-line-search%e4%b8%ad%e7%9a%84%e9%87%8d%e8%a6%81%e5%ae%9a%e7%90%86-%e6%a2%af%e5%ba%a6%e4%b8%8e%e6%96%b9%e5%90%91%e7%9a%84%e7%82%b9%e7%a7%af%e4%b8%ba%e9%9b%b6/#respond</comments>
		
		<dc:creator><![CDATA[learnhard]]></dc:creator>
		<pubDate>Sun, 02 Mar 2014 04:17:53 +0000</pubDate>
				<category><![CDATA[Algorithm]]></category>
		<category><![CDATA[Math]]></category>
		<category><![CDATA[原创]]></category>
		<category><![CDATA[line search]]></category>
		<category><![CDATA[optimization]]></category>
		<category><![CDATA[一维搜索]]></category>
		<category><![CDATA[最优化]]></category>
		<guid isPermaLink="false">http://www.codelast.com/?p=7838</guid>

					<description><![CDATA[<p>
对精确的line search（线搜索），有一个重要的定理：</p>
<div style="text-align: center;">
	<img decoding="async" alt="" src="http://www.codelast.com/wp-content/uploads/ckfinder/images/line_search_important_theory.png" style="width: 292px; height: 62px;" /></div>
<p>这个定理表明，当前点在 <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_66eea6bfeea7fcb327d435f627a2390b.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="{d_k}" /></span><script type='math/tex'>{d_k}</script> 方向上移动到的那一点（ <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_dfce03f6c63c6112ec0a9e19d3390177.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="{x_k} + {\alpha _k}{d_k}" /></span><script type='math/tex'>{x_k} + {\alpha _k}{d_k}</script> ）处的梯度，与当前点的搜索方向 <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_66eea6bfeea7fcb327d435f627a2390b.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="{d_k}" /></span><script type='math/tex'>{d_k}</script> 的点积为零。<br />
<span id="more-7838"></span><br />
其中， <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_501cb8ba16bc463c7329e28f3ec226a7.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="{\alpha _k}" /></span><script type='math/tex'>{\alpha _k}</script> 是称之为&#8220;步长&#8221;的一个实数，它是通过line search算法求出来的。</p>
<p>为什么会有这样的结论？我们来看看。<br />
对每一个line search过程来说，搜索方向 <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_66eea6bfeea7fcb327d435f627a2390b.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="{d_k}" /></span><script type='math/tex'>{d_k}</script> 已经已经是确定的了（在最优化算法中，如何找出一个合适的 <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_66eea6bfeea7fcb327d435f627a2390b.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="{d_k}" /></span><script type='math/tex'>{d_k}</script> 不是line search干的事情）。所以，在一个确定的 <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_66eea6bfeea7fcb327d435f627a2390b.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="{d_k}" /></span><script type='math/tex'>{d_k}</script> 上，要找到一个合适的 <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_501cb8ba16bc463c7329e28f3ec226a7.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="{\alpha _k}" /></span><script type='math/tex'>{\alpha _k}</script> ，使得 <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_ea810edb4a7e8eadbe210b70b3a20fa7.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="\phi (\alpha ) = f({x_k} + \alpha {d_k})" /></span><script type='math/tex'>\phi (\alpha ) = f({x_k} + \alpha {d_k})</script> 这个函数满足 <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_12c0bd0e35955bb786ce9ac5f6f4b864.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="f({x_k} + {\alpha _k}{d_k}) < f({x_k})" /></span><script type='math/tex'>f({x_k} + {\alpha _k}{d_k}) < f({x_k})</script> ，这就是line search的目的。说白了，就是要找到 <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_501cb8ba16bc463c7329e28f3ec226a7.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="{\alpha _k}" /></span><script type='math/tex'>{\alpha _k}</script> 使 <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_17babde0fb3f14619432c61a083d48ae.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="\phi (\alpha )" /></span><script type='math/tex'>\phi (\alpha )</script> 的函数函数值变小。<br />
<span style="color: rgb(255, 255, 255);">文章来源：</span><a href="http://www.codelast.com/" target="_blank" rel="noopener noreferrer"><span style="color: rgb(255, 255, 255);">http://www.codelast.com/</span></a>&#8230; <a href="https://www.codelast.com/%e5%8e%9f%e5%88%9b-line-search%e4%b8%ad%e7%9a%84%e9%87%8d%e8%a6%81%e5%ae%9a%e7%90%86-%e6%a2%af%e5%ba%a6%e4%b8%8e%e6%96%b9%e5%90%91%e7%9a%84%e7%82%b9%e7%a7%af%e4%b8%ba%e9%9b%b6/" class="read-more">Read More </a></p>]]></description>
										<content:encoded><![CDATA[<p>
对精确的line search（线搜索），有一个重要的定理：</p>
<div style="text-align: center;">
	<img decoding="async" alt="" src="http://www.codelast.com/wp-content/uploads/ckfinder/images/line_search_important_theory.png" style="width: 292px; height: 62px;" /></div>
<p>这个定理表明，当前点在 <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_66eea6bfeea7fcb327d435f627a2390b.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="{d_k}" /></span><script type='math/tex'>{d_k}</script> 方向上移动到的那一点（ <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_dfce03f6c63c6112ec0a9e19d3390177.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="{x_k} + {\alpha _k}{d_k}" /></span><script type='math/tex'>{x_k} + {\alpha _k}{d_k}</script> ）处的梯度，与当前点的搜索方向 <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_66eea6bfeea7fcb327d435f627a2390b.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="{d_k}" /></span><script type='math/tex'>{d_k}</script> 的点积为零。<br />
<span id="more-7838"></span><br />
其中， <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_501cb8ba16bc463c7329e28f3ec226a7.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="{\alpha _k}" /></span><script type='math/tex'>{\alpha _k}</script> 是称之为&ldquo;步长&rdquo;的一个实数，它是通过line search算法求出来的。</p>
<p>为什么会有这样的结论？我们来看看。<br />
对每一个line search过程来说，搜索方向 <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_66eea6bfeea7fcb327d435f627a2390b.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="{d_k}" /></span><script type='math/tex'>{d_k}</script> 已经已经是确定的了（在最优化算法中，如何找出一个合适的 <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_66eea6bfeea7fcb327d435f627a2390b.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="{d_k}" /></span><script type='math/tex'>{d_k}</script> 不是line search干的事情）。所以，在一个确定的 <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_66eea6bfeea7fcb327d435f627a2390b.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="{d_k}" /></span><script type='math/tex'>{d_k}</script> 上，要找到一个合适的 <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_501cb8ba16bc463c7329e28f3ec226a7.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="{\alpha _k}" /></span><script type='math/tex'>{\alpha _k}</script> ，使得 <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_ea810edb4a7e8eadbe210b70b3a20fa7.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="\phi (\alpha ) = f({x_k} + \alpha {d_k})" /></span><script type='math/tex'>\phi (\alpha ) = f({x_k} + \alpha {d_k})</script> 这个函数满足 <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_12c0bd0e35955bb786ce9ac5f6f4b864.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="f({x_k} + {\alpha _k}{d_k}) < f({x_k})" /></span><script type='math/tex'>f({x_k} + {\alpha _k}{d_k}) < f({x_k})</script> ，这就是line search的目的。说白了，就是要找到 <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_501cb8ba16bc463c7329e28f3ec226a7.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="{\alpha _k}" /></span><script type='math/tex'>{\alpha _k}</script> 使 <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_17babde0fb3f14619432c61a083d48ae.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="\phi (\alpha )" /></span><script type='math/tex'>\phi (\alpha )</script> 的函数函数值变小。<br />
<span style="color: rgb(255, 255, 255);">文章来源：</span><a href="http://www.codelast.com/" target="_blank" rel="noopener noreferrer"><span style="color: rgb(255, 255, 255);">http://www.codelast.com/</span></a><br />
但是，要小到什么程度呢？假设小到有可能的&ldquo;最小&rdquo;，即：<br />
 <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_57d69503331c217962370d0aba642512.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="\phi ({\alpha _k}) = f({x_k} + {\alpha _k}{d_k}) = \mathop {\min }\limits_{\alpha > 0} f({x_k} + \alpha {d_k}) = \mathop {\min }\limits_{\alpha > 0} \phi (\alpha )" /></span><script type='math/tex'>\phi ({\alpha _k}) = f({x_k} + {\alpha _k}{d_k}) = \mathop {\min }\limits_{\alpha > 0} f({x_k} + \alpha {d_k}) = \mathop {\min }\limits_{\alpha > 0} \phi (\alpha )</script> <br />
那么，我们称这样的line search为&ldquo;精确的line search&rdquo;&mdash;&mdash;你看，这名字好贴切：我们精确地找到了函数值最小的那个点。</p>
<p>既然 <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_dfce03f6c63c6112ec0a9e19d3390177.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="{x_k} + {\alpha _k}{d_k}" /></span><script type='math/tex'>{x_k} + {\alpha _k}{d_k}</script> 是函数值最小的那个点，那么，在该点处的一阶导数（即梯度）为零，所以我们对上式求导（ <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_bccfc7022dfb945174d9bcebad2297bb.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="\alpha " /></span><script type='math/tex'>\alpha </script> 是自变量， <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_550187f469eda08b9e5b55143f19c4ce.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="{x_k}" /></span><script type='math/tex'>{x_k}</script> 和 <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_66eea6bfeea7fcb327d435f627a2390b.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="{d_k}" /></span><script type='math/tex'>{d_k}</script> 为常量）：<br />
 <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_8fb51f475ef3cf5596f7e8252a03b01b.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="\phi '({\alpha _k}) = {\left[ {f({x_k} + {\alpha _k}{d_k})} \right]^\prime } \cdot (0 + 1 \cdot {d_k}) = {\left[ {f({x_k} + {\alpha _k}{d_k})} \right]^\prime }{d_k} = \nabla f{({x_k} + {\alpha _k}{d_k})^T}{d_k} = 0" /></span><script type='math/tex'>\phi '({\alpha _k}) = {\left[ {f({x_k} + {\alpha _k}{d_k})} \right]^\prime } \cdot (0 + 1 \cdot {d_k}) = {\left[ {f({x_k} + {\alpha _k}{d_k})} \right]^\prime }{d_k} = \nabla f{({x_k} + {\alpha _k}{d_k})^T}{d_k} = 0</script> <br />
<span style="color: rgb(255, 255, 255);">文章来源：</span><a href="http://www.codelast.com/" target="_blank" rel="noopener noreferrer"><span style="color: rgb(255, 255, 255);">http://www.codelast.com/</span></a><br />
这就是我们前面说的定理了。</p>
<p><span style="color: rgb(255, 255, 255);">文章来源：</span><a href="https://www.codelast.com/" rel="noopener noreferrer" target="_blank"><span style="color: rgb(255, 255, 255);">https://www.codelast.com/</span></a><br />
<span style="color: rgb(255, 0, 0);">➤➤</span>&nbsp;版权声明&nbsp;<span style="color: rgb(255, 0, 0);">➤➤</span>&nbsp;<br />
转载需注明出处：<u><a href="https://www.codelast.com/" rel="noopener noreferrer" target="_blank"><em><span style="color: rgb(0, 0, 255);"><strong style="font-size: 16px;"><span style="font-family: arial, helvetica, sans-serif;">codelast.com</span></strong></span></em></a></u>&nbsp;<br />
感谢关注我的微信公众号（微信扫一扫）：</p>
<p style="border: 0px; font-size: 13px; margin: 0px 0px 9px; outline: 0px; padding: 0px; color: rgb(77, 77, 77);">
	<img decoding="async" alt="wechat qrcode of codelast" src="https://www.codelast.com/codelast_wechat_qr_code.jpg" style="width: 200px; height: 200px;" /></p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.codelast.com/%e5%8e%9f%e5%88%9b-line-search%e4%b8%ad%e7%9a%84%e9%87%8d%e8%a6%81%e5%ae%9a%e7%90%86-%e6%a2%af%e5%ba%a6%e4%b8%8e%e6%96%b9%e5%90%91%e7%9a%84%e7%82%b9%e7%a7%af%e4%b8%ba%e9%9b%b6/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>[原创]高等数学笔记(24)</title>
		<link>https://www.codelast.com/%e5%8e%9f%e5%88%9b%e9%ab%98%e7%ad%89%e6%95%b0%e5%ad%a6%e7%ac%94%e8%ae%b024/</link>
					<comments>https://www.codelast.com/%e5%8e%9f%e5%88%9b%e9%ab%98%e7%ad%89%e6%95%b0%e5%ad%a6%e7%ac%94%e8%ae%b024/#respond</comments>
		
		<dc:creator><![CDATA[learnhard]]></dc:creator>
		<pubDate>Sun, 22 Dec 2013 09:16:15 +0000</pubDate>
				<category><![CDATA[Math]]></category>
		<category><![CDATA[原创]]></category>
		<category><![CDATA[蔡高厅高等数学]]></category>
		<category><![CDATA[高数教程]]></category>
		<category><![CDATA[高数笔记]]></category>
		<category><![CDATA[高等数学教程]]></category>
		<category><![CDATA[高等数学笔记]]></category>
		<guid isPermaLink="false">http://www.codelast.com/?p=7637</guid>

					<description><![CDATA[<p>
<span style="background-color: rgb(0, 255, 0);">【前言】</span><br />
请看<a href="http://www.codelast.com/?p=6183" target="_blank" rel="noopener noreferrer"><span style="background-color: rgb(255, 160, 122);">此文</span></a>。<br />
要查看高等数学笔记合集，请看<a href="http://www.codelast.com/?p=6363" target="_blank" rel="noopener noreferrer"><span style="background-color: rgb(255, 160, 122);">这里</span></a>。</p>
<p><span style="background-color: rgb(0, 255, 0);">【正文】</span><br />
例2. 证明函数 <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_9b4fbea1e8a995125a014c281dedeac9.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="y = \sqrt[3]{x},y = \sqrt {{x^2}} = \left&#124; x \right&#124;" /></span><script type='math/tex'>y = \sqrt[3]{x},y = \sqrt {{x^2}} = \left&#124; x \right&#124;</script> 在 <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_3dad28281778d5ef4b7a78c7bc7a6b09.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="x = 0" /></span><script type='math/tex'>x = 0</script> 点连续，但是在 <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_3dad28281778d5ef4b7a78c7bc7a6b09.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="x = 0" /></span><script type='math/tex'>x = 0</script> 点不可导。<br />
<span id="more-7637"></span><br />
证：<br />
对 <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_e792c08aeb14d2f64b8026bb73f83d37.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="y = \sqrt[3]{x}" /></span><script type='math/tex'>y = \sqrt[3]{x}</script> ，自变量在 <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_3dad28281778d5ef4b7a78c7bc7a6b09.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="x = 0" /></span><script type='math/tex'>x = 0</script> 点有增量 <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_b56546a86ab832a9b2a5b15f96519319.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="\Delta x" /></span><script type='math/tex'>\Delta x</script> ，则 <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_f93f94f0cbf6f0da71b5bb8ea7a99433.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="\Delta y = \sqrt[3]{{0 + \Delta x}} - \sqrt[3]{0} = \sqrt[3]{{\Delta x}}" /></span><script type='math/tex'>\Delta y = \sqrt[3]{{0 + \Delta x}} - \sqrt[3]{0} = \sqrt[3]{{\Delta x}}</script> <br />
因此 <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_69fb9aba4fde4b2214209ae5ba28526c.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="{(\Delta y)^3} = \Delta x" /></span><script type='math/tex'>{(\Delta y)^3} = \Delta x</script> <br />
因为 <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_dbf8b23fc689a07f8691d4c876c0a720.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="\mathop {\lim }\limits_{\Delta x \to 0} {(\Delta y)^3} = {\left( {\mathop {\lim }\limits_{\Delta x \to 0} \Delta y} \right)^3} = \mathop {\lim }\limits_{\Delta x \to 0} \Delta x = 0" /></span><script type='math/tex'>\mathop {\lim }\limits_{\Delta x \to 0} {(\Delta y)^3} = {\left( {\mathop {\lim }\limits_{\Delta x \to 0} \Delta y} \right)^3} = \mathop {\lim }\limits_{\Delta x \to 0} \Delta x = 0</script> <br />
所以 <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_200d49b633d1b65a19f85e2249aef522.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="\mathop {\lim }\limits_{\Delta x \to 0} \Delta y = 0" /></span><script type='math/tex'>\mathop {\lim }\limits_{\Delta x \to 0} \Delta y = 0</script> <br />
所以 <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_e792c08aeb14d2f64b8026bb73f83d37.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="y = \sqrt[3]{x}" /></span><script type='math/tex'>y = \sqrt[3]{x}</script> 在 <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_3dad28281778d5ef4b7a78c7bc7a6b09.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="x = 0" /></span><script type='math/tex'>x = 0</script> 点连续（注：由<a href="http://www.codelast.com/?p=7083" target="_blank" rel="noopener noreferrer"><span style="background-color:#ffa07a;">第18课</span></a>的连续性定义可知）<br />
<span style="color: rgb(255, 255, 255);">文章来源：</span><a href="http://www.codelast.com/" target="_blank" rel="noopener noreferrer"><span style="color: rgb(255, 255, 255);">http://www.codelast.com/</span></a>&#8230; <a href="https://www.codelast.com/%e5%8e%9f%e5%88%9b%e9%ab%98%e7%ad%89%e6%95%b0%e5%ad%a6%e7%ac%94%e8%ae%b024/" class="read-more">Read More </a></p>]]></description>
										<content:encoded><![CDATA[<p>
<span style="background-color: rgb(0, 255, 0);">【前言】</span><br />
请看<a href="http://www.codelast.com/?p=6183" target="_blank" rel="noopener noreferrer"><span style="background-color: rgb(255, 160, 122);">此文</span></a>。<br />
要查看高等数学笔记合集，请看<a href="http://www.codelast.com/?p=6363" target="_blank" rel="noopener noreferrer"><span style="background-color: rgb(255, 160, 122);">这里</span></a>。</p>
<p><span style="background-color: rgb(0, 255, 0);">【正文】</span><br />
例2. 证明函数 <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_9b4fbea1e8a995125a014c281dedeac9.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="y = \sqrt[3]{x},y = \sqrt {{x^2}} = \left| x \right|" /></span><script type='math/tex'>y = \sqrt[3]{x},y = \sqrt {{x^2}} = \left| x \right|</script> 在 <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_3dad28281778d5ef4b7a78c7bc7a6b09.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="x = 0" /></span><script type='math/tex'>x = 0</script> 点连续，但是在 <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_3dad28281778d5ef4b7a78c7bc7a6b09.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="x = 0" /></span><script type='math/tex'>x = 0</script> 点不可导。<br />
<span id="more-7637"></span><br />
证：<br />
对 <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_e792c08aeb14d2f64b8026bb73f83d37.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="y = \sqrt[3]{x}" /></span><script type='math/tex'>y = \sqrt[3]{x}</script> ，自变量在 <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_3dad28281778d5ef4b7a78c7bc7a6b09.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="x = 0" /></span><script type='math/tex'>x = 0</script> 点有增量 <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_b56546a86ab832a9b2a5b15f96519319.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="\Delta x" /></span><script type='math/tex'>\Delta x</script> ，则 <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_f93f94f0cbf6f0da71b5bb8ea7a99433.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="\Delta y = \sqrt[3]{{0 + \Delta x}} - \sqrt[3]{0} = \sqrt[3]{{\Delta x}}" /></span><script type='math/tex'>\Delta y = \sqrt[3]{{0 + \Delta x}} - \sqrt[3]{0} = \sqrt[3]{{\Delta x}}</script> <br />
因此 <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_69fb9aba4fde4b2214209ae5ba28526c.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="{(\Delta y)^3} = \Delta x" /></span><script type='math/tex'>{(\Delta y)^3} = \Delta x</script> <br />
因为 <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_dbf8b23fc689a07f8691d4c876c0a720.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="\mathop {\lim }\limits_{\Delta x \to 0} {(\Delta y)^3} = {\left( {\mathop {\lim }\limits_{\Delta x \to 0} \Delta y} \right)^3} = \mathop {\lim }\limits_{\Delta x \to 0} \Delta x = 0" /></span><script type='math/tex'>\mathop {\lim }\limits_{\Delta x \to 0} {(\Delta y)^3} = {\left( {\mathop {\lim }\limits_{\Delta x \to 0} \Delta y} \right)^3} = \mathop {\lim }\limits_{\Delta x \to 0} \Delta x = 0</script> <br />
所以 <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_200d49b633d1b65a19f85e2249aef522.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="\mathop {\lim }\limits_{\Delta x \to 0} \Delta y = 0" /></span><script type='math/tex'>\mathop {\lim }\limits_{\Delta x \to 0} \Delta y = 0</script> <br />
所以 <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_e792c08aeb14d2f64b8026bb73f83d37.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="y = \sqrt[3]{x}" /></span><script type='math/tex'>y = \sqrt[3]{x}</script> 在 <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_3dad28281778d5ef4b7a78c7bc7a6b09.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="x = 0" /></span><script type='math/tex'>x = 0</script> 点连续（注：由<a href="http://www.codelast.com/?p=7083" target="_blank" rel="noopener noreferrer"><span style="background-color:#ffa07a;">第18课</span></a>的连续性定义可知）<br />
<span style="color: rgb(255, 255, 255);">文章来源：</span><a href="http://www.codelast.com/" target="_blank" rel="noopener noreferrer"><span style="color: rgb(255, 255, 255);">http://www.codelast.com/</span></a><br />
下面证明导数不存在。<br />
第一个函数：<br />
 <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_3521249ab3c6a9401401fc7400d7e148.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="\mathop {\lim }\limits_{\Delta x \to 0} \frac{{\Delta y}}{{\Delta x}} = \mathop {\lim }\limits_{\Delta x \to 0} \frac{{\sqrt[3]{{\Delta x}}}}{{\Delta x}} = \mathop {\lim }\limits_{\Delta x \to 0} \frac{1}{{{{(\Delta x)}^{\frac{2}{3}}}}} = \infty " /></span><script type='math/tex'>\mathop {\lim }\limits_{\Delta x \to 0} \frac{{\Delta y}}{{\Delta x}} = \mathop {\lim }\limits_{\Delta x \to 0} \frac{{\sqrt[3]{{\Delta x}}}}{{\Delta x}} = \mathop {\lim }\limits_{\Delta x \to 0} \frac{1}{{{{(\Delta x)}^{\frac{2}{3}}}}} = \infty </script> <br />
因此 <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_e792c08aeb14d2f64b8026bb73f83d37.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="y = \sqrt[3]{x}" /></span><script type='math/tex'>y = \sqrt[3]{x}</script> 在 <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_3dad28281778d5ef4b7a78c7bc7a6b09.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="x = 0" /></span><script type='math/tex'>x = 0</script> 点不可导。</p>
<p>第二个函数：<br />
对 <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_511058d385c25a184472ccd495723a8b.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="y = \sqrt {{x^2}} = \left| x \right| = \left\{ {\begin{array}{*{20}{c}}{x,x \ge 0}\\{ - x,x < 0}\end{array}} \right." /></span><script type='math/tex'>y = \sqrt {{x^2}} = \left| x \right| = \left\{ {\begin{array}{*{20}{c}}{x,x \ge 0}\\{ - x,x < 0}\end{array}} \right.</script> ，易证 <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_ed31a05407519a1de0275b7bd37239be.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="y = \left| x \right|" /></span><script type='math/tex'>y = \left| x \right|</script> 在 <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_3dad28281778d5ef4b7a78c7bc7a6b09.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="x = 0" /></span><script type='math/tex'>x = 0</script> 点连续（这里就不详细写了）<br />
设自变量 <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_9dd4e461268c8034f5c8564e155c67a6.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="x" /></span><script type='math/tex'>x</script> 在 <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_3dad28281778d5ef4b7a78c7bc7a6b09.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="x = 0" /></span><script type='math/tex'>x = 0</script> 点有增量 <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_b56546a86ab832a9b2a5b15f96519319.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="\Delta x" /></span><script type='math/tex'>\Delta x</script> ，则：</p>
<div>
	 <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_716ee70d85a3f0b611c0bd0e69dd6c4a.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="\Delta y = \left| {0 + \Delta x} \right| - \left| 0 \right| = \left| {\Delta x} \right| = \left\{ {\begin{array}{*{20}{c}}{\Delta x,\Delta x > 0}\\{ - \Delta x,\Delta x < 0}\end{array}} \right." /></span><script type='math/tex'>\Delta y = \left| {0 + \Delta x} \right| - \left| 0 \right| = \left| {\Delta x} \right| = \left\{ {\begin{array}{*{20}{c}}{\Delta x,\Delta x > 0}\\{ - \Delta x,\Delta x < 0}\end{array}} \right.</script> <br />
	在 <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_3dad28281778d5ef4b7a78c7bc7a6b09.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="x = 0" /></span><script type='math/tex'>x = 0</script> 处的右导数 <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_08abc9ee26c4dfd195104262bced1f95.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="{{f'}_ + }(0) = \mathop {\lim }\limits_{\Delta x \to {0^ + }} \frac{{\Delta y}}{{\Delta x}} = \mathop {\lim }\limits_{\Delta x \to {0^ + }} \frac{{\Delta x}}{{\Delta x}} = 1" /></span><script type='math/tex'>{{f'}_ + }(0) = \mathop {\lim }\limits_{\Delta x \to {0^ + }} \frac{{\Delta y}}{{\Delta x}} = \mathop {\lim }\limits_{\Delta x \to {0^ + }} \frac{{\Delta x}}{{\Delta x}} = 1</script> <br />
	在 <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_3dad28281778d5ef4b7a78c7bc7a6b09.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="x = 0" /></span><script type='math/tex'>x = 0</script> 处的左导数 <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_dbf7d86983f12637d89cf989ecc3b2d8.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="{{f'}_ - }(0) = \mathop {\lim }\limits_{\Delta x \to {0^ - }} \frac{{\Delta y}}{{\Delta x}} = \mathop {\lim }\limits_{\Delta x \to {0^ - }} \frac{{ - \Delta x}}{{\Delta x}} = - 1" /></span><script type='math/tex'>{{f'}_ - }(0) = \mathop {\lim }\limits_{\Delta x \to {0^ - }} \frac{{\Delta y}}{{\Delta x}} = \mathop {\lim }\limits_{\Delta x \to {0^ - }} \frac{{ - \Delta x}}{{\Delta x}} = - 1</script> <br />
	因为 <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_2217e3d0ef602f2355097a1317b33724.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="{{f'}_ + }(0) \ne {{f'}_ - }(0)" /></span><script type='math/tex'>{{f'}_ + }(0) \ne {{f'}_ - }(0)</script> <br />
	所以 <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_3d49eded98e05869cebdd0f9754040af.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="y = f(x) = \left| x \right|" /></span><script type='math/tex'>y = f(x) = \left| x \right|</script> 在 <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_3dad28281778d5ef4b7a78c7bc7a6b09.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="x = 0" /></span><script type='math/tex'>x = 0</script> 点不可导（注：由<a href="http://www.codelast.com/?p=7607" target="_blank" rel="noopener noreferrer"><span style="background-color:#ffa07a;">第23课</span></a>开头的定义可知）<br />
	<span style="color: rgb(255, 255, 255);">文章来源：</span><a href="http://www.codelast.com/" target="_blank" rel="noopener noreferrer"><span style="color: rgb(255, 255, 255);">http://www.codelast.com/</span></a><br />
	从函数图形上很容易看出来：<br />
	<img decoding="async" alt="" src="http://www.codelast.com/wp-content/uploads/ckfinder/images/higher_mathematics_note_24_1.jpg" /><br />
	对右图，在 <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_3dad28281778d5ef4b7a78c7bc7a6b09.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="x = 0" /></span><script type='math/tex'>x = 0</script> 点处，切线垂直于 <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_9dd4e461268c8034f5c8564e155c67a6.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="x" /></span><script type='math/tex'>x</script> 轴，斜率为无穷大，故不可导。<br />
	<span style="color: rgb(255, 255, 255);">文章来源：</span><a href="http://www.codelast.com/" target="_blank" rel="noopener noreferrer"><span style="color: rgb(255, 255, 255);">http://www.codelast.com/</span></a><br />
	五、几个基本初等函数的导数公式<br />
	1. 常数 <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_0d61f8370cad1d412f80b84d143e1257.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="C" /></span><script type='math/tex'>C</script> ： <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_9f1782950e5a012b2ea19c051b21468d.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="f(x) \equiv C, - \infty < x < + \infty " /></span><script type='math/tex'>f(x) \equiv C, - \infty < x < + \infty </script> <br />
	下面推导其导数：<br />
	令 <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_af60de4de21584cc6b4f4330811dce5b.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="y = f(x) \equiv C,\;\forall x \in ( - \infty , + \infty )" /></span><script type='math/tex'>y = f(x) \equiv C,\;\forall x \in ( - \infty , + \infty )</script> <br />
	 <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_69e880686adf3f05ce85433faae9b1fe.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="\Delta y = f(x + \Delta x) - f(x) = C - C = 0" /></span><script type='math/tex'>\Delta y = f(x + \Delta x) - f(x) = C - C = 0</script> <br />
	 <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_cfdc203b18cf9e049db5b07a724440fa.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="f'(x) = \mathop {\lim }\limits_{\Delta x \to 0} \frac{{\Delta y}}{{\Delta x}} = \mathop {\lim }\limits_{\Delta x \to 0} \frac{0}{{\Delta x}} = 0" /></span><script type='math/tex'>f'(x) = \mathop {\lim }\limits_{\Delta x \to 0} \frac{{\Delta y}}{{\Delta x}} = \mathop {\lim }\limits_{\Delta x \to 0} \frac{0}{{\Delta x}} = 0</script> <br />
	因此 <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_6971ec1a2265256346ad30d4daeec33d.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="{\left( C \right)^\prime } = 0" /></span><script type='math/tex'>{\left( C \right)^\prime } = 0</script> <br />
	<span style="color: rgb(255, 255, 255);">文章来源：</span><a href="http://www.codelast.com/" target="_blank" rel="noopener noreferrer"><span style="color: rgb(255, 255, 255);">http://www.codelast.com/</span></a><br />
	2. 幂函数 <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_47b855c36f0342f7b0515644822e23a1.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="y = f(x) = {x^\alpha }" /></span><script type='math/tex'>y = f(x) = {x^\alpha }</script> （ <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_bccfc7022dfb945174d9bcebad2297bb.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="\alpha " /></span><script type='math/tex'>\alpha </script> 为实常数）<br />
	下面推导其导数：<br />
	当 <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_0c89fe546bb00ab99d7fd557224cefbc.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="\alpha = n(n \in N)" /></span><script type='math/tex'>\alpha = n(n \in N)</script> 时，有 <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_ea136adfbc065c61b6f18c805ca4942c.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="\Delta y = f(x + \Delta x) - f(x) = {(x + \Delta x)^n} - {x^n}" /></span><script type='math/tex'>\Delta y = f(x + \Delta x) - f(x) = {(x + \Delta x)^n} - {x^n}</script> <br />
	按二项式定理展开前面的 <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_408da8b2d9ff27b9425008d73c9055cf.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="{(x + \Delta x)^n}" /></span><script type='math/tex'>{(x + \Delta x)^n}</script> ，得：<br />
	 <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_1e43fd8c668f27adb049a8a74a7b8259.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="\Delta y = \left[ {{x^n} + n{x^{n - 1}}\Delta x + \frac{{n(n - 1)}}{{2!}}{x^{n - 2}}{{(\Delta x)}^2} + \cdots + {{(\Delta x)}^n}} \right] - {x^n}" /></span><script type='math/tex'>\Delta y = \left[ {{x^n} + n{x^{n - 1}}\Delta x + \frac{{n(n - 1)}}{{2!}}{x^{n - 2}}{{(\Delta x)}^2} + \cdots + {{(\Delta x)}^n}} \right] - {x^n}</script> <br />
	 <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_228cb2269d34a907e5c5bdc0976a2391.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt=" = n{x^{n - 1}}\Delta x + \frac{{n(n - 1)}}{{2!}}{x^{n - 2}}{(\Delta x)^2} + \cdots + {(\Delta x)^n}" /></span><script type='math/tex'> = n{x^{n - 1}}\Delta x + \frac{{n(n - 1)}}{{2!}}{x^{n - 2}}{(\Delta x)^2} + \cdots + {(\Delta x)^n}</script> <br />
	因此 <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_9cefb5fdfe0eb97bded4401ae51d11ba.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="\frac{{\Delta y}}{{\Delta x}} = n{x^{n - 1}} + \frac{{n(n - 1)}}{{2!}}{x^{n - 2}}\Delta x + \cdots + {(\Delta x)^{n - 1}}" /></span><script type='math/tex'>\frac{{\Delta y}}{{\Delta x}} = n{x^{n - 1}} + \frac{{n(n - 1)}}{{2!}}{x^{n - 2}}\Delta x + \cdots + {(\Delta x)^{n - 1}}</script> <br />
	因此 <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_4143c83a2beadee016f970dc6ce66db2.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="\mathop {\lim }\limits_{\Delta x \to 0} \frac{{\Delta y}}{{\Delta x}} = \mathop {\lim }\limits_{\Delta x \to 0} \left[ {n{x^{n - 1}} + \frac{{n(n - 1)}}{{2!}}{x^{n - 2}}\Delta x + \cdots + {{(\Delta x)}^{n - 1}}} \right] = n{x^{n - 1}}" /></span><script type='math/tex'>\mathop {\lim }\limits_{\Delta x \to 0} \frac{{\Delta y}}{{\Delta x}} = \mathop {\lim }\limits_{\Delta x \to 0} \left[ {n{x^{n - 1}} + \frac{{n(n - 1)}}{{2!}}{x^{n - 2}}\Delta x + \cdots + {{(\Delta x)}^{n - 1}}} \right] = n{x^{n - 1}}</script> <br />
	（注：从第二项开始，每一项的极限均为0）<br />
	因此 <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_6a0eaf67eb57e086d283afd47a2f9b78.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="({x^n})' = n{x^{n - 1}}" /></span><script type='math/tex'>({x^n})' = n{x^{n - 1}}</script> <br />
	 <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_bccfc7022dfb945174d9bcebad2297bb.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="\alpha " /></span><script type='math/tex'>\alpha </script> 为任何实常数时， <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_3beec52d9228ac3b517474de0203c25d.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="({x^\alpha })' = \alpha {x^{\alpha - 1}}" /></span><script type='math/tex'>({x^\alpha })' = \alpha {x^{\alpha - 1}}</script> ，这个结论以后再证明。<br />
	<span style="color: rgb(255, 255, 255);">文章来源：</span><a href="http://www.codelast.com/" target="_blank" rel="noopener noreferrer"><span style="color: rgb(255, 255, 255);">http://www.codelast.com/</span></a><br />
	3. 正弦、余弦函数 <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_d2654bbe3ec797289b85ca4573e374a4.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="y = f(x) = \sin x,f(x) = \cos x" /></span><script type='math/tex'>y = f(x) = \sin x,f(x) = \cos x</script> <br />
	先来推导正弦函数的导数：<br />
	 <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_e1bd25e28e3aea92ed8e6272c82da660.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="y = \sin x,\; - \infty < x < + \infty " /></span><script type='math/tex'>y = \sin x,\; - \infty < x < + \infty </script> <br />
	 <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_32973eb885f75d62b22bf9b01b41eb4b.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="\forall x \in ( - \infty , + \infty )" /></span><script type='math/tex'>\forall x \in ( - \infty , + \infty )</script> ，自变量有增量 <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_4942f4057e2834cce76bac31807380f7.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="{\Delta x}" /></span><script type='math/tex'>{\Delta x}</script> ，函数 <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_441bad5c5b571c78799e80e873cc5ab3.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="y = \sin x" /></span><script type='math/tex'>y = \sin x</script> 的增量 <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_2128efdf72e64db6c65cc35a3d4770ad.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="\Delta y = \sin (x + \Delta x) - \sin x = 2\sin \frac{{\Delta x}}{2}\cos (x + \frac{{\Delta x}}{2})" /></span><script type='math/tex'>\Delta y = \sin (x + \Delta x) - \sin x = 2\sin \frac{{\Delta x}}{2}\cos (x + \frac{{\Delta x}}{2})</script> <br />
	（注：三角函数的和差化积公式）<br />
	因此 <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_810a03afb680f74c31f50377f73b9e5e.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="\frac{{\Delta y}}{{\Delta x}} = \frac{{2\sin \frac{{\Delta x}}{2}\cos (x + \frac{{\Delta x}}{2})}}{{\Delta x}}" /></span><script type='math/tex'>\frac{{\Delta y}}{{\Delta x}} = \frac{{2\sin \frac{{\Delta x}}{2}\cos (x + \frac{{\Delta x}}{2})}}{{\Delta x}}</script> <br />
	因此 <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_e7fad22f1d4959f0c3a7582a91ab2b34.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="\mathop {\lim }\limits_{\Delta x \to 0} \frac{{\Delta y}}{{\Delta x}} = \mathop {\lim }\limits_{\Delta x \to 0} \frac{{2\sin \frac{{\Delta x}}{2}}}{{\Delta x}} \cdot \mathop {\lim }\limits_{\Delta x \to 0} \cos (x + \frac{{\Delta x}}{2}) = 1 \cdot \cos x = \cos x" /></span><script type='math/tex'>\mathop {\lim }\limits_{\Delta x \to 0} \frac{{\Delta y}}{{\Delta x}} = \mathop {\lim }\limits_{\Delta x \to 0} \frac{{2\sin \frac{{\Delta x}}{2}}}{{\Delta x}} \cdot \mathop {\lim }\limits_{\Delta x \to 0} \cos (x + \frac{{\Delta x}}{2}) = 1 \cdot \cos x = \cos x</script> <br />
	（注： <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_113c75456a81674fd181485551156342.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="\mathop {\lim }\limits_{\Delta x \to 0} \frac{{2\sin \frac{{\Delta x}}{2}}}{{\Delta x}} = 1" /></span><script type='math/tex'>\mathop {\lim }\limits_{\Delta x \to 0} \frac{{2\sin \frac{{\Delta x}}{2}}}{{\Delta x}} = 1</script> 是重要极限之一； <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_ae1c9c53a3217f895d7cce542ccd578d.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="y = \cos x" /></span><script type='math/tex'>y = \cos x</script> 是连续函数，因此 <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_1592150cd7fe55d77ec1c61a965daace.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="\mathop {\lim }\limits_{\Delta x \to 0} \cos (x + \frac{{\Delta x}}{2})" /></span><script type='math/tex'>\mathop {\lim }\limits_{\Delta x \to 0} \cos (x + \frac{{\Delta x}}{2})</script> 的极限号可以放进去）<br />
	因此 <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_621bb232d81c01be945a54b21f855e8c.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="(\sin x)' = \cos x" /></span><script type='math/tex'>(\sin x)' = \cos x</script> <br />
	<span style="color: rgb(255, 255, 255);">文章来源：</span><a href="http://www.codelast.com/" target="_blank" rel="noopener noreferrer"><span style="color: rgb(255, 255, 255);">http://www.codelast.com/</span></a><br />
	再来推导余弦函数的导数：<br />
	 <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_4932430222035f04fd38b3fe1ad08736.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="y = \cos x,\; - \infty < x < + \infty " /></span><script type='math/tex'>y = \cos x,\; - \infty < x < + \infty </script> <br />
	 <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_32973eb885f75d62b22bf9b01b41eb4b.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="\forall x \in ( - \infty , + \infty )" /></span><script type='math/tex'>\forall x \in ( - \infty , + \infty )</script> ， <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_5a05fa6a0d1633644380501f2a3f5085.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="\mathop {\lim }\limits_{\Delta x \to 0} \frac{{\Delta y}}{{\Delta x}} = \mathop {\lim }\limits_{\Delta x \to 0} \frac{{\cos (x + \Delta x) - \cos x}}{{\Delta x}} = \mathop {\lim }\limits_{\Delta x \to 0} \frac{{ - 2\sin \frac{{\Delta x}}{2}\sin \left( {x + \frac{{\Delta x}}{2}} \right)}}{{\Delta x}}" /></span><script type='math/tex'>\mathop {\lim }\limits_{\Delta x \to 0} \frac{{\Delta y}}{{\Delta x}} = \mathop {\lim }\limits_{\Delta x \to 0} \frac{{\cos (x + \Delta x) - \cos x}}{{\Delta x}} = \mathop {\lim }\limits_{\Delta x \to 0} \frac{{ - 2\sin \frac{{\Delta x}}{2}\sin \left( {x + \frac{{\Delta x}}{2}} \right)}}{{\Delta x}}</script> <br />
	 <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_b554b7d521acc4b9828284f8b4617fa3.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt=" = - \mathop {\lim }\limits_{\Delta x \to 0} \frac{{\sin \frac{{\Delta x}}{2}}}{{\frac{{\Delta x}}{2}}} \cdot \mathop {\lim }\limits_{\Delta x \to 0} \sin \left( {x + \frac{{\Delta x}}{2}} \right) = - \sin x" /></span><script type='math/tex'> = - \mathop {\lim }\limits_{\Delta x \to 0} \frac{{\sin \frac{{\Delta x}}{2}}}{{\frac{{\Delta x}}{2}}} \cdot \mathop {\lim }\limits_{\Delta x \to 0} \sin \left( {x + \frac{{\Delta x}}{2}} \right) = - \sin x</script> <br />
	因此 <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_eaf0ad9c75dedc0fbb09ca17eaa725be.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="(\cos x)' = - \sin x" /></span><script type='math/tex'>(\cos x)' = - \sin x</script> <br />
	<span style="color: rgb(255, 255, 255);">文章来源：</span><a href="http://www.codelast.com/" target="_blank" rel="noopener noreferrer"><span style="color: rgb(255, 255, 255);">http://www.codelast.com/</span></a><br />
	4. 对数函数 <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_501e211ea95a806d51a67fb63b0ab90d.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="y = f(x) = {\log _a}x\;(a > 0,a \ne 1)" /></span><script type='math/tex'>y = f(x) = {\log _a}x\;(a > 0,a \ne 1)</script> <br />
	 <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_c5e053f66f138c17da8e910829712cd5.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="y = {\log _a}x,\;0 < x < + \infty " /></span><script type='math/tex'>y = {\log _a}x,\;0 < x < + \infty </script> <br />
	 <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_a92718c8225bc2e06388bfcc3c7e03df.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="\forall x \in (0, + \infty )" /></span><script type='math/tex'>\forall x \in (0, + \infty )</script> ，设自变量 <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_9dd4e461268c8034f5c8564e155c67a6.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="x" /></span><script type='math/tex'>x</script> 有增量 <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_4942f4057e2834cce76bac31807380f7.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="{\Delta x}" /></span><script type='math/tex'>{\Delta x}</script> ，函数对应的增量：<br />
	 <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_1cdd6483d4b4f14ade3b8adc7d3187c4.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="\Delta y = {\log _a}(x + \Delta x) - {\log _a}x = {\log _a}\left( {\frac{{x + \Delta x}}{x}} \right) = {\log _a}\left( {1 + \frac{{\Delta x}}{x}} \right)" /></span><script type='math/tex'>\Delta y = {\log _a}(x + \Delta x) - {\log _a}x = {\log _a}\left( {\frac{{x + \Delta x}}{x}} \right) = {\log _a}\left( {1 + \frac{{\Delta x}}{x}} \right)</script> <br />
	因此 <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_af1e09eb6161f1300e5c4fadbb821de6.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="\frac{{\Delta y}}{{\Delta x}} = \frac{1}{{\Delta x}}{\log _a}\left( {1 + \frac{{\Delta x}}{x}} \right) = \frac{1}{x} \cdot \frac{x}{{\Delta x}}{\log _a}\left( {1 + \frac{{\Delta x}}{x}} \right) = \frac{1}{x}{\log _a}{\left( {1 + \frac{{\Delta x}}{x}} \right)^{\frac{x}{{\Delta x}}}}" /></span><script type='math/tex'>\frac{{\Delta y}}{{\Delta x}} = \frac{1}{{\Delta x}}{\log _a}\left( {1 + \frac{{\Delta x}}{x}} \right) = \frac{1}{x} \cdot \frac{x}{{\Delta x}}{\log _a}\left( {1 + \frac{{\Delta x}}{x}} \right) = \frac{1}{x}{\log _a}{\left( {1 + \frac{{\Delta x}}{x}} \right)^{\frac{x}{{\Delta x}}}}</script> <br />
	<span style="color: rgb(255, 255, 255);">文章来源：</span><a href="http://www.codelast.com/" target="_blank" rel="noopener noreferrer"><span style="color: rgb(255, 255, 255);">http://www.codelast.com/</span></a><br />
	因此 <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_3c94fdefbb16015343e8b96aa292f2c6.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="\mathop {\lim }\limits_{\Delta x \to 0} \frac{{\Delta y}}{{\Delta x}} = \mathop {\lim }\limits_{\Delta x \to 0} \left[ {\frac{1}{x}{{\log }_a}{{\left( {1 + \frac{{\Delta x}}{x}} \right)}^{\frac{x}{{\Delta x}}}}} \right] = \frac{1}{x} \cdot \mathop {\lim }\limits_{\Delta x \to 0} \left[ {{{\log }_a}{{\left( {1 + \frac{{\Delta x}}{x}} \right)}^{\frac{x}{{\Delta x}}}}} \right]" /></span><script type='math/tex'>\mathop {\lim }\limits_{\Delta x \to 0} \frac{{\Delta y}}{{\Delta x}} = \mathop {\lim }\limits_{\Delta x \to 0} \left[ {\frac{1}{x}{{\log }_a}{{\left( {1 + \frac{{\Delta x}}{x}} \right)}^{\frac{x}{{\Delta x}}}}} \right] = \frac{1}{x} \cdot \mathop {\lim }\limits_{\Delta x \to 0} \left[ {{{\log }_a}{{\left( {1 + \frac{{\Delta x}}{x}} \right)}^{\frac{x}{{\Delta x}}}}} \right]</script> <br />
	 <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_494a5129ad7a88f5a7907f6383e2d623.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt=" = \frac{1}{x} \cdot {\log _a}\left[ {\mathop {\lim }\limits_{\Delta x \to 0} {{\left( {1 + \frac{{\Delta x}}{x}} \right)}^{\frac{x}{{\Delta x}}}}} \right] = \frac{1}{x} \cdot {\log _a}e = \frac{1}{x} \cdot \frac{1}{{\ln a}} = \frac{1}{{x\ln a}}" /></span><script type='math/tex'> = \frac{1}{x} \cdot {\log _a}\left[ {\mathop {\lim }\limits_{\Delta x \to 0} {{\left( {1 + \frac{{\Delta x}}{x}} \right)}^{\frac{x}{{\Delta x}}}}} \right] = \frac{1}{x} \cdot {\log _a}e = \frac{1}{x} \cdot \frac{1}{{\ln a}} = \frac{1}{{x\ln a}}</script> <br />
	（注：<span style="color:#0000ff;"> <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_f64f2431be20826db8e0302fe3006e21.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="\mathop {\lim }\limits_{\Delta x \to 0} {\left( {1 + \frac{{\Delta x}}{x}} \right)^{\frac{x}{{\Delta x}}}} = e" /></span><script type='math/tex'>\mathop {\lim }\limits_{\Delta x \to 0} {\left( {1 + \frac{{\Delta x}}{x}} \right)^{\frac{x}{{\Delta x}}}} = e</script> 是重要极限之一，即 <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_8ff7afa07310006af535872bb1fd982e.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="\mathop {\lim }\limits_{\alpha \to 0} {(1 + \alpha )^{\frac{1}{\alpha }}} = e" /></span><script type='math/tex'>\mathop {\lim }\limits_{\alpha \to 0} {(1 + \alpha )^{\frac{1}{\alpha }}} = e</script> </span>）<br />
	因此 <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_338d22bd95e18c36f6808c897417ca4c.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="{\left( {{{\log }_a}x} \right)^\prime } = \frac{1}{{x\ln a}}" /></span><script type='math/tex'>{\left( {{{\log }_a}x} \right)^\prime } = \frac{1}{{x\ln a}}</script> <br />
	 <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_d8ecf5392c8725ec45fa958574123313.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="(\ln x)' = \frac{1}{{x\ln e}} = \frac{1}{x}" /></span><script type='math/tex'>(\ln x)' = \frac{1}{{x\ln e}} = \frac{1}{x}</script> <br />
	<span style="color: rgb(255, 255, 255);">文章来源：</span><a href="http://www.codelast.com/" target="_blank" rel="noopener noreferrer"><span style="color: rgb(255, 255, 255);">http://www.codelast.com/</span></a><br />
	本课推导的常用的导数公式总结：<br />
	<span style="color:#b22222;"> <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_6971ec1a2265256346ad30d4daeec33d.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="{\left( C \right)^\prime } = 0" /></span><script type='math/tex'>{\left( C \right)^\prime } = 0</script> <br />
	 <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_9c9fb33f868f94173a8c8b8a5b8f32e4.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="{\left( {{x^\alpha }} \right)^\prime } = \alpha {x^{\alpha - 1}}" /></span><script type='math/tex'>{\left( {{x^\alpha }} \right)^\prime } = \alpha {x^{\alpha - 1}}</script> <br />
	 <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_6777ebafb9c48ca6d9b4173e20979001.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="{\left( {\sin x} \right)^\prime } = \cos x" /></span><script type='math/tex'>{\left( {\sin x} \right)^\prime } = \cos x</script> <br />
	 <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_3af642b26a2051682e6a94c2567488fa.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="{\left( {\cos x} \right)^\prime } = - \sin x" /></span><script type='math/tex'>{\left( {\cos x} \right)^\prime } = - \sin x</script> <br />
	 <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_338d22bd95e18c36f6808c897417ca4c.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="{\left( {{{\log }_a}x} \right)^\prime } = \frac{1}{{x\ln a}}" /></span><script type='math/tex'>{\left( {{{\log }_a}x} \right)^\prime } = \frac{1}{{x\ln a}}</script> <br />
	 <span class='MathJax_Preview'><img src='https://www.codelast.com/wp-content/plugins/latex/cache/tex_b690179a00bd2fe14191f55e339f0d5e.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="{\left( {\ln x} \right)^\prime } = \frac{1}{x}" /></span><script type='math/tex'>{\left( {\ln x} \right)^\prime } = \frac{1}{x}</script> </span><br />
	<span style="color: rgb(255, 255, 255);">文章来源：</span><a href="http://www.codelast.com/" target="_blank" rel="noopener noreferrer"><span style="color: rgb(255, 255, 255);">http://www.codelast.com/</span></a><br />
	<span style="color: rgb(255, 0, 0);">（第24课完）</span></p>
<p>	<span style="color: rgb(255, 255, 255);">文章来源：</span><a href="https://www.codelast.com/" rel="noopener noreferrer" target="_blank"><span style="color: rgb(255, 255, 255);">https://www.codelast.com/</span></a><br />
	<span style="color: rgb(255, 0, 0);">➤➤</span>&nbsp;版权声明&nbsp;<span style="color: rgb(255, 0, 0);">➤➤</span>&nbsp;<br />
	转载需注明出处：<u><a href="https://www.codelast.com/" rel="noopener noreferrer" target="_blank"><em><span style="color: rgb(0, 0, 255);"><strong style="font-size: 16px;"><span style="font-family: arial, helvetica, sans-serif;">codelast.com</span></strong></span></em></a></u>&nbsp;<br />
	感谢关注我的微信公众号（微信扫一扫）：</p>
<p style="border: 0px; font-size: 13px; margin: 0px 0px 9px; outline: 0px; padding: 0px; color: rgb(77, 77, 77);">
		<img decoding="async" alt="wechat qrcode of codelast" src="https://www.codelast.com/codelast_wechat_qr_code.jpg" style="width: 200px; height: 200px;" /></p>
</div>
]]></content:encoded>
					
					<wfw:commentRss>https://www.codelast.com/%e5%8e%9f%e5%88%9b%e9%ab%98%e7%ad%89%e6%95%b0%e5%ad%a6%e7%ac%94%e8%ae%b024/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
