<?xml version="1.0" encoding="utf-8"?><feed xmlns="http://www.w3.org/2005/Atom" xml:lang="cn"><generator uri="https://jekyllrb.com/" version="4.3.4">Jekyll</generator><link href="https://jkfx.github.io/feed.xml" rel="self" type="application/atom+xml"/><link href="https://jkfx.github.io/" rel="alternate" type="text/html" hreflang="cn"/><updated>2026-03-17T14:34:05+08:00</updated><id>https://jkfx.github.io/feed.xml</id><title type="html">blank</title><subtitle></subtitle><entry><title type="html">LaTeX Math Typesetting Guide</title><link href="https://jkfx.github.io/blog/2026/LaTeX-Math-Typesetting-Guide/" rel="alternate" type="text/html" title="LaTeX Math Typesetting Guide"/><published>2026-01-08T11:52:00+08:00</published><updated>2026-01-08T11:52:00+08:00</updated><id>https://jkfx.github.io/blog/2026/LaTeX%20Math%20Typesetting%20Guide</id><content type="html" xml:base="https://jkfx.github.io/blog/2026/LaTeX-Math-Typesetting-Guide/"><![CDATA[<ul> <li><a href="#style-issue-basics">Style Issue Basics</a> <ul> <li><a href="#variables">Variables</a></li> <li><a href="#vectors">Vectors</a></li> <li><a href="#functions">Functions</a></li> <li><a href="#alignment-and-line-breaks-for-display-formulas">Alignment and Line Breaks for Display Formulas</a></li> <li><a href="#avoid-obsolete-codes-and-delimiters-eqnarray--display-math-delimiters">Avoid Obsolete Codes and Delimiters (<code class="language-plaintext highlighter-rouge">eqnarray</code>, <code class="language-plaintext highlighter-rouge">$$</code> display math delimiters)</a></li> <li><a href="#use-appropriate-delimiters-for-display-equations">Use Appropriate Delimiters for Display Equations</a></li> <li><a href="#mathcal-vs-rsfs-script">mathcal vs. RSFS script</a></li> </ul> </li> <li><a href="#example-i-cases">Example I: Cases</a> <ul> <li><a href="#example-1-1">Example 1-1</a></li> <li><a href="#example-1-2">Example 1-2</a></li> <li><a href="#example-1-3">Example 1-3</a></li> </ul> </li> <li><a href="#example-ii-text-functions">Example II: Text Functions</a> <ul> <li><a href="#example-2-1">Example 2-1</a></li> <li><a href="#example-2-2">Example 2-2</a></li> <li><a href="#example-2-3">Example 2-3</a></li> </ul> </li> <li><a href="#example-iii-limits">Example III: Limits</a> <ul> <li><a href="#example-3-1">Example 3-1</a></li> <li><a href="#example-3-2">Example 3-2</a></li> </ul> </li> <li><a href="#example-iv-text-acronyms">Example IV: Text Acronyms</a> <ul> <li><a href="#example-4-1">Example 4-1</a></li> <li><a href="#example-4-2">Example 4-2</a></li> <li><a href="#example-4-3">Example 4-3</a></li> </ul> </li> <li><a href="#example-v-fences">Example V: Fences</a> <ul> <li><a href="#example-5-1">Example 5-1</a></li> <li><a href="#example-5-2">Example 5-2</a></li> <li><a href="#example-5-3">Example 5-3</a></li> </ul> </li> </ul> <h2 id="style-issue-basics">Style Issue Basics</h2> <h3 id="variables">Variables</h3> <p>Variables should always be set in <em>italic</em> font in both text and in equations.</p> <h3 id="vectors">Vectors</h3> <p>Vectors should always be in <strong>bold</strong> type.</p> <h3 id="functions">Functions</h3> <p>Functions should always be set as roman type.</p> <h3 id="alignment-and-line-breaks-for-display-formulas">Alignment and Line Breaks for Display Formulas</h3> <ul> <li>Break and Align on Mathematical Verbs</li> </ul> \[\begin{aligned} |q\rangle &amp; =\cos \frac{\theta}{2}|0\rangle+(\cos \varphi+i \sin \varphi) \sin \frac{\theta}{2}|1\rangle \\ &amp; =\cos \frac{\theta}{2}|0\rangle+\cos \varphi \sin \frac{\theta}{2}|1\rangle+i \sin \varphi \sin \frac{\theta}{2}|1\rangle \end{aligned}\] <ul> <li>Break at Mathematical Conjunctions and Align to the Right of the First Mathematical Verb</li> </ul> \[\begin{aligned} |q\rangle = &amp; \cos \frac{\theta(t)}{2}|0\rangle + \cos \varphi(t) \sin \frac{\theta(t)}{2}|1\rangle \\ &amp;+ i \sin \varphi(t) \sin \frac{\theta(t)}{2}|1\rangle \end{aligned}\] <ul> <li>Always Keep Expressions Visually Within Fences</li> </ul> \[\begin{aligned} \overline{P}_{H, rx}^{(E R_{C W}^{f})} = \frac{1}{T_{E R}} &amp; \left( T_{h v} P_{S, tx} |\mathbf{g}^{T} \mathbf{w}|^{2} + T_{tx} P_{S, tx} |\mathbf{g}^{T} \mathbf{w} \right. \\ &amp;\quad \left. + \sqrt{\rho_{1} \eta (P_{E R^{f}, rx})} |\mathbf{f}_{1}^{T} \mathbf{w}| f_{2} e^{-j(\theta_{2}-\theta_{1})} |^{2} \right), \end{aligned}\] <blockquote> <p>Note the position of the “+” under and to the right of the parentheses surrounding the expression.</p> </blockquote> <h3 id="avoid-obsolete-codes-and-delimiters-eqnarray--display-math-delimiters">Avoid Obsolete Codes and Delimiters (<code class="language-plaintext highlighter-rouge">eqnarray</code>, <code class="language-plaintext highlighter-rouge">$$</code> display math delimiters)</h3> <p>Avoid the use of outdated macros, such as <code class="language-plaintext highlighter-rouge">eqnarray</code> and <code class="language-plaintext highlighter-rouge">$$</code> math delimiters, for display equations.</p> <h3 id="use-appropriate-delimiters-for-display-equations">Use Appropriate Delimiters for Display Equations</h3> <ul> <li>For single-line unnumbered display equations, please use only the following delimiters: <code class="language-plaintext highlighter-rouge">\[ . . . \]</code> or <code class="language-plaintext highlighter-rouge">\begin{equation*} . . . \end{equation*}</code></li> <li>For multiline unnumbered display equations, please use only the following delimiters: <code class="language-plaintext highlighter-rouge">\begin{align} . . . \end{align}</code></li> <li>For single-line numbered display equations, please use only the following delimiters: <code class="language-plaintext highlighter-rouge">\begin{equation} . . . \end{equation}</code></li> <li>For multiline numbered display equations, please use only the following delimiters: <code class="language-plaintext highlighter-rouge">\begin{align} . . . \end{align}</code></li> </ul> <h3 id="mathcal-vs-rsfs-script">mathcal vs. RSFS script</h3> <p>Please see the RSFS documentation at <a href="https://ctan.org/pkg/rsfs">https://ctan.org/pkg/rsfs</a> for proper use.</p> <h2 id="example-i-cases">Example I: Cases</h2> <h3 id="example-1-1">Example 1-1</h3> <p><strong>Incorrect Example:</strong> The wrong environment is used (<code class="language-plaintext highlighter-rouge">array</code> instead of <code class="language-plaintext highlighter-rouge">cases</code>), the tabs are missing, and the text is not formatted correctly (should not be <em>italic</em>).</p> <div class="language-tex highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nt">\begin{equation}</span>
  P(Y=1|<span class="k">\boldsymbol</span><span class="p">{</span>X<span class="p">_{</span>i<span class="p">}^{</span>j<span class="p">}}</span>)=
  <span class="k">\left\lbrace</span>
  <span class="nt">\begin{array}</span><span class="p">{</span>l<span class="p">}</span>
    0, correct <span class="k">\\</span>
    1, erroneous.
  <span class="nt">\end{array}</span>
  <span class="k">\right</span>.
  <span class="k">\tag</span><span class="p">{</span>1<span class="p">}</span>
<span class="nt">\end{equation}</span>
</code></pre></div></div> \[\begin{equation} P(Y=1|\boldsymbol{X_{i}^{j}})= \left\lbrace \begin{array}{l} 0, correct \\ 1, erroneous. \end{array} \right. \tag{1} \end{equation}\] <p><strong>Correct Example:</strong> The correct environment is used. Using the <code class="language-plaintext highlighter-rouge">cases</code> environment will save keystrokes (from not having to type the <code class="language-plaintext highlighter-rouge">\left\brace{</code>) and automatically provide the correct column alignment. The tabs have been inserted and the text formatting corrected.</p> <div class="language-tex highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nt">\begin{equation*}</span>
  P(Y=1|<span class="k">\boldsymbol</span><span class="p">{</span>X<span class="p">_{</span>i<span class="p">}^{</span>j<span class="p">}}</span>)=
  <span class="nt">\begin{cases}</span>
    0, <span class="p">&amp;</span> <span class="k">\text</span><span class="p">{</span>correct<span class="p">}</span> <span class="k">\\</span>
    1,<span class="p">&amp;</span> <span class="k">\text</span><span class="p">{</span>erroneous.<span class="p">}</span>
  <span class="nt">\end{cases}</span>
  <span class="k">\tag</span><span class="p">{</span>1a<span class="p">}</span>
<span class="nt">\end{equation*}</span>
</code></pre></div></div> \[\begin{equation*} P(Y=1|\boldsymbol{X_{i}^{j}})= \begin{cases} 0, &amp; \text{correct} \\ 1,&amp; \text{erroneous.} \end{cases} \tag{1a} \end{equation*}\] <h3 id="example-1-2">Example 1-2</h3> <p><strong>Incorrect Example:</strong> The wrong environment is used and the column alignment is incorrect. Columns in cases should be left aligned.</p> <div class="language-tex highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nt">\begin{equation}</span>
  <span class="p">{</span>z<span class="p">_</span>m(t)<span class="p">}</span> = <span class="k">\left\lbrace</span> <span class="p">{</span>
    <span class="nt">\begin{array}</span><span class="p">{</span>cc<span class="p">}</span>
      1,<span class="p">&amp;{{</span><span class="k">\mathrm</span> <span class="p">{</span>if<span class="p">}}</span><span class="k">\  </span><span class="p">{{</span><span class="k">\beta</span> <span class="p">}_</span>m(t)<span class="p">}</span> &lt; <span class="k">\frac</span><span class="p">{</span><span class="k">\mathfrak</span> <span class="p">{</span>B<span class="p">}_{</span>m<span class="p">}^{</span><span class="k">\max</span> <span class="p">}}{{</span> |<span class="k">\mathcal</span> <span class="p">{</span>U<span class="p">}_</span>m|r<span class="p">_{</span>m,i<span class="p">}^{</span><span class="k">\min</span> <span class="p">}</span> <span class="p">}}}</span>,<span class="k">\\</span>
      <span class="p">{</span>0,<span class="p">}&amp;{{</span><span class="k">\mathrm</span> <span class="p">{</span>otherwise.<span class="p">}}}</span>
  <span class="nt">\end{array}</span><span class="p">}</span>
  <span class="k">\right</span>.
  <span class="k">\tag</span><span class="p">{</span>2<span class="p">}</span>
<span class="nt">\end{equation}</span>
</code></pre></div></div> \[\begin{equation} {z_m(t)} = \left\lbrace { \begin{array}{cc} 1,&amp;{{\mathrm {if}}\ {{\beta }_m(t)} &lt; \frac{\mathfrak {B}_{m}^{\max }}{{ |\mathcal {U}_m|r_{m,i}^{\min } }}},\\ {0,}&amp;{{\mathrm {otherwise.}}} \end{array}} \right. \tag{2} \end{equation}\] <p><strong>Correct Example:</strong> The correct environment is being used. Using the <code class="language-plaintext highlighter-rouge">cases</code> environment will save keystrokes (from not having to type the <code class="language-plaintext highlighter-rouge">\left\brace{</code>) and automatically provide the correct column alignment.</p> <div class="language-tex highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nt">\begin{equation*}</span>
  <span class="p">{</span>z<span class="p">_</span>m(t)<span class="p">}</span> =
  <span class="nt">\begin{cases}</span>
    1,<span class="p">&amp;{</span><span class="k">\mathrm</span> <span class="p">{</span>if<span class="p">}}</span><span class="k">\ </span><span class="p">{</span><span class="k">\beta</span> <span class="p">}_</span>m(t) &lt; <span class="k">\frac</span><span class="p">{</span><span class="k">\mathfrak</span> <span class="p">{</span>B<span class="p">}_{</span>m<span class="p">}^{</span><span class="k">\max</span> <span class="p">}}{{</span> |<span class="k">\mathcal</span> <span class="p">{</span>U<span class="p">}_</span>m|r<span class="p">_{</span>m,i<span class="p">}^{</span><span class="k">\min</span> <span class="p">}</span> <span class="p">}}</span>,<span class="k">\\</span>
    <span class="p">{</span>0,<span class="p">}&amp;{</span><span class="k">\mathrm</span> <span class="p">{</span>otherwise.<span class="p">}}</span>
  <span class="nt">\end{cases}</span>
  <span class="k">\tag</span><span class="p">{</span>2a<span class="p">}</span>
<span class="nt">\end{equation*}</span>
</code></pre></div></div> \[\begin{equation*} {z_m(t)} = \begin{cases} 1,&amp;{\mathrm {if}}\ {\beta }_m(t) &lt; \frac{\mathfrak {B}_{m}^{\max }}{{ |\mathcal {U}_m|r_{m,i}^{\min } }},\\ {0,}&amp;{\mathrm {otherwise.}} \end{cases} \tag{2a} \end{equation*}\] <h3 id="example-1-3">Example 1-3</h3> <p><strong>Incorrect Example:</strong> The wrong environment is used; a space is missing after the word “if.” In this instance an extra bit of space is needed.</p> <div class="language-tex highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nt">\begin{align}</span>
  h<span class="p">_{</span>i<span class="p">}</span>(x,y) <span class="p">&amp;</span>= <span class="k">\left\lbrace</span>
  <span class="nt">\begin{array}</span><span class="p">{</span>ll<span class="p">}</span>
    +1 <span class="p">&amp;</span> <span class="k">\mathrm</span><span class="p">{</span>if<span class="p">}</span> <span class="k">\xi</span> <span class="p">_{</span>i<span class="p">}</span>(x)=<span class="k">\eta</span> <span class="p">_{</span>i<span class="p">}</span>(y),<span class="k">\\</span>
    -1 <span class="p">&amp;</span> <span class="k">\mathrm</span><span class="p">{</span>otherwise <span class="p">}</span>,
  <span class="nt">\end{array}</span>
  <span class="k">\right</span>.<span class="k">\nonumber</span> <span class="k">\\</span>
  <span class="p">&amp;</span>=(2 <span class="k">\xi</span> <span class="p">_{</span>i<span class="p">}</span>(x)-1)(2<span class="k">\eta</span> <span class="p">_{</span>i<span class="p">}</span>(y)-1),
  <span class="k">\tag</span><span class="p">{</span>3<span class="p">}</span>
<span class="nt">\end{align}</span>
</code></pre></div></div> \[\begin{align} h_{i}(x,y) &amp;= \left\lbrace \begin{array}{ll} +1 &amp; \mathrm{if} \xi _{i}(x)=\eta _{i}(y),\\ -1 &amp; \mathrm{otherwise }, \end{array} \right.\nonumber \\ &amp;=(2 \xi _{i}(x)-1)(2\eta _{i}(y)-1), \tag{3} \end{align}\] <p><strong>Correct Example:</strong> The correct environment is being used. Using the <code class="language-plaintext highlighter-rouge">cases</code> environment will save keystrokes (from not having to type the <code class="language-plaintext highlighter-rouge">\left\brace{</code>) and automatically provide the correct column alignment. The text formatting is corrected by using <code class="language-plaintext highlighter-rouge">\text{}</code> to surround the textual elements “if” and “otherwise.”</p> <div class="language-tex highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nt">\begin{align}</span>
  h<span class="p">_{</span>i<span class="p">}</span>(x,y) <span class="p">&amp;</span>=
  <span class="nt">\begin{cases}</span>
    +1 <span class="p">&amp;</span> <span class="k">\mathrm</span><span class="p">{</span>if <span class="p">}</span>~ <span class="k">\xi</span> <span class="p">_{</span>i<span class="p">}</span>(x)=<span class="k">\eta</span> <span class="p">_{</span>i<span class="p">}</span>(y),<span class="k">\\</span>
    -1 <span class="p">&amp;</span> <span class="k">\text</span><span class="p">{</span>otherwise <span class="p">}</span>,
  <span class="nt">\end{cases}</span> <span class="k">\nonumber</span> <span class="k">\\</span>
  <span class="p">&amp;</span>=(2 <span class="k">\xi</span> <span class="p">_{</span>i<span class="p">}</span>(x)-1)(2<span class="k">\eta</span> <span class="p">_{</span>i<span class="p">}</span>(y)-1),
  <span class="k">\tag</span><span class="p">{</span>3a<span class="p">}</span>
<span class="nt">\end{align}</span>
</code></pre></div></div> \[\begin{align} h_{i}(x,y) &amp;= \begin{cases} +1 &amp; \mathrm{if }~ \xi _{i}(x)=\eta _{i}(y),\\ -1 &amp; \text{otherwise }, \end{cases} \nonumber \\ &amp;=(2 \xi _{i}(x)-1)(2\eta _{i}(y)-1), \tag{3a} \end{align}\] <h2 id="example-ii-text-functions">Example II: Text Functions</h2> <h3 id="example-2-1">Example 2-1</h3> <p><strong>Incorrect Example:</strong> This example has incorrect text formatting and alignment issues. Please use <code class="language-plaintext highlighter-rouge">\max</code>, <code class="language-plaintext highlighter-rouge">\min</code>, and <code class="language-plaintext highlighter-rouge">\text{...}</code> for the conditions or text. <code class="language-plaintext highlighter-rouge">\;</code> should not be used for spacing: when the code is reused in other composition software, it will likely format differently than expected. Using tabs will provide concrete alignment points.</p> <div class="language-tex highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nt">\begin{equation}</span>
  LD(a<span class="p">_{</span>x<span class="p">}</span>,b<span class="p">_{</span>y<span class="p">}</span>)
  <span class="nt">\begin{cases}</span>
    max(x,y) <span class="k">\;\;\;\;\;\;\;\;\;\;\;</span>if<span class="k">\;</span> min(x,y)=0 <span class="k">\\</span>
    min
    <span class="nt">\begin{cases}</span>
      L(a,b)(x-1,y)+1 <span class="k">\\</span>
      L(a,b)(x,y-1,j)+1 <span class="p">&amp;</span> Otherwise<span class="k">\\</span>
      L(a,b)(x-1,y-1)+1(a<span class="p">_{</span>x<span class="p">}</span><span class="k">\neq</span> b<span class="p">_{</span>y<span class="p">}</span>)
    <span class="nt">\end{cases}</span>
  <span class="nt">\end{cases}</span>
  <span class="k">\tag</span><span class="p">{</span>7<span class="p">}</span>
<span class="nt">\end{equation}</span>
</code></pre></div></div> \[\begin{equation} LD(a_{x},b_{y}) \begin{cases} max(x,y) \;\;\;\;\;\;\;\;\;\;\;if\; min(x,y)=0 \\ min \begin{cases} L(a,b)(x-1,y)+1 \\ L(a,b)(x,y-1,j)+1 &amp; Otherwise\\ L(a,b)(x-1,y-1)+1(a_{x}\neq b_{y}) \end{cases} \end{cases} \tag{7} \end{equation}\] <p><strong>Correct Example:</strong> This example has the correct text formatting and tabs are used to correctly set column alignment. Note the use of <code class="language-plaintext highlighter-rouge">\hfill</code> to replace the multiple <code class="language-plaintext highlighter-rouge">\;</code> for alignment purposes.</p> <div class="language-tex highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nt">\begin{equation}</span>
  LD(a<span class="p">_{</span>x<span class="p">}</span>,b<span class="p">_{</span>y<span class="p">}</span>)
  <span class="nt">\begin{cases}</span>
    <span class="k">\max</span>(x,y) <span class="k">\hfill</span> <span class="k">\text</span><span class="p">{</span>if <span class="p">}</span> <span class="k">\min</span>(x,y)=0 <span class="k">\\</span>
    <span class="k">\min</span>
    <span class="nt">\begin{cases}</span>
      L(a,b)(x-1,y)+1 <span class="p">&amp;</span> <span class="k">\\</span>
      L(a,b)(x,y-1,j)+1 <span class="p">&amp;</span> <span class="k">\text</span><span class="p">{</span>Otherwise<span class="p">}</span> <span class="k">\\</span>
      L(a,b)(x-1,y-1)+1 <span class="p">&amp;</span> (a<span class="p">_{</span>x<span class="p">}</span><span class="k">\neq</span> b<span class="p">_{</span>y<span class="p">}</span>)
    <span class="nt">\end{cases}</span>
  <span class="nt">\end{cases}</span>
  <span class="k">\tag</span><span class="p">{</span>7a<span class="p">}</span>
<span class="nt">\end{equation}</span>
</code></pre></div></div> \[\begin{equation} LD(a_{x},b_{y}) \begin{cases} \max(x,y) \hfill \text{if } \min(x,y)=0 \\ \min \begin{cases} L(a,b)(x-1,y)+1 &amp; \\ L(a,b)(x,y-1,j)+1 &amp; \text{Otherwise} \\ L(a,b)(x-1,y-1)+1 &amp; (a_{x}\neq b_{y}) \end{cases} \end{cases} \tag{7a} \end{equation}\] <h3 id="example-2-2">Example 2-2</h3> <p><strong>Incorrect Example:</strong> This example has bad formatting of the function min. When coded as shown, it formats incorrectly as <em>italic</em> text.</p> <div class="language-tex highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nt">\begin{equation*}</span>
  d<span class="p">_{</span>l<span class="p">}^{</span>KM<span class="p">}</span> = <span class="k">\underset</span> <span class="p">{</span><span class="k">\mathbf</span> <span class="p">{</span>p<span class="p">}_{</span>w<span class="p">}}{</span>min<span class="p">}</span> || <span class="k">\mathbf</span> <span class="p">{</span>p<span class="p">}_{</span>f<span class="p">}^{</span>l<span class="p">}</span> – <span class="k">\mathbf</span> <span class="p">{</span>p<span class="p">}_{</span>w<span class="p">}</span> ||,
  <span class="k">\tag</span><span class="p">{</span>12<span class="p">}</span>
<span class="nt">\end{equation*}</span>
</code></pre></div></div> \[\begin{equation*} d_{l}^{KM} = \underset {\mathbf {p}_{w}}{min} || \mathbf {p}_{f}^{l} – \mathbf {p}_{w} ||, \tag{12} \end{equation*}\] <p><strong>Correct Example:</strong> This example shows the use of <code class="language-plaintext highlighter-rouge">\min</code> to get the correct formatting of the function min.</p> <div class="language-tex highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nt">\begin{equation*}</span>
  d<span class="p">_{</span>l<span class="p">}^{</span>KM<span class="p">}</span> = <span class="k">\underset</span> <span class="p">{</span><span class="k">\mathbf</span> <span class="p">{</span>p<span class="p">}_{</span>w<span class="p">}}</span><span class="k">\min</span> || <span class="k">\mathbf</span> <span class="p">{</span>p<span class="p">}_{</span>f<span class="p">}^{</span>l<span class="p">}</span> – <span class="k">\mathbf</span> <span class="p">{</span>p<span class="p">}_{</span>w<span class="p">}</span> ||,
  <span class="k">\tag</span><span class="p">{</span>12a<span class="p">}</span>
<span class="nt">\end{equation*}</span>
</code></pre></div></div> \[\begin{equation*} d_{l}^{KM} = \underset {\mathbf {p}_{w}}\min || \mathbf {p}_{f}^{l} – \mathbf {p}_{w} ||, \tag{12a} \end{equation*}\] <h3 id="example-2-3">Example 2-3</h3> <p><strong>Incorrect Example:</strong> This example has bad formatting of the function “arg min.” When coded as shown, it formats incorrectly as <em>italic</em> text.</p> <div class="language-tex highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nt">\begin{equation*}</span>
  d<span class="p">_{</span>R<span class="p">}^{</span>KM<span class="p">}</span> = <span class="k">\underset</span> <span class="p">{</span>d<span class="p">_{</span>l<span class="p">}^{</span>KM<span class="p">}}{</span>arg~<span class="p">{</span>min<span class="p">}}</span> <span class="k">\{</span> d<span class="p">_{</span>1<span class="p">}^{</span>KM<span class="p">}</span>,<span class="k">\ldots</span>,d<span class="p">_{</span>6<span class="p">}^{</span>KM<span class="p">}</span><span class="k">\}</span>.
  <span class="k">\tag</span><span class="p">{</span>13<span class="p">}</span>
<span class="nt">\end{equation*}</span>
</code></pre></div></div> \[\begin{equation*} d_{R}^{KM} = \underset {d_{l}^{KM}}{arg~{min}} \{ d_{1}^{KM},\ldots,d_{6}^{KM}\}. \tag{13} \end{equation*}\] <p><strong>Correct Example:</strong> This example shows the use of {<code class="language-plaintext highlighter-rouge">\text{arg min}</code>} to get the correct formatting of the function “arg min.”</p> <div class="language-tex highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nt">\begin{equation*}</span>
  d<span class="p">_{</span>R<span class="p">}^{</span>KM<span class="p">}</span> = <span class="k">\underset</span> <span class="p">{</span>d<span class="p">_{</span>l<span class="p">}^{</span>KM<span class="p">}}</span> <span class="p">{</span><span class="k">\text</span><span class="p">{</span>arg min<span class="p">}}</span> <span class="k">\{</span> d<span class="p">_{</span>1<span class="p">}^{</span>KM<span class="p">}</span>,<span class="k">\ldots</span>,d<span class="p">_{</span>6<span class="p">}^{</span>KM<span class="p">}</span><span class="k">\}</span>.
  <span class="k">\tag</span><span class="p">{</span>13a<span class="p">}</span>
<span class="nt">\end{equation*}</span>
</code></pre></div></div> \[\begin{equation*} d_{R}^{KM} = \underset {d_{l}^{KM}} {\text{arg min}} \{ d_{1}^{KM},\ldots,d_{6}^{KM}\}. \tag{13a} \end{equation*}\] <h2 id="example-iii-limits">Example III: Limits</h2> <h3 id="example-3-1">Example 3-1</h3> <p><strong>Incorrect Example:</strong> The upper and lower limits in a display formula should generally be above and below the operators.</p> <div class="language-tex highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nt">\begin{equation*}</span>
  c<span class="p">_{</span>r<span class="p">_</span>i<span class="p">}</span> = <span class="k">\beta</span> <span class="p">_</span>0+<span class="k">\sum</span> <span class="k">\nolimits</span> <span class="p">_{</span>j=1<span class="p">}^{</span>n<span class="p">}{</span><span class="k">\beta</span> <span class="p">_</span>j <span class="k">\times</span> c<span class="p">_{</span>r<span class="p">_</span>j<span class="p">}}</span>,
  <span class="k">\tag</span><span class="p">{</span>15<span class="p">}</span>
<span class="nt">\end{equation*}</span>
</code></pre></div></div> \[\begin{equation*} c_{r_i} = \beta _0+\sum \nolimits _{j=1}^{n}{\beta _j \times c_{r_j}}, \tag{15} \end{equation*}\] <p><strong>Correct Example:</strong> In this example, the <code class="language-plaintext highlighter-rouge">\nolimits</code> was removed as it was causing the incorrect formatting. <code class="language-plaintext highlighter-rouge">\nolimits</code> has appropriate uses for inline equations and in certain subelements of a display equation.</p> <div class="language-tex highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nt">\begin{equation*}</span>
  c<span class="p">_{</span>r<span class="p">_</span>i<span class="p">}</span> = <span class="k">\beta</span> <span class="p">_</span>0+<span class="k">\sum</span><span class="p">_{</span>j=1<span class="p">}^{</span>n<span class="p">}{</span><span class="k">\beta</span> <span class="p">_</span>j <span class="k">\times</span> c<span class="p">_{</span>r<span class="p">_</span>j<span class="p">}}</span>,
  <span class="k">\tag</span><span class="p">{</span>15a<span class="p">}</span>
<span class="nt">\end{equation*}</span>
</code></pre></div></div> \[\begin{equation*} c_{r_i} = \beta _0+\sum_{j=1}^{n}{\beta _j \times c_{r_j}}, \tag{15a} \end{equation*}\] <h3 id="example-3-2">Example 3-2</h3> <p><strong>Incorrect Example:</strong> When limits appear in fractions within a display formula, they should be off to the side of the operator.</p> <div class="language-tex highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nt">\begin{equation*}</span>
  <span class="p">{</span>C<span class="p">_{</span>D<span class="p">}}</span> = <span class="k">\frac</span> <span class="p">{{</span><span class="k">\sum</span> <span class="k">\limits</span> <span class="p">_{</span>i = 1<span class="p">}^{</span>N<span class="p">}</span> <span class="p">{</span><span class="k">\left</span> (<span class="p">{{</span>C<span class="p">_{</span>D<span class="p">}</span>(<span class="p">{</span>n<span class="p">_{</span><span class="k">\max</span> <span class="p">}}</span>) – <span class="p">{</span>C<span class="p">_{</span>D<span class="p">}}</span>(<span class="p">{</span>n<span class="p">_{</span>i<span class="p">}}</span>)<span class="p">}</span> <span class="p">}</span><span class="k">\right</span>)<span class="p">}</span> <span class="p">}}{{</span> <span class="k">\sum</span> <span class="k">\limits</span> <span class="p">_{</span>i = 1<span class="p">}^{</span>N<span class="p">}</span> <span class="p">{</span><span class="k">\left</span> (<span class="p">{{</span>C<span class="p">_{</span>D<span class="p">}</span>(n<span class="p">_{</span><span class="k">\max</span> <span class="p">}^</span> <span class="p">{</span>*<span class="p">}</span>) – <span class="p">{</span>C<span class="p">_{</span>D<span class="p">}}</span>(n<span class="p">_{</span>i<span class="p">}^{</span>*<span class="p">}</span>)<span class="p">}</span> <span class="p">}</span><span class="k">\right</span>)<span class="p">}</span> <span class="p">}}</span>
  <span class="k">\tag</span><span class="p">{</span>18<span class="p">}</span>
<span class="nt">\end{equation*}</span>
</code></pre></div></div> \[\begin{equation*} {C_{D}} = \frac {{\sum \limits _{i = 1}^{N} {\left ({{C_{D}({n_{\max }}) – {C_{D}}({n_{i}})} }\right)} }}{{ \sum \limits _{i = 1}^{N} {\left ({{C_{D}(n_{\max }^ {*}) – {C_{D}}(n_{i}^{*})} }\right)} }} \tag{18} \end{equation*}\] <p><strong>Correct Example:</strong> This example shows the proper formatting when <code class="language-plaintext highlighter-rouge">\limits</code> are removed. LaTeX will automatically format the limits correctly when within a fraction.</p> <div class="language-tex highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nt">\begin{equation*}</span>
  <span class="p">{</span>C<span class="p">_{</span>D<span class="p">}}</span> = <span class="k">\frac</span> <span class="p">{{</span><span class="k">\sum</span> <span class="p">_{</span>i = 1<span class="p">}^{</span>N<span class="p">}</span> <span class="p">{</span><span class="k">\left</span> (<span class="p">{{</span>C<span class="p">_{</span>D<span class="p">}</span>(<span class="p">{</span>n<span class="p">_{</span><span class="k">\max</span> <span class="p">}}</span>) <span class="p">{</span>C<span class="p">_{</span>D<span class="p">}}</span>(<span class="p">{</span>n<span class="p">_{</span>i<span class="p">}}</span>)<span class="p">}</span> <span class="p">}</span><span class="k">\right</span>)<span class="p">}</span> <span class="p">}}{{</span> <span class="k">\sum</span> <span class="p">_{</span>i = 1<span class="p">}^{</span>N<span class="p">}</span> <span class="p">{</span><span class="k">\left</span> (<span class="p">{{</span>C<span class="p">_{</span>D<span class="p">}</span>(n<span class="p">_{</span><span class="k">\max</span> <span class="p">}^</span> <span class="p">{</span>*<span class="p">}</span>) – <span class="p">{</span>C<span class="p">_{</span>D<span class="p">}}</span>(n<span class="p">_{</span>i<span class="p">}^{</span>*<span class="p">}</span>)<span class="p">}</span> <span class="p">}</span><span class="k">\right</span>)<span class="p">}</span> <span class="p">}}</span>
  <span class="k">\tag</span><span class="p">{</span>18a<span class="p">}</span>
<span class="nt">\end{equation*}</span>
</code></pre></div></div> \[\begin{equation*} {C_{D}} = \frac {{\sum _{i = 1}^{N} {\left ({{C_{D}({n_{\max }}) {C_{D}}({n_{i}})} }\right)} }}{{ \sum _{i = 1}^{N} {\left ({{C_{D}(n_{\max }^ {*}) – {C_{D}}(n_{i}^{*})} }\right)} }} \tag{18a} \end{equation*}\] <h2 id="example-iv-text-acronyms">Example IV: Text Acronyms</h2> <h3 id="example-4-1">Example 4-1</h3> <p><strong>Incorrect Example:</strong> This example shows when the acronym “MSE” is not coded as text, it will appear in <em>italic</em>. This is inconsistent with how it appears in the text and it should be consistent.</p> <div class="language-tex highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nt">\begin{equation*}</span>
  MSE = <span class="k">\frac</span> <span class="p">{</span>1<span class="p">}{</span>n<span class="p">}</span><span class="k">\sum</span> <span class="p">_{</span>i=1<span class="p">}^{</span>n<span class="p">}</span>(Y<span class="p">_{</span>i<span class="p">}</span> – <span class="k">\hat</span> <span class="p">{</span>Y<span class="p">_{</span>i<span class="p">}}</span>)<span class="p">^{</span>2<span class="p">}</span>
  <span class="k">\tag</span><span class="p">{</span>19<span class="p">}</span>
<span class="nt">\end{equation*}</span>
</code></pre></div></div> \[\begin{equation*} MSE = \frac {1}{n}\sum _{i=1}^{n}(Y_{i} – \hat {Y_{i}})^{2} \tag{19} \end{equation*}\] <p><strong>Correct Example:</strong> This example shows where the acronym “MSE” is coded using <code class="language-plaintext highlighter-rouge">\text{}</code> to match how it appears in the text.</p> <div class="language-tex highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nt">\begin{equation*}</span>
  <span class="k">\text</span> <span class="p">{</span>MSE<span class="p">}</span> = <span class="k">\frac</span> <span class="p">{</span>1<span class="p">}{</span>n<span class="p">}</span><span class="k">\sum</span> <span class="p">_{</span>i=1<span class="p">}^{</span>n<span class="p">}</span>(Y<span class="p">_{</span>i<span class="p">}</span> – <span class="k">\hat</span> <span class="p">{</span>Y<span class="p">_{</span>i<span class="p">}}</span>)<span class="p">^{</span>2<span class="p">}</span>
  <span class="k">\tag</span><span class="p">{</span>19a<span class="p">}</span>
<span class="nt">\end{equation*}</span>
</code></pre></div></div> \[\begin{equation*} \text {MSE} = \frac {1}{n}\sum _{i=1}^{n}(Y_{i} – \hat {Y_{i}})^{2} \tag{19a} \end{equation*}\] <h3 id="example-4-2">Example 4-2</h3> <p><strong>Incorrect Example:</strong> This example shows an instance where the formatting of the acronym “NCC” is inconsistent between text and its use in a formula.</p> <div class="language-tex highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nt">\begin{equation*}</span>
  <span class="p">{</span>NCC<span class="p">}</span>=<span class="k">\dfrac</span> <span class="p">{</span><span class="k">\left</span> |<span class="p">{</span><span class="k">\sum</span> <span class="p">_{</span>i=1<span class="p">}^{</span>n<span class="p">}</span>(a<span class="p">_{</span>i<span class="p">}</span>-<span class="k">\mu</span> <span class="p">_{</span>A<span class="p">}</span>)(b<span class="p">_{</span>i<span class="p">}</span>-<span class="k">\mu</span> <span class="p">_{</span>B<span class="p">}</span>)<span class="p">}</span><span class="k">\right</span> |<span class="p">}{</span>l<span class="k">\times</span> <span class="k">\sigma</span> <span class="p">_{</span>A<span class="p">}</span> <span class="k">\times</span> <span class="k">\sigma</span> <span class="p">_{</span>B<span class="p">}}</span>,
  <span class="k">\tag</span><span class="p">{</span>20<span class="p">}</span>
<span class="nt">\end{equation*}</span>
</code></pre></div></div> \[\begin{equation*} {NCC}=\dfrac {\left |{\sum _{i=1}^{n}(a_{i}-\mu _{A})(b_{i}-\mu _{B})}\right |}{l\times \sigma _{A} \times \sigma _{B}}, \tag{20} \end{equation*}\] <p><strong>Correct Example:</strong> This example shows where the acronym “NCC” is coded using <code class="language-plaintext highlighter-rouge">\text{}</code> to match how it appears in the text.</p> <div class="language-tex highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nt">\begin{equation*}</span>
  <span class="k">\text</span> <span class="p">{</span>NCC<span class="p">}</span>=<span class="k">\dfrac</span> <span class="p">{</span><span class="k">\left</span> |<span class="p">{</span><span class="k">\sum</span> <span class="p">_{</span>i=1<span class="p">}^{</span>n<span class="p">}</span>(a<span class="p">_{</span>i<span class="p">}</span>-<span class="k">\mu</span> <span class="p">_{</span>A<span class="p">}</span>)(b<span class="p">_{</span>i<span class="p">}</span>-<span class="k">\mu</span> <span class="p">_{</span>B<span class="p">}</span>)<span class="p">}</span><span class="k">\right</span> |<span class="p">}{</span>l<span class="k">\times</span> <span class="k">\sigma</span> <span class="p">_{</span>A<span class="p">}</span> <span class="k">\times</span> <span class="k">\sigma</span> <span class="p">_{</span>B<span class="p">}}</span>,
  <span class="k">\tag</span><span class="p">{</span>20a<span class="p">}</span>
<span class="nt">\end{equation*}</span>
</code></pre></div></div> \[\begin{equation*} \text {NCC}=\dfrac {\left |{\sum _{i=1}^{n}(a_{i}-\mu _{A})(b_{i}-\mu _{B})}\right |}{l\times \sigma _{A} \times \sigma _{B}}, \tag{20a} \end{equation*}\] <h3 id="example-4-3">Example 4-3</h3> <p><strong>Incorrect Example:</strong> This example shows an instance where the formatting of the acronym “RMS” is inconsistent between text and its use in a formula.</p> <div class="language-tex highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nt">\begin{equation*}</span>
  RMS<span class="p">_{</span>rs<span class="p">}</span>=<span class="k">\sqrt</span> <span class="p">{</span><span class="k">\frac</span> <span class="p">{</span>1<span class="p">}{</span>N<span class="p">}</span><span class="k">\sum</span> <span class="k">\limits</span> <span class="p">_{</span>i<span class="p">}^{</span>N<span class="p">}</span> <span class="p">{</span><span class="k">\left</span> (<span class="p">{{</span>d<span class="p">_{</span>rs<span class="p">}</span>(i)<span class="p">}</span> <span class="p">}</span><span class="k">\right</span>)<span class="p">^{</span>2<span class="p">}}}</span>
  <span class="k">\tag</span><span class="p">{</span>32<span class="p">}</span>
<span class="nt">\end{equation*}</span>
</code></pre></div></div> \[\begin{equation*} RMS_{rs}=\sqrt {\frac {1}{N}\sum \limits _{i}^{N} {\left ({{d_{rs}(i)} }\right)^{2}}} \tag{32} \end{equation*}\] <p><strong>Correct Example:</strong> This example shows where the acronym “RMS” is coded using <code class="language-plaintext highlighter-rouge">\text{}</code> to match how it appears in the text.</p> <div class="language-tex highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nt">\begin{equation*}</span>
  <span class="k">\text</span><span class="p">{</span>RMS<span class="p">}_{</span>rs<span class="p">}</span>=<span class="k">\sqrt</span> <span class="p">{</span><span class="k">\frac</span> <span class="p">{</span>1<span class="p">}{</span>N<span class="p">}</span><span class="k">\sum</span> <span class="k">\limits</span> <span class="p">_{</span>i<span class="p">}^{</span>N<span class="p">}</span> <span class="p">{</span><span class="k">\left</span> (<span class="p">{{</span>d<span class="p">_{</span>rs<span class="p">}</span>(i)<span class="p">}</span> <span class="p">}</span><span class="k">\right</span>)<span class="p">^{</span>2<span class="p">}}}</span>
  <span class="k">\tag</span><span class="p">{</span>32a<span class="p">}</span>
<span class="nt">\end{equation*}</span>
</code></pre></div></div> \[\begin{equation*} \text{RMS}_{rs}=\sqrt {\frac {1}{N}\sum \limits _{i}^{N} {\left ({{d_{rs}(i)} }\right)^{2}}} \tag{32a} \end{equation*}\] <h2 id="example-v-fences">Example V: Fences</h2> <h3 id="example-5-1">Example 5-1</h3> <p><strong>Incorrect Example:</strong> In this example, the parentheses are not growing to properly surround the content in between them.</p> <div class="language-tex highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nt">\begin{equation*}</span>
  <span class="k">\delta</span> <span class="k">\approx</span> 1 – (<span class="p">{</span>e<span class="p">^{</span>-<span class="k">\frac</span> <span class="p">{</span>d<span class="p">^{</span>2<span class="p">}}{</span>2 <span class="k">\times</span> C<span class="p">^{</span>m<span class="p">}_{</span>T<span class="p">}}}</span> <span class="k">\times</span> e<span class="p">^{</span>-<span class="k">\frac</span> <span class="p">{</span>d<span class="p">^{</span>2<span class="p">}}{</span>2 <span class="k">\times</span> C<span class="p">^{</span>m-1<span class="p">}_{</span>T<span class="p">}}}}</span>)
  <span class="k">\tag</span><span class="p">{</span>21<span class="p">}</span>
<span class="nt">\end{equation*}</span>
</code></pre></div></div> \[\begin{equation*} \delta \approx 1 – ({e^{-\frac {d^{2}}{2 \times C^{m}_{T}}} \times e^{-\frac {d^{2}}{2 \times C^{m-1}_{T}}}}) \tag{21} \end{equation*}\] <p><strong>Correct Example:</strong> In this example, the use of <code class="language-plaintext highlighter-rouge">\left(</code> and <code class="language-plaintext highlighter-rouge">\right)</code> enables the parentheses to grow to the height of the content in between them.</p> <div class="language-tex highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nt">\begin{equation*}</span>
  <span class="k">\delta</span> <span class="k">\approx</span> 1 – <span class="k">\left</span>(<span class="p">{</span>e<span class="p">^{</span>-<span class="k">\frac</span> <span class="p">{</span>d<span class="p">^{</span>2<span class="p">}}{</span>2 <span class="k">\times</span> C<span class="p">^{</span>m<span class="p">}_{</span>T<span class="p">}}}</span> <span class="k">\times</span> e<span class="p">^{</span>-<span class="k">\frac</span> <span class="p">{</span>d<span class="p">^{</span>2<span class="p">}}{</span>2 <span class="k">\times</span> C<span class="p">^{</span>m-1<span class="p">}_{</span>T<span class="p">}}}}</span><span class="k">\right</span>)
  <span class="k">\tag</span><span class="p">{</span>21a<span class="p">}</span>
<span class="nt">\end{equation*}</span>
</code></pre></div></div> \[\begin{equation*} \delta \approx 1 – \left({e^{-\frac {d^{2}}{2 \times C^{m}_{T}}} \times e^{-\frac {d^{2}}{2 \times C^{m-1}_{T}}}}\right) \tag{21a} \end{equation*}\] <h3 id="example-5-2">Example 5-2</h3> <p><strong>Incorrect Example:</strong> In this example, the square brackets are not growing to properly surround the content in between them.</p> <div class="language-tex highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nt">\begin{equation*}</span>
  [<span class="k">\sqrt</span> <span class="p">{</span>(<span class="k">\Delta</span> x<span class="p">_{</span>i<span class="p">}</span>+d<span class="p">_{</span>x<span class="p">}</span>)<span class="p">^{</span>2<span class="p">}</span>+(<span class="k">\Delta</span> y<span class="p">_{</span>i<span class="p">}</span>)<span class="p">^{</span>2<span class="p">}}</span> -<span class="k">\mu</span> <span class="p">^{</span>k<span class="p">}</span>]&gt;<span class="k">\epsilon</span> <span class="k">\mu</span> <span class="p">^{</span>k<span class="p">}</span>
  <span class="k">\tag</span><span class="p">{</span>22<span class="p">}</span>
<span class="nt">\end{equation*}</span>
</code></pre></div></div> \[\begin{equation*} [\sqrt {(\Delta x_{i}+d_{x})^{2}+(\Delta y_{i})^{2}} -\mu ^{k}]&gt;\epsilon \mu ^{k} \tag{22} \end{equation*}\] <p><strong>Correct Example:</strong> In this example, the use of <code class="language-plaintext highlighter-rouge">\left[</code> and <code class="language-plaintext highlighter-rouge">\right]</code> enables the square brackets to grow to the height of the content in between them.</p> <div class="language-tex highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nt">\begin{equation*}</span>
  <span class="k">\left</span><span class="na">[ \sqrt {(\Delta x_{i}+d_{x})^{2}+(\Delta y_{i})^{2}} -\mu ^{k}\right]</span> &gt;<span class="k">\epsilon</span> <span class="k">\mu</span> <span class="p">^{</span>k<span class="p">}</span>
  <span class="k">\tag</span><span class="p">{</span>22a<span class="p">}</span>
<span class="nt">\end{equation*}</span>
</code></pre></div></div> \[\begin{equation*} \left[ \sqrt {(\Delta x_{i}+d_{x})^{2}+(\Delta y_{i})^{2}} -\mu ^{k}\right] &gt;\epsilon \mu ^{k} \tag{22a} \end{equation*}\] <h3 id="example-5-3">Example 5-3</h3> <p><strong>Incorrect Example:</strong> In this example, the parentheses are not growing to properly surround the content in between them.</p> <div class="language-tex highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nt">\begin{equation*}</span>
  <span class="k">\textrm</span> <span class="p">{</span>T<span class="p">}</span> = (<span class="p">{</span><span class="k">\frac</span> <span class="p">{</span>c<span class="p">}{</span>B<span class="p">}}</span>)<span class="p">^{</span>2<span class="p">}</span>
  <span class="k">\tag</span><span class="p">{</span>34<span class="p">}</span>
<span class="nt">\end{equation*}</span>
</code></pre></div></div> \[\begin{equation*} \textrm {T} = ({\frac {c}{B}})^{2} \tag{34} \end{equation*}\] <p><strong>Correct Example:</strong> In this example, the use of <code class="language-plaintext highlighter-rouge">\left(</code> and <code class="language-plaintext highlighter-rouge">\right)</code> enables the parentheses to grow to the height of the content in between them.</p> <div class="language-tex highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nt">\begin{equation*}</span>
  <span class="k">\textrm</span> <span class="p">{</span>T<span class="p">}</span> = <span class="k">\left</span>(<span class="p">{</span><span class="k">\frac</span> <span class="p">{</span>c<span class="p">}{</span>B<span class="p">}}</span><span class="k">\right</span>)<span class="p">^{</span>2<span class="p">}</span>
  <span class="k">\tag</span><span class="p">{</span>34a<span class="p">}</span>
<span class="nt">\end{equation*}</span>
</code></pre></div></div> \[\begin{equation*} \textrm {T} = \left({\frac {c}{B}}\right)^{2} \tag{34a} \end{equation*}\]]]></content><author><name></name></author><summary type="html"><![CDATA[Style Issue Basics Variables Vectors Functions Alignment and Line Breaks for Display Formulas Avoid Obsolete Codes and Delimiters (eqnarray, $$ display math delimiters) Use Appropriate Delimiters for Display Equations mathcal vs. RSFS script Example I: Cases Example 1-1 Example 1-2 Example 1-3 Example II: Text Functions Example 2-1 Example 2-2 Example 2-3 Example III: Limits Example 3-1 Example 3-2 Example IV: Text Acronyms Example 4-1 Example 4-2 Example 4-3 Example V: Fences Example 5-1 Example 5-2 Example 5-3]]></summary></entry><entry><title type="html">Shortcuts Cheat Sheet</title><link href="https://jkfx.github.io/blog/2025/Shortcuts-Cheat-Sheet/" rel="alternate" type="text/html" title="Shortcuts Cheat Sheet"/><published>2025-12-30T15:12:00+08:00</published><updated>2025-12-30T15:12:00+08:00</updated><id>https://jkfx.github.io/blog/2025/Shortcuts%20Cheat%20Sheet</id><content type="html" xml:base="https://jkfx.github.io/blog/2025/Shortcuts-Cheat-Sheet/"><![CDATA[<pre><code class="language-mermaid">kanban
  tmux
    [tmux new -s $SESSION]
    [C-b ?]
    [tmux attach -t $SESSION]
    [C-b c : create window]
    [C-b % : split horizontally]
    [C-b " : split vertically]
    [C-b 0]
    [C-b q : print pane numbers]
    [C-b s : show sessions]
    [C-b w : show windows]
    [x : kill selected item]
    [X : kill tagged items]
    [t : toggle tagged]
    [T : tag no items]
    [C-t : tag all items]
    [C-b D : list clients]
    [d : detach selected client]
    [D : detach tagged clients]
    [C-b &amp; : kill current window]
    [C-b x : kill active pane]
    [C-b $ : prompt new name for session]
    [C-b , : prompt new name for window]
    ["C-b { / }: swapped with the pane"]
    [C-b . : prompt new index for window]
    [C-b z : temporarily take up whole window]
    ["C-b [ : enter copy mode"]
    [C-Space : start a selection]
    [C-w : copy selection and exit copy mode]
    ["C-b ] : paste buffer"]
    [C-b = : enter buffer mode]
    [p : paste selected buffer]
    [P : paste tagged buffers]
    [d : delete selected buffer]
    [D : delete tagged buffers]
    [:set -g mouse on]
  vscode
    [Ctrl+Shift+P, F1 : Show Command Palette]
    [Alt+ ↓ / ↑ : Move line down/up]
    [Ctrl+Enter : Insert line below]
    [Ctrl+Shift+Enter : Insert line above]
    ["Ctrl+] / Ctrl+[ : Indent/Outdent line"]
    ["Ctrl+Shift+ [ / ] : Fold/unfold region"]
    [Ctrl+/ : Toggle line comment]
    [Shift+Ctrl+ ↑ / ↓ : Insert cursor above/below]
    [Ctrl+\ : Split editor]
    [Ctrl+` : Show integrated terminal]
    [Ctrl+Shift+` : Create new terminal]
  linux
    [who | w | whoami | last]
    [lscpu | lsblk | lscpu | lsof]
    [free -h]
    [df -h]
    [env]
    ["uptime [-p|-s]"]
    [date | timedatectl]
    [ls -lt]
    [cd -]
    [rmdir dirname]
    [less filename]
    [tail -f logfile]
    [locate filename]
    ["find /path -name ''*.log'' -exec rm {} \;"]
    [cp -p file.txt backup.txt]
    [chown user:group filename]
    [chown -R user:group directory/]
    ["ps [aux]"]
    [ps -ef --forest]
    [ps -u username]
    [jobs]
    ["bg %1 | fg %1"]
    [command &amp;]
    [nohup command &amp;]
    ["kill [-9] PID"]
    [killall processname]
    [kill -l]
    [htop]
    [iotop]
    [systemctl enable servicename]
    [journalctl -f]
    ["ip [addr|route] show"]
    [netstat -tuln]
    [netstat -tuln | grep LISTEN]
    [ss -tuln]
    [netstat -tulnp]
    [netstat -tuln | grep :80]
    [traceroute google.com]
    [mtr google.com]
    [grep -r "pattern" /path/]
    [grep -n "pattern" filename]
    ["sort [-n] filename"]
    [uniq filename]
    ["wc [-l] filename"]
    [sed 's/old/new/g' filename]
    [sed '/pattern/d' filename]
    [cut -d',' -f1 file.csv]
    [tar -xzf archive.tar.gz -C /destination/]
    [unzip -l archive.zip]
    [du -h --max-depth=1 /path/]
    [du -h | sort -hr | head -10]
    [cat /proc/meminfo]
    ["vmstat [2]"]
    [swapon --show]
    [top -p PID]
    ["iostat [2]"]
    [iostat -x /dev/sda]
    ["journalctl [-f]"]
    [journalctl -u servicename]
    [dmesg]
    [usermod -aG groupname username]
    ["userdel [-r username]"]
    ["su [-]"]
    [sudo -u username command]
    [groupadd groupname]
    [groups username]
    [cat /etc/group]
    [usermod -g groupname username]
    ["passwd [username]"]
    [chage -l username]
    [command &gt; output.txt]
    [command &gt;&gt; output.txt]
    [command &lt; input.txt]
    [command1 | command2]
    [alias ll='ls -la']
    [alias]
    [unalias ll]
    [printenv]
    [md5sum filename]
    [sha256sum file]
    [sha256sum -c checksums.txt]
    [ufw status verbose]
    [ufw allow ssh]
    [ufw deny 23]
    [iptables -L]
    [tail -f /var/log/auth.log]
    [tail -f /var/log/syslog]
    [journalctl -p err]
    [mount /dev/sda1 /mnt]
    [chroot /mnt]
    [grub-install /dev/sda]
    [update-grub]
    [systemctl status servicename]
    [journalctl -u servicename]
    [systemctl --failed]
</code></pre>]]></content><author><name></name></author><summary type="html"><![CDATA[kanban tmux [tmux new -s $SESSION] [C-b ?] [tmux attach -t $SESSION] [C-b c : create window] [C-b % : split horizontally] [C-b " : split vertically] [C-b 0] [C-b q : print pane numbers] [C-b s : show sessions] [C-b w : show windows] [x : kill selected item] [X : kill tagged items] [t : toggle tagged] [T : tag no items] [C-t : tag all items] [C-b D : list clients] [d : detach selected client] [D : detach tagged clients] [C-b &amp; : kill current window] [C-b x : kill active pane] [C-b $ : prompt new name for session] [C-b , : prompt new name for window] ["C-b { / }: swapped with the pane"] [C-b . : prompt new index for window] [C-b z : temporarily take up whole window] ["C-b [ : enter copy mode"] [C-Space : start a selection] [C-w : copy selection and exit copy mode] ["C-b ] : paste buffer"] [C-b = : enter buffer mode] [p : paste selected buffer] [P : paste tagged buffers] [d : delete selected buffer] [D : delete tagged buffers] [:set -g mouse on] vscode [Ctrl+Shift+P, F1 : Show Command Palette] [Alt+ ↓ / ↑ : Move line down/up] [Ctrl+Enter : Insert line below] [Ctrl+Shift+Enter : Insert line above] ["Ctrl+] / Ctrl+[ : Indent/Outdent line"] ["Ctrl+Shift+ [ / ] : Fold/unfold region"] [Ctrl+/ : Toggle line comment] [Shift+Ctrl+ ↑ / ↓ : Insert cursor above/below] [Ctrl+\ : Split editor] [Ctrl+` : Show integrated terminal] [Ctrl+Shift+` : Create new terminal] linux [who | w | whoami | last] [lscpu | lsblk | lscpu | lsof] [free -h] [df -h] [env] ["uptime [-p|-s]"] [date | timedatectl] [ls -lt] [cd -] [rmdir dirname] [less filename] [tail -f logfile] [locate filename] ["find /path -name ''*.log'' -exec rm {} \;"] [cp -p file.txt backup.txt] [chown user:group filename] [chown -R user:group directory/] ["ps [aux]"] [ps -ef --forest] [ps -u username] [jobs] ["bg %1 | fg %1"] [command &amp;] [nohup command &amp;] ["kill [-9] PID"] [killall processname] [kill -l] [htop] [iotop] [systemctl enable servicename] [journalctl -f] ["ip [addr|route] show"] [netstat -tuln] [netstat -tuln | grep LISTEN] [ss -tuln] [netstat -tulnp] [netstat -tuln | grep :80] [traceroute google.com] [mtr google.com] [grep -r "pattern" /path/] [grep -n "pattern" filename] ["sort [-n] filename"] [uniq filename] ["wc [-l] filename"] [sed 's/old/new/g' filename] [sed '/pattern/d' filename] [cut -d',' -f1 file.csv] [tar -xzf archive.tar.gz -C /destination/] [unzip -l archive.zip] [du -h --max-depth=1 /path/] [du -h | sort -hr | head -10] [cat /proc/meminfo] ["vmstat [2]"] [swapon --show] [top -p PID] ["iostat [2]"] [iostat -x /dev/sda] ["journalctl [-f]"] [journalctl -u servicename] [dmesg] [usermod -aG groupname username] ["userdel [-r username]"] ["su [-]"] [sudo -u username command] [groupadd groupname] [groups username] [cat /etc/group] [usermod -g groupname username] ["passwd [username]"] [chage -l username] [command &gt; output.txt] [command &gt;&gt; output.txt] [command &lt; input.txt] [command1 | command2] [alias ll='ls -la'] [alias] [unalias ll] [printenv] [md5sum filename] [sha256sum file] [sha256sum -c checksums.txt] [ufw status verbose] [ufw allow ssh] [ufw deny 23] [iptables -L] [tail -f /var/log/auth.log] [tail -f /var/log/syslog] [journalctl -p err] [mount /dev/sda1 /mnt] [chroot /mnt] [grub-install /dev/sda] [update-grub] [systemctl status servicename] [journalctl -u servicename] [systemctl --failed]]]></summary></entry><entry><title type="html">RTX 5060 Ti 安装 TensorFlow</title><link href="https://jkfx.github.io/blog/2025/RTX-5060-Ti-%E5%AE%89%E8%A3%85-TensorFlow/" rel="alternate" type="text/html" title="RTX 5060 Ti 安装 TensorFlow"/><published>2025-12-19T17:41:00+08:00</published><updated>2025-12-19T17:41:00+08:00</updated><id>https://jkfx.github.io/blog/2025/RTX%205060%20Ti%20%E5%AE%89%E8%A3%85%20TensorFlow</id><content type="html" xml:base="https://jkfx.github.io/blog/2025/RTX-5060-Ti-%E5%AE%89%E8%A3%85-TensorFlow/"><![CDATA[<blockquote> <p>RTX 5060 has compute capability 12.0 - a very new architecture. Stable TensorFlow versions lack pre-compiled GPU kernels for this architecture, causing JIT compilation failures for certain operations (especially float32).</p> </blockquote> <h2 id="step-by-step-solution">Step by Step Solution</h2> <div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code>conda create <span class="nt">--name</span> tf_gpu <span class="nv">python</span><span class="o">=</span>3.11
conda activate tf_gpu

conda <span class="nb">install </span>nvidia/label/cuda-12.5.1::cuda-toolkit

pip <span class="nb">install </span>tf-nightly[and-cuda]

conda <span class="nb">env </span>config vars <span class="nb">set </span><span class="nv">LD_LIBRARY_PATH</span><span class="o">=</span><span class="nv">$CONDA_PREFIX</span>/lib:<span class="nv">$LD_LIBRARY_PATH</span>

conda deactivate
conda activate tf_gpu
</code></pre></div></div>]]></content><author><name></name></author><summary type="html"><![CDATA[RTX 5060 has compute capability 12.0 - a very new architecture. Stable TensorFlow versions lack pre-compiled GPU kernels for this architecture, causing JIT compilation failures for certain operations (especially float32).]]></summary></entry><entry><title type="html">tmux User Guides</title><link href="https://jkfx.github.io/blog/2025/tmux-User-Guides/" rel="alternate" type="text/html" title="tmux User Guides"/><published>2025-12-19T17:41:00+08:00</published><updated>2025-12-19T17:41:00+08:00</updated><id>https://jkfx.github.io/blog/2025/tmux%20User%20Guides</id><content type="html" xml:base="https://jkfx.github.io/blog/2025/tmux-User-Guides/"><![CDATA[<ul> <li><a href="#basic-concepts">Basic concepts</a> <ul> <li><a href="#the-tmux-server-and-clients">The tmux server and clients</a></li> <li><a href="#sessions-windows-and-panes">Sessions, windows and panes</a></li> <li><a href="#summary">Summary</a></li> </ul> </li> <li><a href="#using-tmux-interactively">Using tmux interactively</a> <ul> <li><a href="#creating-sessions">Creating sessions</a></li> <li><a href="#the-prefix-key">The prefix key</a></li> <li><a href="#help-keys">Help keys</a></li> <li><a href="#the-command-prompt">The command prompt</a></li> <li><a href="#attaching-and-detaching">Attaching and detaching</a></li> <li><a href="#listing-sessions">Listing sessions</a></li> <li><a href="#killing-tmux-entirely">Killing tmux entirely</a></li> <li><a href="#creating-new-windows">Creating new windows</a></li> <li><a href="#splitting-the-window">Splitting the window</a></li> <li><a href="#changing-the-current-window">Changing the current window</a></li> <li><a href="#changing-the-active-pane">Changing the active pane</a></li> <li><a href="#choosing-sessions-windows-and-panes">Choosing sessions, windows and panes</a></li> <li><a href="#detaching-other-clients">Detaching other clients</a></li> <li><a href="#killing-a-session-window-or-pane">Killing a session, window or pane</a></li> <li><a href="#renaming-sessions-and-windows">Renaming sessions and windows</a></li> <li><a href="#swapping-and-moving">Swapping and moving</a></li> <li><a href="#resizing-and-zooming-panes">Resizing and zooming panes</a></li> <li><a href="#window-layouts">Window layouts</a></li> <li><a href="#copy-and-paste">Copy and paste</a></li> <li><a href="#finding-windows-and-panes">Finding windows and panes</a></li> <li><a href="#using-the-mouse">Using the mouse</a></li> </ul> </li> </ul> <h2 id="basic-concepts">Basic concepts</h2> <h3 id="the-tmux-server-and-clients">The tmux server and clients</h3> <p>tmux keeps all its state in a single main process, called the tmux server. This runs in the background and manages all the programs running inside tmux and keeps track of their output. The tmux server is started automatically when the user runs a tmux command and by default exits when there are no running programs.</p> <p>Users attach to the tmux server by starting a client. This takes over the terminal where it is run and talks to the server using a socket file in <code class="language-plaintext highlighter-rouge">/tmp</code> . Each client is identified by the name of the outside terminal where it is started, for example <code class="language-plaintext highlighter-rouge">/dev/ttypf</code>.</p> <h3 id="sessions-windows-and-panes">Sessions, windows and panes</h3> <p>Every terminal inside tmux belongs to one pane, this is a rectangular area which shows the content of the terminal inside tmux.</p> <p>Each pane appears in one window. A window is made up of one or more panes which together cover its entire area - so multiple panes may be visible at the same time.</p> <p>Every window has a name. Window names do not have to be unique, windows are usually identified by the session and the window index rather than their name.</p> <p>Each pane is separated from the panes around it by a line, this is called the pane border. There is one pane in each window called the active pane.</p> <p>Multiple windows are grouped together into sessions. Windows may be linked to multiple sessions at the same time, although mostly they are only in one. Each window in a session has a number, called the window index - the same window may be linked at different indexes in different sessions.</p> <p>Each session has one current window.</p> <p>A session may be attached to one or more clients, which means it is shown on the outside terminal where that client is running. Sessions do not have an index but they do have a name, which must be unique.</p> <h3 id="summary">Summary</h3> <ul> <li>Seriver <ul> <li>Client 1 <ul> <li>Session 1 (attached) <ul> <li>Windows 1 <ul> <li>Pane 1</li> <li>Pane 2</li> </ul> </li> <li>Windows 2 <ul> <li>Pane 1</li> </ul> </li> </ul> </li> <li>Session 2</li> </ul> </li> <li>Client 2</li> </ul> </li> </ul> <h2 id="using-tmux-interactively">Using tmux interactively</h2> <h3 id="creating-sessions">Creating sessions</h3> <div class="language-console highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="go">tmux new -s mysession
</span></code></pre></div></div> <h3 id="the-prefix-key">The prefix key</h3> <p>The default prefix key is <code class="language-plaintext highlighter-rouge">C-b</code>, which means the <code class="language-plaintext highlighter-rouge">Ctrl</code> key and <code class="language-plaintext highlighter-rouge">b</code>.</p> <h3 id="help-keys">Help keys</h3> <p><code class="language-plaintext highlighter-rouge">C-b ?</code></p> <h3 id="the-command-prompt">The command prompt</h3> <p>tmux has an interactive command prompt. This can be opened by pressing <code class="language-plaintext highlighter-rouge">C-b :</code>.</p> <p>Multiple commands may be entered together at the command prompt by separating them with a semicolon (<code class="language-plaintext highlighter-rouge">;</code>). This is called a command sequence.</p> <h3 id="attaching-and-detaching">Attaching and detaching</h3> <p>To detach tmux, the <code class="language-plaintext highlighter-rouge">C-b d</code> key binding is used.</p> <div class="language-console highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="go">tmux attach -t mysession
</span></code></pre></div></div> <h3 id="listing-sessions">Listing sessions</h3> <p>The list-sessions command (alias ls) shows a list of available sessions that can be attached.</p> <div class="language-console highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="gp">$</span><span class="w"> </span>tmux <span class="nb">ls</span>
<span class="go">1: 3 windows (created Sat Feb 22 11:44:51 2020)
2: 1 windows (created Sat Feb 22 11:44:51 2020)
myothersession: 2 windows (created Sat Feb 22 11:44:51 2020)
mysession: 1 windows (created Sat Feb 22 11:44:51 2020)
</span></code></pre></div></div> <h3 id="killing-tmux-entirely">Killing tmux entirely</h3> <div class="language-console highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="go">:kill-server
</span></code></pre></div></div> <h3 id="creating-new-windows">Creating new windows</h3> <p>A new window can be created in an attached session with the <code class="language-plaintext highlighter-rouge">C-b c</code> key binding which runs the new-window command.</p> <h3 id="splitting-the-window">Splitting the window</h3> <p>A pane is created by splitting a window. This is done with the <code class="language-plaintext highlighter-rouge">split-window</code> command which is bound to two keys by default:</p> <ul> <li><code class="language-plaintext highlighter-rouge">C-b %</code> splits the current pane into two horizontally.</li> <li><code class="language-plaintext highlighter-rouge">C-b "</code> splits the current pane into two vertically.</li> </ul> <h3 id="changing-the-current-window">Changing the current window</h3> <ul> <li><code class="language-plaintext highlighter-rouge">C-b 0</code> changes to window 0, <code class="language-plaintext highlighter-rouge">C-b 1</code> to window 1, up to window <code class="language-plaintext highlighter-rouge">C-b 9</code> for window 9.</li> <li><code class="language-plaintext highlighter-rouge">C-b '</code> prompts for a window index and changes to that window.</li> <li><code class="language-plaintext highlighter-rouge">C-b n</code> changes to the next window in the window list by number.</li> <li><code class="language-plaintext highlighter-rouge">C-b p</code> changes to the previous window in the window list by number.</li> <li><code class="language-plaintext highlighter-rouge">C-b l</code> changes to the last window.</li> </ul> <h3 id="changing-the-active-pane">Changing the active pane</h3> <ul> <li><code class="language-plaintext highlighter-rouge">C-b Up</code>, <code class="language-plaintext highlighter-rouge">C-b Down</code>, <code class="language-plaintext highlighter-rouge">C-b Left</code> and <code class="language-plaintext highlighter-rouge">C-b Right</code> change to the pane above, below, left or right of the active pane.</li> <li><code class="language-plaintext highlighter-rouge">C-b q</code> prints the pane numbers and their sizes on top of the panes for a short time. Pressing one of the number keys before they disappear changes the active pane to the chosen pane, so <code class="language-plaintext highlighter-rouge">C-b q 1</code> will change to pane number 1.</li> <li><code class="language-plaintext highlighter-rouge">C-b o</code> moves to the next pane by pane number.</li> <li><code class="language-plaintext highlighter-rouge">C-b C-o</code> swaps that pane with the active pane.</li> </ul> <h3 id="choosing-sessions-windows-and-panes">Choosing sessions, windows and panes</h3> <p>tmux includes a mode where sessions, windows or panes can be chosen from a tree, this is called tree mode.</p> <p>There are two key bindings to enter tree mode:</p> <ul> <li><code class="language-plaintext highlighter-rouge">C-b s</code> starts showing only sessions and with the attached session selected;</li> <li><code class="language-plaintext highlighter-rouge">C-b w</code> starts with sessions expanded so windows are shown and with the current window in the attached session selected.</li> </ul> <p>Items in the tree are tagged by pressing <code class="language-plaintext highlighter-rouge">t</code> and untagged by pressing <code class="language-plaintext highlighter-rouge">t</code> again. Tagged items are shown in bold and with <code class="language-plaintext highlighter-rouge">*</code> after their name.</p> <p>All tagged items may be untagged by pressing <code class="language-plaintext highlighter-rouge">T</code>.</p> <p>Tagged items may be killed together by pressing <code class="language-plaintext highlighter-rouge">X</code>, or a command applied to them all by pressing <code class="language-plaintext highlighter-rouge">:</code> for a prompt.</p> <p>Each item in the tree has as shortcut key in brackets at the start of the line. Pressing this key will immediately choose that item (as if it had been selected and <code class="language-plaintext highlighter-rouge">Enter</code> pressed).</p> <table> <thead> <tr> <th>Key</th> <th>Function</th> </tr> </thead> <tbody> <tr> <td><code class="language-plaintext highlighter-rouge">Enter</code></td> <td>Change the attached session, current window or active pane</td> </tr> <tr> <td><code class="language-plaintext highlighter-rouge">Up</code></td> <td>Select previous item</td> </tr> <tr> <td><code class="language-plaintext highlighter-rouge">Down</code></td> <td>Select next item</td> </tr> <tr> <td><code class="language-plaintext highlighter-rouge">Right</code></td> <td>Expand item</td> </tr> <tr> <td><code class="language-plaintext highlighter-rouge">Left</code></td> <td>Collapse item</td> </tr> <tr> <td><code class="language-plaintext highlighter-rouge">x</code></td> <td>Kill selected item</td> </tr> <tr> <td><code class="language-plaintext highlighter-rouge">X</code></td> <td>Kill tagged items</td> </tr> <tr> <td><code class="language-plaintext highlighter-rouge">&lt;</code></td> <td>Scroll preview left</td> </tr> <tr> <td><code class="language-plaintext highlighter-rouge">&gt;</code></td> <td>Scroll preview right</td> </tr> <tr> <td><code class="language-plaintext highlighter-rouge">C-s</code></td> <td>Search by name</td> </tr> <tr> <td><code class="language-plaintext highlighter-rouge">n</code></td> <td>Repeat last search</td> </tr> <tr> <td><code class="language-plaintext highlighter-rouge">t</code></td> <td>Toggle if item is tagged</td> </tr> <tr> <td><code class="language-plaintext highlighter-rouge">T</code></td> <td>Tag no items</td> </tr> <tr> <td><code class="language-plaintext highlighter-rouge">C-t</code></td> <td>Tag all items</td> </tr> <tr> <td><code class="language-plaintext highlighter-rouge">:</code></td> <td>Prompt for a command to run for the selected item or each tagged item</td> </tr> <tr> <td><code class="language-plaintext highlighter-rouge">O</code></td> <td>Change sort field</td> </tr> <tr> <td><code class="language-plaintext highlighter-rouge">r</code></td> <td>Reverse sort order</td> </tr> <tr> <td><code class="language-plaintext highlighter-rouge">v</code></td> <td>Toggle preview</td> </tr> <tr> <td><code class="language-plaintext highlighter-rouge">q</code></td> <td>Exit tree mode</td> </tr> </tbody> </table> <h3 id="detaching-other-clients">Detaching other clients</h3> <p>A list of clients is available by pressing <code class="language-plaintext highlighter-rouge">C-b D</code> (that is, <code class="language-plaintext highlighter-rouge">C-b S-d</code>).</p> <table> <thead> <tr> <th>Key</th> <th>Function</th> </tr> </thead> <tbody> <tr> <td><code class="language-plaintext highlighter-rouge">Enter</code></td> <td>Detach selected client</td> </tr> <tr> <td><code class="language-plaintext highlighter-rouge">d</code></td> <td>Detach selected client, same as <code class="language-plaintext highlighter-rouge">Enter</code></td> </tr> <tr> <td><code class="language-plaintext highlighter-rouge">D</code></td> <td>Detach tagged clients</td> </tr> <tr> <td><code class="language-plaintext highlighter-rouge">x</code></td> <td>Detach selected client and try to kill the shell it was started from</td> </tr> <tr> <td><code class="language-plaintext highlighter-rouge">X</code></td> <td>Detach tagged clients and try to kill the shells they were started from</td> </tr> </tbody> </table> <h3 id="killing-a-session-window-or-pane">Killing a session, window or pane</h3> <p>Pressing <code class="language-plaintext highlighter-rouge">C-b &amp;</code> prompts for confirmation then kills (closes) the current window.</p> <p><code class="language-plaintext highlighter-rouge">C-b x</code> kills only the active pane.</p> <h3 id="renaming-sessions-and-windows">Renaming sessions and windows</h3> <p><code class="language-plaintext highlighter-rouge">C-b $</code> will prompt for a new name for the attached session.</p> <p><code class="language-plaintext highlighter-rouge">C-b ,</code> prompts for a new name for the current window.</p> <h3 id="swapping-and-moving">Swapping and moving</h3> <p>Panes can additionally be swapped with the pane above or below using the <code class="language-plaintext highlighter-rouge">C-b {</code> and <code class="language-plaintext highlighter-rouge">C-b }</code> key bindings.</p> <p>Pressing <code class="language-plaintext highlighter-rouge">C-b .</code> will prompt for a new index for the current window. If a window already exists at the given index, an error will be shown.</p> <h3 id="resizing-and-zooming-panes">Resizing and zooming panes</h3> <p>Panes may be resized in small steps with <code class="language-plaintext highlighter-rouge">C-b C-Left</code>, <code class="language-plaintext highlighter-rouge">C-b C-Right</code>, <code class="language-plaintext highlighter-rouge">C-b C-Up</code> and <code class="language-plaintext highlighter-rouge">C-b C-Down</code> and in larger steps with <code class="language-plaintext highlighter-rouge">C-b M-Left</code>, <code class="language-plaintext highlighter-rouge">C-b M-Right</code>, <code class="language-plaintext highlighter-rouge">C-b M-Up</code> and <code class="language-plaintext highlighter-rouge">C-b M-Down</code>. These use the resize-pane command.</p> <p>A single pane may be temporarily made to take up the whole window with <code class="language-plaintext highlighter-rouge">C-b z</code>, hiding any other panes. Pressing <code class="language-plaintext highlighter-rouge">C-b z</code> again puts the pane and window layout back to how it was. This is called zooming and unzooming.</p> <h3 id="window-layouts">Window layouts</h3> <p>The panes in a window may be automatically arranged into one of several named layouts, these may be rotated between with the <code class="language-plaintext highlighter-rouge">C-b Space</code> key binding or chosen directly with <code class="language-plaintext highlighter-rouge">C-b M-1</code>, <code class="language-plaintext highlighter-rouge">C-b M-2</code> and so on.</p> <table> <thead> <tr> <th>Name</th> <th>Key</th> <th>Description</th> </tr> </thead> <tbody> <tr> <td>even-horizontal</td> <td><code class="language-plaintext highlighter-rouge">C-b M-1</code></td> <td>Spread out evenly across</td> </tr> <tr> <td>even-vertical</td> <td><code class="language-plaintext highlighter-rouge">C-b M-2</code></td> <td>Spread out evenly up and down</td> </tr> <tr> <td>main-horizontal</td> <td><code class="language-plaintext highlighter-rouge">C-b M-3</code></td> <td>One large pane at the top, the rest spread out evenly across</td> </tr> <tr> <td>main-vertical</td> <td><code class="language-plaintext highlighter-rouge">C-b M-4</code></td> <td>One large pane on the left, the rest spread out evenly up and down</td> </tr> <tr> <td>tiled</td> <td><code class="language-plaintext highlighter-rouge">C-b M-5</code></td> <td>Tiled in the same number of rows as columns</td> </tr> </tbody> </table> <h3 id="copy-and-paste">Copy and paste</h3> <p>Text is copied using copy mode, entered with <code class="language-plaintext highlighter-rouge">C-b [</code>, and the most recently copied text is pasted into the active pane with <code class="language-plaintext highlighter-rouge">C-b ]</code>.</p> <table> <thead> <tr> <th>Key</th> <th>Action</th> </tr> </thead> <tbody> <tr> <td><code class="language-plaintext highlighter-rouge">Up, Down, Left, Right</code></td> <td>Move the cursor</td> </tr> <tr> <td><code class="language-plaintext highlighter-rouge">C-Space</code></td> <td>Start a selection</td> </tr> <tr> <td><code class="language-plaintext highlighter-rouge">C-w</code></td> <td>Copy the selection and exit copy mode</td> </tr> <tr> <td><code class="language-plaintext highlighter-rouge">q</code></td> <td>Exit copy mode</td> </tr> <tr> <td><code class="language-plaintext highlighter-rouge">C-g</code></td> <td>Stop selecting without copying, or stop searching</td> </tr> <tr> <td><code class="language-plaintext highlighter-rouge">C-a</code></td> <td>Move the cursor to the start of the line</td> </tr> <tr> <td><code class="language-plaintext highlighter-rouge">C-e</code></td> <td>Move the cursor to the end of the line</td> </tr> <tr> <td><code class="language-plaintext highlighter-rouge">C-r</code></td> <td>Search interactively backwards</td> </tr> <tr> <td><code class="language-plaintext highlighter-rouge">M-f</code></td> <td>Move the cursor to the next word</td> </tr> <tr> <td><code class="language-plaintext highlighter-rouge">M-b</code></td> <td>Move the cursor to the previous word</td> </tr> </tbody> </table> <p>Once some text is copied, the most recent may be pasted with <code class="language-plaintext highlighter-rouge">C-b ]</code> or an older buffer pasted by using buffer mode, entered with <code class="language-plaintext highlighter-rouge">C-b =</code>.</p> <table> <thead> <tr> <th>Key</th> <th>Function</th> </tr> </thead> <tbody> <tr> <td><code class="language-plaintext highlighter-rouge">Enter</code></td> <td>Paste selected buffer</td> </tr> <tr> <td><code class="language-plaintext highlighter-rouge">p</code></td> <td>Paste selected buffer, same as Enter</td> </tr> <tr> <td><code class="language-plaintext highlighter-rouge">P</code></td> <td>Paste tagged buffers</td> </tr> <tr> <td><code class="language-plaintext highlighter-rouge">d</code></td> <td>Delete selected buffer</td> </tr> <tr> <td><code class="language-plaintext highlighter-rouge">D</code></td> <td>Delete tagged buffers</td> </tr> </tbody> </table> <h3 id="finding-windows-and-panes">Finding windows and panes</h3> <p><code class="language-plaintext highlighter-rouge">C-b f</code> prompts for some text and then enters tree mode with a filter to show only panes where that text appears in the visible content or title of the pane or in the window name.</p> <h3 id="using-the-mouse">Using the mouse</h3> <div class="language-console highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="go">:set -g mouse on
</span></code></pre></div></div>]]></content><author><name></name></author><summary type="html"><![CDATA[Basic concepts The tmux server and clients Sessions, windows and panes Summary Using tmux interactively Creating sessions The prefix key Help keys The command prompt Attaching and detaching Listing sessions Killing tmux entirely Creating new windows Splitting the window Changing the current window Changing the active pane Choosing sessions, windows and panes Detaching other clients Killing a session, window or pane Renaming sessions and windows Swapping and moving Resizing and zooming panes Window layouts Copy and paste Finding windows and panes Using the mouse]]></summary></entry><entry><title type="html">Ubuntu 22.04 MacOS Monterey 主题</title><link href="https://jkfx.github.io/blog/2022/Ubuntu-22.04-MacOS-Monterey-%E4%B8%BB%E9%A2%98/" rel="alternate" type="text/html" title="Ubuntu 22.04 MacOS Monterey 主题"/><published>2022-05-28T22:03:00+08:00</published><updated>2022-05-28T22:03:00+08:00</updated><id>https://jkfx.github.io/blog/2022/Ubuntu%2022.04%20MacOS%20Monterey%20%E4%B8%BB%E9%A2%98</id><content type="html" xml:base="https://jkfx.github.io/blog/2022/Ubuntu-22.04-MacOS-Monterey-%E4%B8%BB%E9%A2%98/"><![CDATA[<p>首先更新源以及升级软件：</p> <div class="language-sh highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nb">sudo </span>apt update
<span class="nb">sudo </span>apt upgrade
</code></pre></div></div> <blockquote> <p>也可以更新一下驱动：</p> <p><code class="language-plaintext highlighter-rouge">sudo ubuntu-drivers autoinstall</code></p> </blockquote> <hr/> <p>之后安装 <code class="language-plaintext highlighter-rouge">gnome-tweaks</code> 以及 <code class="language-plaintext highlighter-rouge">gnome-shell-extensions</code> ：</p> <div class="language-sh highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nb">sudo </span>apt <span class="nb">install </span>gnome-tweaks gnome-shell-extensions
</code></pre></div></div> <p>到<em>GNOME Shell Extensions</em>网站安装谷歌浏览器扩展：<a href="https://extensions.gnome.org/">https://extensions.gnome.org/</a> 。</p> <p>接下来安装 <em>User Themes</em> 主题插件： <a href="https://extensions.gnome.org/extension/19/user-themes/">https://extensions.gnome.org/extension/19/user-themes/</a> 。</p> <hr/> <p>克隆 GitHub 上的 <em>WhiteSur-gtk-theme</em> 主题： <a href="https://github.com/vinceliuice/WhiteSur-gtk-theme">https://github.com/vinceliuice/WhiteSur-gtk-theme</a> 到任意你想存放的目录。</p> <p>进入到 <em>WhiteSur-gtk-theme</em> 目录下，找到 <code class="language-plaintext highlighter-rouge">install.sh</code> 以及 <code class="language-plaintext highlighter-rouge">tweaks.sh</code> 脚本文件，执行命令安装主题：</p> <div class="language-sh highlighter-rouge"><div class="highlight"><pre class="highlight"><code>./install.sh <span class="nt">-t</span> all <span class="nt">-N</span> glassy <span class="nt">-s</span> 220
<span class="nb">sudo</span> ./tweaks.sh <span class="nt">-g</span> <span class="nt">-f</span> monterey
</code></pre></div></div> <p>下载并提取 <em>Mkos-Big-Sur</em> 图标包到你的 <strong>home</strong> 下的 <code class="language-plaintext highlighter-rouge">.icons</code> 目录： <a href="https://www.gnome-look.org/p/1400021">https://www.gnome-look.org/p/1400021</a> 。</p> <hr/> <p>找到 Ubuntu 应用程序 优化（<em>tweaks</em>），选择 <em>外观</em> 菜单，在 <em>图标</em> 、 <em>Shell</em> 以及 <em>过时应用程序</em> 中应用 <em>WhiteSur-</em> 主题以及 <em>Mkos-Big-Sur</em> 图标包。</p> <p>在 <em>窗口标题栏</em> 菜单中将 <em>标题栏按钮</em> 放置到 <em>左</em> 侧。</p> <p>在 <em>GNOME Shell Extensions</em> 网站安装 <em>Blur my Shell</em> 插件： <a href="https://extensions.gnome.org/extension/3193/blur-my-shell/">https://extensions.gnome.org/extension/3193/blur-my-shell/</a> 。</p> <p>在 <em>GNOME Shell Extensions</em> 网站安装 <em>Compiz alike magic lamp effect</em> 插件： <a href="https://extensions.gnome.org/extension/3740/compiz-alike-magic-lamp-effect/">https://extensions.gnome.org/extension/3740/compiz-alike-magic-lamp-effect/</a> 。</p> <p>在终端中执行命令：</p> <div class="language-sh highlighter-rouge"><div class="highlight"><pre class="highlight"><code>gsettings <span class="nb">set </span>org.gnome.shell.extensions.dash-to-dock click-action <span class="s1">'minimize'</span>
</code></pre></div></div> <p>找到 Ubuntu 应用程序的 扩展（<em>extensions</em>），找到 <em>Blur my Shell</em> 扩展，点击 <em>设置</em> 按钮，在 <em>Dash</em> 窗口中将 <em>Dash to Dock blur</em> 选项取消勾选。</p> <p>最后，选择一张你喜欢的 MacOS 壁纸，也可以到这个 GitHub 仓库下载： <a href="https://github.com/vinceliuice/WhiteSur-wallpapers">https://github.com/vinceliuice/WhiteSur-wallpapers</a> 。</p> <ul> <li>参考链接： <a href="https://youtu.be/Y6k7THQ3x6U">https://youtu.be/Y6k7THQ3x6U</a></li> </ul> <hr/> <p>常用 Gnome Shell Extensions</p> <ul> <li><a href="https://extensions.gnome.org/extension/1460/vitals/">Vitals</a></li> <li><a href="https://extensions.gnome.org/extension/675/lunar-calendar/">Lunar Calendar 农历</a></li> <li><a href="https://extensions.gnome.org/extension/1401/bluetooth-quick-connect/">Bluetooth Quick Connect</a></li> <li><a href="https://extensions.gnome.org/extension/3740/compiz-alike-magic-lamp-effect/">Compiz alike magic lamp effect</a></li> <li><a href="https://extensions.gnome.org/extension/6784/wiggle/">Wiggle</a></li> <li><a href="https://extensions.gnome.org/extension/97/coverflow-alt-tab/">Coverflow Alt-Tab</a></li> <li><a href="https://extensions.gnome.org/extension/5489/search-light/">Search Light</a></li> <li><a href="https://extensions.gnome.org/extension/3193/blur-my-shell/">Blur my Shell</a></li> <li><a href="https://extensions.gnome.org/extension/5660/weather-or-not/">Weather or Not</a></li> <li><a href="https://extensions.gnome.org/extension/779/clipboard-indicator/">Clipboard Indicator</a></li> </ul>]]></content><author><name></name></author><summary type="html"><![CDATA[首先更新源以及升级软件：]]></summary></entry><entry><title type="html">CASIA-WebMaskedFace 模拟佩戴口罩人脸数据集</title><link href="https://jkfx.github.io/blog/2022/CASIA-WebMaskedFace-%E6%A8%A1%E6%8B%9F%E4%BD%A9%E6%88%B4%E5%8F%A3%E7%BD%A9%E4%BA%BA%E8%84%B8%E6%95%B0%E6%8D%AE%E9%9B%86/" rel="alternate" type="text/html" title="CASIA-WebMaskedFace 模拟佩戴口罩人脸数据集"/><published>2022-04-14T10:55:00+08:00</published><updated>2022-04-14T10:55:00+08:00</updated><id>https://jkfx.github.io/blog/2022/CASIA-WebMaskedFace%20%E6%A8%A1%E6%8B%9F%E4%BD%A9%E6%88%B4%E5%8F%A3%E7%BD%A9%E4%BA%BA%E8%84%B8%E6%95%B0%E6%8D%AE%E9%9B%86</id><content type="html" xml:base="https://jkfx.github.io/blog/2022/CASIA-WebMaskedFace-%E6%A8%A1%E6%8B%9F%E4%BD%A9%E6%88%B4%E5%8F%A3%E7%BD%A9%E4%BA%BA%E8%84%B8%E6%95%B0%E6%8D%AE%E9%9B%86/"><![CDATA[<p>Based on CASIA-WebFace Dataset using MaskTheFace tool mask the face images of datasets.</p> <p>基于CASIA-WebFace数据集，使用MaskTheFace工具给数据集中的人脸图像“戴上口罩”。</p> <h2 id="数据集介绍">数据集介绍</h2> <p>此数据集是在源数据集 <a href="https://arxiv.org/pdf/1411.7923v1.pdf">CASIA-Webface</a> 之上，使用 <a href="https://arxiv.org/abs/2008.11104">MaskTheFace</a> 工具对 CASIA-Webface 数据集中的图像进行佩戴口罩，此数据所涉及到的口罩类型有：Surgical（白色医用外科口罩）、Surgical Blue（蓝色医用外科口罩）、N95、KN95以及Cloth（黑色布质口罩）。口罩的分布类型都是均匀分布随机生成的。</p> <p><img src="https://image.baidu.com/search/down?url=https://tvax4.sinaimg.cn/large/006VTcCxly1h191411yh2j313w0aujyr.jpg" alt="image"/></p> <p>关于口罩类型以及口罩颜色和材质的类型的更多介绍，可以查看 <a href="https://github.com/aqeelanwar/MaskTheFace">原工具仓库</a> 。</p> <p>CASIA-WebMaskedFace 有 10,575 个实体人物， 494,414 张人脸图像。</p> <blockquote> <p>此数据集是在 CASIA-Webface 数据集原封不动的基础上进行配到口罩的模拟，所以与原数据集有相同的实体和图像数量。</p> </blockquote> <p>武汉大学国家多媒体软件工程技术研究中心在最早做了相关的 <a href="https://arxiv.org/abs/2003.09093">研究</a> ，也提出了当时最大的模拟口罩人脸数据集和一个真实世界的人脸佩戴口罩的数据集。</p> <p><a href="https://arxiv.org/abs/2008.11104">Aqeel Anwar, Arijit Raychowdhury</a> 在之后也提出了一个真实世界佩戴口罩的人脸数据集，并且提出了一个工具，也就是上文提到的 <a href="https://github.com/aqeelanwar/MaskTheFace">MaskTheFace</a> 用来在已有的人脸数据集上进行模拟佩戴口罩。</p> <h3 id="数据示例">数据示例</h3> <p><img src="https://image.baidu.com/search/down?url=https://tvax1.sinaimg.cn/large/006VTcCxly1h191m9mhfyj30pf0atwme.jpg" alt="image"/></p> <p><img src="https://image.baidu.com/search/down?url=https://tvax4.sinaimg.cn/large/006VTcCxly1h191pig6fmj30pm0al7be.jpg" alt="image"/></p> <p><img src="https://image.baidu.com/search/down?url=https://tvax2.sinaimg.cn/large/006VTcCxly1h191ojwfj1j30pd0aswmv.jpg" alt="image"/></p> <p><img src="https://image.baidu.com/search/down?url=https://tvax1.sinaimg.cn/large/006VTcCxly1h191qg3bm0j30pe0amwn6.jpg" alt="image"/></p> <h2 id="下载地址">下载地址</h2> <ul class="task-list"> <li class="task-list-item"><input type="checkbox" class="task-list-item-checkbox" disabled="disabled" checked="checked"/>Kaggle：<a href="https://www.kaggle.com/datasets/geekfx/casia-webmaskedface">https://www.kaggle.com/datasets/geekfx/casia-webmaskedface</a></li> <li class="task-list-item"><input type="checkbox" class="task-list-item-checkbox" disabled="disabled" checked="checked"/>Kaggle (cropped using MTCNN, 160x160)：<a href="https://www.kaggle.com/datasets/geekfx/casia-webmaskedface-cropped">https://www.kaggle.com/datasets/geekfx/casia-webmaskedface-cropped</a></li> <li class="task-list-item"><input type="checkbox" class="task-list-item-checkbox" disabled="disabled"/>百度网盘</li> <li class="task-list-item"><input type="checkbox" class="task-list-item-checkbox" disabled="disabled"/>Google Drive</li> <li class="task-list-item"><input type="checkbox" class="task-list-item-checkbox" disabled="disabled"/>GitHub</li> </ul>]]></content><author><name></name></author><summary type="html"><![CDATA[Based on CASIA-WebFace Dataset using MaskTheFace tool mask the face images of datasets.]]></summary></entry><entry><title type="html">LaTeX Workshop 配置信息</title><link href="https://jkfx.github.io/blog/2022/LaTeX-Workshop-%E9%85%8D%E7%BD%AE%E4%BF%A1%E6%81%AF/" rel="alternate" type="text/html" title="LaTeX Workshop 配置信息"/><published>2022-02-25T12:33:00+08:00</published><updated>2022-02-25T12:33:00+08:00</updated><id>https://jkfx.github.io/blog/2022/LaTeX%20Workshop%20%E9%85%8D%E7%BD%AE%E4%BF%A1%E6%81%AF</id><content type="html" xml:base="https://jkfx.github.io/blog/2022/LaTeX-Workshop-%E9%85%8D%E7%BD%AE%E4%BF%A1%E6%81%AF/"><![CDATA[<p>使用 VS Code 编写 LaTeX 论文时，安装 LaTeX Workshop 插件可以实现非常多的功能，但是由于 LaTeX Workshop 默认配置的编译命令是 <code class="language-plaintext highlighter-rouge">latexmk</code> ，而在编写中文论文时通常需要使用 <code class="language-plaintext highlighter-rouge">xelatex</code> 命令来编译文件源代码，所以为了正常使用 LaTeX Workshop 编写中文论文，通常需要对 LaTeX Workshop 进行自定义修改。</p> <p>以下是笔者根据官方文档自己修改的设置选项信息，每一项的设置上面都写好了中文注释，也为了日后笔者更方便的进行配置、修改。</p> <blockquote> <p>关于 LaTeX Workshop 的配置官方文档信息，可以参考 <a href="https://github.com/James-Yu/LaTeX-Workshop/wiki">LaTeX Workshop GitHub Wiki</a></p> </blockquote> <p>本文给出 3 种编译方式：</p> <ul> <li>使用 <code class="language-plaintext highlighter-rouge">xelatex</code> 命令编译两次</li> </ul> <blockquote> <p>通常生成目录时，通常先编译一次生成目录所需的辅助文件，例如目录项等，然后编译第二遍结合辅助文件生成最终的 PDF</p> </blockquote> <ul> <li>使用 <code class="language-plaintext highlighter-rouge">BibTeX</code> 参考文献工具时所需用到的编译命令</li> <li>使用 <code class="language-plaintext highlighter-rouge">BibLaTeX</code> 参考文献所需用到的编译命令</li> </ul> <div class="language-js highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="c1">// ******** LaTeX Workshop 配置信息 ********</span>
<span class="c1">// 文件修改时不自动编译</span>
<span class="c1">// "never", "onSave", "onFileChange"</span>
<span class="dl">"</span><span class="s2">latex-workshop.latex.autoBuild.run</span><span class="dl">"</span><span class="p">:</span> <span class="dl">"</span><span class="s2">never</span><span class="dl">"</span><span class="p">,</span>
<span class="c1">// LaTeX Workshop 编译源代码文件的快捷键默认为：ctrl + alt + b</span>
<span class="c1">// 但是在有些情况下，ctrl + alt 快捷键被占用</span>
<span class="c1">// 将下面设置项改为 true 可以启动替代的快捷键</span>
<span class="c1">// ctrl + l / alt + letter</span>
<span class="dl">"</span><span class="s2">latex-workshop.bind.altKeymap.enabled</span><span class="dl">"</span><span class="p">:</span> <span class="kc">false</span><span class="p">,</span>
<span class="c1">// 编译文件时选用哪种 recipes 方案</span>
<span class="c1">// recipes 的定义在下文</span>
<span class="c1">// "first" （默认）为定义在下文 recipes 中的第一项</span>
<span class="c1">// "lastUsed" 为上次使用运行的 recipe</span>
<span class="dl">"</span><span class="s2">latex-workshop.latex.recipe.default</span><span class="dl">"</span><span class="p">:</span> <span class="dl">"</span><span class="s2">lastUsed</span><span class="dl">"</span><span class="p">,</span>
<span class="c1">// 预览生产的 pdf 文件方式：在 vscode 窗口中预览</span>
<span class="dl">"</span><span class="s2">latex-workshop.view.pdf.viewer</span><span class="dl">"</span><span class="p">:</span> <span class="dl">"</span><span class="s2">tab</span><span class="dl">"</span><span class="p">,</span>
<span class="c1">// 设置在使用 LaTeX Workshop 编译后，自动清理辅助文件</span>
<span class="c1">// 也可以设置为 "never" 表示不自动清理辅助文件</span>
<span class="c1">// 设置 "onFailed" 为当编译失败时自动清理辅助文件</span>
<span class="dl">"</span><span class="s2">latex-workshop.latex.autoClean.run</span><span class="dl">"</span><span class="p">:</span> <span class="dl">"</span><span class="s2">onBuilt</span><span class="dl">"</span><span class="p">,</span>
<span class="c1">// 编译 LaTeX 时使用的工具（tool）顺序</span>
<span class="c1">// 工具（tool）需要自定义</span>
<span class="dl">"</span><span class="s2">latex-workshop.latex.recipes</span><span class="dl">"</span><span class="p">:</span> <span class="p">[</span>
    <span class="c1">// 没有参考文献的编译方式</span>
    <span class="c1">// 为了正确生成目录项，一般需要编译两次源代码</span>
    <span class="p">{</span>
        <span class="dl">"</span><span class="s2">name</span><span class="dl">"</span><span class="p">:</span> <span class="dl">"</span><span class="s2">xelatex</span><span class="dl">"</span><span class="p">,</span>
        <span class="dl">"</span><span class="s2">tools</span><span class="dl">"</span><span class="p">:</span> <span class="p">[</span>
            <span class="dl">"</span><span class="s2">xelatex</span><span class="dl">"</span><span class="p">,</span>
            <span class="dl">"</span><span class="s2">xelatex</span><span class="dl">"</span>
        <span class="p">]</span>
    <span class="p">},</span>
    <span class="c1">// 使用 BibTeX 参考文献工具的编译方式</span>
    <span class="p">{</span>
        <span class="dl">"</span><span class="s2">name</span><span class="dl">"</span><span class="p">:</span> <span class="dl">"</span><span class="s2">xelatex ➞ bibtex ➞ xelatex × 2</span><span class="dl">"</span><span class="p">,</span>
        <span class="dl">"</span><span class="s2">tools</span><span class="dl">"</span><span class="p">:</span> <span class="p">[</span>
            <span class="dl">"</span><span class="s2">xelatex</span><span class="dl">"</span><span class="p">,</span>
            <span class="dl">"</span><span class="s2">bibtex</span><span class="dl">"</span><span class="p">,</span>
            <span class="dl">"</span><span class="s2">xelatex</span><span class="dl">"</span><span class="p">,</span>
            <span class="dl">"</span><span class="s2">xelatex</span><span class="dl">"</span>
        <span class="p">]</span>
    <span class="p">},</span>
    <span class="c1">// 使用 BibLaTeX 参考文献工具的编译方式</span>
    <span class="p">{</span>
        <span class="dl">"</span><span class="s2">name</span><span class="dl">"</span><span class="p">:</span> <span class="dl">"</span><span class="s2">xelatex ➞ biber ➞ xelatex × 2</span><span class="dl">"</span><span class="p">,</span>
        <span class="dl">"</span><span class="s2">tools</span><span class="dl">"</span><span class="p">:</span> <span class="p">[</span>
            <span class="dl">"</span><span class="s2">xelatex</span><span class="dl">"</span><span class="p">,</span>
            <span class="dl">"</span><span class="s2">biber</span><span class="dl">"</span><span class="p">,</span>
            <span class="dl">"</span><span class="s2">xelatex</span><span class="dl">"</span><span class="p">,</span>
            <span class="dl">"</span><span class="s2">xelatex</span><span class="dl">"</span>
        <span class="p">]</span>
    <span class="p">}</span>
<span class="p">],</span>
<span class="c1">// 定义 recipes 中工具的命令以及参数</span>
<span class="c1">// 以下列出 LaTeX Workshop 定义好的占位符</span>
<span class="c1">// %DOC%             The root file full path without the extension</span>
<span class="c1">// %DOC_W32%         The root file full path without the extension with \ path separator on Windows</span>
<span class="c1">// %DOCFILE%         The root file name without the extension</span>
<span class="c1">// %DOC_EXT%         The root file full path with the extension</span>
<span class="c1">// %DOC_EXT_W32%     The root file full path with the extension with \ path separator on Windows</span>
<span class="c1">// %DOCFILE_EXT%     The root file name with the extension</span>
<span class="c1">// %DIR%             The root file directory</span>
<span class="c1">// %DIR_W32%         The root file directory with \ path separator on Windows</span>
<span class="c1">// %TMPDIR%             A temporary folder for storing ancillary files</span>
<span class="c1">// %OUTDIR%             The output directory configured in latex-workshop.latex.outDir</span>
<span class="c1">// %OUTDIR_W32%         The output directory configured in latex-workshop.latex.outDir with \ path separator on Windows</span>
<span class="c1">// %WORKSPACE_FOLDER% The current workspace path</span>
<span class="c1">// %RELATIVE_DIR%     The root file directory relative to the workspace folder</span>
<span class="c1">// %RELATIVE_DOC%     file root file path relative to the workspace folder</span>
<span class="dl">"</span><span class="s2">latex-workshop.latex.tools</span><span class="dl">"</span><span class="p">:</span> <span class="p">[</span>
    <span class="p">{</span>
        <span class="dl">"</span><span class="s2">name</span><span class="dl">"</span><span class="p">:</span> <span class="dl">"</span><span class="s2">xelatex</span><span class="dl">"</span><span class="p">,</span>
        <span class="dl">"</span><span class="s2">command</span><span class="dl">"</span><span class="p">:</span> <span class="dl">"</span><span class="s2">xelatex</span><span class="dl">"</span><span class="p">,</span>
        <span class="dl">"</span><span class="s2">args</span><span class="dl">"</span><span class="p">:</span> <span class="p">[</span>
            <span class="dl">"</span><span class="s2">-synctex=1</span><span class="dl">"</span><span class="p">,</span>
            <span class="dl">"</span><span class="s2">-interaction=nonstopmode</span><span class="dl">"</span><span class="p">,</span>
            <span class="dl">"</span><span class="s2">-file-line-error</span><span class="dl">"</span><span class="p">,</span>
            <span class="dl">"</span><span class="s2">%DOC%</span><span class="dl">"</span>
        <span class="p">],</span>
        <span class="dl">"</span><span class="s2">env</span><span class="dl">"</span><span class="p">:</span> <span class="p">{}</span>
    <span class="p">},</span>
    <span class="p">{</span>
        <span class="dl">"</span><span class="s2">name</span><span class="dl">"</span><span class="p">:</span> <span class="dl">"</span><span class="s2">bibtex</span><span class="dl">"</span><span class="p">,</span>
        <span class="dl">"</span><span class="s2">command</span><span class="dl">"</span><span class="p">:</span> <span class="dl">"</span><span class="s2">bibtex</span><span class="dl">"</span><span class="p">,</span>
        <span class="dl">"</span><span class="s2">args</span><span class="dl">"</span><span class="p">:</span> <span class="p">[</span>
            <span class="dl">"</span><span class="s2">%DOCFILE%</span><span class="dl">"</span>
        <span class="p">],</span>
        <span class="dl">"</span><span class="s2">env</span><span class="dl">"</span><span class="p">:</span> <span class="p">{}</span>
    <span class="p">},</span>
    <span class="p">{</span>
        <span class="dl">"</span><span class="s2">name</span><span class="dl">"</span><span class="p">:</span> <span class="dl">"</span><span class="s2">biber</span><span class="dl">"</span><span class="p">,</span>
        <span class="dl">"</span><span class="s2">command</span><span class="dl">"</span><span class="p">:</span> <span class="dl">"</span><span class="s2">biber</span><span class="dl">"</span><span class="p">,</span>
        <span class="dl">"</span><span class="s2">args</span><span class="dl">"</span><span class="p">:</span> <span class="p">[</span>
            <span class="dl">"</span><span class="s2">%DOCFILE%</span><span class="dl">"</span>
        <span class="p">],</span>
        <span class="dl">"</span><span class="s2">env</span><span class="dl">"</span><span class="p">:</span> <span class="p">{}</span>
    <span class="p">}</span>
<span class="p">],</span>
</code></pre></div></div> <p>使用以上配置选项将上述代码拷贝到你的 VS Code 的 <code class="language-plaintext highlighter-rouge">json</code> 设置文件下即可。</p>]]></content><author><name></name></author><summary type="html"><![CDATA[使用 VS Code 编写 LaTeX 论文时，安装 LaTeX Workshop 插件可以实现非常多的功能，但是由于 LaTeX Workshop 默认配置的编译命令是 latexmk ，而在编写中文论文时通常需要使用 xelatex 命令来编译文件源代码，所以为了正常使用 LaTeX Workshop 编写中文论文，通常需要对 LaTeX Workshop 进行自定义修改。]]></summary></entry><entry><title type="html">关于Linux下LaTeX无法找到已安装字体的问题与解决</title><link href="https://jkfx.github.io/blog/2021/%E5%85%B3%E4%BA%8ELinux%E4%B8%8BLaTeX%E6%97%A0%E6%B3%95%E6%89%BE%E5%88%B0%E5%B7%B2%E5%AE%89%E8%A3%85%E5%AD%97%E4%BD%93%E7%9A%84%E9%97%AE%E9%A2%98%E4%B8%8E%E8%A7%A3%E5%86%B3/" rel="alternate" type="text/html" title="关于Linux下LaTeX无法找到已安装字体的问题与解决"/><published>2021-08-12T22:47:00+08:00</published><updated>2021-08-12T22:47:00+08:00</updated><id>https://jkfx.github.io/blog/2021/%E5%85%B3%E4%BA%8ELinux%E4%B8%8BLaTeX%E6%97%A0%E6%B3%95%E6%89%BE%E5%88%B0%E5%B7%B2%E5%AE%89%E8%A3%85%E5%AD%97%E4%BD%93%E7%9A%84%E9%97%AE%E9%A2%98%E4%B8%8E%E8%A7%A3%E5%86%B3</id><content type="html" xml:base="https://jkfx.github.io/blog/2021/%E5%85%B3%E4%BA%8ELinux%E4%B8%8BLaTeX%E6%97%A0%E6%B3%95%E6%89%BE%E5%88%B0%E5%B7%B2%E5%AE%89%E8%A3%85%E5%AD%97%E4%BD%93%E7%9A%84%E9%97%AE%E9%A2%98%E4%B8%8E%E8%A7%A3%E5%86%B3/"><![CDATA[<p>当我在Ubuntu系统下使用Latex时，在编译渲染时报出了<code class="language-plaintext highlighter-rouge">Font "xxx" does not contain requested</code>这种错误，其中<code class="language-plaintext highlighter-rouge">xxx</code>就是你可能想使用的字体格式。</p> <p>然而我的Ubuntu系统已经正确安装了一些常用中文字体，然而在LaTeX编译渲染时还会报出错误。</p> <p>由于笔者为了解决这个问题翻遍了国内外的网站、去查看了Texlive官方文档，耗费了许多时间与精力，都没能找到解决我的问题的信息，人们的时间往往都很珍贵，一般找不到解决方案过后，往往都不了了之，本着互联网极客精神（<strong>开源精神</strong>），在这里将笔者的解决过程记录并分享，希望人们可以将这种精神继承并传承下去。</p> <blockquote> <p>我甚至在Texlive的官方安装文档中看到这么一段话：</p> <p><img src="https://image.baidu.com/search/down?url=https://tva2.sinaimg.cn/large/006VTcCxly1gtee10q7x6j31f10cbqgx.jpg" alt="image"/></p> <p>可以看到关乎于LaTeX排版中让人非常头疼的问题就是汉字的一些处理了，好在今天有非常多好用的宏包可以解决处理这个问题。</p> </blockquote> <p>首先看一下笔者出现的问题：</p> <p><img src="https://image.baidu.com/search/down?url=https://tva3.sinaimg.cn/large/006VTcCxly1gtedg611ydj60w00a9q7w02.jpg" alt="image"/></p> <p><img src="https://image.baidu.com/search/down?url=https://tva4.sinaimg.cn/large/006VTcCxly1gtediiunx3j618z07d79402.jpg" alt="image"/></p> <p>可以看到终端给出的错误提示是未能找到已安装的字体（<em>installed font not found</em>），有了这句话的提示，笔者想的可能是，在我的系统上已安装了的字体中，在LaTeX中未能正确地引用，查看代码中可以看到：</p> <p><img src="https://image.baidu.com/search/down?url=https://tvax4.sinaimg.cn/large/006VTcCxly1gtedm8youxj30mt061jvl.jpg" alt="image"/></p> <p>在这里设置字体格式的时候我们设置楷体对应的字体文件为<code class="language-plaintext highlighter-rouge">simkai</code>，我们可以查看我们的字体库中是否有<code class="language-plaintext highlighter-rouge">simkai.ttf</code>楷体的字体文件：</p> <p>在Ubuntu存放字体的目录<code class="language-plaintext highlighter-rouge">/usr/share/fonts/</code>下可以使用<code class="language-plaintext highlighter-rouge">find</code>命令查找：</p> <p><img src="https://image.baidu.com/search/down?url=https://tva1.sinaimg.cn/large/006VTcCxly1gtedq0ili0j61570aigqc02.jpg" alt="image"/></p> <p>可以看到，笔者的系统中已经存放了<code class="language-plaintext highlighter-rouge">simkai.ttf</code>这个字体文件，为什么LaTeX还没有找到这个字体呢。</p> <p>通过一番排查，原来是在Ubuntu中，对字体的使用并不仅仅是字体文件名，而是另一个别名。</p> <p>我们可以使用<code class="language-plaintext highlighter-rouge">fc-list</code>来查看系统可用的字体列表，然后使用<code class="language-plaintext highlighter-rouge">grep</code>匹配<code class="language-plaintext highlighter-rouge">simkai.ttf</code>的字体文件，可以进一步查看字体的信息：</p> <p><img src="https://image.baidu.com/search/down?url=https://tva1.sinaimg.cn/large/006VTcCxly1gtedsq4tgrj61580r9b2902.jpg" alt="image"/></p> <p>原来，图中1号框中的名字只是字体文件名，而在系统应用中想要使用这个字体，我们需要指定2号框中的字体名，例如本图，我们想要使用楷体就需要指定<code class="language-plaintext highlighter-rouge">KaiTi</code>或<code class="language-plaintext highlighter-rouge">楷体</code>这个名字。</p> <p>回到LaTeX代码中，将之前出现错误原因的<code class="language-plaintext highlighter-rouge">simkai</code>替换成<code class="language-plaintext highlighter-rouge">KaiTi</code>即可解决问题。</p> <p><img src="https://image.baidu.com/search/down?url=https://tva4.sinaimg.cn/large/006VTcCxly1gtedwcpyd0j60no06dtd402.jpg" alt="image"/></p> <p><img src="https://image.baidu.com/search/down?url=https://tvax3.sinaimg.cn/large/006VTcCxly1gteduycwvij60i102swf302.jpg" alt="image"/></p> <p>为了进一步验证笔者的猜想，可以看到上图代码中，在<code class="language-plaintext highlighter-rouge">KaiTi</code>的下面还使用了<code class="language-plaintext highlighter-rouge">SimSun</code>宋体的使用，然而<code class="language-plaintext highlighter-rouge">SimSun</code>并不报错，这里笔者想可以继续查看<code class="language-plaintext highlighter-rouge">SimSun</code>的字体信息，其后面的别名应该包含<code class="language-plaintext highlighter-rouge">SimSun</code>。</p> <p><img src="https://image.baidu.com/search/down?url=https://tva2.sinaimg.cn/large/006VTcCxly1gtedz60mqcj61540r77wh02.jpg" alt="image"/></p> <p>所以笔者的猜想是正确的，所以在我们不同的系统、不同的字体文件中，每个人发生无法正确找到我们想要使用的字体的错误可能都不一样，因为我们使用的字体文件不同可能导致我们的在应用中使用字体中需要引用的名称的不同而不同，所以出现这种问题我们要具体问题具体分析，对症下药。</p>]]></content><author><name></name></author><summary type="html"><![CDATA[当我在Ubuntu系统下使用Latex时，在编译渲染时报出了Font "xxx" does not contain requested这种错误，其中xxx就是你可能想使用的字体格式。]]></summary></entry><entry><title type="html">关于 RNN 循环神经网络的反向传播求导</title><link href="https://jkfx.github.io/blog/2021/%E5%85%B3%E4%BA%8E-RNN-%E5%BE%AA%E7%8E%AF%E7%A5%9E%E7%BB%8F%E7%BD%91%E7%BB%9C%E7%9A%84%E5%8F%8D%E5%90%91%E4%BC%A0%E6%92%AD%E6%B1%82%E5%AF%BC/" rel="alternate" type="text/html" title="关于 RNN 循环神经网络的反向传播求导"/><published>2021-01-11T20:19:00+08:00</published><updated>2021-01-11T20:19:00+08:00</updated><id>https://jkfx.github.io/blog/2021/%E5%85%B3%E4%BA%8E%20RNN%20%E5%BE%AA%E7%8E%AF%E7%A5%9E%E7%BB%8F%E7%BD%91%E7%BB%9C%E7%9A%84%E5%8F%8D%E5%90%91%E4%BC%A0%E6%92%AD%E6%B1%82%E5%AF%BC</id><content type="html" xml:base="https://jkfx.github.io/blog/2021/%E5%85%B3%E4%BA%8E-RNN-%E5%BE%AA%E7%8E%AF%E7%A5%9E%E7%BB%8F%E7%BD%91%E7%BB%9C%E7%9A%84%E5%8F%8D%E5%90%91%E4%BC%A0%E6%92%AD%E6%B1%82%E5%AF%BC/"><![CDATA[<p>本文是对 RNN 循环神经网络中的每一个神经元进行反向传播求导的数学推导过程，下面还使用 <code class="language-plaintext highlighter-rouge">PyTorch</code> 对导数公式进行编程求证。</p> <h2 id="rnn-神经网络架构">RNN 神经网络架构</h2> <p>一个普通的 RNN 神经网络如下图所示：</p> <p><img src="https://image.baidu.com/search/down?url=https://tvax1.sinaimg.cn/large/006VTcCxly1gmfae8mswmj317a0e00u2.jpg" alt="图片1"/></p> <p>其中 $x^{\langle t \rangle}$ 表示某一个输入数据在 $t$ 时刻的输入；$a^{\langle t \rangle}$ 表示神经网络在 $t$ 时刻时的<em>hidden state</em>，也就是要传送到 $t+1$ 时刻的值；$y^{\langle t \rangle}$ 则表示在第 $t$ 时刻输入数据传入以后产生的预测值，在进行预测或 <em>sampling</em> 时 $y^{\langle t \rangle}$ 通常作为下一时刻即 $t+1$ 时刻的输入，也就是说 $x^{\langle t \rangle}=\hat{y}^{\langle t \rangle}$ ；下面对数据的维度进行说明。</p> <ul> <li>输入： $x\in\mathbb{R}^{n_x\times m\times T_x}$ 其中 $n_x$ 表示每一个时刻输入向量的长度；$m$ 表示数据批量数（<em>batch</em>）；$T_x$ 表示共有多少个输入的时刻（<em>time step</em>）。</li> <li>hidden state：$a\in\mathbb{R}^{n_a\times m\times T_x}$ 其中 $n_a$ 表示每一个 <em>hidden state</em> 的长度。</li> <li>预测：$y\in\mathbb{R}^{n_y\times m\times T_y}$ 其中 $n_y$ 表示预测输出的长度；$T_y$ 表示共有多少个输出的时刻（<em>time step</em>）。</li> </ul> <h2 id="rnn-神经元">RNN 神经元</h2> <p>下图所示的是一个特定的 RNN 神经元：</p> <p><img src="https://image.baidu.com/search/down?url=https://tvax2.sinaimg.cn/large/006VTcCxly1gmfaesc2joj30z20didhj.jpg" alt="图片2"/></p> <p>上图说明了在第 $t$ 时刻的神经元中，数据的输入 $x^{\langle t \rangle}$ 和上一层的 <em>hidden state</em> $a^{\langle t \rangle}$ 是如何经过计算得到下一层的 <em>hidden state</em> 和预测输出 $\hat{y}^{\langle t \rangle}$ 。</p> <p>下面是对五个参数的维度说明：</p> <ul> <li>$W_{aa}\in\mathbb{R}^{n_a\times n_a}$</li> <li>$W_{ax}\in\mathbb{R}^{n_a\times n_x}$</li> <li>$b_a\in\mathbb{R}^{n_a\times 1}$</li> <li>$W_{ya}\in\mathbb{R}^{n_y\times n_a}$</li> <li>$b_y\in\mathbb{R}^{n_y\times 1}$</li> </ul> <p>计算 $t$ 时刻的 <em>hidden state</em> $a^{\langle t \rangle}$ ：</p> \[\begin{split} z1^{\langle t \rangle} &amp;= W_{aa} a^{\langle t-1 \rangle} + W_{ax} x^{\langle t \rangle} + b_a\\ a^{\langle t \rangle} &amp;= \tanh(z1^{\langle t \rangle}) \end{split}\] <p>预测 $t$ 时刻的输出 $\hat{y}^{\langle t \rangle}$ ：</p> \[\begin{split} z2^{\langle t \rangle} &amp;= W_{ya} a^{\langle t \rangle} + b_y\\ \hat{y}^{\langle t \rangle} &amp;= softmax(z2^{\langle t \rangle}) = \frac{e^{z2^{\langle t \rangle}}}{\sum_{i=1}^{n_y}e^{z2_i^{\langle t \rangle}}} \end{split}\] <h2 id="rnn-循环神经网络反向传播">RNN 循环神经网络反向传播</h2> <p>在当今流行的深度学习编程框架中，我们只需要编写一个神经网络的结构和负责神经网络的前向传播，至于反向传播的求导和参数更新，完全由框架搞定；即便如此，我们在学习阶段也要自己动手证明一下反向传播的有效性。</p> <h3 id="rnn-神经元的反向传播">RNN 神经元的反向传播</h3> <p>下图是 RNN 神经网络中的一个基本的神经元，图中标注了反向传播所需传来的参数和输出等。</p> <p><img src="https://image.baidu.com/search/down?url=https://tva4.sinaimg.cn/large/006VTcCxly1gmfagctqx4j30qu0e9t96.jpg" alt="图片3"/></p> <p>就如一个全连接的神经网络一样，损失函数 $J$ 的导数通过微积分的链式法则（<em>chain rule</em>）反向传播到每一个时间轴上。</p> <p>为了方便，我们将损失函数关于神经元中参数的偏导符号简记为 $\mathrm{d}\mathit{parameters}$ ；例如将 $\frac{\partial J}{\partial W_{ax}}$ 记为 $\mathrm{d}W_{ax}$ 。</p> <p><img src="https://image.baidu.com/search/down?url=https://tva4.sinaimg.cn/large/006VTcCxly1gmfagmbbw5j30zk0k0ta2.jpg" alt="图片4"/></p> <p>上图的反向传播的实现并没有包括全连接层和 <em>Softmax</em> 层。</p> <h3 id="反向传播求导">反向传播求导</h3> <p>计算损失函数关于各个参数的偏导数之前，我们先引入一个计算图（<em>computation graph</em>），其演示了一个 RNN 神经元的前向传播和如何利用计算图进行链式法则的反向求导。</p> <p><img src="https://image.baidu.com/search/down?url=https://tva1.sinaimg.cn/large/006VTcCxly1gmiwwe017fj31ia0j1go0.jpg" alt="image"/></p> <p>因为当进行反向传播求导时，我们需要将整个时间轴的输入全部输入之后，才可以从最后一个时刻开始往前传进行反向传播，所以我们假设 $t$ 时刻就为最后一个时刻 $T_x$ 。</p> <p>如果我们想要先计算 $\frac{\partial\ell}{\partial W_{ax}}$ 所以我们可以从计算图中看到，反向传播的路径：</p> <p><img src="https://image.baidu.com/search/down?url=https://tva1.sinaimg.cn/large/006VTcCxly1gmiwutfx3gj31ig0j1mzn.jpg" alt="image"/></p> <p>我们需要按部就班的分别对从 $W_{ax}$ 计算到 $\ell$ 一路相关的变量进行求偏导，利用链式法则，将红色路线上一路的偏导数相乘到一起，就可以求出偏导数 $\frac{\partial\ell}{\partial W_{ax}}$ ；所以我们得到：</p> \[\begin{split} \frac{\partial\ell}{\partial W_{ax}} &amp;= \frac{\partial\ell}{\partial\ell^{\langle t\rangle}} {\color{Red}{ \frac{\partial\ell^{\langle t\rangle}}{\partial\hat{y}^{\langle t\rangle}} \frac{\partial\hat{y}^{\langle t\rangle}}{\partial z2^{\langle t\rangle}} }} \frac{\partial z2^{\langle t\rangle}}{\partial a^{\langle t\rangle}} \frac{\partial a^{\langle t\rangle}}{\partial z1^{\langle t\rangle}} \frac{\partial z1^{\langle t\rangle}}{\partial W_{ax}} \end{split}\] <p>在上面的公式中，我们仅需要分别求出每一个偏导即可，其中红色的部分就是关于 $\mathrm{Softmax}$ 的求导，关于 $\mathrm{Softmax}$ 求导的推导过程，可以看本人的另一篇博客： <a href="/blog/2020/%E5%85%B3%E4%BA%8E-Softmax-%E5%9B%9E%E5%BD%92%E7%9A%84%E5%8F%8D%E5%90%91%E4%BC%A0%E6%92%AD%E6%B1%82%E5%AF%BC%E6%95%B0%E8%BF%87%E7%A8%8B/">关于 Softmax 回归的反向传播求导数过程</a></p> <p>关于 $\mathrm{tanh}$ 的求导公式如下：</p> \[\frac{\partial \tanh(x)} {\partial x} = 1 - \tanh^2(x)\] <p>所以上面的式子就得到：</p> \[\begin{split} \frac{\partial\ell}{\partial W_{ax}} &amp;= \frac{\partial\ell}{\partial\ell^{\langle t\rangle}} {\color{Red}{ \frac{\partial\ell^{\langle t\rangle}}{\partial\hat{y}^{\langle t\rangle}} \frac{\partial\hat{y}^{\langle t\rangle}}{\partial z2^{\langle t\rangle}} }} \frac{\partial z2^{\langle t\rangle}}{\partial a^{\langle t\rangle}} \frac{\partial a^{\langle t\rangle}}{\partial z1^{\langle t\rangle}} \frac{\partial z1^{\langle t\rangle}}{\partial W_{ax}}\\ &amp;= {\color{Red}{ (\hat{y}^{\langle t\rangle}-y^{\langle t\rangle}) }} W_{ya} (1-\tanh^2(z1^{\langle t\rangle})) x^{\langle t\rangle} \end{split}\] <p>我们就可以得到在最后时刻 $t$ 参数 $W_{ax}$ 的偏导数。</p> <blockquote> <p>关于上面式子中的偏导数的计算，除了标量对矩阵的求导，在后面还包括了两个一个矩阵或向量对另一个矩阵或向量中的求导，实际上这是非常麻烦的一件事。</p> <p>比如在计算 $\frac{\partial z1^{\langle t\rangle}}{\partial W_{ax}}$ 偏导数的时候，我们发现 $z1^{\langle t\rangle}$ 是一个 $\mathbb{R}^{n_a\times m}$ 的矩阵，而 $W_{ax}$ 则是一个 $\mathbb{R}^{n_a\times n_x}$ 的矩阵，这一项就是一个矩阵对另一个矩阵求偏导，如果直接对其求导我们将会得到一个四维的矩阵 $\mathbb{R}^{n_a\times n_x\times n_a\times m}$ （<em>雅可比矩阵 Jacobian matrix</em>）；只不过这个高维矩阵中偏导数的值有很多 $0$ 。</p> <p>在神经网络中，如果直接将这个高维矩阵直接生搬硬套进梯度下降里更新参数是不可行，因为我们需要得到的梯度是关于自变量同型的向量或矩阵而且我们还要处理更高维度的矩阵的乘法；所以我们需要将结果进行一定的处理得到我们仅仅需要的信息。</p> <p>一般在深度学习框架中都会有自动求梯度的功能包，这些包（比如 <code class="language-plaintext highlighter-rouge">PyTorch</code> ）中就只允许一个标量对向量或矩阵求导，其他情况是不允许的，除非在反向传播的函数里传入一个同型的权重向量或矩阵才可以得到导数。</p> </blockquote> <p>我们先简单求出一个偏导数 $\frac{\partial\ell}{\partial W_{ax}}$ 我们下面使用 <code class="language-plaintext highlighter-rouge">PyTorch</code> 中的自动求梯度的包进行验证我们的公式是否正确。</p> <div class="language-python highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="kn">import</span> <span class="n">torch</span>
</code></pre></div></div> <div class="language-python highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="c1"># 这是神经网络中的一些架构的参数
</span><span class="n">n_x</span> <span class="o">=</span> <span class="mi">6</span>
<span class="n">n_y</span> <span class="o">=</span> <span class="mi">6</span>
<span class="n">m</span> <span class="o">=</span> <span class="mi">1</span>
<span class="n">T_x</span> <span class="o">=</span> <span class="mi">5</span>
<span class="n">T_y</span> <span class="o">=</span> <span class="mi">5</span>
<span class="n">n_a</span> <span class="o">=</span> <span class="mi">3</span>
</code></pre></div></div> <div class="language-python highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="c1"># 定义所有参数矩阵
# requires_grad 为 True 表明在涉及这个变量的运算时建立计算图
# 为了之后反向传播求导
</span><span class="n">W_ax</span> <span class="o">=</span> <span class="n">torch</span><span class="p">.</span><span class="nf">randn</span><span class="p">((</span><span class="n">n_a</span><span class="p">,</span> <span class="n">n_x</span><span class="p">),</span> <span class="n">requires_grad</span><span class="o">=</span><span class="bp">True</span><span class="p">)</span>
<span class="n">W_aa</span> <span class="o">=</span> <span class="n">torch</span><span class="p">.</span><span class="nf">randn</span><span class="p">((</span><span class="n">n_a</span><span class="p">,</span> <span class="n">n_a</span><span class="p">),</span> <span class="n">requires_grad</span><span class="o">=</span><span class="bp">True</span><span class="p">)</span>
<span class="n">ba</span> <span class="o">=</span> <span class="n">torch</span><span class="p">.</span><span class="nf">randn</span><span class="p">((</span><span class="n">n_a</span><span class="p">,</span> <span class="mi">1</span><span class="p">),</span> <span class="n">requires_grad</span><span class="o">=</span><span class="bp">True</span><span class="p">)</span>
<span class="n">W_ya</span> <span class="o">=</span> <span class="n">torch</span><span class="p">.</span><span class="nf">randn</span><span class="p">((</span><span class="n">n_y</span><span class="p">,</span> <span class="n">n_a</span><span class="p">),</span> <span class="n">requires_grad</span><span class="o">=</span><span class="bp">True</span><span class="p">)</span>
<span class="n">by</span> <span class="o">=</span> <span class="n">torch</span><span class="p">.</span><span class="nf">randn</span><span class="p">((</span><span class="n">n_y</span><span class="p">,</span> <span class="mi">1</span><span class="p">),</span> <span class="n">requires_grad</span><span class="o">=</span><span class="bp">True</span><span class="p">)</span>
</code></pre></div></div> <div class="language-python highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="c1"># t 时刻的输入和上一时刻的 hidden state
</span><span class="n">x_t</span> <span class="o">=</span> <span class="n">torch</span><span class="p">.</span><span class="nf">randn</span><span class="p">((</span><span class="n">n_x</span><span class="p">,</span> <span class="n">m</span><span class="p">),</span> <span class="n">requires_grad</span><span class="o">=</span><span class="bp">True</span><span class="p">)</span>
<span class="n">a_prev</span> <span class="o">=</span> <span class="n">torch</span><span class="p">.</span><span class="nf">randn</span><span class="p">((</span><span class="n">n_a</span><span class="p">,</span> <span class="n">m</span><span class="p">),</span> <span class="n">requires_grad</span><span class="o">=</span><span class="bp">True</span><span class="p">)</span>
<span class="n">y_t</span> <span class="o">=</span> <span class="n">torch</span><span class="p">.</span><span class="nf">randn</span><span class="p">((</span><span class="n">n_y</span><span class="p">,</span> <span class="n">m</span><span class="p">),</span> <span class="n">requires_grad</span><span class="o">=</span><span class="bp">True</span><span class="p">)</span>
</code></pre></div></div> <div class="language-python highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="c1"># 开始模拟一个神经元 t 时刻的前向传播
# 从输入一直到计算出 loss
</span><span class="n">z1_t</span> <span class="o">=</span> <span class="n">torch</span><span class="p">.</span><span class="nf">matmul</span><span class="p">(</span><span class="n">W_ax</span><span class="p">,</span> <span class="n">x_t</span><span class="p">)</span> <span class="o">+</span> <span class="n">torch</span><span class="p">.</span><span class="nf">matmul</span><span class="p">(</span><span class="n">W_aa</span><span class="p">,</span> <span class="n">a_prev</span><span class="p">)</span> <span class="o">+</span> <span class="n">ba</span>
<span class="n">z1_t</span><span class="p">.</span><span class="nf">retain_grad</span><span class="p">()</span>
<span class="n">a_t</span> <span class="o">=</span> <span class="n">torch</span><span class="p">.</span><span class="nf">tanh</span><span class="p">(</span><span class="n">z1_t</span><span class="p">)</span>
<span class="n">a_t</span><span class="p">.</span><span class="nf">retain_grad</span><span class="p">()</span>
<span class="n">z2_t</span> <span class="o">=</span> <span class="n">torch</span><span class="p">.</span><span class="nf">matmul</span><span class="p">(</span><span class="n">W_ya</span><span class="p">,</span> <span class="n">a_t</span><span class="p">)</span> <span class="o">+</span> <span class="n">by</span>
<span class="n">z2_t</span><span class="p">.</span><span class="nf">retain_grad</span><span class="p">()</span>
<span class="n">y_hat</span> <span class="o">=</span> <span class="n">torch</span><span class="p">.</span><span class="nf">exp</span><span class="p">(</span><span class="n">z2_t</span><span class="p">)</span> <span class="o">/</span> <span class="n">torch</span><span class="p">.</span><span class="nf">sum</span><span class="p">(</span><span class="n">torch</span><span class="p">.</span><span class="nf">exp</span><span class="p">(</span><span class="n">z2_t</span><span class="p">),</span> <span class="n">dim</span><span class="o">=</span><span class="mi">0</span><span class="p">)</span>
<span class="n">y_hat</span><span class="p">.</span><span class="nf">retain_grad</span><span class="p">()</span>
<span class="n">loss_t</span> <span class="o">=</span> <span class="o">-</span><span class="n">torch</span><span class="p">.</span><span class="nf">sum</span><span class="p">(</span><span class="n">y_t</span> <span class="o">*</span> <span class="n">torch</span><span class="p">.</span><span class="nf">log</span><span class="p">(</span><span class="n">y_hat</span><span class="p">),</span> <span class="n">dim</span><span class="o">=</span><span class="mi">0</span><span class="p">)</span>
<span class="n">loss_t</span><span class="p">.</span><span class="nf">retain_grad</span><span class="p">()</span>
</code></pre></div></div> <div class="language-python highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="c1"># 对最后的 loss 标量开始进行反向传播求导
</span><span class="n">loss_t</span><span class="p">.</span><span class="nf">backward</span><span class="p">()</span>
</code></pre></div></div> <div class="language-python highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="c1"># 我们就可以得到 W_ax 的导数
# 存储在后缀 _autograd 变量中，表明是由框架自动求导得到的
</span><span class="n">W_ax_autograd</span> <span class="o">=</span> <span class="n">W_ax</span><span class="p">.</span><span class="n">grad</span>
</code></pre></div></div> <div class="language-python highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="c1"># 查看框架计算得到的导数
</span><span class="n">W_ax_autograd</span>
</code></pre></div></div> <div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>tensor([[ 0.5252,  1.1938, -0.2352,  1.1571, -1.0168,  0.3195],
        [-1.0536, -2.3949,  0.4718, -2.3213,  2.0398, -0.6410],
        [-0.0316, -0.0717,  0.0141, -0.0695,  0.0611, -0.0192]])
</code></pre></div></div> <div class="language-python highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="c1"># 我们对自己推演出的公式进行手动计算导数
# 存储在后缀 _manugrad 变量中，表明是手动由公式计算得到的
</span><span class="n">W_ax_manugrad</span> <span class="o">=</span> <span class="n">torch</span><span class="p">.</span><span class="nf">matmul</span><span class="p">(</span><span class="n">torch</span><span class="p">.</span><span class="nf">matmul</span><span class="p">((</span><span class="n">y_hat</span> <span class="o">-</span> <span class="n">y_t</span><span class="p">).</span><span class="n">T</span><span class="p">,</span> <span class="n">W_ya</span><span class="p">).</span><span class="n">T</span> <span class="o">*</span> <span class="p">(</span><span class="mi">1</span> <span class="o">-</span> <span class="n">torch</span><span class="p">.</span><span class="nf">square</span><span class="p">(</span><span class="n">torch</span><span class="p">.</span><span class="nf">tanh</span><span class="p">(</span><span class="n">z1_t</span><span class="p">))),</span> <span class="n">x_t</span><span class="p">.</span><span class="n">T</span><span class="p">)</span>
<span class="c1">#torch.matmul(torch.matmul(W_ya.T, y_hat - y_t) * (1 - torch.square(torch.tanh(z1_t))), x_t.T)
</span></code></pre></div></div> <div class="language-python highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="c1"># 输出手动计算的导数
</span><span class="n">W_ax_manugrad</span>
</code></pre></div></div> <div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>tensor([[ 0.5195,  1.1809, -0.2327,  1.1447, -1.0058,  0.3161],
        [-1.0195, -2.3172,  0.4565, -2.2461,  1.9737, -0.6202],
        [-0.0309, -0.0703,  0.0138, -0.0681,  0.0599, -0.0188]],
       grad_fn=&lt;MmBackward&gt;)
</code></pre></div></div> <div class="language-python highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="c1"># 查看两种求导结果的之差的 L2 范数
</span><span class="n">torch</span><span class="p">.</span><span class="nf">norm</span><span class="p">(</span><span class="n">W_ax_manugrad</span> <span class="o">-</span> <span class="n">W_ax_autograd</span><span class="p">)</span>
</code></pre></div></div> <div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>tensor(0.1356, grad_fn=&lt;CopyBackwards&gt;)
</code></pre></div></div> <p>通过上面的编程输出可以看到，我们手动计算的导数和框架自己求出的导数虽然有一定的误差，但是一一对照可以大体看到我们手动求出来的导数大体是对的，并没有说错的非常离谱。</p> <p>但上面只是当 $t=T_x$ 即 $t$ 时刻是最后一个输入单元的时候，也就是说所求的关于 $<em>W{ax}$ 的导数只是全部导数的一部分，因为参数共享，所以每一时刻的神经元都有对 $W</em>{ax}$ 的导数，所以需要将所有时刻的神经元关于 $W_{ax}$ 的导数全部加起来。</p> <p>若 $t$ 不是最后一时刻，可能是神经网络里的中间的某一时刻的神经元；也就是说，在进行反向传播的时候，想要求 $t$ 时刻的导数，就得等到 $t+1$ 时刻的导数值传进来，然后根据链式法则才可以计算当前时刻参数的导数。</p> <p>下面是一个简易的计算图，只绘制出了 $W_ax$ 到 $\ell$ 的计算中，共涉及到哪些变量（在整个神经网络中的 $W_{ax}$ 的权重参数是共享的）：</p> <p><img src="https://image.baidu.com/search/down?url=https://tva2.sinaimg.cn/large/006VTcCxly1gmizn9a86aj318y0t8goe.jpg" alt="image"/></p> <p>下面使用一个视频展示整个神经网络中从 $W_{ax}$ 到一个数据批量的损失值 $\ell$ 的大体流向：</p> <p><img src="https://yun.zyxweb.cn/index.php?explorer/share/file&amp;hash=1439457NtxPsb8asnr_vVtY66j-3v_8NDjbXDkWQTo-Tq5zESZQQZxsY&amp;name=forward.mp4" alt="forward.mp4"/></p> <p>计算完 $\ell$ 之后就可以计算 $\frac{\partial\ell}{\partial W_{ax}}$ 的导数值，但是 RNN 神经网络的反向传播区别于全连接神经网络的。</p> <p><img src="https://image.baidu.com/search/down?url=https://tvax2.sinaimg.cn/large/006VTcCxly1gmj0k2u79mj31980swacc.jpg" alt="image"/></p> <p>然后，我们演示一下如何进行反向传播的，注意看每一个时刻的 $a^{\langle t\rangle}$ 的计算都是等 $a^{\langle t+1\rangle}$ 的导数值传进来才进行计算的；同样地，$W_{ax}$ 导数的计算也不是一步到位的，也是需要等到所有时刻的 $a$ 的值全部传到才计算完。</p> <p><img src="https://yun.zyxweb.cn/index.php?explorer/share/file&amp;hash=1fc3U3bwTyfi-h40ykZa-0dfBrIcvkwjhXDDD_fGLGyO7xj52MiHSxWa&amp;name=backward.mp4" alt="backward.mp4"/></p> <p>所以对于神经网络中间某一个单元 $t$ 我们有：</p> \[\begin{split} \frac{\partial\ell}{\partial W_{ax}} &amp;= {\color{Red}{ \left( \frac{\partial\ell}{\partial a^{\langle t\rangle}} +\frac{\partial\ell}{\partial z1^{\langle t+1\rangle}} \frac{\partial z1^{\langle t+1\rangle}}{\partial a^{\langle t\rangle}} \right) }} \frac{\partial a^{\langle t\rangle}}{\partial z1^{\langle t\rangle}} \frac{\partial z1^{\langle t\rangle}}{\partial W_{ax}} \end{split}\] <p>关于红色的部分的意思是需要等到 $t+1$ 时刻的导数值传进来，然后才可以进行对 $t+1$ 时刻关于当前时刻 $t$ 的参数求导，最后得到参数梯度的一个分量。其实若仔细展开每一个偏导项，就像是一个递归一样，每次求某一时刻的导数总是要从最后一时刻往前传到当前时刻才可以进行。</p> <blockquote> <p><strong>多元复合函数的求导法则</strong></p> <p>如果函数 $u=\varphi(t)$ 及 $v=\psi(t)$ 都在点 $t$ 可导，函数 $z=f(u,v)$ 在对应点 $(u,v)$ 具有连续偏导数，那么复合函数 $z=f[\varphi(t),\psi(t)]$ 在点 $t$ 可导，且有 $\frac{\mathrm{d}z}{\mathrm{d}t}=\frac{\partial z}{\partial u}\frac{\mathrm{d}u}{\mathrm{d}t}+\frac{\partial z}{\partial v}\frac{\mathrm{d}v}{\mathrm{d}t}$</p> </blockquote> <p>下面使用一张计算图说明 $a^{\langle t\rangle}$ 到 $\ell$ 的计算关系。</p> <p><img src="https://image.baidu.com/search/down?url=https://tvax4.sinaimg.cn/large/006VTcCxly1gmjsx4kqcqj30w80audg6.jpg" alt="image"/></p> <p>也就是说第 $t$ 时刻 $\ell$ 关于 $a^{\langle t\rangle}$ 的导数是由两部分相加组成，也就是说是由两条路径反向传播，这两条路径分别是 $\ell\to\ell^{\langle t\rangle}\to\hat{y}^{\langle t\rangle}\to z2^{\langle t\rangle}\to a^{\langle t\rangle}$ 和 $\ell\to\ell^{\langle t+1\rangle}\to\hat{y}^{\langle t+1\rangle}\to z2^{\langle t+1\rangle}\to a^{\langle t+1\rangle}\to z1^{\langle t+1\rangle}\to a^{\langle t\rangle}$ ，我们将这两条路径导数之和使用 $\mathrm{d}a_{\mathrm{next}}$ 表示。</p> <p>所以我们可以得到在中间某一时刻的神经单元关于 $W_{ax}$ 的导数为：</p> \[\frac{\partial\ell}{\partial W_{ax}}=\left(\mathrm{d}a_{\mathrm{next}} * \left( 1-\tanh^2(z1^{\langle t \rangle}\right)\right) x^{\langle t \rangle T}\] <p>通过同样的方法，我们就可以得到其它参数的导数：</p> \[\begin{align} \frac{\partial\ell}{\partial W_{aa}} &amp;= \left(\mathrm{d}a_{\mathrm{next}} * \left( 1-\tanh^2(z1^{\langle t\rangle}) \right)\right) a^{\langle t-1 \rangle T}\\ \frac{\partial\ell}{\partial b_a} &amp; = \sum_{batch}\left( da_{next} * \left( 1-\tanh^2(z1^{\langle t\rangle}) \right)\right)\\ \end{align}\] <p>除了传递参数的导数，在第 $t$ 时刻还需要传送 $\ell$ 关于 $z1^{\langle t\rangle}$ 的导数到 $t-1$ 时刻，将需要传送到上一时刻的导数记作为 $\mathrm{d}a_{\mathrm{prev}}$ 我们得到：</p> \[\begin{split} \mathrm{d}a_{\mathrm{prev}} &amp;= \mathrm{d}a_\mathrm{next}\frac{\partial a^{\langle t\rangle}}{\partial z1^{\langle t\rangle}}\frac{\partial z1^{\langle t\rangle}}{\partial a^{\langle t-1\rangle}}\\ &amp;= { W_{aa}}^T\left(\mathrm{d}a_{\mathrm{next}} * \left( 1-\tanh^2(z1^{\langle t\rangle}) \right)\right) \end{split}\] <p>可以看到，一个循环神经网络的反向传播实际上是非常复杂的，因为每一时刻的神经元都与参数有计算关系，所以反向传播时的路径非常杂乱，其中还涉及到了高维的矩阵，所以在计算时需要对高维矩阵进行一定的矩阵代数转换才方便导数和更新参数的计算。</p>]]></content><author><name></name></author><summary type="html"><![CDATA[本文是对 RNN 循环神经网络中的每一个神经元进行反向传播求导的数学推导过程，下面还使用 PyTorch 对导数公式进行编程求证。]]></summary></entry><entry><title type="html">向量、矩阵和张量的导数</title><link href="https://jkfx.github.io/blog/2021/%E5%90%91%E9%87%8F-%E7%9F%A9%E9%98%B5%E5%92%8C%E5%BC%A0%E9%87%8F%E7%9A%84%E5%AF%BC%E6%95%B0/" rel="alternate" type="text/html" title="向量、矩阵和张量的导数"/><published>2021-01-09T15:21:00+08:00</published><updated>2021-01-09T15:21:00+08:00</updated><id>https://jkfx.github.io/blog/2021/%E5%90%91%E9%87%8F%E3%80%81%E7%9F%A9%E9%98%B5%E5%92%8C%E5%BC%A0%E9%87%8F%E7%9A%84%E5%AF%BC%E6%95%B0</id><content type="html" xml:base="https://jkfx.github.io/blog/2021/%E5%90%91%E9%87%8F-%E7%9F%A9%E9%98%B5%E5%92%8C%E5%BC%A0%E9%87%8F%E7%9A%84%E5%AF%BC%E6%95%B0/"><![CDATA[<blockquote> <p>[著] Erik Learned-Miller</p> <p>本文翻译自 Vector, Matrix, and Tensor Derivatives</p> <p>本人英语水平有限，文章中有翻译不到位的地方请热心指出并改正！</p> </blockquote> <p>本文的目的是帮助学习向量（vectors）、矩阵（matrices）和更高阶张量（tensors）的导数，关于向量、矩阵和高阶张量求导。</p> <h2 id="1-简化简化简化">1 简化，简化，简化</h2> <p>关于对数组求导的许多困惑都来自于想要一次性做太多的事情。这些“事情”包括一次性同时对多个组成部分的公式进行求导，在求和符号前面求导和应用链式求导法则。通过做这些事情的同时，我们更有可能犯错，至少在我们有经验之前是这样的。</p> <h3 id="11-扩展符号到显式求和方程式的每个部分">1.1 扩展符号到显式求和方程式的每个部分</h3> <p>为了简化一个给定的计算，对于输出的单个标量元素（<em>a single scalar element</em>）除了标量变量（<em>scalar variables</em>）写出显示公式通常是非常有用的。一旦对于输出的单个标量元素根据其它标量值有一个显式的公式，然后就可以使用微积分计算，这比同时尝试做所有的矩阵数学、求和和求导工作要简单得多。</p> <p><strong>Example.</strong> 假如我们有一个由一个 $C$ 行 $D$ 列的矩阵 $W$ 乘以一个长度为 $D$ 的列向量 $\vec{x}$ 得到的长度为 $C$ 的列向量 $\vec{y}$ ：</p> \[\vec{y}=W\vec{x}\tag{1}\] <p>假如我们对 $\vec{y}$ 关于 $\vec{x}$ 的导数感兴趣。这个导数的完整表征需要 $\vec{y}$ 的每一个分量关于 $\vec{x}$ 的每一个分量的（偏）导数，在这个例子中，将包含 $C\times D$ 个值，因为 $\vec{y}$ 中有 $C$ 个分量，在 $x$ 中有 $D$ 个分量。</p> <p>让我们开始计算其中的一个，对于 $\vec{y}$ 的第 $3$ 个分量关于关于 $\vec{x}$ 的第 $7$ 个分量；即我们想要计算：</p> \[\frac{\partial\vec{y}_3}{\partial\vec{x}_7}\] <p>这只是一个标量关于另一个标量的导数。</p> <p>要做的第一件事就是写出对于计算 $\vec{y}_3$ 的公式，然后我们就可以对其求导。从矩阵-向量相乘的定义，$\vec{y}_3$ 的值通过 $W$ 的第 $3$ 行和向量 $\vec{x}$ 的点积计算得到：</p> \[\vec{y}_3=\sum_{j=1}^DW_{3,j}\vec{x}_j\tag{2}\] <p>此时，我们将原先的矩阵方程（公式 $(1)$ ）简化为一个标量方程。这使得计算想要的导数更加容易。</p> <h3 id="12-移除求和符号">1.2 移除求和符号</h3> <p>因为直接计算公式 $(2)$ 的导数是可以的，人们经常犯的错误就是当微分表达式中包含求和符号（$\sum$）或是连乘符号（$\prod$）。当我们开始计算时，写出来不包含任何求和符号确保做的每一步都是正确的有时候是非常有用的。使用 $1$ 作为第一个索引，我们有：</p> \[\vec{y}_3=W_{3,1}\vec{x}_1+W_{3,2}\vec{x}_2+\dots+W_{3,7}\vec{x}_7+\dots+W_{3,D}\vec{x}_D\] <p>当然，我们明确地包括了含有 $\vec{x}<em>7$ 这一项，因为这就是我们在此的不同之处。此时，我们可以看到对于 $y_3$ 仅依赖在 $\vec{x}_7$ 之上的表达式只有 $W</em>{3,7}\vec{x}_7$ 这一个项。因为在累加中没有其它项包括 $\vec{x}_7$ 即它们关于 $\vec{x}_7$ 的导数都是 $0$ 。因此，我们有：</p> \[\begin{split} \frac{\partial\vec{y}_3}{\partial\vec{x}_7} &amp;=\frac{\partial}{\partial\vec{x}_7}\left[W_{3,1}\vec{x}_1+W_{3,2}\vec{x}_2+\dots+W_{3,7}\vec{x}_7+\dots+W_{3,D}\vec{x}_D\right]\\ &amp;=0+0+\dots+\frac{\partial}{\partial\vec{x}_7}\left[W_{3,7}\vec{x}_7\right]+\dots+0\\ &amp;=\frac{\partial}{\partial\vec{x}_7}\left[W_{3,7}\vec{x}_7\right]\\ &amp;=W_{3,7} \end{split}\] <p>通过关注在 $\vec{y}$ 的一个分量和 $\vec{x}$ 的一个分量，我们尽可能地简化计算。在未来，当你感到困惑时，尝试减少一个问题最基本的设置可以帮助你查看哪里出错。</p> <h4 id="121-完善导数雅可比jacobian矩阵">1.2.1 完善导数：雅可比（<em>Jacobian</em>）矩阵</h4> <p>回想我们的原始目标是计算 $\vec{y}$ 每一个分量关于 $\vec{x}$ 的每一个分量的导数，并且我们注意到其中会有 $C\times D$ 个。它们可以写成如下形式的一个矩阵：</p> \[\begin{bmatrix} \frac{\partial\vec{y}_1}{\partial\vec{x}_1}&amp;\frac{\partial\vec{y}_1}{\partial\vec{x}_2}&amp;\frac{\partial\vec{y}_1}{\partial\vec{x}_3}&amp;\dots&amp;\frac{\partial\vec{y}_1}{\partial\vec{x}_D}\\ \frac{\partial\vec{y}_2}{\partial\vec{x}_1}&amp;\frac{\partial\vec{y}_2}{\partial\vec{x}_2}&amp;\frac{\partial\vec{y}_2}{\partial\vec{x}_3}&amp;\dots&amp;\frac{\partial\vec{y}_2}{\partial\vec{x}_D}\\ \vdots&amp;\vdots&amp;\vdots&amp;\ddots &amp;\vdots\\ \frac{\partial\vec{y}_D}{\partial\vec{x}_1}&amp;\frac{\partial\vec{y}_D}{\partial\vec{x}_2}&amp;\frac{\partial\vec{y}_D}{\partial\vec{x}_3}&amp;\dots&amp;\frac{\partial\vec{y}_D}{\partial\vec{x}_D}\\ \end{bmatrix}\] <p>在这个特别的例子中，这个矩阵被称为雅可比矩阵（<em>Jacobian matrix</em>），但是这个术语对于我们的目的不重要。</p> <p>注意对于如下方程：</p> \[\vec{y}=W\vec{x}\] <p>$\vec{y}<em>3$ 关于 $\vec{x}_7$ 的部分简单地由 $W</em>{3,7}$ 给出。如果你做相同的处理方式到其它部分上，你将会发现，对于所有的 $i$ 和 $j$ ：</p> \[\frac{\partial\vec{y}_i}{\partial\vec{x}_j}=W_{i,j}\] <p>这意味着偏导数的矩阵是</p> \[\begin{bmatrix} \frac{\partial\vec{y}_1}{\partial\vec{x}_1}&amp;\frac{\partial\vec{y}_1}{\partial\vec{x}_2}&amp;\frac{\partial\vec{y}_1}{\partial\vec{x}_3}&amp;\dots&amp;\frac{\partial\vec{y}_1}{\partial\vec{x}_D}\\ \frac{\partial\vec{y}_2}{\partial\vec{x}_1}&amp;\frac{\partial\vec{y}_2}{\partial\vec{x}_2}&amp;\frac{\partial\vec{y}_2}{\partial\vec{x}_3}&amp;\dots&amp;\frac{\partial\vec{y}_2}{\partial\vec{x}_D}\\ \vdots&amp;\vdots&amp;\vdots&amp;\ddots &amp;\vdots\\ \frac{\partial\vec{y}_D}{\partial\vec{x}_1}&amp;\frac{\partial\vec{y}_D}{\partial\vec{x}_2}&amp;\frac{\partial\vec{y}_D}{\partial\vec{x}_3}&amp;\dots&amp;\frac{\partial\vec{y}_D}{\partial\vec{x}_D}\\ \end{bmatrix} = \begin{bmatrix} W_{1,1}&amp;W_{1,2}&amp;W_{1,3}&amp;\dots&amp;W_{1,D}\\ W_{2,1}&amp;W_{2,2}&amp;W_{2,3}&amp;\dots&amp;W_{2,D}\\ \vdots&amp;\vdots&amp;\vdots&amp;\ddots&amp;\vdots\\ W_{C,1}&amp;W_{C,2}&amp;W_{C,3}&amp;\dots&amp;W_{C,D}\\ \end{bmatrix}\] <p>当然，这就是 $W$ 本身。</p> <p>因此，做完这些所有工作后，我们可以得出结论</p> \[\vec{y}=W\vec{x}\] <p>我们有</p> \[\frac{\mathrm{d}\vec{y}}{\mathrm{d}\vec{x}}=W\] <h2 id="2-行向量而不是列向量">2 行向量而不是列向量</h2> <p>在使用不同的神经网络包时要密切关注权重（weight）矩阵和数据矩阵等的排列方式是很重要的。举个例子，如果一个数据矩阵 $X$ 包含许多不同的向量，每一个向量表示一个输入，矩阵 $X$ 的一行或是一列哪一个是数据向量？</p> <p>在第一章节的例子中，我们使用的向量 $\vec{x}$ 是一个列向量。但是，当 $\vec{x}$ 是一个行向量时你也应该有能力使用同样的基础想法。</p> <h3 id="21-example-2">2.1 Example 2</h3> <p>令 $\vec{y}$ 的长度为 $C$ 的行向量（<em>row vector</em>）是由另一个长度为 $D$ 的行向量 $\vec{x}$ 与 $D$ 行 $C$ 列的矩阵 $W$ 相乘得到。</p> \[\vec{y}=\vec{x}W\] <p>重要地是，尽管 $\vec{y}$ 和 $\vec{x}$ 依旧有着相同数量的成分，$W$ 的形状（shape）是我们之前使用的 $W$ 的形状的转置（<em>transpose</em>）。尤其是，因为我们现在使用 $\vec{x}$ 左乘，然而，之前的 $\vec{x}$ 是在右边的，$W$ 对于矩阵代数必须是转置的才行得通。</p> <p>在这个例子，你将会看到，通过写出</p> \[\vec{y}_3=\sum_{j=1}^D\vec{x}_jW_{j,3}\] <p>得到</p> \[\frac{\partial\vec{y}_3}{\partial\vec{x}_7}=W_{7,3}\] <p>注意到 $W$ 的索引是与第一个例子是相反的。但是，当我们组成所有的雅可比矩阵，我们仍然可以看到此例中也是</p> \[\frac{\mathrm{d}\vec{y}}{\mathrm{d}\vec{x}}=W\tag{7}\] <h2 id="3-高于两维的处理">3 高于两维的处理</h2> <p>让我们来考虑另一个密切相关的问题，计算</p> \[\frac{\mathrm{d}\vec{y}}{\mathrm{d}W}\] <p>在这个例子中，$\vec{y}$ 变量沿着一个坐标变化而 $W$ 变量沿着两个坐标变化。因此，全部的导数最自然地包含在三维数组中。我们避免术语“三维矩阵（<em>three</em>-dimensional matrix）”，因为如何做定义在三维数组上的矩阵相乘和其它矩阵运算是不清晰的。</p> <p>三维数组的处理，找到一种输出排列它们的方法可能会变得更加麻烦。相反，我们应该简单地定义我们的结果为可以适用于所需三维数组的任意一个元素结果的公式。</p> <p>让我们再次计算在 $\vec{y}$ 上的一个分量的标量导数，比如 $\vec{y}<em>3$ 和 $W$ 的一个成分，比如是 $W</em>{7,8}$ 。让我们从相同的基本设置开始，其中我们根据其它标量分量写下一个 $\vec{y}<em>3$ 的等式。现在，我们想要一个根据其它标量值表示 $\vec{y}_3$ 的等式，并且显示出 $W</em>{7,8}$ 在它的计算中扮演的角色。</p> <p>但是，我们可以看到，$W_{7,8}$ 在 $\vec{y}<em>3$ 的计算中是没有作用（_no role</em>）的，因为：</p> \[\vec{y}_3=\vec{x}_1W_{1,3}+\vec{x}_2W_{2,3}+\dots+\vec{x}_DW_{D,3} \tag{8}\] <p>换句话说，即：</p> \[\frac{\partial\vec{y}_3}{\partial W_{7,8}}=0\] <p>但是，$\vec{y}<em>3$ 关于 $W$ 的第 $3$ 列元素的偏导数将一定不为 $0$ 。举个例子，$\vec{y}_3$ 关于 $W</em>{2,3}$ 的导数如下给出：</p> \[\frac{\partial\vec{y}_3}{\partial W_{2,3}}=\vec{x}_2 \tag{9}\] <p>其可以通过公式 $(8)$ 简单地看出。</p> <p>总的来说，当 $\vec{y}$ 的分量的索引等于 $W$ 的第二个索引，导数就将非零，同时对于其它情况就为零。我们可以写出：</p> \[\frac{\partial\vec{y}_j}{\partial W_{i,j}}=\vec{x}_i\] <p>但是其它三维数组的元素将会是 $0$ 。如果我们令 $F$ 表示 $\vec{y}$ 关于 $W$ 的导数的三维数组，其中：</p> \[F_{i,j,k}=\frac{\partial\vec{y}_i}{\partial W_{j,k}}\] <p>则</p> \[F_{i,j,i}=\vec{x}_j\] <p>对于 $F$ 的其它元素都为零。</p> <p>最后，如果我们定义一个新的二维（<em>two-dimensional</em>）数组 $G$ 为：</p> \[G_{i,j}=F_{i,j,i}\] <p>我们可以看到我们需要关于 $F$ 的所有信息都被存放到 $G$ 中，并且 $F$ 有用的（<em>non-trivial</em>）部分实际上是二维的，而不是三维的。</p> <p>在高效的神经网络实现中，将导数数组中重要的部分以一个紧凑的方式表示出是至关重要的。</p> <h2 id="4-多个数据点">4 多个数据点</h2> <p>重复之前的一些例子是很好的练习，并且使用 $\vec{x}$ 的多个例子，堆叠在一起形成一个矩阵 $X$ 。让我们假设每一个单独的 $\vec{x}$ 是一个长度为 $D$ 的行向量，$X$ 是一个 $N$ 行 $D$ 列的二维数组。作为我们的上一个例子，$W$ 将会是一个 $D$ 行 $C$ 列的矩阵。$Y$ 由下给出：</p> \[Y=XW\] <p>也是一个 $N$ 行 $C$ 列的矩阵。因此，$Y$ 的每一行将给出与输入 $X$ 的相应行的相关联的行向量。</p> <p>坚持我们写出一个对于给定的输出成分的表达式的技术，我们有：</p> \[Y_{i,j}=\sum_{k=1}^DX_{i,k}W_{k,j}\] <p>我们立即可以从这个等式中看到导数：</p> \[\frac{\partial Y_{a,b}}{\partial X_{c,d}}\] <p>除了 $a=c$ 的情况，它们都为零。这也就是因为每一个 $Y$ 的分量仅仅通过 $X$ 的相应的行计算得到，$Y$ 和 $X$ 的不同行之间分量的导数都为零。</p> <p>此外，我们可以看到：</p> \[\frac{\partial Y_{i,j}}{\partial X_{i,k}}=W_{k,j} \tag{10}\] <p>这完全不取决于上面我们正在比较的 $X$ 和 $Y$ 的行。</p> <p>实际上，矩阵 $W$ 保持所有的这些部分，我们只需要记住根据公式 $(10)$ 索引到其中来获得我们想要的具体的偏导数。</p> <p>如果我们令 $Y_{i,:}$ 为 $Y$ 的第 $i$ 行，令 $X_{i,:}$ 为 $X$ 的第 $i$ 行，我们就可以看到：</p> \[\frac{\partial Y_{i,:}}{\partial X_{i,:}}=W\] <p>这是一个我们之前由公式 $(7)$ 得到的结果的简单的归纳。</p> <h2 id="链式法则与向量和矩阵的结合">链式法则与向量和矩阵的结合</h2> <p>现在我们已经解决了几个基础的例子，让我们结合这些思想到一个链式法则（<em>chain rule</em>）的例子上。同样，假设 $\vec{y}$ 和 $\vec{x}$ 都是列向量，让我们从这个等式开始：</p> \[\vec{y}=VW\vec{x}\] <p>并且尝试计算 $\vec{y}$ 关于 $\vec{x}$ 的导数。我们应该简单地观察两个矩阵 $V$ 和 $W$ 的乘积不过是另一个矩阵，记作 $U$ ，因此</p> \[\frac{\mathrm{d}\vec{y}}{\mathrm{d}\vec{x}}=VW=U\] <p>但是，我们想要通过使用链式法则的处理得到中间结果的定义，以便我们可以看到在这种情况下链式法则如何应用到非标量导数上。</p> <p>让我们定义中间结果：</p> \[\vec{m}=W\vec{x}\] <p>然后我们有：</p> \[\vec{y}=V\vec{m}\] <p>然后我们使用链式法则写出：</p> \[\frac{\mathrm{d}\vec{y}}{\mathrm{d}\vec{x}}=\frac{\mathrm{d}\vec{y}}{\mathrm{d}\vec{m}}\frac{\mathrm{d}\vec{m}}{\mathrm{d}\vec{x}}\] <p>为了确保我们准确地知道这是什么意思，让我们一次分析一个分量的老方法，以 $\vec{y}$ 的一个分量和 $\vec{x}$ 的一个分量开始：</p> \[\frac{\mathrm{d}\vec{y}_i}{\mathrm{d}\vec{x}_j}=\frac{\mathrm{d}\vec{y}_i}{\mathrm{d}\vec{m}}\frac{\mathrm{d}\vec{m}}{\mathrm{d}\vec{x}_j}\] <p>但是我们应该如何准确地解释右边的乘积？链式法则的思想是以 $\vec{y}<em>i$ 关于每一个标量（_each scalar</em>）中间变量的变化乘以（<em>multiply</em>）每一个标量中间变量关于 $\vec{x}_j$ 的变化。尤其如果 $\vec{m}$ 由 $M$ 个分量组成，然后我们写出：</p> \[\frac{\mathrm{d}\vec{y}_i}{\mathrm{d}\vec{x}_j}=\sum_{k=1}^M\frac{\mathrm{d}\vec{y}_i}{\mathrm{d}\vec{m}_k}\frac{\mathrm{d}\vec{m}_k}{\mathrm{d}\vec{x}_j}\] <p>回想我们之前关于一个向量关于一个向量的导数的结果：</p> \[\frac{\mathrm{d}\vec{y}_i}{\mathrm{d}\vec{m}_k}\] <p>就是 $V_{i,k}$ 并且：</p> \[\frac{\mathrm{d}\vec{m}_k}{\mathrm{d}\vec{x}_j}\] <p>就是 $W_{k,j}$ 。所以我们可以写出：</p> \[\frac{\mathrm{d}\vec{y}_i}{\mathrm{d}\vec{x}_j}=\sum_{k=1}^MV_{i,k}W_{k,j}\] <p>其就是对 $VW$ 的分量表达式，就是我们原先对这个问题的答案。</p> <p>总结一下，我们可以在向量和矩阵导数的背景下使用链式法则：</p> <ul> <li>明确说明中间结果和用于表示它们的变量</li> <li>表示最终导数各个分量的链式法则</li> <li>对链式法则表达式内的中间结果上适当求和</li> </ul>]]></content><author><name></name></author><summary type="html"><![CDATA[[著] Erik Learned-Miller 本文翻译自 Vector, Matrix, and Tensor Derivatives 本人英语水平有限，文章中有翻译不到位的地方请热心指出并改正！]]></summary></entry></feed>