代码拉取完成,页面将自动刷新
<?xml version="1.0" encoding="utf-8"?>
<search>
<entry>
<title>推荐系统算法:协同过滤 & 隐语义模型</title>
<link href="posts/27716/"/>
<url>posts/27716/</url>
<content type="html"><![CDATA[<script src="\assets\js\APlayer.min.js"> </script><h2 id="协同过滤算法">协同过滤算法</h2><p>常见计算相似度的方法:</p><ul><li><p>欧几里得距离(Euclidean Distance)</p><p><span class="katex-display"><span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><semantics><mrow><mi>d</mi><mo stretchy="false">(</mo><mi>x</mi><mo separator="true">,</mo><mi>y</mi><mo stretchy="false">)</mo><mo>=</mo><msqrt><mrow><mo>∑</mo><mrow><mo stretchy="false">(</mo><msub><mi>x</mi><mi>i</mi></msub><mo>−</mo><msub><mi>y</mi><mi>i</mi></msub><msup><mo stretchy="false">)</mo><mn>2</mn></msup></mrow></mrow></msqrt><mo separator="true">,</mo><mtext> sim</mtext><mo stretchy="false">(</mo><mi>x</mi><mo separator="true">,</mo><mi>y</mi><mo stretchy="false">)</mo><mo>=</mo><mfrac><mn>1</mn><mrow><mn>1</mn><mo>+</mo><mi>d</mi><mo stretchy="false">(</mo><mi>x</mi><mo separator="true">,</mo><mi>y</mi><mo stretchy="false">)</mo></mrow></mfrac></mrow><annotation encoding="application/x-tex">d(x,y)=\sqrt{\sum{(x_i-y_i)^2}}, \text{ sim}(x,y)=\frac{1}{1+d(x,y)}</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:1em;vertical-align:-0.25em;"></span><span class="mord mathnormal">d</span><span class="mopen">(</span><span class="mord mathnormal">x</span><span class="mpunct">,</span><span class="mspace" style="margin-right:0.16666666666666666em;"></span><span class="mord mathnormal" style="margin-right:0.03588em;">y</span><span class="mclose">)</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span><span class="mrel">=</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span></span><span class="base"><span class="strut" style="height:1.84em;vertical-align:-0.5561299999999998em;"></span><span class="mord sqrt"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:1.2838700000000003em;"><span class="svg-align" style="top:-3.8em;"><span class="pstrut" style="height:3.8em;"></span><span class="mord" style="padding-left:1em;"><span class="mop op-symbol large-op" style="position:relative;top:-0.000004999999999977245em;">∑</span><span class="mspace" style="margin-right:0.16666666666666666em;"></span><span class="mord"><span class="mopen">(</span><span class="mord"><span class="mord mathnormal">x</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.31166399999999994em;"><span style="top:-2.5500000000000003em;margin-left:0em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mathnormal mtight">i</span></span></span></span><span class="vlist-s"></span></span><span class="vlist-r"><span class="vlist" style="height:0.15em;"><span></span></span></span></span></span></span><span class="mspace" style="margin-right:0.2222222222222222em;"></span><span class="mbin">−</span><span class="mspace" style="margin-right:0.2222222222222222em;"></span><span class="mord"><span class="mord mathnormal" style="margin-right:0.03588em;">y</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.31166399999999994em;"><span style="top:-2.5500000000000003em;margin-left:-0.03588em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mathnormal mtight">i</span></span></span></span><span class="vlist-s"></span></span><span class="vlist-r"><span class="vlist" style="height:0.15em;"><span></span></span></span></span></span></span><span class="mclose"><span class="mclose">)</span><span class="msupsub"><span class="vlist-t"><span class="vlist-r"><span class="vlist" style="height:0.740108em;"><span style="top:-2.9890000000000003em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight">2</span></span></span></span></span></span></span></span></span></span></span><span style="top:-3.2438700000000003em;"><span class="pstrut" style="height:3.8em;"></span><span class="hide-tail" style="min-width:1.02em;height:1.8800000000000001em;"><svg width='400em' height='1.8800000000000001em' viewBox='0 0 400000 1944' preserveAspectRatio='xMinYMin slice'><path d='M983 90l0 -0c4,-6.7,10,-10,18,-10 H400000v40H1013.1s-83.4,268,-264.1,840c-180.7,572,-277,876.3,-289,913c-4.7,4.7,-12.7,7,-24,7s-12,0,-12,0c-1.3,-3.3,-3.7,-11.7,-7,-25c-35.3,-125.3,-106.7,-373.3,-214,-744c-10,12,-21,25,-33,39s-32,39,-32,39c-6,-5.3,-15,-14,-27,-26s25,-30,25,-30c26.7,-32.7,52,-63,76,-91s52,-60,52,-60s208,722,208,722c56,-175.3,126.3,-397.3,211,-666c84.7,-268.7,153.8,-488.2,207.5,-658.5c53.7,-170.3,84.5,-266.8,92.5,-289.5zM1001 80h400000v40h-400000z'/></svg></span></span></span><span class="vlist-s"></span></span><span class="vlist-r"><span class="vlist" style="height:0.5561299999999998em;"><span></span></span></span></span></span><span class="mpunct">,</span><span class="mspace" style="margin-right:0.16666666666666666em;"></span><span class="mord text"><span class="mord"> sim</span></span><span class="mopen">(</span><span class="mord mathnormal">x</span><span class="mpunct">,</span><span class="mspace" style="margin-right:0.16666666666666666em;"></span><span class="mord mathnormal" style="margin-right:0.03588em;">y</span><span class="mclose">)</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span><span class="mrel">=</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span></span><span class="base"><span class="strut" style="height:2.25744em;vertical-align:-0.936em;"></span><span class="mord"><span class="mopen nulldelimiter"></span><span class="mfrac"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:1.32144em;"><span style="top:-2.314em;"><span class="pstrut" style="height:3em;"></span><span class="mord"><span class="mord">1</span><span class="mspace" style="margin-right:0.2222222222222222em;"></span><span class="mbin">+</span><span class="mspace" style="margin-right:0.2222222222222222em;"></span><span class="mord mathnormal">d</span><span class="mopen">(</span><span class="mord mathnormal">x</span><span class="mpunct">,</span><span class="mspace" style="margin-right:0.16666666666666666em;"></span><span class="mord mathnormal" style="margin-right:0.03588em;">y</span><span class="mclose">)</span></span></span><span style="top:-3.23em;"><span class="pstrut" style="height:3em;"></span><span class="frac-line" style="border-bottom-width:0.04em;"></span></span><span style="top:-3.677em;"><span class="pstrut" style="height:3em;"></span><span class="mord"><span class="mord">1</span></span></span></span><span class="vlist-s"></span></span><span class="vlist-r"><span class="vlist" style="height:0.936em;"><span></span></span></span></span></span><span class="mclose nulldelimiter"></span></span></span></span></span></span></p></li><li><p>皮尔逊相关系数(Pearson Correlation Coefficient)</p><p><span class="katex-display"><span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><semantics><mrow><mi>p</mi><mo stretchy="false">(</mo><mi>x</mi><mo separator="true">,</mo><mi>y</mi><mo stretchy="false">)</mo><mo>=</mo><mfrac><mrow><mo>∑</mo><mrow><msub><mi>x</mi><mi>i</mi></msub><msub><mi>y</mi><mi>i</mi></msub></mrow><mo>−</mo><mi>n</mi><mover accent="true"><mrow><mi>x</mi><mi>y</mi></mrow><mo stretchy="true">‾</mo></mover></mrow><mrow><mo stretchy="false">(</mo><mi>n</mi><mo>−</mo><mn>1</mn><mo stretchy="false">)</mo><msub><mi>s</mi><mi>x</mi></msub><msub><mi>s</mi><mi>y</mi></msub></mrow></mfrac><mo>=</mo><mfrac><mrow><mi>n</mi><mo>∑</mo><mrow><msub><mi>x</mi><mi>i</mi></msub><msub><mi>y</mi><mi>i</mi></msub></mrow><mo>−</mo><mo>∑</mo><msub><mi>x</mi><mi>i</mi></msub><mo>∑</mo><msub><mi>y</mi><mi>i</mi></msub></mrow><mrow><msqrt><mrow><mi>n</mi><mo>∑</mo><msup><msub><mi>x</mi><mi>i</mi></msub><mn>2</mn></msup><mo>−</mo><mo stretchy="false">(</mo><mo>∑</mo><msub><mi>x</mi><mi>i</mi></msub><msup><mo stretchy="false">)</mo><mn>2</mn></msup></mrow></msqrt><msqrt><mrow><mi>n</mi><mo>∑</mo><msup><msub><mi>y</mi><mi>i</mi></msub><mn>2</mn></msup><mo>−</mo><mo stretchy="false">(</mo><mo>∑</mo><msub><mi>y</mi><mi>i</mi></msub><msup><mo stretchy="false">)</mo><mn>2</mn></msup></mrow></msqrt></mrow></mfrac></mrow><annotation encoding="application/x-tex">p(x,y)=\frac{\sum{x_iy_i}-n\overline{xy}}{(n-1)s_xs_y}=\frac{n\sum{x_iy_i}-\sum{x_i}\sum{y_i}}{\sqrt{n\sum{x_i}^2-(\sum{x_i})^2}\sqrt{n\sum{y_i}^2-(\sum{y_i})^2}}</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:1em;vertical-align:-0.25em;"></span><span class="mord mathnormal">p</span><span class="mopen">(</span><span class="mord mathnormal">x</span><span class="mpunct">,</span><span class="mspace" style="margin-right:0.16666666666666666em;"></span><span class="mord mathnormal" style="margin-right:0.03588em;">y</span><span class="mclose">)</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span><span class="mrel">=</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span></span><span class="base"><span class="strut" style="height:2.399108em;vertical-align:-0.972108em;"></span><span class="mord"><span class="mopen nulldelimiter"></span><span class="mfrac"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:1.427em;"><span style="top:-2.314em;"><span class="pstrut" style="height:3em;"></span><span class="mord"><span class="mopen">(</span><span class="mord mathnormal">n</span><span class="mspace" style="margin-right:0.2222222222222222em;"></span><span class="mbin">−</span><span class="mspace" style="margin-right:0.2222222222222222em;"></span><span class="mord">1</span><span class="mclose">)</span><span class="mord"><span class="mord mathnormal">s</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.151392em;"><span style="top:-2.5500000000000003em;margin-left:0em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mathnormal mtight">x</span></span></span></span><span class="vlist-s"></span></span><span class="vlist-r"><span class="vlist" style="height:0.15em;"><span></span></span></span></span></span></span><span class="mord"><span class="mord mathnormal">s</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.15139200000000003em;"><span style="top:-2.5500000000000003em;margin-left:0em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mathnormal mtight" style="margin-right:0.03588em;">y</span></span></span></span><span class="vlist-s"></span></span><span class="vlist-r"><span class="vlist" style="height:0.286108em;"><span></span></span></span></span></span></span></span></span><span style="top:-3.23em;"><span class="pstrut" style="height:3em;"></span><span class="frac-line" style="border-bottom-width:0.04em;"></span></span><span style="top:-3.677em;"><span class="pstrut" style="height:3em;"></span><span class="mord"><span class="mop op-symbol small-op" style="position:relative;top:-0.0000050000000000050004em;">∑</span><span class="mspace" style="margin-right:0.16666666666666666em;"></span><span class="mord"><span class="mord"><span class="mord mathnormal">x</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.31166399999999994em;"><span style="top:-2.5500000000000003em;margin-left:0em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mathnormal mtight">i</span></span></span></span><span class="vlist-s"></span></span><span class="vlist-r"><span class="vlist" style="height:0.15em;"><span></span></span></span></span></span></span><span class="mord"><span class="mord mathnormal" style="margin-right:0.03588em;">y</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.31166399999999994em;"><span style="top:-2.5500000000000003em;margin-left:-0.03588em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mathnormal mtight">i</span></span></span></span><span class="vlist-s"></span></span><span class="vlist-r"><span class="vlist" style="height:0.15em;"><span></span></span></span></span></span></span></span><span class="mspace" style="margin-right:0.2222222222222222em;"></span><span class="mbin">−</span><span class="mspace" style="margin-right:0.2222222222222222em;"></span><span class="mord mathnormal">n</span><span class="mord overline"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.63056em;"><span style="top:-3em;"><span class="pstrut" style="height:3em;"></span><span class="mord"><span class="mord mathnormal">x</span><span class="mord mathnormal" style="margin-right:0.03588em;">y</span></span></span><span style="top:-3.55056em;"><span class="pstrut" style="height:3em;"></span><span class="overline-line" style="border-bottom-width:0.04em;"></span></span></span><span class="vlist-s"></span></span><span class="vlist-r"><span class="vlist" style="height:0.19444em;"><span></span></span></span></span></span></span></span></span><span class="vlist-s"></span></span><span class="vlist-r"><span class="vlist" style="height:0.972108em;"><span></span></span></span></span></span><span class="mclose nulldelimiter"></span></span><span class="mspace" style="margin-right:0.2777777777777778em;"></span><span class="mrel">=</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span></span><span class="base"><span class="strut" style="height:2.557em;vertical-align:-1.13em;"></span><span class="mord"><span class="mopen nulldelimiter"></span><span class="mfrac"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:1.427em;"><span style="top:-2.175005em;"><span class="pstrut" style="height:3em;"></span><span class="mord"><span class="mord sqrt"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.934995em;"><span class="svg-align" style="top:-3.2em;"><span class="pstrut" style="height:3.2em;"></span><span class="mord" style="padding-left:1em;"><span class="mord mathnormal">n</span><span class="mspace" style="margin-right:0.16666666666666666em;"></span><span class="mop op-symbol small-op" style="position:relative;top:-0.0000050000000000050004em;">∑</span><span class="mspace" style="margin-right:0.16666666666666666em;"></span><span class="mord"><span class="mord"><span class="mord"><span class="mord mathnormal">x</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.31166399999999994em;"><span style="top:-2.5500000000000003em;margin-left:0em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mathnormal mtight">i</span></span></span></span><span class="vlist-s"></span></span><span class="vlist-r"><span class="vlist" style="height:0.15em;"><span></span></span></span></span></span></span></span><span class="msupsub"><span class="vlist-t"><span class="vlist-r"><span class="vlist" style="height:0.740108em;"><span style="top:-2.9890000000000003em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight">2</span></span></span></span></span></span></span></span><span class="mspace" style="margin-right:0.2222222222222222em;"></span><span class="mbin">−</span><span class="mspace" style="margin-right:0.2222222222222222em;"></span><span class="mopen">(</span><span class="mop op-symbol small-op" style="position:relative;top:-0.0000050000000000050004em;">∑</span><span class="mspace" style="margin-right:0.16666666666666666em;"></span><span class="mord"><span class="mord"><span class="mord mathnormal">x</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.31166399999999994em;"><span style="top:-2.5500000000000003em;margin-left:0em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mathnormal mtight">i</span></span></span></span><span class="vlist-s"></span></span><span class="vlist-r"><span class="vlist" style="height:0.15em;"><span></span></span></span></span></span></span></span><span class="mclose"><span class="mclose">)</span><span class="msupsub"><span class="vlist-t"><span class="vlist-r"><span class="vlist" style="height:0.740108em;"><span style="top:-2.9890000000000003em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight">2</span></span></span></span></span></span></span></span></span></span><span style="top:-2.894995em;"><span class="pstrut" style="height:3.2em;"></span><span class="hide-tail" style="min-width:1.02em;height:1.28em;"><svg width='400em' height='1.28em' viewBox='0 0 400000 1296' preserveAspectRatio='xMinYMin slice'><path d='M263,681c0.7,0,18,39.7,52,119c34,79.3,68.167,158.7,102.5,238c34.3,79.3,51.8,119.3,52.5,120c340,-704.7,510.7,-1060.3,512,-1067l0 -0c4.7,-7.3,11,-11,19,-11H40000v40H1012.3s-271.3,567,-271.3,567c-38.7,80.7,-84,175,-136,283c-52,108,-89.167,185.3,-111.5,232c-22.3,46.7,-33.8,70.3,-34.5,71c-4.7,4.7,-12.3,7,-23,7s-12,-1,-12,-1s-109,-253,-109,-253c-72.7,-168,-109.3,-252,-110,-252c-10.7,8,-22,16.7,-34,26c-22,17.3,-33.3,26,-34,26s-26,-26,-26,-26s76,-59,76,-59s76,-60,76,-60zM1001 80h400000v40h-400000z'/></svg></span></span></span><span class="vlist-s"></span></span><span class="vlist-r"><span class="vlist" style="height:0.30500499999999997em;"><span></span></span></span></span></span><span class="mord sqrt"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.934995em;"><span class="svg-align" style="top:-3.2em;"><span class="pstrut" style="height:3.2em;"></span><span class="mord" style="padding-left:1em;"><span class="mord mathnormal">n</span><span class="mspace" style="margin-right:0.16666666666666666em;"></span><span class="mop op-symbol small-op" style="position:relative;top:-0.0000050000000000050004em;">∑</span><span class="mspace" style="margin-right:0.16666666666666666em;"></span><span class="mord"><span class="mord"><span class="mord"><span class="mord mathnormal" style="margin-right:0.03588em;">y</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.31166399999999994em;"><span style="top:-2.5500000000000003em;margin-left:-0.03588em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mathnormal mtight">i</span></span></span></span><span class="vlist-s"></span></span><span class="vlist-r"><span class="vlist" style="height:0.15em;"><span></span></span></span></span></span></span></span><span class="msupsub"><span class="vlist-t"><span class="vlist-r"><span class="vlist" style="height:0.740108em;"><span style="top:-2.9890000000000003em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight">2</span></span></span></span></span></span></span></span><span class="mspace" style="margin-right:0.2222222222222222em;"></span><span class="mbin">−</span><span class="mspace" style="margin-right:0.2222222222222222em;"></span><span class="mopen">(</span><span class="mop op-symbol small-op" style="position:relative;top:-0.0000050000000000050004em;">∑</span><span class="mspace" style="margin-right:0.16666666666666666em;"></span><span class="mord"><span class="mord"><span class="mord mathnormal" style="margin-right:0.03588em;">y</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.31166399999999994em;"><span style="top:-2.5500000000000003em;margin-left:-0.03588em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mathnormal mtight">i</span></span></span></span><span class="vlist-s"></span></span><span class="vlist-r"><span class="vlist" style="height:0.15em;"><span></span></span></span></span></span></span></span><span class="mclose"><span class="mclose">)</span><span class="msupsub"><span class="vlist-t"><span class="vlist-r"><span class="vlist" style="height:0.740108em;"><span style="top:-2.9890000000000003em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight">2</span></span></span></span></span></span></span></span></span></span><span style="top:-2.894995em;"><span class="pstrut" style="height:3.2em;"></span><span class="hide-tail" style="min-width:1.02em;height:1.28em;"><svg width='400em' height='1.28em' viewBox='0 0 400000 1296' preserveAspectRatio='xMinYMin slice'><path d='M263,681c0.7,0,18,39.7,52,119c34,79.3,68.167,158.7,102.5,238c34.3,79.3,51.8,119.3,52.5,120c340,-704.7,510.7,-1060.3,512,-1067l0 -0c4.7,-7.3,11,-11,19,-11H40000v40H1012.3s-271.3,567,-271.3,567c-38.7,80.7,-84,175,-136,283c-52,108,-89.167,185.3,-111.5,232c-22.3,46.7,-33.8,70.3,-34.5,71c-4.7,4.7,-12.3,7,-23,7s-12,-1,-12,-1s-109,-253,-109,-253c-72.7,-168,-109.3,-252,-110,-252c-10.7,8,-22,16.7,-34,26c-22,17.3,-33.3,26,-34,26s-26,-26,-26,-26s76,-59,76,-59s76,-60,76,-60zM1001 80h400000v40h-400000z'/></svg></span></span></span><span class="vlist-s"></span></span><span class="vlist-r"><span class="vlist" style="height:0.30500499999999997em;"><span></span></span></span></span></span></span></span><span style="top:-3.23em;"><span class="pstrut" style="height:3em;"></span><span class="frac-line" style="border-bottom-width:0.04em;"></span></span><span style="top:-3.677em;"><span class="pstrut" style="height:3em;"></span><span class="mord"><span class="mord mathnormal">n</span><span class="mspace" style="margin-right:0.16666666666666666em;"></span><span class="mop op-symbol small-op" style="position:relative;top:-0.0000050000000000050004em;">∑</span><span class="mspace" style="margin-right:0.16666666666666666em;"></span><span class="mord"><span class="mord"><span class="mord mathnormal">x</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.31166399999999994em;"><span style="top:-2.5500000000000003em;margin-left:0em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mathnormal mtight">i</span></span></span></span><span class="vlist-s"></span></span><span class="vlist-r"><span class="vlist" style="height:0.15em;"><span></span></span></span></span></span></span><span class="mord"><span class="mord mathnormal" style="margin-right:0.03588em;">y</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.31166399999999994em;"><span style="top:-2.5500000000000003em;margin-left:-0.03588em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mathnormal mtight">i</span></span></span></span><span class="vlist-s"></span></span><span class="vlist-r"><span class="vlist" style="height:0.15em;"><span></span></span></span></span></span></span></span><span class="mspace" style="margin-right:0.2222222222222222em;"></span><span class="mbin">−</span><span class="mspace" style="margin-right:0.2222222222222222em;"></span><span class="mop op-symbol small-op" style="position:relative;top:-0.0000050000000000050004em;">∑</span><span class="mspace" style="margin-right:0.16666666666666666em;"></span><span class="mord"><span class="mord"><span class="mord mathnormal">x</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.31166399999999994em;"><span style="top:-2.5500000000000003em;margin-left:0em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mathnormal mtight">i</span></span></span></span><span class="vlist-s"></span></span><span class="vlist-r"><span class="vlist" style="height:0.15em;"><span></span></span></span></span></span></span></span><span class="mspace" style="margin-right:0.16666666666666666em;"></span><span class="mop op-symbol small-op" style="position:relative;top:-0.0000050000000000050004em;">∑</span><span class="mspace" style="margin-right:0.16666666666666666em;"></span><span class="mord"><span class="mord"><span class="mord mathnormal" style="margin-right:0.03588em;">y</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.31166399999999994em;"><span style="top:-2.5500000000000003em;margin-left:-0.03588em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mathnormal mtight">i</span></span></span></span><span class="vlist-s"></span></span><span class="vlist-r"><span class="vlist" style="height:0.15em;"><span></span></span></span></span></span></span></span></span></span></span><span class="vlist-s"></span></span><span class="vlist-r"><span class="vlist" style="height:1.13em;"><span></span></span></span></span></span><span class="mclose nulldelimiter"></span></span></span></span></span></span></p><p><span class="katex-display"><span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><semantics><mrow><msub><mi>ρ</mi><mrow><mi>X</mi><mo separator="true">,</mo><mi>Y</mi></mrow></msub><mo>=</mo><mtext>corr</mtext><mo stretchy="false">(</mo><mi>X</mi><mo separator="true">,</mo><mi>Y</mi><mo stretchy="false">)</mo><mo>=</mo><mfrac><mrow><mtext>cov</mtext><mo stretchy="false">(</mo><mi>X</mi><mo separator="true">,</mo><mi>Y</mi><mo stretchy="false">)</mo></mrow><mrow><msub><mi>σ</mi><mi>X</mi></msub><msub><mi>σ</mi><mi>Y</mi></msub></mrow></mfrac><mo>=</mo><mfrac><mrow><mi>E</mi><mo stretchy="false">[</mo><mo stretchy="false">(</mo><mi>X</mi><mo>−</mo><msub><mi>μ</mi><mi>X</mi></msub><mo stretchy="false">)</mo><mo stretchy="false">(</mo><mi>Y</mi><mo>−</mo><msub><mi>μ</mi><mi>Y</mi></msub><mo stretchy="false">)</mo><mo stretchy="false">]</mo></mrow><mrow><msub><mi>σ</mi><mi>X</mi></msub><msub><mi>σ</mi><mi>Y</mi></msub></mrow></mfrac></mrow><annotation encoding="application/x-tex">\rho_{X,Y}=\text{corr}(X,Y)=\frac{\text{cov}(X,Y)}{\sigma_X\sigma_Y}=\frac{E[(X-\mu_X)(Y-\mu_Y)]}{\sigma_X\sigma_Y}</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.716668em;vertical-align:-0.286108em;"></span><span class="mord"><span class="mord mathnormal">ρ</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.328331em;"><span style="top:-2.5500000000000003em;margin-left:0em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight"><span class="mord mathnormal mtight" style="margin-right:0.07847em;">X</span><span class="mpunct mtight">,</span><span class="mord mathnormal mtight" style="margin-right:0.22222em;">Y</span></span></span></span></span><span class="vlist-s"></span></span><span class="vlist-r"><span class="vlist" style="height:0.286108em;"><span></span></span></span></span></span></span><span class="mspace" style="margin-right:0.2777777777777778em;"></span><span class="mrel">=</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span></span><span class="base"><span class="strut" style="height:1em;vertical-align:-0.25em;"></span><span class="mord text"><span class="mord">corr</span></span><span class="mopen">(</span><span class="mord mathnormal" style="margin-right:0.07847em;">X</span><span class="mpunct">,</span><span class="mspace" style="margin-right:0.16666666666666666em;"></span><span class="mord mathnormal" style="margin-right:0.22222em;">Y</span><span class="mclose">)</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span><span class="mrel">=</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span></span><span class="base"><span class="strut" style="height:2.263em;vertical-align:-0.8360000000000001em;"></span><span class="mord"><span class="mopen nulldelimiter"></span><span class="mfrac"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:1.427em;"><span style="top:-2.3139999999999996em;"><span class="pstrut" style="height:3em;"></span><span class="mord"><span class="mord"><span class="mord mathnormal" style="margin-right:0.03588em;">σ</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.32833099999999993em;"><span style="top:-2.5500000000000003em;margin-left:-0.03588em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mathnormal mtight" style="margin-right:0.07847em;">X</span></span></span></span><span class="vlist-s"></span></span><span class="vlist-r"><span class="vlist" style="height:0.15em;"><span></span></span></span></span></span></span><span class="mord"><span class="mord mathnormal" style="margin-right:0.03588em;">σ</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.32833099999999993em;"><span style="top:-2.5500000000000003em;margin-left:-0.03588em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mathnormal mtight" style="margin-right:0.22222em;">Y</span></span></span></span><span class="vlist-s"></span></span><span class="vlist-r"><span class="vlist" style="height:0.15em;"><span></span></span></span></span></span></span></span></span><span style="top:-3.23em;"><span class="pstrut" style="height:3em;"></span><span class="frac-line" style="border-bottom-width:0.04em;"></span></span><span style="top:-3.677em;"><span class="pstrut" style="height:3em;"></span><span class="mord"><span class="mord text"><span class="mord">cov</span></span><span class="mopen">(</span><span class="mord mathnormal" style="margin-right:0.07847em;">X</span><span class="mpunct">,</span><span class="mspace" style="margin-right:0.16666666666666666em;"></span><span class="mord mathnormal" style="margin-right:0.22222em;">Y</span><span class="mclose">)</span></span></span></span><span class="vlist-s"></span></span><span class="vlist-r"><span class="vlist" style="height:0.8360000000000001em;"><span></span></span></span></span></span><span class="mclose nulldelimiter"></span></span><span class="mspace" style="margin-right:0.2777777777777778em;"></span><span class="mrel">=</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span></span><span class="base"><span class="strut" style="height:2.263em;vertical-align:-0.8360000000000001em;"></span><span class="mord"><span class="mopen nulldelimiter"></span><span class="mfrac"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:1.427em;"><span style="top:-2.3139999999999996em;"><span class="pstrut" style="height:3em;"></span><span class="mord"><span class="mord"><span class="mord mathnormal" style="margin-right:0.03588em;">σ</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.32833099999999993em;"><span style="top:-2.5500000000000003em;margin-left:-0.03588em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mathnormal mtight" style="margin-right:0.07847em;">X</span></span></span></span><span class="vlist-s"></span></span><span class="vlist-r"><span class="vlist" style="height:0.15em;"><span></span></span></span></span></span></span><span class="mord"><span class="mord mathnormal" style="margin-right:0.03588em;">σ</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.32833099999999993em;"><span style="top:-2.5500000000000003em;margin-left:-0.03588em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mathnormal mtight" style="margin-right:0.22222em;">Y</span></span></span></span><span class="vlist-s"></span></span><span class="vlist-r"><span class="vlist" style="height:0.15em;"><span></span></span></span></span></span></span></span></span><span style="top:-3.23em;"><span class="pstrut" style="height:3em;"></span><span class="frac-line" style="border-bottom-width:0.04em;"></span></span><span style="top:-3.677em;"><span class="pstrut" style="height:3em;"></span><span class="mord"><span class="mord mathnormal" style="margin-right:0.05764em;">E</span><span class="mopen">[</span><span class="mopen">(</span><span class="mord mathnormal" style="margin-right:0.07847em;">X</span><span class="mspace" style="margin-right:0.2222222222222222em;"></span><span class="mbin">−</span><span class="mspace" style="margin-right:0.2222222222222222em;"></span><span class="mord"><span class="mord mathnormal">μ</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.32833099999999993em;"><span style="top:-2.5500000000000003em;margin-left:0em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mathnormal mtight" style="margin-right:0.07847em;">X</span></span></span></span><span class="vlist-s"></span></span><span class="vlist-r"><span class="vlist" style="height:0.15em;"><span></span></span></span></span></span></span><span class="mclose">)</span><span class="mopen">(</span><span class="mord mathnormal" style="margin-right:0.22222em;">Y</span><span class="mspace" style="margin-right:0.2222222222222222em;"></span><span class="mbin">−</span><span class="mspace" style="margin-right:0.2222222222222222em;"></span><span class="mord"><span class="mord mathnormal">μ</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.32833099999999993em;"><span style="top:-2.5500000000000003em;margin-left:0em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mathnormal mtight" style="margin-right:0.22222em;">Y</span></span></span></span><span class="vlist-s"></span></span><span class="vlist-r"><span class="vlist" style="height:0.15em;"><span></span></span></span></span></span></span><span class="mclose">)</span><span class="mclose">]</span></span></span></span><span class="vlist-s"></span></span><span class="vlist-r"><span class="vlist" style="height:0.8360000000000001em;"><span></span></span></span></span></span><span class="mclose nulldelimiter"></span></span></span></span></span></span></p></li><li><p>余弦相似度</p><p><span class="katex-display"><span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><semantics><mrow><mi>T</mi><mo stretchy="false">(</mo><mi>x</mi><mo separator="true">,</mo><mi>y</mi><mo stretchy="false">)</mo><mo>=</mo><mfrac><mrow><mi>x</mi><mi>y</mi></mrow><mrow><mi mathvariant="normal">∥</mi><mi>x</mi><msup><mi mathvariant="normal">∥</mi><mn>2</mn></msup><mo>×</mo><mi mathvariant="normal">∥</mi><mi>y</mi><msup><mi mathvariant="normal">∥</mi><mn>2</mn></msup></mrow></mfrac><mo>=</mo><mfrac><mrow><mo>∑</mo><mrow><msub><mi>x</mi><mi>i</mi></msub><msub><mi>y</mi><mi>i</mi></msub></mrow></mrow><mrow><msqrt><mrow><mo>∑</mo><msup><msub><mi>x</mi><mi>i</mi></msub><mn>2</mn></msup></mrow></msqrt><msqrt><mrow><mo>∑</mo><msup><msub><mi>y</mi><mi>i</mi></msub><mn>2</mn></msup></mrow></msqrt></mrow></mfrac></mrow><annotation encoding="application/x-tex">T(x,y)=\frac{xy}{\|x\|^2\times\|y\|^2}=\frac{\sum{x_iy_i}}{\sqrt{\sum{x_i}^2}\sqrt{\sum{y_i}^2}}</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:1em;vertical-align:-0.25em;"></span><span class="mord mathnormal" style="margin-right:0.13889em;">T</span><span class="mopen">(</span><span class="mord mathnormal">x</span><span class="mpunct">,</span><span class="mspace" style="margin-right:0.16666666666666666em;"></span><span class="mord mathnormal" style="margin-right:0.03588em;">y</span><span class="mclose">)</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span><span class="mrel">=</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span></span><span class="base"><span class="strut" style="height:2.04356em;vertical-align:-0.936em;"></span><span class="mord"><span class="mopen nulldelimiter"></span><span class="mfrac"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:1.1075599999999999em;"><span style="top:-2.314em;"><span class="pstrut" style="height:3em;"></span><span class="mord"><span class="mord">∥</span><span class="mord mathnormal">x</span><span class="mord"><span class="mord">∥</span><span class="msupsub"><span class="vlist-t"><span class="vlist-r"><span class="vlist" style="height:0.740108em;"><span style="top:-2.9890000000000003em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight">2</span></span></span></span></span></span></span></span><span class="mspace" style="margin-right:0.2222222222222222em;"></span><span class="mbin">×</span><span class="mspace" style="margin-right:0.2222222222222222em;"></span><span class="mord">∥</span><span class="mord mathnormal" style="margin-right:0.03588em;">y</span><span class="mord"><span class="mord">∥</span><span class="msupsub"><span class="vlist-t"><span class="vlist-r"><span class="vlist" style="height:0.740108em;"><span style="top:-2.9890000000000003em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight">2</span></span></span></span></span></span></span></span></span></span><span style="top:-3.23em;"><span class="pstrut" style="height:3em;"></span><span class="frac-line" style="border-bottom-width:0.04em;"></span></span><span style="top:-3.677em;"><span class="pstrut" style="height:3em;"></span><span class="mord"><span class="mord mathnormal">x</span><span class="mord mathnormal" style="margin-right:0.03588em;">y</span></span></span></span><span class="vlist-s"></span></span><span class="vlist-r"><span class="vlist" style="height:0.936em;"><span></span></span></span></span></span><span class="mclose nulldelimiter"></span></span><span class="mspace" style="margin-right:0.2777777777777778em;"></span><span class="mrel">=</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span></span><span class="base"><span class="strut" style="height:2.557em;vertical-align:-1.13em;"></span><span class="mord"><span class="mopen nulldelimiter"></span><span class="mfrac"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:1.427em;"><span style="top:-2.175005em;"><span class="pstrut" style="height:3em;"></span><span class="mord"><span class="mord sqrt"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.934995em;"><span class="svg-align" style="top:-3.2em;"><span class="pstrut" style="height:3.2em;"></span><span class="mord" style="padding-left:1em;"><span class="mop op-symbol small-op" style="position:relative;top:-0.0000050000000000050004em;">∑</span><span class="mspace" style="margin-right:0.16666666666666666em;"></span><span class="mord"><span class="mord"><span class="mord"><span class="mord mathnormal">x</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.31166399999999994em;"><span style="top:-2.5500000000000003em;margin-left:0em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mathnormal mtight">i</span></span></span></span><span class="vlist-s"></span></span><span class="vlist-r"><span class="vlist" style="height:0.15em;"><span></span></span></span></span></span></span></span><span class="msupsub"><span class="vlist-t"><span class="vlist-r"><span class="vlist" style="height:0.740108em;"><span style="top:-2.9890000000000003em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight">2</span></span></span></span></span></span></span></span></span></span><span style="top:-2.894995em;"><span class="pstrut" style="height:3.2em;"></span><span class="hide-tail" style="min-width:1.02em;height:1.28em;"><svg width='400em' height='1.28em' viewBox='0 0 400000 1296' preserveAspectRatio='xMinYMin slice'><path d='M263,681c0.7,0,18,39.7,52,119c34,79.3,68.167,158.7,102.5,238c34.3,79.3,51.8,119.3,52.5,120c340,-704.7,510.7,-1060.3,512,-1067l0 -0c4.7,-7.3,11,-11,19,-11H40000v40H1012.3s-271.3,567,-271.3,567c-38.7,80.7,-84,175,-136,283c-52,108,-89.167,185.3,-111.5,232c-22.3,46.7,-33.8,70.3,-34.5,71c-4.7,4.7,-12.3,7,-23,7s-12,-1,-12,-1s-109,-253,-109,-253c-72.7,-168,-109.3,-252,-110,-252c-10.7,8,-22,16.7,-34,26c-22,17.3,-33.3,26,-34,26s-26,-26,-26,-26s76,-59,76,-59s76,-60,76,-60zM1001 80h400000v40h-400000z'/></svg></span></span></span><span class="vlist-s"></span></span><span class="vlist-r"><span class="vlist" style="height:0.30500499999999997em;"><span></span></span></span></span></span><span class="mord sqrt"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.934995em;"><span class="svg-align" style="top:-3.2em;"><span class="pstrut" style="height:3.2em;"></span><span class="mord" style="padding-left:1em;"><span class="mop op-symbol small-op" style="position:relative;top:-0.0000050000000000050004em;">∑</span><span class="mspace" style="margin-right:0.16666666666666666em;"></span><span class="mord"><span class="mord"><span class="mord"><span class="mord mathnormal" style="margin-right:0.03588em;">y</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.31166399999999994em;"><span style="top:-2.5500000000000003em;margin-left:-0.03588em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mathnormal mtight">i</span></span></span></span><span class="vlist-s"></span></span><span class="vlist-r"><span class="vlist" style="height:0.15em;"><span></span></span></span></span></span></span></span><span class="msupsub"><span class="vlist-t"><span class="vlist-r"><span class="vlist" style="height:0.740108em;"><span style="top:-2.9890000000000003em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight">2</span></span></span></span></span></span></span></span></span></span><span style="top:-2.894995em;"><span class="pstrut" style="height:3.2em;"></span><span class="hide-tail" style="min-width:1.02em;height:1.28em;"><svg width='400em' height='1.28em' viewBox='0 0 400000 1296' preserveAspectRatio='xMinYMin slice'><path d='M263,681c0.7,0,18,39.7,52,119c34,79.3,68.167,158.7,102.5,238c34.3,79.3,51.8,119.3,52.5,120c340,-704.7,510.7,-1060.3,512,-1067l0 -0c4.7,-7.3,11,-11,19,-11H40000v40H1012.3s-271.3,567,-271.3,567c-38.7,80.7,-84,175,-136,283c-52,108,-89.167,185.3,-111.5,232c-22.3,46.7,-33.8,70.3,-34.5,71c-4.7,4.7,-12.3,7,-23,7s-12,-1,-12,-1s-109,-253,-109,-253c-72.7,-168,-109.3,-252,-110,-252c-10.7,8,-22,16.7,-34,26c-22,17.3,-33.3,26,-34,26s-26,-26,-26,-26s76,-59,76,-59s76,-60,76,-60zM1001 80h400000v40h-400000z'/></svg></span></span></span><span class="vlist-s"></span></span><span class="vlist-r"><span class="vlist" style="height:0.30500499999999997em;"><span></span></span></span></span></span></span></span><span style="top:-3.23em;"><span class="pstrut" style="height:3em;"></span><span class="frac-line" style="border-bottom-width:0.04em;"></span></span><span style="top:-3.677em;"><span class="pstrut" style="height:3em;"></span><span class="mord"><span class="mop op-symbol small-op" style="position:relative;top:-0.0000050000000000050004em;">∑</span><span class="mspace" style="margin-right:0.16666666666666666em;"></span><span class="mord"><span class="mord"><span class="mord mathnormal">x</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.31166399999999994em;"><span style="top:-2.5500000000000003em;margin-left:0em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mathnormal mtight">i</span></span></span></span><span class="vlist-s"></span></span><span class="vlist-r"><span class="vlist" style="height:0.15em;"><span></span></span></span></span></span></span><span class="mord"><span class="mord mathnormal" style="margin-right:0.03588em;">y</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.31166399999999994em;"><span style="top:-2.5500000000000003em;margin-left:-0.03588em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mathnormal mtight">i</span></span></span></span><span class="vlist-s"></span></span><span class="vlist-r"><span class="vlist" style="height:0.15em;"><span></span></span></span></span></span></span></span></span></span></span><span class="vlist-s"></span></span><span class="vlist-r"><span class="vlist" style="height:1.13em;"><span></span></span></span></span></span><span class="mclose nulldelimiter"></span></span></span></span></span></span></p></li><li><p>协方差</p><p><span class="katex-display"><span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><semantics><mrow><mtext>cov</mtext><mo stretchy="false">(</mo><mi>X</mi><mo separator="true">,</mo><mi>Y</mi><mo stretchy="false">)</mo><mo>=</mo><mfrac><mrow><munderover><mo>∑</mo><mrow><mi>i</mi><mo>=</mo><mn>1</mn></mrow><mi>n</mi></munderover><mrow><mo stretchy="false">(</mo><msub><mi>X</mi><mi>i</mi></msub><mo>−</mo><mover accent="true"><mi>X</mi><mo stretchy="true">‾</mo></mover><mo stretchy="false">)</mo><mo stretchy="false">(</mo><msub><mi>Y</mi><mi>i</mi></msub><mo>−</mo><mover accent="true"><mi>Y</mi><mo stretchy="true">‾</mo></mover><mo stretchy="false">)</mo></mrow></mrow><mrow><mi>n</mi><mo>−</mo><mn>1</mn></mrow></mfrac></mrow><annotation encoding="application/x-tex">\text{cov}(X,Y)=\frac{\sum_{i=1}^{n}{(X_i-\overline{X})(Y_i-\overline{Y})}}{n-1}</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:1em;vertical-align:-0.25em;"></span><span class="mord text"><span class="mord">cov</span></span><span class="mopen">(</span><span class="mord mathnormal" style="margin-right:0.07847em;">X</span><span class="mpunct">,</span><span class="mspace" style="margin-right:0.16666666666666666em;"></span><span class="mord mathnormal" style="margin-right:0.22222em;">Y</span><span class="mclose">)</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span><span class="mrel">=</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span></span><span class="base"><span class="strut" style="height:2.3423700000000003em;vertical-align:-0.7693300000000001em;"></span><span class="mord"><span class="mopen nulldelimiter"></span><span class="mfrac"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:1.5730400000000002em;"><span style="top:-2.314em;"><span class="pstrut" style="height:3em;"></span><span class="mord"><span class="mord mathnormal">n</span><span class="mspace" style="margin-right:0.2222222222222222em;"></span><span class="mbin">−</span><span class="mspace" style="margin-right:0.2222222222222222em;"></span><span class="mord">1</span></span></span><span style="top:-3.23em;"><span class="pstrut" style="height:3em;"></span><span class="frac-line" style="border-bottom-width:0.04em;"></span></span><span style="top:-3.6897100000000003em;"><span class="pstrut" style="height:3em;"></span><span class="mord"><span class="mop"><span class="mop op-symbol small-op" style="position:relative;top:-0.0000050000000000050004em;">∑</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.804292em;"><span style="top:-2.40029em;margin-left:0em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight"><span class="mord mathnormal mtight">i</span><span class="mrel mtight">=</span><span class="mord mtight">1</span></span></span></span><span style="top:-3.2029em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight"><span class="mord mathnormal mtight">n</span></span></span></span></span><span class="vlist-s"></span></span><span class="vlist-r"><span class="vlist" style="height:0.29971000000000003em;"><span></span></span></span></span></span></span><span class="mspace" style="margin-right:0.16666666666666666em;"></span><span class="mord"><span class="mopen">(</span><span class="mord"><span class="mord mathnormal" style="margin-right:0.07847em;">X</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.31166399999999994em;"><span style="top:-2.5500000000000003em;margin-left:-0.07847em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mathnormal mtight">i</span></span></span></span><span class="vlist-s"></span></span><span class="vlist-r"><span class="vlist" style="height:0.15em;"><span></span></span></span></span></span></span><span class="mspace" style="margin-right:0.2222222222222222em;"></span><span class="mbin">−</span><span class="mspace" style="margin-right:0.2222222222222222em;"></span><span class="mord overline"><span class="vlist-t"><span class="vlist-r"><span class="vlist" style="height:0.8833300000000001em;"><span style="top:-3em;"><span class="pstrut" style="height:3em;"></span><span class="mord"><span class="mord mathnormal" style="margin-right:0.07847em;">X</span></span></span><span style="top:-3.80333em;"><span class="pstrut" style="height:3em;"></span><span class="overline-line" style="border-bottom-width:0.04em;"></span></span></span></span></span></span><span class="mclose">)</span><span class="mopen">(</span><span class="mord"><span class="mord mathnormal" style="margin-right:0.22222em;">Y</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.31166399999999994em;"><span style="top:-2.5500000000000003em;margin-left:-0.22222em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mathnormal mtight">i</span></span></span></span><span class="vlist-s"></span></span><span class="vlist-r"><span class="vlist" style="height:0.15em;"><span></span></span></span></span></span></span><span class="mspace" style="margin-right:0.2222222222222222em;"></span><span class="mbin">−</span><span class="mspace" style="margin-right:0.2222222222222222em;"></span><span class="mord overline"><span class="vlist-t"><span class="vlist-r"><span class="vlist" style="height:0.8833300000000001em;"><span style="top:-3em;"><span class="pstrut" style="height:3em;"></span><span class="mord"><span class="mord mathnormal" style="margin-right:0.22222em;">Y</span></span></span><span style="top:-3.80333em;"><span class="pstrut" style="height:3em;"></span><span class="overline-line" style="border-bottom-width:0.04em;"></span></span></span></span></span></span><span class="mclose">)</span></span></span></span></span><span class="vlist-s"></span></span><span class="vlist-r"><span class="vlist" style="height:0.7693300000000001em;"><span></span></span></span></span></span><span class="mclose nulldelimiter"></span></span></span></span></span></span></p></li></ul>]]></content>
<categories>
<category> 数学 </category>
<category> 机器学习 </category>
</categories>
<tags>
<tag> 算法 </tag>
<tag> 机器学习 </tag>
<tag> 推荐系统 </tag>
<tag> 协同过滤 </tag>
<tag> 隐语义模型 </tag>
<tag> 奇异值分解 </tag>
</tags>
</entry>
<entry>
<title>人民网评:B站向北邮师生道歉,警示了谁?</title>
<link href="posts/30315/"/>
<url>posts/30315/</url>
<content type="html"><![CDATA[<script src="\assets\js\APlayer.min.js"> </script><h1>人民网评:B站向北邮师生道歉,警示了谁?</h1><blockquote><p>转载自:<a href="http://opinion.people.com.cn/n1/2021/0426/c223228-32088418.html">http://opinion.people.com.cn/n1/2021/0426/c223228-32088418.html</a></p><p>2021年04月26日12:07 | 来源:<a href="http://opinion.people.com.cn/">人民网-观点频道</a></p></blockquote><p>4月24日,有自称是北京邮电大学的学生在网上称,B站面试官在面试时炫耀资产,而且贬低北邮人。25日下午,B站官方回应称,面试员存在说教与争论等不职业行为,但不存在攻击北邮等言论,并表示:“因这次事件给北邮同学造成了困扰,公司向所有北邮师生表示诚恳的歉意。”</p><p>涉事面试员因面试时说教、争论,向当事人道歉,B站因此次事件给北邮同学造成困扰,向所有北邮师生表示歉意,尽管是危机“公关”,但也算完成了和解。<strong>对双方来说,只有实现握手言和,并举一反三,事件才能划上句号。然而对即将到来的校招季来说,此事还是起到了警示作用。</strong></p><p><img src="https://gitee.com/sg2019/picgo/raw/master/bilibili-night.jpeg" alt=""></p><p>事实上,招聘方和应聘方是利益共同体,一方是想招到为其所用的优秀人才,一方是想找到可以施展才华的宽广舞台。双方本质上有着共同的目标,不该也不能生发龃龉,否则没有谁是赢家,只会带来双输。</p><p>不可否认,一些招聘企业对应聘者缺乏基本的尊重。比如,有的企业HR在校招宣讲会上称,“管培生只要985、211的学生”。有的公司HR甚至说“对不起,我们只要二本以上统招的”,并“补刀”称:“考不上本科的都是智商有问题的”。如此乱象,令人愕然。无论这样的HR能否代表公司立场,但抛出这样的观点,都是极不称职的,必定给公司抹黑,必定激化矛盾,必定引发社会谴责。</p><p>向社会提供就业机会,值得肯定。 <strong>但企业招聘时不能高高在上,面试官在面试应聘者时不能忘乎所以。</strong> 尊重应聘者,既是基本的企业伦理,也是应有的道义责任。无论羞辱应聘者还是歧视应聘者,都是下下策,不可能赢得应聘者的好感,也不可能赢得社会认可。</p><p>据报道,2021届高校毕业生总规模预计909万人,同比增加35万,面临的就业形势严峻复杂。当前,各级党委和政府十分关心高校毕业生等群体就业,将其作为重大民生工作任务,并积极创造条件确保高校毕业生就业。在这种背景下,有关企业应积极响应号召,为大学生就业创造有利条件,而不是设置障碍;应该用善意带给他们温情和信心,而不是出语伤人。</p><p><img src="https://gitee.com/sg2019/picgo/raw/master/bupt-winter.jpeg" alt=""></p><p><strong>对于大学生来说,找工作时也要不卑不亢,坚定从容。</strong> 面对再大的企业,都要展现出应有的青春风采,维护应有的人格尊严。同时,还要善于维护自身的合法权益。比如,碰到倨傲的面试官要敢于据理以争,碰到不合理的规定应敢于说不,遇到明显带有歧视色彩的言行应注意收集证据。对那些设置招聘陷阱,乃至坑骗应聘者的不法行径,更要自觉拿起法律武器保护自己。</p><p><strong>越是就业形势严峻,越要关心关爱高校毕业生;越是就业市场供过于求,越要善待每一名应聘者,让他们感受到制度暖意。</strong> 这是相关部门的责任,也需要全社会参与。就业一头连着千万家庭,一头连着经济大势,被誉为最大的民生工程和民心工程,多用心、用情和用力,让大学生等群体的就业之路更顺畅,是所有人的朴素愿望。</p><blockquote><p>相关参考:学习大国</p></blockquote>]]></content>
<categories>
<category> 思想 </category>
<category> 时评 </category>
</categories>
<tags>
<tag> 时评 </tag>
</tags>
</entry>
<entry>
<title>形式语言与自动机——语言及文法</title>
<link href="posts/51055/"/>
<url>posts/51055/</url>
<content type="html"><![CDATA[<script src="\assets\js\APlayer.min.js"> </script><h1>语言及文法</h1><p>主要内容:</p><ul><li>定义形式语言的术语</li><li>给出文法的定义和文法的分类</li></ul><p>要求掌握:</p><ul><li>语言和文法的形式定义</li><li>CHOMSKY文法体系的分类</li></ul><h2 id="语言的定义与运算">语言的定义与运算</h2><ul><li><p>字母表:字符的有限集合</p></li><li><p>字符串:由字母表中的字符构成的<strong>有限</strong>序列</p></li></ul><h3 id="关于字符串的运算">关于字符串的运算</h3><ul><li><p>连接(concatenation)</p><p>性质:</p><ul><li><span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mo stretchy="false">(</mo><mi>x</mi><mi>y</mi><mo stretchy="false">)</mo><mi>z</mi><mo>=</mo><mi>x</mi><mo stretchy="false">(</mo><mi>y</mi><mi>z</mi><mo stretchy="false">)</mo></mrow><annotation encoding="application/x-tex">(xy)z = x(yz)</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:1em;vertical-align:-0.25em;"></span><span class="mopen">(</span><span class="mord mathnormal">x</span><span class="mord mathnormal" style="margin-right:0.03588em;">y</span><span class="mclose">)</span><span class="mord mathnormal" style="margin-right:0.04398em;">z</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span><span class="mrel">=</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span></span><span class="base"><span class="strut" style="height:1em;vertical-align:-0.25em;"></span><span class="mord mathnormal">x</span><span class="mopen">(</span><span class="mord mathnormal" style="margin-right:0.03588em;">y</span><span class="mord mathnormal" style="margin-right:0.04398em;">z</span><span class="mclose">)</span></span></span></span></li><li><span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>ϵ</mi><mi>x</mi><mo>=</mo><mi>x</mi><mi>ϵ</mi><mo>=</mo><mi>x</mi></mrow><annotation encoding="application/x-tex">\epsilon x = x \epsilon = x</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.43056em;vertical-align:0em;"></span><span class="mord mathnormal">ϵ</span><span class="mord mathnormal">x</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span><span class="mrel">=</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span></span><span class="base"><span class="strut" style="height:0.43056em;vertical-align:0em;"></span><span class="mord mathnormal">x</span><span class="mord mathnormal">ϵ</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span><span class="mrel">=</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span></span><span class="base"><span class="strut" style="height:0.43056em;vertical-align:0em;"></span><span class="mord mathnormal">x</span></span></span></span></li><li><span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi mathvariant="normal">∣</mi><mi>x</mi><mi>y</mi><mi mathvariant="normal">∣</mi><mo>=</mo><mi mathvariant="normal">∣</mi><mi>x</mi><mi mathvariant="normal">∣</mi><mo>+</mo><mi mathvariant="normal">∣</mi><mi>y</mi><mi mathvariant="normal">∣</mi></mrow><annotation encoding="application/x-tex">|xy|=|x|+|y|</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:1em;vertical-align:-0.25em;"></span><span class="mord">∣</span><span class="mord mathnormal">x</span><span class="mord mathnormal" style="margin-right:0.03588em;">y</span><span class="mord">∣</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span><span class="mrel">=</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span></span><span class="base"><span class="strut" style="height:1em;vertical-align:-0.25em;"></span><span class="mord">∣</span><span class="mord mathnormal">x</span><span class="mord">∣</span><span class="mspace" style="margin-right:0.2222222222222222em;"></span><span class="mbin">+</span><span class="mspace" style="margin-right:0.2222222222222222em;"></span></span><span class="base"><span class="strut" style="height:1em;vertical-align:-0.25em;"></span><span class="mord">∣</span><span class="mord mathnormal" style="margin-right:0.03588em;">y</span><span class="mord">∣</span></span></span></span></li></ul></li><li><p>其他:去头字符,取尾部,子串匹配</p><ul><li><p><strong>空串是任何字符的前缀,后缀及子串</strong></p></li><li><p>字符串<span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>ω</mi></mrow><annotation encoding="application/x-tex">\omega</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.43056em;vertical-align:0em;"></span><span class="mord mathnormal" style="margin-right:0.03588em;">ω</span></span></span></span>的逆用<span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mover accent="true"><mi>ω</mi><mo>~</mo></mover></mrow><annotation encoding="application/x-tex">\tilde\omega</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.6678599999999999em;vertical-align:0em;"></span><span class="mord accent"><span class="vlist-t"><span class="vlist-r"><span class="vlist" style="height:0.6678599999999999em;"><span style="top:-3em;"><span class="pstrut" style="height:3em;"></span><span class="mord mathnormal" style="margin-right:0.03588em;">ω</span></span><span style="top:-3.35em;"><span class="pstrut" style="height:3em;"></span><span class="accent-body" style="left:-0.25em;"><span class="mord">~</span></span></span></span></span></span></span></span></span></span>表示,是字符串<span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>ω</mi></mrow><annotation encoding="application/x-tex">\omega</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.43056em;vertical-align:0em;"></span><span class="mord mathnormal" style="margin-right:0.03588em;">ω</span></span></span></span>的倒置</p></li><li><p>空串<span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>ϵ</mi></mrow><annotation encoding="application/x-tex">\epsilon</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.43056em;vertical-align:0em;"></span><span class="mord mathnormal">ϵ</span></span></span></span>的逆还是<span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>ϵ</mi></mrow><annotation encoding="application/x-tex">\epsilon</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.43056em;vertical-align:0em;"></span><span class="mord mathnormal">ϵ</span></span></span></span></p></li></ul></li></ul><h3 id="字母表的幂运算">字母表的幂运算</h3><ul><li><p><span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mo>∗</mo></mrow><annotation encoding="application/x-tex">*</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.46528em;vertical-align:0em;"></span><span class="mord">∗</span></span></span></span> 闭包</p><p><span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msup><mi>T</mi><mo lspace="0em" rspace="0em">∗</mo></msup><mo>=</mo><msup><mi>T</mi><mn>0</mn></msup><mo>∪</mo><msup><mi>T</mi><mn>1</mn></msup><mo>∪</mo><msup><mi>T</mi><mn>2</mn></msup><mo>∪</mo><mo>…</mo></mrow><annotation encoding="application/x-tex">T^{ * } = T^{0} \cup T^{1} \cup T^{2} \cup \dots</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.688696em;vertical-align:0em;"></span><span class="mord"><span class="mord mathnormal" style="margin-right:0.13889em;">T</span><span class="msupsub"><span class="vlist-t"><span class="vlist-r"><span class="vlist" style="height:0.688696em;"><span style="top:-3.063em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight"><span class="mord mtight">∗</span></span></span></span></span></span></span></span></span><span class="mspace" style="margin-right:0.2777777777777778em;"></span><span class="mrel">=</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span></span><span class="base"><span class="strut" style="height:0.8141079999999999em;vertical-align:0em;"></span><span class="mord"><span class="mord mathnormal" style="margin-right:0.13889em;">T</span><span class="msupsub"><span class="vlist-t"><span class="vlist-r"><span class="vlist" style="height:0.8141079999999999em;"><span style="top:-3.063em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight"><span class="mord mtight">0</span></span></span></span></span></span></span></span></span><span class="mspace" style="margin-right:0.2222222222222222em;"></span><span class="mbin">∪</span><span class="mspace" style="margin-right:0.2222222222222222em;"></span></span><span class="base"><span class="strut" style="height:0.8141079999999999em;vertical-align:0em;"></span><span class="mord"><span class="mord mathnormal" style="margin-right:0.13889em;">T</span><span class="msupsub"><span class="vlist-t"><span class="vlist-r"><span class="vlist" style="height:0.8141079999999999em;"><span style="top:-3.063em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight"><span class="mord mtight">1</span></span></span></span></span></span></span></span></span><span class="mspace" style="margin-right:0.2222222222222222em;"></span><span class="mbin">∪</span><span class="mspace" style="margin-right:0.2222222222222222em;"></span></span><span class="base"><span class="strut" style="height:0.8141079999999999em;vertical-align:0em;"></span><span class="mord"><span class="mord mathnormal" style="margin-right:0.13889em;">T</span><span class="msupsub"><span class="vlist-t"><span class="vlist-r"><span class="vlist" style="height:0.8141079999999999em;"><span style="top:-3.063em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight"><span class="mord mtight">2</span></span></span></span></span></span></span></span></span><span class="mspace" style="margin-right:0.2222222222222222em;"></span><span class="mbin">∪</span><span class="mspace" style="margin-right:0.2222222222222222em;"></span></span><span class="base"><span class="strut" style="height:0.12em;vertical-align:0em;"></span><span class="minner">…</span></span></span></span></p></li><li><p><span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mo>+</mo></mrow><annotation encoding="application/x-tex">+</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.66666em;vertical-align:-0.08333em;"></span><span class="mord">+</span></span></span></span> 闭包</p><p><span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msup><mi>T</mi><mo lspace="0em" rspace="0em">+</mo></msup><mo>=</mo><msup><mi>T</mi><mn>1</mn></msup><mo>∪</mo><msup><mi>T</mi><mn>2</mn></msup><mo>∪</mo><msup><mi>T</mi><mn>3</mn></msup><mo>∪</mo><mo>…</mo></mrow><annotation encoding="application/x-tex">T^{+} = T^{1} \cup T^{2} \cup T^{3} \cup \dots</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.771331em;vertical-align:0em;"></span><span class="mord"><span class="mord mathnormal" style="margin-right:0.13889em;">T</span><span class="msupsub"><span class="vlist-t"><span class="vlist-r"><span class="vlist" style="height:0.771331em;"><span style="top:-3.063em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight"><span class="mord mtight">+</span></span></span></span></span></span></span></span></span><span class="mspace" style="margin-right:0.2777777777777778em;"></span><span class="mrel">=</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span></span><span class="base"><span class="strut" style="height:0.8141079999999999em;vertical-align:0em;"></span><span class="mord"><span class="mord mathnormal" style="margin-right:0.13889em;">T</span><span class="msupsub"><span class="vlist-t"><span class="vlist-r"><span class="vlist" style="height:0.8141079999999999em;"><span style="top:-3.063em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight"><span class="mord mtight">1</span></span></span></span></span></span></span></span></span><span class="mspace" style="margin-right:0.2222222222222222em;"></span><span class="mbin">∪</span><span class="mspace" style="margin-right:0.2222222222222222em;"></span></span><span class="base"><span class="strut" style="height:0.8141079999999999em;vertical-align:0em;"></span><span class="mord"><span class="mord mathnormal" style="margin-right:0.13889em;">T</span><span class="msupsub"><span class="vlist-t"><span class="vlist-r"><span class="vlist" style="height:0.8141079999999999em;"><span style="top:-3.063em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight"><span class="mord mtight">2</span></span></span></span></span></span></span></span></span><span class="mspace" style="margin-right:0.2222222222222222em;"></span><span class="mbin">∪</span><span class="mspace" style="margin-right:0.2222222222222222em;"></span></span><span class="base"><span class="strut" style="height:0.8141079999999999em;vertical-align:0em;"></span><span class="mord"><span class="mord mathnormal" style="margin-right:0.13889em;">T</span><span class="msupsub"><span class="vlist-t"><span class="vlist-r"><span class="vlist" style="height:0.8141079999999999em;"><span style="top:-3.063em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight"><span class="mord mtight">3</span></span></span></span></span></span></span></span></span><span class="mspace" style="margin-right:0.2222222222222222em;"></span><span class="mbin">∪</span><span class="mspace" style="margin-right:0.2222222222222222em;"></span></span><span class="base"><span class="strut" style="height:0.12em;vertical-align:0em;"></span><span class="minner">…</span></span></span></span></p></li><li><p><span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msup><mi>T</mi><mo lspace="0em" rspace="0em">∗</mo></msup><mo>=</mo><msup><mi>T</mi><mo lspace="0em" rspace="0em">+</mo></msup><mo>∪</mo><mo stretchy="false">{</mo><mi>ϵ</mi><mo stretchy="false">}</mo></mrow><annotation encoding="application/x-tex">T^{ * } = T^{+} \cup \{ \epsilon \}</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.688696em;vertical-align:0em;"></span><span class="mord"><span class="mord mathnormal" style="margin-right:0.13889em;">T</span><span class="msupsub"><span class="vlist-t"><span class="vlist-r"><span class="vlist" style="height:0.688696em;"><span style="top:-3.063em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight"><span class="mord mtight">∗</span></span></span></span></span></span></span></span></span><span class="mspace" style="margin-right:0.2777777777777778em;"></span><span class="mrel">=</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span></span><span class="base"><span class="strut" style="height:0.771331em;vertical-align:0em;"></span><span class="mord"><span class="mord mathnormal" style="margin-right:0.13889em;">T</span><span class="msupsub"><span class="vlist-t"><span class="vlist-r"><span class="vlist" style="height:0.771331em;"><span style="top:-3.063em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight"><span class="mord mtight">+</span></span></span></span></span></span></span></span></span><span class="mspace" style="margin-right:0.2222222222222222em;"></span><span class="mbin">∪</span><span class="mspace" style="margin-right:0.2222222222222222em;"></span></span><span class="base"><span class="strut" style="height:1em;vertical-align:-0.25em;"></span><span class="mopen">{</span><span class="mord mathnormal">ϵ</span><span class="mclose">}</span></span></span></span>,<span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msup><mi>T</mi><mo lspace="0em" rspace="0em">+</mo></msup><mo>=</mo><msup><mi>T</mi><mo lspace="0em" rspace="0em">∗</mo></msup><mo>−</mo><mo stretchy="false">{</mo><mi>ϵ</mi><mo stretchy="false">}</mo></mrow><annotation encoding="application/x-tex">T^{+} = T^{ * } - \{ \epsilon \}</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.771331em;vertical-align:0em;"></span><span class="mord"><span class="mord mathnormal" style="margin-right:0.13889em;">T</span><span class="msupsub"><span class="vlist-t"><span class="vlist-r"><span class="vlist" style="height:0.771331em;"><span style="top:-3.063em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight"><span class="mord mtight">+</span></span></span></span></span></span></span></span></span><span class="mspace" style="margin-right:0.2777777777777778em;"></span><span class="mrel">=</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span></span><span class="base"><span class="strut" style="height:0.772026em;vertical-align:-0.08333em;"></span><span class="mord"><span class="mord mathnormal" style="margin-right:0.13889em;">T</span><span class="msupsub"><span class="vlist-t"><span class="vlist-r"><span class="vlist" style="height:0.688696em;"><span style="top:-3.063em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight"><span class="mord mtight">∗</span></span></span></span></span></span></span></span></span><span class="mspace" style="margin-right:0.2222222222222222em;"></span><span class="mbin">−</span><span class="mspace" style="margin-right:0.2222222222222222em;"></span></span><span class="base"><span class="strut" style="height:1em;vertical-align:-0.25em;"></span><span class="mopen">{</span><span class="mord mathnormal">ϵ</span><span class="mclose">}</span></span></span></span></p></li></ul><h3 id="闭包的物理意义">闭包的物理意义</h3><ul><li><span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>T</mi></mrow><annotation encoding="application/x-tex">T</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.68333em;vertical-align:0em;"></span><span class="mord mathnormal" style="margin-right:0.13889em;">T</span></span></span></span>的星闭包<span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msup><mi>T</mi><mo lspace="0em" rspace="0em">∗</mo></msup></mrow><annotation encoding="application/x-tex">T^{ * }</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.688696em;vertical-align:0em;"></span><span class="mord"><span class="mord mathnormal" style="margin-right:0.13889em;">T</span><span class="msupsub"><span class="vlist-t"><span class="vlist-r"><span class="vlist" style="height:0.688696em;"><span style="top:-3.063em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight"><span class="mord mtight">∗</span></span></span></span></span></span></span></span></span></span></span></span>:字母表T上所有的字符串和空串的集合</li><li><span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>T</mi></mrow><annotation encoding="application/x-tex">T</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.68333em;vertical-align:0em;"></span><span class="mord mathnormal" style="margin-right:0.13889em;">T</span></span></span></span>的正(加)闭包<span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msup><mi>T</mi><mo lspace="0em" rspace="0em">+</mo></msup></mrow><annotation encoding="application/x-tex">T^{+}</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.771331em;vertical-align:0em;"></span><span class="mord"><span class="mord mathnormal" style="margin-right:0.13889em;">T</span><span class="msupsub"><span class="vlist-t"><span class="vlist-r"><span class="vlist" style="height:0.771331em;"><span style="top:-3.063em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight"><span class="mord mtight">+</span></span></span></span></span></span></span></span></span></span></span></span>:字母表T上所有的字符串构成的集合</li></ul><h2 id="语言">语言</h2><p>语言是集合,对于几何的运算可以应用于对语言的计算,如:并、交、补、差……</p><ul><li><span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msub><mi>L</mi><mn>1</mn></msub><mo>=</mo><mo stretchy="false">{</mo><mi>ϵ</mi><mo stretchy="false">}</mo></mrow><annotation encoding="application/x-tex">L _ {1} = \{\epsilon\}</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.83333em;vertical-align:-0.15em;"></span><span class="mord"><span class="mord mathnormal">L</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.30110799999999993em;"><span style="top:-2.5500000000000003em;margin-left:0em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight"><span class="mord mtight">1</span></span></span></span></span><span class="vlist-s"></span></span><span class="vlist-r"><span class="vlist" style="height:0.15em;"><span></span></span></span></span></span></span><span class="mspace" style="margin-right:0.2777777777777778em;"></span><span class="mrel">=</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span></span><span class="base"><span class="strut" style="height:1em;vertical-align:-0.25em;"></span><span class="mopen">{</span><span class="mord mathnormal">ϵ</span><span class="mclose">}</span></span></span></span> 只有一个空句子的语言</li><li><span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msub><mi>L</mi><mn>2</mn></msub><mo>=</mo><mo stretchy="false">{</mo><mo stretchy="false">}</mo><mo>=</mo><mi mathvariant="normal">∅</mi></mrow><annotation encoding="application/x-tex">L _ 2 = \{\} = \varnothing</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.83333em;vertical-align:-0.15em;"></span><span class="mord"><span class="mord mathnormal">L</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.30110799999999993em;"><span style="top:-2.5500000000000003em;margin-left:0em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight">2</span></span></span></span><span class="vlist-s"></span></span><span class="vlist-r"><span class="vlist" style="height:0.15em;"><span></span></span></span></span></span></span><span class="mspace" style="margin-right:0.2777777777777778em;"></span><span class="mrel">=</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span></span><span class="base"><span class="strut" style="height:1em;vertical-align:-0.25em;"></span><span class="mopen">{</span><span class="mclose">}</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span><span class="mrel">=</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span></span><span class="base"><span class="strut" style="height:0.66334em;vertical-align:-0.08167em;"></span><span class="mord amsrm">∅</span></span></span></span> 空语言</li></ul><h3 id="语言的基本运算">语言的基本运算</h3><ul><li><p>语言的积:两个语言的字符串连接所构成的字符串的集合</p><p><strong>语言的积不可交换</strong></p></li><li><p>语言的幂:</p><p><span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msup><mi>L</mi><mn>0</mn></msup><mo>=</mo><mo stretchy="false">{</mo><mi>ϵ</mi><mo stretchy="false">}</mo></mrow><annotation encoding="application/x-tex">L^0 = \{\epsilon\}</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.8141079999999999em;vertical-align:0em;"></span><span class="mord"><span class="mord mathnormal">L</span><span class="msupsub"><span class="vlist-t"><span class="vlist-r"><span class="vlist" style="height:0.8141079999999999em;"><span style="top:-3.063em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight">0</span></span></span></span></span></span></span></span><span class="mspace" style="margin-right:0.2777777777777778em;"></span><span class="mrel">=</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span></span><span class="base"><span class="strut" style="height:1em;vertical-align:-0.25em;"></span><span class="mopen">{</span><span class="mord mathnormal">ϵ</span><span class="mclose">}</span></span></span></span></p><p><span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msup><mi>L</mi><mi>n</mi></msup><mo>=</mo><mi>L</mi><mo>⋅</mo><msup><mi>L</mi><mrow><mi>n</mi><mo>−</mo><mn>1</mn></mrow></msup><mo>=</mo><msup><mi>L</mi><mrow><mi>n</mi><mo>−</mo><mn>1</mn></mrow></msup><mo>⋅</mo><mi>L</mi></mrow><annotation encoding="application/x-tex">L^n = L \cdot L^{n-1} = L^{n-1} \cdot L</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.68333em;vertical-align:0em;"></span><span class="mord"><span class="mord mathnormal">L</span><span class="msupsub"><span class="vlist-t"><span class="vlist-r"><span class="vlist" style="height:0.664392em;"><span style="top:-3.063em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mathnormal mtight">n</span></span></span></span></span></span></span></span><span class="mspace" style="margin-right:0.2777777777777778em;"></span><span class="mrel">=</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span></span><span class="base"><span class="strut" style="height:0.68333em;vertical-align:0em;"></span><span class="mord mathnormal">L</span><span class="mspace" style="margin-right:0.2222222222222222em;"></span><span class="mbin">⋅</span><span class="mspace" style="margin-right:0.2222222222222222em;"></span></span><span class="base"><span class="strut" style="height:0.8141079999999999em;vertical-align:0em;"></span><span class="mord"><span class="mord mathnormal">L</span><span class="msupsub"><span class="vlist-t"><span class="vlist-r"><span class="vlist" style="height:0.8141079999999999em;"><span style="top:-3.063em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight"><span class="mord mathnormal mtight">n</span><span class="mbin mtight">−</span><span class="mord mtight">1</span></span></span></span></span></span></span></span></span><span class="mspace" style="margin-right:0.2777777777777778em;"></span><span class="mrel">=</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span></span><span class="base"><span class="strut" style="height:0.8141079999999999em;vertical-align:0em;"></span><span class="mord"><span class="mord mathnormal">L</span><span class="msupsub"><span class="vlist-t"><span class="vlist-r"><span class="vlist" style="height:0.8141079999999999em;"><span style="top:-3.063em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight"><span class="mord mathnormal mtight">n</span><span class="mbin mtight">−</span><span class="mord mtight">1</span></span></span></span></span></span></span></span></span><span class="mspace" style="margin-right:0.2222222222222222em;"></span><span class="mbin">⋅</span><span class="mspace" style="margin-right:0.2222222222222222em;"></span></span><span class="base"><span class="strut" style="height:0.68333em;vertical-align:0em;"></span><span class="mord mathnormal">L</span></span></span></span></p></li></ul><h2 id="文法">文法</h2><p>定义:文法是用来定义语言的一个数学模型</p><p>方法:</p><ul><li>有限集合:列举法</li><li>无限集合:<ul><li>文法产生系统</li><li>机器识别系统</li></ul></li></ul><h3 id="元语言">元语言</h3><p>元语言:描述语言的语言</p><ul><li><p>BNF:巴科斯范式</p><p><数字> ::= 0|1|2|……9</p><p><字母> ::= A|B|C……Z|a|b|……z</p><p><标识符> ::= <字母> | <标识符><字母> | <标识符><数字></p></li><li><p>文法是一种元语言</p></li></ul><h3 id="Chomsky文法体系">Chomsky文法体系</h3><p>文法G是一个四元组<mark><span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>G</mi><mo>=</mo><mo stretchy="false">(</mo><mi>N</mi><mo separator="true">,</mo><mi>P</mi><mo separator="true">,</mo><mi>T</mi><mo separator="true">,</mo><mi>S</mi><mo stretchy="false">)</mo></mrow><annotation encoding="application/x-tex">G=(N,P,T,S)</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.68333em;vertical-align:0em;"></span><span class="mord mathnormal">G</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span><span class="mrel">=</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span></span><span class="base"><span class="strut" style="height:1em;vertical-align:-0.25em;"></span><span class="mopen">(</span><span class="mord mathnormal" style="margin-right:0.10903em;">N</span><span class="mpunct">,</span><span class="mspace" style="margin-right:0.16666666666666666em;"></span><span class="mord mathnormal" style="margin-right:0.13889em;">P</span><span class="mpunct">,</span><span class="mspace" style="margin-right:0.16666666666666666em;"></span><span class="mord mathnormal" style="margin-right:0.13889em;">T</span><span class="mpunct">,</span><span class="mspace" style="margin-right:0.16666666666666666em;"></span><span class="mord mathnormal" style="margin-right:0.05764em;">S</span><span class="mclose">)</span></span></span></span></mark>,其中:</p><ul><li>N:非终结符的有限集合</li><li>T:终结符的有限集合,<span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>N</mi><mo>∩</mo><mi>T</mi><mo>=</mo><mi mathvariant="normal">∅</mi></mrow><annotation encoding="application/x-tex">N\cap T = \varnothing</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.68333em;vertical-align:0em;"></span><span class="mord mathnormal" style="margin-right:0.10903em;">N</span><span class="mspace" style="margin-right:0.2222222222222222em;"></span><span class="mbin">∩</span><span class="mspace" style="margin-right:0.2222222222222222em;"></span></span><span class="base"><span class="strut" style="height:0.68333em;vertical-align:0em;"></span><span class="mord mathnormal" style="margin-right:0.13889em;">T</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span><span class="mrel">=</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span></span><span class="base"><span class="strut" style="height:0.66334em;vertical-align:-0.08167em;"></span><span class="mord amsrm">∅</span></span></span></span></li><li>P:形式为<span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>α</mi><mo>→</mo><mi>β</mi></mrow><annotation encoding="application/x-tex">\alpha \rightarrow \beta</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.43056em;vertical-align:0em;"></span><span class="mord mathnormal" style="margin-right:0.0037em;">α</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span><span class="mrel">→</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span></span><span class="base"><span class="strut" style="height:0.8888799999999999em;vertical-align:-0.19444em;"></span><span class="mord mathnormal" style="margin-right:0.05278em;">β</span></span></span></span>的生成式的有限集合,且<span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>α</mi><mo>∈</mo><mo stretchy="false">(</mo><mi>N</mi><mo>∪</mo><mi>T</mi><msup><mo stretchy="false">)</mo><mo lspace="0em" rspace="0em">∗</mo></msup><msup><mi>N</mi><mo lspace="0em" rspace="0em">+</mo></msup><mo stretchy="false">(</mo><mi>N</mi><mo>∪</mo><mi>T</mi><msup><mo stretchy="false">)</mo><mo lspace="0em" rspace="0em">∗</mo></msup></mrow><annotation encoding="application/x-tex">\alpha \in (N\cup T)^{ * }N^{+}(N\cup T)^{ * }</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.5782em;vertical-align:-0.0391em;"></span><span class="mord mathnormal" style="margin-right:0.0037em;">α</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span><span class="mrel">∈</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span></span><span class="base"><span class="strut" style="height:1em;vertical-align:-0.25em;"></span><span class="mopen">(</span><span class="mord mathnormal" style="margin-right:0.10903em;">N</span><span class="mspace" style="margin-right:0.2222222222222222em;"></span><span class="mbin">∪</span><span class="mspace" style="margin-right:0.2222222222222222em;"></span></span><span class="base"><span class="strut" style="height:1.021331em;vertical-align:-0.25em;"></span><span class="mord mathnormal" style="margin-right:0.13889em;">T</span><span class="mclose"><span class="mclose">)</span><span class="msupsub"><span class="vlist-t"><span class="vlist-r"><span class="vlist" style="height:0.688696em;"><span style="top:-3.063em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight"><span class="mord mtight">∗</span></span></span></span></span></span></span></span></span><span class="mord"><span class="mord mathnormal" style="margin-right:0.10903em;">N</span><span class="msupsub"><span class="vlist-t"><span class="vlist-r"><span class="vlist" style="height:0.771331em;"><span style="top:-3.063em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight"><span class="mord mtight">+</span></span></span></span></span></span></span></span></span><span class="mopen">(</span><span class="mord mathnormal" style="margin-right:0.10903em;">N</span><span class="mspace" style="margin-right:0.2222222222222222em;"></span><span class="mbin">∪</span><span class="mspace" style="margin-right:0.2222222222222222em;"></span></span><span class="base"><span class="strut" style="height:1em;vertical-align:-0.25em;"></span><span class="mord mathnormal" style="margin-right:0.13889em;">T</span><span class="mclose"><span class="mclose">)</span><span class="msupsub"><span class="vlist-t"><span class="vlist-r"><span class="vlist" style="height:0.688696em;"><span style="top:-3.063em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight"><span class="mord mtight">∗</span></span></span></span></span></span></span></span></span></span></span></span>,<span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>β</mi><mo>∈</mo><mo stretchy="false">(</mo><mi>N</mi><mo>∪</mo><mi>T</mi><msup><mo stretchy="false">)</mo><mo lspace="0em" rspace="0em">∗</mo></msup></mrow><annotation encoding="application/x-tex">\beta \in (N\cup T)^{ * }</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.8888799999999999em;vertical-align:-0.19444em;"></span><span class="mord mathnormal" style="margin-right:0.05278em;">β</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span><span class="mrel">∈</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span></span><span class="base"><span class="strut" style="height:1em;vertical-align:-0.25em;"></span><span class="mopen">(</span><span class="mord mathnormal" style="margin-right:0.10903em;">N</span><span class="mspace" style="margin-right:0.2222222222222222em;"></span><span class="mbin">∪</span><span class="mspace" style="margin-right:0.2222222222222222em;"></span></span><span class="base"><span class="strut" style="height:1em;vertical-align:-0.25em;"></span><span class="mord mathnormal" style="margin-right:0.13889em;">T</span><span class="mclose"><span class="mclose">)</span><span class="msupsub"><span class="vlist-t"><span class="vlist-r"><span class="vlist" style="height:0.688696em;"><span style="top:-3.063em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight"><span class="mord mtight">∗</span></span></span></span></span></span></span></span></span></span></span></span></li><li>S:起始符,且<span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>S</mi><mo>∈</mo><mi>N</mi></mrow><annotation encoding="application/x-tex">S\in N</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.72243em;vertical-align:-0.0391em;"></span><span class="mord mathnormal" style="margin-right:0.05764em;">S</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span><span class="mrel">∈</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span></span><span class="base"><span class="strut" style="height:0.68333em;vertical-align:0em;"></span><span class="mord mathnormal" style="margin-right:0.10903em;">N</span></span></span></span></li></ul><h3 id="文法产生的语言">文法产生的语言</h3><p>文法G产生的语言为L(G),L(G)中的一个字符串,必是由终结符组成的,并且是由起始符推导来的</p><h2 id="Chomsky文法体系分类">Chomsky文法体系分类</h2><table><thead><tr><th></th><th>文法</th><th>形式语言</th><th>自动机(接收机)</th></tr></thead><tbody><tr><td>0型</td><td>无限制文法</td><td>非限定性语言</td><td>图灵机</td></tr><tr><td>1型</td><td>上下文有关文法</td><td>上下文有关语言</td><td>线性有界自动机</td></tr><tr><td>2型</td><td>上下文无关文法</td><td>上下文无关语言</td><td>下推(存贮)自动机</td></tr><tr><td>3型</td><td>右线性文法 & 左线型文法</td><td>正则语言</td><td>有限自动机</td></tr></tbody></table><p><span class="katex-display"><span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><semantics><mrow><mi>G</mi><mo>=</mo><mo stretchy="false">(</mo><mi>N</mi><mo separator="true">,</mo><mi>P</mi><mo separator="true">,</mo><mi>T</mi><mo separator="true">,</mo><mi>S</mi><mo stretchy="false">)</mo></mrow><annotation encoding="application/x-tex">G=(N,P,T,S)</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.68333em;vertical-align:0em;"></span><span class="mord mathnormal">G</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span><span class="mrel">=</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span></span><span class="base"><span class="strut" style="height:1em;vertical-align:-0.25em;"></span><span class="mopen">(</span><span class="mord mathnormal" style="margin-right:0.10903em;">N</span><span class="mpunct">,</span><span class="mspace" style="margin-right:0.16666666666666666em;"></span><span class="mord mathnormal" style="margin-right:0.13889em;">P</span><span class="mpunct">,</span><span class="mspace" style="margin-right:0.16666666666666666em;"></span><span class="mord mathnormal" style="margin-right:0.13889em;">T</span><span class="mpunct">,</span><span class="mspace" style="margin-right:0.16666666666666666em;"></span><span class="mord mathnormal" style="margin-right:0.05764em;">S</span><span class="mclose">)</span></span></span></span></span></p><h3 id="0型文法">0型文法</h3><p><span class="katex-display"><span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><semantics><mrow><mi>P</mi><mo>:</mo><mi>α</mi><mo>→</mo><mi>β</mi></mrow><annotation encoding="application/x-tex">P: \alpha \rightarrow \beta</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.68333em;vertical-align:0em;"></span><span class="mord mathnormal" style="margin-right:0.13889em;">P</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span><span class="mrel">:</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span></span><span class="base"><span class="strut" style="height:0.43056em;vertical-align:0em;"></span><span class="mord mathnormal" style="margin-right:0.0037em;">α</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span><span class="mrel">→</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span></span><span class="base"><span class="strut" style="height:0.8888799999999999em;vertical-align:-0.19444em;"></span><span class="mord mathnormal" style="margin-right:0.05278em;">β</span></span></span></span></span></p><p>其中,<span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>α</mi><mo>∈</mo><mo stretchy="false">(</mo><mi>N</mi><mo>∪</mo><mi>T</mi><msup><mo stretchy="false">)</mo><mo lspace="0em" rspace="0em">∗</mo></msup><msup><mi>N</mi><mo lspace="0em" rspace="0em">+</mo></msup><mo stretchy="false">(</mo><mi>N</mi><mo>∪</mo><mi>T</mi><msup><mo stretchy="false">)</mo><mo lspace="0em" rspace="0em">∗</mo></msup></mrow><annotation encoding="application/x-tex">\alpha \in (N\cup T)^{ * }N^{+}(N\cup T)^{ * }</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.5782em;vertical-align:-0.0391em;"></span><span class="mord mathnormal" style="margin-right:0.0037em;">α</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span><span class="mrel">∈</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span></span><span class="base"><span class="strut" style="height:1em;vertical-align:-0.25em;"></span><span class="mopen">(</span><span class="mord mathnormal" style="margin-right:0.10903em;">N</span><span class="mspace" style="margin-right:0.2222222222222222em;"></span><span class="mbin">∪</span><span class="mspace" style="margin-right:0.2222222222222222em;"></span></span><span class="base"><span class="strut" style="height:1.021331em;vertical-align:-0.25em;"></span><span class="mord mathnormal" style="margin-right:0.13889em;">T</span><span class="mclose"><span class="mclose">)</span><span class="msupsub"><span class="vlist-t"><span class="vlist-r"><span class="vlist" style="height:0.688696em;"><span style="top:-3.063em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight"><span class="mord mtight">∗</span></span></span></span></span></span></span></span></span><span class="mord"><span class="mord mathnormal" style="margin-right:0.10903em;">N</span><span class="msupsub"><span class="vlist-t"><span class="vlist-r"><span class="vlist" style="height:0.771331em;"><span style="top:-3.063em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight"><span class="mord mtight">+</span></span></span></span></span></span></span></span></span><span class="mopen">(</span><span class="mord mathnormal" style="margin-right:0.10903em;">N</span><span class="mspace" style="margin-right:0.2222222222222222em;"></span><span class="mbin">∪</span><span class="mspace" style="margin-right:0.2222222222222222em;"></span></span><span class="base"><span class="strut" style="height:1em;vertical-align:-0.25em;"></span><span class="mord mathnormal" style="margin-right:0.13889em;">T</span><span class="mclose"><span class="mclose">)</span><span class="msupsub"><span class="vlist-t"><span class="vlist-r"><span class="vlist" style="height:0.688696em;"><span style="top:-3.063em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight"><span class="mord mtight">∗</span></span></span></span></span></span></span></span></span></span></span></span>,<mark><span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>β</mi><mo>∈</mo><mo stretchy="false">(</mo><mi>N</mi><mo>∪</mo><mi>T</mi><msup><mo stretchy="false">)</mo><mo lspace="0em" rspace="0em">∗</mo></msup></mrow><annotation encoding="application/x-tex">\beta \in (N\cup T)^{ * }</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.8888799999999999em;vertical-align:-0.19444em;"></span><span class="mord mathnormal" style="margin-right:0.05278em;">β</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span><span class="mrel">∈</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span></span><span class="base"><span class="strut" style="height:1em;vertical-align:-0.25em;"></span><span class="mopen">(</span><span class="mord mathnormal" style="margin-right:0.10903em;">N</span><span class="mspace" style="margin-right:0.2222222222222222em;"></span><span class="mbin">∪</span><span class="mspace" style="margin-right:0.2222222222222222em;"></span></span><span class="base"><span class="strut" style="height:1em;vertical-align:-0.25em;"></span><span class="mord mathnormal" style="margin-right:0.13889em;">T</span><span class="mclose"><span class="mclose">)</span><span class="msupsub"><span class="vlist-t"><span class="vlist-r"><span class="vlist" style="height:0.688696em;"><span style="top:-3.063em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight"><span class="mord mtight">∗</span></span></span></span></span></span></span></span></span></span></span></span></mark></p><h3 id="1型文法">1型文法</h3><p><span class="katex-display"><span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><semantics><mrow><mi>P</mi><mo>:</mo><mi>α</mi><mo>→</mo><mi>β</mi></mrow><annotation encoding="application/x-tex">P: \alpha \rightarrow \beta</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.68333em;vertical-align:0em;"></span><span class="mord mathnormal" style="margin-right:0.13889em;">P</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span><span class="mrel">:</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span></span><span class="base"><span class="strut" style="height:0.43056em;vertical-align:0em;"></span><span class="mord mathnormal" style="margin-right:0.0037em;">α</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span><span class="mrel">→</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span></span><span class="base"><span class="strut" style="height:0.8888799999999999em;vertical-align:-0.19444em;"></span><span class="mord mathnormal" style="margin-right:0.05278em;">β</span></span></span></span></span></p><p>其中,<span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi mathvariant="normal">∣</mi><mi>α</mi><mi mathvariant="normal">∣</mi><mo>≤</mo><mi mathvariant="normal">∣</mi><mi>β</mi><mi mathvariant="normal">∣</mi></mrow><annotation encoding="application/x-tex">|\alpha|\le|\beta|</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:1em;vertical-align:-0.25em;"></span><span class="mord">∣</span><span class="mord mathnormal" style="margin-right:0.0037em;">α</span><span class="mord">∣</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span><span class="mrel">≤</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span></span><span class="base"><span class="strut" style="height:1em;vertical-align:-0.25em;"></span><span class="mord">∣</span><span class="mord mathnormal" style="margin-right:0.05278em;">β</span><span class="mord">∣</span></span></span></span>,<span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>α</mi><mo>∈</mo><mo stretchy="false">(</mo><mi>N</mi><mo>∪</mo><mi>T</mi><msup><mo stretchy="false">)</mo><mo lspace="0em" rspace="0em">∗</mo></msup><msup><mi>N</mi><mo lspace="0em" rspace="0em">+</mo></msup><mo stretchy="false">(</mo><mi>N</mi><mo>∪</mo><mi>T</mi><msup><mo stretchy="false">)</mo><mo lspace="0em" rspace="0em">∗</mo></msup></mrow><annotation encoding="application/x-tex">\alpha \in (N\cup T)^{ * }N^{+}(N\cup T)^{ * }</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.5782em;vertical-align:-0.0391em;"></span><span class="mord mathnormal" style="margin-right:0.0037em;">α</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span><span class="mrel">∈</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span></span><span class="base"><span class="strut" style="height:1em;vertical-align:-0.25em;"></span><span class="mopen">(</span><span class="mord mathnormal" style="margin-right:0.10903em;">N</span><span class="mspace" style="margin-right:0.2222222222222222em;"></span><span class="mbin">∪</span><span class="mspace" style="margin-right:0.2222222222222222em;"></span></span><span class="base"><span class="strut" style="height:1.021331em;vertical-align:-0.25em;"></span><span class="mord mathnormal" style="margin-right:0.13889em;">T</span><span class="mclose"><span class="mclose">)</span><span class="msupsub"><span class="vlist-t"><span class="vlist-r"><span class="vlist" style="height:0.688696em;"><span style="top:-3.063em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight"><span class="mord mtight">∗</span></span></span></span></span></span></span></span></span><span class="mord"><span class="mord mathnormal" style="margin-right:0.10903em;">N</span><span class="msupsub"><span class="vlist-t"><span class="vlist-r"><span class="vlist" style="height:0.771331em;"><span style="top:-3.063em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight"><span class="mord mtight">+</span></span></span></span></span></span></span></span></span><span class="mopen">(</span><span class="mord mathnormal" style="margin-right:0.10903em;">N</span><span class="mspace" style="margin-right:0.2222222222222222em;"></span><span class="mbin">∪</span><span class="mspace" style="margin-right:0.2222222222222222em;"></span></span><span class="base"><span class="strut" style="height:1em;vertical-align:-0.25em;"></span><span class="mord mathnormal" style="margin-right:0.13889em;">T</span><span class="mclose"><span class="mclose">)</span><span class="msupsub"><span class="vlist-t"><span class="vlist-r"><span class="vlist" style="height:0.688696em;"><span style="top:-3.063em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight"><span class="mord mtight">∗</span></span></span></span></span></span></span></span></span></span></span></span>,<mark><span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>β</mi><mo>∈</mo><mo stretchy="false">(</mo><mi>N</mi><mo>∪</mo><mi>T</mi><msup><mo stretchy="false">)</mo><mo lspace="0em" rspace="0em">+</mo></msup></mrow><annotation encoding="application/x-tex">\beta \in (N\cup T)^{+}</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.8888799999999999em;vertical-align:-0.19444em;"></span><span class="mord mathnormal" style="margin-right:0.05278em;">β</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span><span class="mrel">∈</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span></span><span class="base"><span class="strut" style="height:1em;vertical-align:-0.25em;"></span><span class="mopen">(</span><span class="mord mathnormal" style="margin-right:0.10903em;">N</span><span class="mspace" style="margin-right:0.2222222222222222em;"></span><span class="mbin">∪</span><span class="mspace" style="margin-right:0.2222222222222222em;"></span></span><span class="base"><span class="strut" style="height:1.021331em;vertical-align:-0.25em;"></span><span class="mord mathnormal" style="margin-right:0.13889em;">T</span><span class="mclose"><span class="mclose">)</span><span class="msupsub"><span class="vlist-t"><span class="vlist-r"><span class="vlist" style="height:0.771331em;"><span style="top:-3.063em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight"><span class="mord mtight">+</span></span></span></span></span></span></span></span></span></span></span></span></mark></p><p>隐含条件:<span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>β</mi></mrow><annotation encoding="application/x-tex">\beta</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.8888799999999999em;vertical-align:-0.19444em;"></span><span class="mord mathnormal" style="margin-right:0.05278em;">β</span></span></span></span> 不能取 <span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>ϵ</mi></mrow><annotation encoding="application/x-tex">\epsilon</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.43056em;vertical-align:0em;"></span><span class="mord mathnormal">ϵ</span></span></span></span></p><h3 id="2型文法">2型文法</h3><p><span class="katex-display"><span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><semantics><mrow><mi>P</mi><mo>:</mo><mi>A</mi><mo>→</mo><mi>β</mi></mrow><annotation encoding="application/x-tex">P: A \rightarrow \beta</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.68333em;vertical-align:0em;"></span><span class="mord mathnormal" style="margin-right:0.13889em;">P</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span><span class="mrel">:</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span></span><span class="base"><span class="strut" style="height:0.68333em;vertical-align:0em;"></span><span class="mord mathnormal">A</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span><span class="mrel">→</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span></span><span class="base"><span class="strut" style="height:0.8888799999999999em;vertical-align:-0.19444em;"></span><span class="mord mathnormal" style="margin-right:0.05278em;">β</span></span></span></span></span></p><p>其中,<span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>A</mi><mo>∈</mo><mi>N</mi></mrow><annotation encoding="application/x-tex">A \in N</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.72243em;vertical-align:-0.0391em;"></span><span class="mord mathnormal">A</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span><span class="mrel">∈</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span></span><span class="base"><span class="strut" style="height:0.68333em;vertical-align:0em;"></span><span class="mord mathnormal" style="margin-right:0.10903em;">N</span></span></span></span>,<span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>β</mi><mo>∈</mo><mo stretchy="false">(</mo><mi>N</mi><mo>∪</mo><mi>T</mi><msup><mo stretchy="false">)</mo><mo lspace="0em" rspace="0em">∗</mo></msup></mrow><annotation encoding="application/x-tex">\beta \in (N\cup T)^{ * }</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.8888799999999999em;vertical-align:-0.19444em;"></span><span class="mord mathnormal" style="margin-right:0.05278em;">β</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span><span class="mrel">∈</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span></span><span class="base"><span class="strut" style="height:1em;vertical-align:-0.25em;"></span><span class="mopen">(</span><span class="mord mathnormal" style="margin-right:0.10903em;">N</span><span class="mspace" style="margin-right:0.2222222222222222em;"></span><span class="mbin">∪</span><span class="mspace" style="margin-right:0.2222222222222222em;"></span></span><span class="base"><span class="strut" style="height:1em;vertical-align:-0.25em;"></span><span class="mord mathnormal" style="margin-right:0.13889em;">T</span><span class="mclose"><span class="mclose">)</span><span class="msupsub"><span class="vlist-t"><span class="vlist-r"><span class="vlist" style="height:0.688696em;"><span style="top:-3.063em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight"><span class="mord mtight">∗</span></span></span></span></span></span></span></span></span></span></span></span></p><h3 id="3型文法">3型文法</h3><ul><li>右线性文法</li></ul><p><span class="katex-display"><span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><semantics><mrow><mi>P</mi><mo>:</mo><mi>A</mi><mo>→</mo><mi>ω</mi><mi>B</mi><mtext> 或 </mtext><mi>A</mi><mo>→</mo><mi>ω</mi></mrow><annotation encoding="application/x-tex">P: A \rightarrow \omega B \text{ 或 } A \rightarrow \omega</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.68333em;vertical-align:0em;"></span><span class="mord mathnormal" style="margin-right:0.13889em;">P</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span><span class="mrel">:</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span></span><span class="base"><span class="strut" style="height:0.68333em;vertical-align:0em;"></span><span class="mord mathnormal">A</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span><span class="mrel">→</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span></span><span class="base"><span class="strut" style="height:0.68333em;vertical-align:0em;"></span><span class="mord mathnormal" style="margin-right:0.03588em;">ω</span><span class="mord mathnormal" style="margin-right:0.05017em;">B</span><span class="mord text"><span class="mord"> </span><span class="mord cjk_fallback">或</span><span class="mord"> </span></span><span class="mord mathnormal">A</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span><span class="mrel">→</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span></span><span class="base"><span class="strut" style="height:0.43056em;vertical-align:0em;"></span><span class="mord mathnormal" style="margin-right:0.03588em;">ω</span></span></span></span></span></p><ul><li>左线性文法</li></ul><p><span class="katex-display"><span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><semantics><mrow><mi>P</mi><mo>:</mo><mi>A</mi><mo>→</mo><mi>B</mi><mi>ω</mi><mtext> 或 </mtext><mi>A</mi><mo>→</mo><mi>ω</mi></mrow><annotation encoding="application/x-tex">P: A \rightarrow B \omega \text{ 或 } A \rightarrow \omega</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.68333em;vertical-align:0em;"></span><span class="mord mathnormal" style="margin-right:0.13889em;">P</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span><span class="mrel">:</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span></span><span class="base"><span class="strut" style="height:0.68333em;vertical-align:0em;"></span><span class="mord mathnormal">A</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span><span class="mrel">→</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span></span><span class="base"><span class="strut" style="height:0.68333em;vertical-align:0em;"></span><span class="mord mathnormal" style="margin-right:0.05017em;">B</span><span class="mord mathnormal" style="margin-right:0.03588em;">ω</span><span class="mord text"><span class="mord"> </span><span class="mord cjk_fallback">或</span><span class="mord"> </span></span><span class="mord mathnormal">A</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span><span class="mrel">→</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span></span><span class="base"><span class="strut" style="height:0.43056em;vertical-align:0em;"></span><span class="mord mathnormal" style="margin-right:0.03588em;">ω</span></span></span></span></span></p><p>其中,<span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>A</mi><mtext>、</mtext><mi>B</mi><mo>∈</mo><mi>N</mi></mrow><annotation encoding="application/x-tex">A、B \in N</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.72243em;vertical-align:-0.0391em;"></span><span class="mord mathnormal">A</span><span class="mord cjk_fallback">、</span><span class="mord mathnormal" style="margin-right:0.05017em;">B</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span><span class="mrel">∈</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span></span><span class="base"><span class="strut" style="height:0.68333em;vertical-align:0em;"></span><span class="mord mathnormal" style="margin-right:0.10903em;">N</span></span></span></span>,<span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>ω</mi><mo>∈</mo><msup><mi>T</mi><mo lspace="0em" rspace="0em">∗</mo></msup></mrow><annotation encoding="application/x-tex">\omega \in T^{ * }</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.5782em;vertical-align:-0.0391em;"></span><span class="mord mathnormal" style="margin-right:0.03588em;">ω</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span><span class="mrel">∈</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span></span><span class="base"><span class="strut" style="height:0.688696em;vertical-align:0em;"></span><span class="mord"><span class="mord mathnormal" style="margin-right:0.13889em;">T</span><span class="msupsub"><span class="vlist-t"><span class="vlist-r"><span class="vlist" style="height:0.688696em;"><span style="top:-3.063em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight"><span class="mord mtight">∗</span></span></span></span></span></span></span></span></span></span></span></span></p>]]></content>
<categories>
<category> 专业课 </category>
<category> 形式语言与自动机 </category>
</categories>
<tags>
<tag> 形式语言与自动机 </tag>
</tags>
</entry>
<entry>
<title>TCP/IP网络协议基础</title>
<link href="posts/37195/"/>
<url>posts/37195/</url>
<content type="html"><![CDATA[<script src="\assets\js\APlayer.min.js"> </script><p>网络协议栈结构 OSI 七层模型与 TCP/IP 四层结构对比如下所示:</p><table> <tr> <th> OSI 七层模型 </th> <th> TCP/IP 四层模型 </th> <th> 常见协议 </th> </tr> <tr> <th> 应用层 </th> <th rowspan="3"> 应用层 </th> <th rowspan="3"> SMTP HTTPS DNS </br> HTTP Telnet POP3 </br> SNMP FTP NFS </th> </tr> <tr> <th> 表示层 </th> </tr> <tr> <th> 会话层 </th> </tr> <tr> <th> 传输层 </th> <th> 传输层 </th> <th> TCP UDP </th> </tr> <tr> <th> 网络层 </th> <th> 网络层 </th> <th> IP ICMP ARP </th> </tr> <tr> <th> 数据链路层 </th> <th rowspan="2"> 网络接口层 </th> <th rowspan="2"> PPP Ethernet</th> </tr> <tr> <th> 物理层 </th> </tr></table><p>TCP/IP 被分为 4 层,每层承担的任务不一样,各层的协议的工作方式也不一样,每层封装上层数据的方式也不一样:</p><ul><li>应用层:应用程序通过这一层访问网络,常见 FTP、HTTP、DNS 和 TELNET 协议</li><li>传输层:TCP 协议和 UDP 协议</li><li>网络层:IP 协议,ARP、RARP 协议,ICMP 协议等</li><li>网络接口层: TCP/IP 协议的基层,负责数据帧的发送和接收</li></ul><p>以下,将自底向上分层次对 TCP/IP 的各协议做详细介绍。</p><h2 id="TCP-IP-简介">TCP/IP 简介</h2><p>上世纪 70 年代,随着计算机技术的发展,计算机使用者意识到:要想发挥计算机更大的作用,就要将世界各地的计算机连接起来。但是简单的连接是远远不够的,因为计算机之间无法沟通。因此设计一种通用的“语言”来交流是必不可少的,这时 TCP/IP 协议就应运而生了。</p><p>TCP/IP(Transmission Control Protocol/Internet Protocol)是传输控制协议和网络协议的简称,它定义了电子设备如何连入因特网,以及数据如何在它们之间传输的标准。</p><p>TCP/IP 不是一个协议,而是一个协议族的统称,里面包括了 IP 协议、ICMP 协议、TCP 协议、以及 HTTP、FTP、POP3 协议等。网络中的计算机都采用这套协议族进行互联。</p><h3 id="IP地址">IP地址</h3><p>网络上每一个节点都必须有一个独立的 IP 地址,通常使用的 IP 地址是一个 32bit 的数字,被 <code>.</code> 分成 4 组,例如,<code>255.255.255.255</code> 就是一个 IP 地址。有了 IP 地址,用户的计算机就可以发现并连接互联网中的另外一台计算机。</p><p>在终端输入 <code>ifconfig -a</code> 命令查看自己的 IP 地址:</p><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">ifconfig -a</span><br></pre></td></tr></table></figure><p><img src="https://gitee.com/sg2019/picgo/raw/master/image-20210424170205949.png" alt="image-20210424170205949"></p><p>我的 Linux 虚拟机运行结果,可以看到 IP 地址为:192.168.116.128,是北邮本地局域网的地址 。</p><h3 id="域名">域名</h3><p>用 12 位数字组成的 IP 地址很难记忆,在实际应用时,用户一般不需要记住 IP 地址,互联网给每个 IP 地址起了一个别名,习惯上称作域名。</p><p>域名与计算机的 IP 地址相对应,并把这种对应关系存储在域名服务系统 DNS(Domain Name System)中,这样用户只需记住域名就可以与指定的计算机进行通信了。</p><p>常见的域名包括 com、net 和 org 三种顶级域名后缀,除此之外每个国家还有自己国家专属的域名后缀(比如我国的域名后缀为 cn)。比如常见域名:百度(<a href="https://www.baidu.com/">www.baidu.com</a>)、Linux 组织(<a href="https://lwn.net/">www.lwn.net</a>)等等。</p><p>我们可以使用命令 <code>nslookup</code> 或者 <code>ping</code> 来查看与域名相对应的 IP 地址,比如 <code>ping</code> 一下 <code>github</code> :</p><p><img src="https://gitee.com/sg2019/picgo/raw/master/image-20210424171747514.png" alt="image-20210424171747514"></p><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">ping www.github.com</span><br></pre></td></tr></table></figure><h3 id="MAC地址">MAC地址</h3><p>MAC(Media Access Control)地址,或称为物理地址、硬件地址,用来定义互联网中设备的位置。</p><p>在 TCP/IP 层次模型中,网络层管理 IP 地址,链路层则负责 MAC 地址。因此每个网络位置会有一个专属于它的 IP 地址,而每个主机会有一个专属于它 MAC 地址。</p><h3 id="端口号">端口号</h3><p>IP 地址用来发现和查找网络中的地址,而不同程序互相通信则需要端口号识别。端口采用 16 比特的端口号标识,一个 IP 地址的端口可以有 65536(即:<span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msup><mn>2</mn><mn>16</mn></msup></mrow><annotation encoding="application/x-tex">2^{16}</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.8141079999999999em;vertical-align:0em;"></span><span class="mord"><span class="mord">2</span><span class="msupsub"><span class="vlist-t"><span class="vlist-r"><span class="vlist" style="height:0.8141079999999999em;"><span style="top:-3.063em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight"><span class="mord mtight">1</span><span class="mord mtight">6</span></span></span></span></span></span></span></span></span></span></span></span>)个端口。</p><p>服务器的默认程序一般通过人们熟知的端口号识别。例如,对于每个 TCP/IP 实现来说,SMTP(简单邮件传输协议)服务器的 TCP 端口号都是 <code>25</code>,FTP(文件传输协议)服务器的 TCP 端口号都是 <code>21</code>,TFTP(简单文件传输协议)服务器的 UDP 端口号都是 <code>69</code>。任何 TCP/IP 实现所提供的服务都使用 <code>1-1023</code> 之间的端口号。这些人们熟知的端口号由 Internet 端口号分配机构(Internet Assigned Numbers Authority,IANA)来管理。</p><p>常用协议对应端口号:</p><ul><li>SSH 22</li><li>FTP 20 和 21</li><li>Telnet 23</li><li>SMTP 25</li><li>TFTP 69</li><li>HTTP 80</li><li>SNMP 161</li><li>Ping 使用 ICMP,无具体端口号</li></ul><h3 id="封装和分用">封装和分用</h3><p><strong>封装</strong>:当应用程序发送数据的时候,数据在协议层次当中自顶向下通过每一层,每一层都会对数据增加一些首部或尾部信息,这样的信息称之为协议数据单元(Protocol Data Unit,缩写为 PDU),在分层协议系统里,在指定的协议层上传送的数据单元,包含了该层的协议控制信息和用户信息。</p><ul><li>物理层(一层)PDU 指数据位(Bit)</li><li>数据链路层(二层)PDU 指数据帧(Frame)</li><li>网络层(三层)PDU 指数据包(Packet)</li><li>传输层(四层)PDU 指数据段(Segment)</li><li>第五层以上为数据(data)</li></ul><p><img src="https://gitee.com/sg2019/picgo/raw/master/1548670748600.png" alt="1548670748600"></p><p><strong>分用</strong>:当主机收到一个数据帧时,数据就从协议层底向上升,通过每一层时,检查并去掉对应层次的报文首部或尾部,与封装过程正好相反。</p><h3 id="RFC">RFC</h3><p>RFC(Request for Comment)文档是所有以太网协议的正式标准,并在其官网上面公布,由 IETF 标准协会制定。大量的 RFC 并不是正式的标准,出版的目的只是为了提供信息。RFC 的篇幅不一,从几页到几百页不等。每一种协议都用一个数字来标识,如 RFC 3720 是 iSCSI 协议的标准,数字越大意味着 RFC 的内容越新或者是对应的协议(标准)出现的比较晚。</p><p>所有的 RFC 文档都可以从网络上找到,其官网为 <a href="https://www.ietf.org/">IETF</a>。在网站上面可以通过分类以及搜索快速找到目标协议的 RFC 文档。</p><h2 id="链路层介绍">链路层介绍</h2><p>如上所述,网络层协议的数据单元是 <strong>IP 数据报</strong>,而数据链路层的工作是把网络层交下来的 IP 数据报 封装为<strong>帧</strong>(frame)发送到链路上,以及把接收到的帧中的数据取出并上交给网络层。 为达到这一目的,数据链路必须具备一系列相应的功能,主要有:</p><ul><li>将数据封装为帧(frame),帧是数据链路层的传送单位;</li><li>控制帧的传输,包括处理传输差错,调节发送速率与接收方相匹配;</li><li>在两个网络实体之间提供数据链路通路的建立、维持和释放的管理。</li></ul><p>数据帧的结构是这样的:</p><p><img src="C:%5CUsers%5Cjiangshan%5CDesktop%5C1548670989256.png" alt="1548670989256"></p>]]></content>
<categories>
<category> 专业课 </category>
<category> 计算机网络 </category>
</categories>
<tags>
<tag> 基础 </tag>
<tag> 计算机网络 </tag>
<tag> TCP/IP </tag>
</tags>
</entry>
<entry>
<title>人脸检测+识别项目:MTCNN+FaceNet</title>
<link href="posts/39544/"/>
<url>posts/39544/</url>
<content type="html"><![CDATA[<script src="\assets\js\APlayer.min.js"> </script><p>[TOC]</p><h1>MTCNN人脸检测</h1><h2 id="MTCNN概述">MTCNN概述</h2><p>MTCNN,英文全称是Multi-task convolutional neural network,中文全称是多任务卷积神经网络,总体可分为P-Net、R-Net、和O-Net三层网络结构。MTCNN在同一个网络里实现了人脸区域检测与人脸关键点五点标定的模型,主要通过CNN模型级联实现多任务学习网络,从而实现人脸检测与对齐。</p><p>整个模型分为三个阶段:</p><ul><li>第一阶段(O-net):通过一个浅层的CNN网络快速产生一系列的候选窗口</li><li>第二阶段:通过一个能力更强的CNN网络过滤掉绝大部分非人脸候选窗口</li><li>第三阶段:通过一个能力更加强的网络找到人脸上面的五个标记点</li></ul><p>完整的MTCNN模型级联如下:</p><p><img src="https://gitee.com/sg2019/picgo/raw/master/image-20210420144945504.png" alt="image-20210420144945504"></p><p>该模型的特征跟HAAR级联检测在某些程度上有一定的相通之处,都是采用了级联方式,都是在初期就拒绝了绝大多数的图像区域,有效的降低了后期CNN网络的计算量与计算时间。</p><p>MTCNN模型主要贡献在于:</p><ul><li>提供一种基于CNN方式的级联检测方法,基于轻量级的CNN模型实现人脸检测与点位标定,而且性能实时</li><li>实现了对难样本挖掘在线训练提升性能</li><li>一次可以完成多个任务</li></ul><h2 id="MTCNN实现">MTCNN实现</h2><h3 id="1-构建图像金字塔">1. 构建图像金字塔</h3><h4 id="原理">原理</h4><p>图像金字塔是图像多尺度表达的一种常用方法,构造一系列以金字塔形状排列的、分辨率逐步降低、且来源于同一张原始图的图像集合,以适应不同大小的人脸,进行多尺度人脸检测。</p><p>构建方式是通过不同的缩放系数factor对图片进行缩放,每次缩小为原来的factor大小,在MTCNN代码中,按照习惯设为<code>factor = 0.709</code>。</p><p>对应图解:</p><p><img src="https://gitee.com/sg2019/picgo/raw/master/image-20210420151632498.png" alt="image-20210420151632498"></p><h4 id="代码">代码</h4><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># 计算原始输入图像每一次缩放的比例</span></span><br><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">calculateScales</span>(<span class="params">img</span>):</span></span><br><span class="line"> pr_scale = <span class="number">1.0</span></span><br><span class="line"> h, w, _ = img.shape</span><br><span class="line"></span><br><span class="line"> <span class="comment"># 如果图像的短边大于500,则将短边固定为500</span></span><br><span class="line"> <span class="comment"># 如果图像的长边小于500,则将长边固定为500</span></span><br><span class="line"> <span class="keyword">if</span> <span class="built_in">min</span>(w, h) > <span class="number">500</span>:</span><br><span class="line"> pr_scale = <span class="number">500.0</span> / <span class="built_in">min</span>(h, w)</span><br><span class="line"> w = <span class="built_in">int</span>(w * pr_scale)</span><br><span class="line"> h = <span class="built_in">int</span>(h * pr_scale)</span><br><span class="line"> <span class="keyword">elif</span> <span class="built_in">max</span>(w, h) < <span class="number">500</span>:</span><br><span class="line"> pr_scale = <span class="number">500.0</span> / <span class="built_in">max</span>(h, w)</span><br><span class="line"> w = <span class="built_in">int</span>(w * pr_scale)</span><br><span class="line"> h = <span class="built_in">int</span>(h * pr_scale)</span><br><span class="line"></span><br><span class="line"> <span class="comment"># 建立图像金字塔的scales,防止图像的宽高小于12</span></span><br><span class="line"> scales = []</span><br><span class="line"> factor = <span class="number">0.709</span></span><br><span class="line"> factor_count = <span class="number">0</span></span><br><span class="line"> min_len = <span class="built_in">min</span>(h, w)</span><br><span class="line"> <span class="keyword">while</span> min_len >= <span class="number">12</span>:</span><br><span class="line"> scales.append(pr_scale * <span class="built_in">pow</span>(factor, factor_count))</span><br><span class="line"> min_len *= factor</span><br><span class="line"> factor_count += <span class="number">1</span></span><br><span class="line"> <span class="keyword">return</span> scales</span><br></pre></td></tr></table></figure><h3 id="2-P-Net">2. P-Net</h3><h4 id="原理-2">原理</h4><p>P-Net的全称为Proposal Network,即推荐网络,其基本的构造是一个全卷积网络。对上一步构建完成的图像金字塔,通过一个FCN进行初步特征提取与标定边框。</p><p>P-Net网络较为简单,但在完成初步提取后,还需要进行Bounding-Box Regression调整窗口与NMS进行大部分窗口的过滤。</p><p>P-Net有两个输出,classifier用于判断这个网格点上的框的可信度,<code>bbox_regress</code>表示框的位置。</p><p><code>bbox_regress</code>并不代表这个框在图片上的真实位置,如果需要将<code>bbox_regress</code>映射到真实图像上,还需要进行一次解码过程。</p><p>解码过程利用<code>detect_face_12net</code>函数实现,其实现步骤如下(需要配合代码理解):</p><ol><li>判断哪些网格点的置信度较高,即该网格点内存在人脸</li><li>记录该网格点的x、y轴</li><li>利用函数计算bb1和bb2,分别代表图中框的左上角基点和右下角基点,二者之间差了11个像素,堆叠得到bounding_box</li><li>利用bbox_regress计算解码结果,解码公式为<code>bounding_box = bounding_box + offset*12.0*scale</code></li></ol><p>P-Net的输出将整个网格分割成若干个网格点,每个网格点初始状态下是一个11x11的框,之后<code>bbox_regress</code>代表每个网格点确定的框 的<strong>左上角基点和右下角基点</strong>的偏移情况。</p><h4 id="代码-2">代码</h4><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># 粗略获取人脸框</span></span><br><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">create_Pnet</span>(<span class="params">weight_path</span>):</span></span><br><span class="line"> inputs = Input(shape=[<span class="literal">None</span>, <span class="literal">None</span>, <span class="number">3</span>])</span><br><span class="line"></span><br><span class="line"> x = Conv2D(<span class="number">10</span>, (<span class="number">3</span>, <span class="number">3</span>), strides=<span class="number">1</span>, padding=<span class="string">'valid'</span>, name=<span class="string">'conv1'</span>)(inputs)</span><br><span class="line"> x = PReLU(shared_axes=[<span class="number">1</span>,<span class="number">2</span>],name=<span class="string">'PReLU1'</span>)(x)</span><br><span class="line"> x = MaxPool2D(pool_size=<span class="number">2</span>)(x)</span><br><span class="line"></span><br><span class="line"> x = Conv2D(<span class="number">16</span>, (<span class="number">3</span>, <span class="number">3</span>), strides=<span class="number">1</span>, padding=<span class="string">'valid'</span>, name=<span class="string">'conv2'</span>)(x)</span><br><span class="line"> x = PReLU(shared_axes=[<span class="number">1</span>,<span class="number">2</span>],name=<span class="string">'PReLU2'</span>)(x)</span><br><span class="line"></span><br><span class="line"> x = Conv2D(<span class="number">32</span>, (<span class="number">3</span>, <span class="number">3</span>), strides=<span class="number">1</span>, padding=<span class="string">'valid'</span>, name=<span class="string">'conv3'</span>)(x)</span><br><span class="line"> x = PReLU(shared_axes=[<span class="number">1</span>,<span class="number">2</span>],name=<span class="string">'PReLU3'</span>)(x)</span><br><span class="line"></span><br><span class="line"> classifier = Conv2D(<span class="number">2</span>, (<span class="number">1</span>, <span class="number">1</span>), activation=<span class="string">'softmax'</span>, name=<span class="string">'conv4-1'</span>)(x)</span><br><span class="line"> <span class="comment"># 无激活函数</span></span><br><span class="line"> bbox_regress = Conv2D(<span class="number">4</span>, (<span class="number">1</span>, <span class="number">1</span>), name=<span class="string">'conv4-2'</span>)(x)</span><br><span class="line"></span><br><span class="line"> model = Model([inputs], [classifier, bbox_regress])</span><br><span class="line"> model.load_weights(weight_path, by_name=<span class="literal">True</span>)</span><br><span class="line"> <span class="keyword">return</span> model</span><br></pre></td></tr></table></figure><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># 对Pnet处理后的结果进行处理</span></span><br><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">detect_face_12net</span>(<span class="params">cls_prob, roi, out_side, scale, width, height, threshold</span>):</span></span><br><span class="line"> <span class="comment"># 计算特征点之间的步长</span></span><br><span class="line"> stride = <span class="number">0</span></span><br><span class="line"> <span class="keyword">if</span> out_side != <span class="number">1</span>:</span><br><span class="line"> stride = <span class="built_in">float</span>(<span class="number">2</span> * out_side - <span class="number">1</span>) / (out_side - <span class="number">1</span>)</span><br><span class="line"></span><br><span class="line"> <span class="comment"># 获得满足得分门限的特征点的坐标</span></span><br><span class="line"> (y, x) = np.where(cls_prob >= threshold)</span><br><span class="line"></span><br><span class="line"> <span class="comment"># 获得满足得分门限的特征点得分</span></span><br><span class="line"> score = np.expand_dims(cls_prob[y, x], -<span class="number">1</span>)</span><br><span class="line"></span><br><span class="line"> <span class="comment"># 将对应的特征点的坐标转换成位于原图上的先验框的坐标</span></span><br><span class="line"> bounding_box = np.concatenate([np.expand_dims(x, -<span class="number">1</span>), np.expand_dims(y, -<span class="number">1</span>)], axis=-<span class="number">1</span>)</span><br><span class="line"> top_left = np.fix(stride * bounding_box + <span class="number">0</span>)</span><br><span class="line"> bottom_right = np.fix(stride * bounding_box + <span class="number">11</span>)</span><br><span class="line"> bounding_box = np.concatenate((top_left, bottom_right), axis=-<span class="number">1</span>)</span><br><span class="line"> bounding_box = (bounding_box + roi[y, x] * <span class="number">12.0</span>) * scale</span><br><span class="line"></span><br><span class="line"> <span class="comment"># 将预测框和得分堆叠,转换成正方形</span></span><br><span class="line"> rectangles = np.concatenate((bounding_box, score), axis=-<span class="number">1</span>)</span><br><span class="line"> rectangles = rect2square(rectangles)</span><br><span class="line"></span><br><span class="line"> rectangles[:, [<span class="number">1</span>, <span class="number">3</span>]] = np.clip(rectangles[:, [<span class="number">1</span>, <span class="number">3</span>]], <span class="number">0</span>, height)</span><br><span class="line"> rectangles[:, [<span class="number">0</span>, <span class="number">2</span>]] = np.clip(rectangles[:, [<span class="number">0</span>, <span class="number">2</span>]], <span class="number">0</span>, width)</span><br><span class="line"> <span class="keyword">return</span> rectangles</span><br></pre></td></tr></table></figure><h3 id="3-R-Net">3. R-Net</h3><h4 id="原理-3">原理</h4><p>R-Net全称为Refine Network,即优化网络,其基本的构造是一个卷积神经网络。相对于第一层的P-Net来说,增加了一个全连接层,因此对于输入数据的筛选会更加严格。在图片经过P-Net后,会留下许多预测窗口,我们将所有的预测窗口送入R-Net,这个网络会滤除大量效果比较差的候选框。</p><p>最后对选定的候选框进行Bounding-Box Regression和NMS进一步优化预测结果。</p><p>R-Net有两个输出,classifier用于判断这个网格点上的框的可信度,bbox_regress表示框的位置。</p><p>bbox_regress并不代表这个框在图片上的真实位置,如果需要将bbox_regress映射到真实图像上,还需要进行一次解码过程。</p><h4 id="代码-3">代码</h4><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># 精修框</span></span><br><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">create_Rnet</span>(<span class="params">weight_path</span>):</span></span><br><span class="line"> inputs = Input(shape=[<span class="number">24</span>, <span class="number">24</span>, <span class="number">3</span>])</span><br><span class="line"> <span class="comment"># 24,24,3 -> 22,22,28 -> 11,11,28</span></span><br><span class="line"> x = Conv2D(<span class="number">28</span>, (<span class="number">3</span>, <span class="number">3</span>), strides=<span class="number">1</span>, padding=<span class="string">'valid'</span>, name=<span class="string">'conv1'</span>)(inputs)</span><br><span class="line"> x = PReLU(shared_axes=[<span class="number">1</span>, <span class="number">2</span>], name=<span class="string">'prelu1'</span>)(x)</span><br><span class="line"> x = MaxPool2D(pool_size=<span class="number">3</span>,strides=<span class="number">2</span>, padding=<span class="string">'same'</span>)(x)</span><br><span class="line"></span><br><span class="line"> <span class="comment"># 11,11,28 -> 9,9,48 -> 4,4,48</span></span><br><span class="line"> x = Conv2D(<span class="number">48</span>, (<span class="number">3</span>, <span class="number">3</span>), strides=<span class="number">1</span>, padding=<span class="string">'valid'</span>, name=<span class="string">'conv2'</span>)(x)</span><br><span class="line"> x = PReLU(shared_axes=[<span class="number">1</span>, <span class="number">2</span>], name=<span class="string">'prelu2'</span>)(x)</span><br><span class="line"> x = MaxPool2D(pool_size=<span class="number">3</span>, strides=<span class="number">2</span>)(x)</span><br><span class="line"></span><br><span class="line"> <span class="comment"># 4,4,48 -> 3,3,64</span></span><br><span class="line"> x = Conv2D(<span class="number">64</span>, (<span class="number">2</span>, <span class="number">2</span>), strides=<span class="number">1</span>, padding=<span class="string">'valid'</span>, name=<span class="string">'conv3'</span>)(x)</span><br><span class="line"> x = PReLU(shared_axes=[<span class="number">1</span>, <span class="number">2</span>], name=<span class="string">'prelu3'</span>)(x)</span><br><span class="line"></span><br><span class="line"> <span class="comment"># 3,3,64 -> 64,3,3</span></span><br><span class="line"> x = Permute((<span class="number">3</span>, <span class="number">2</span>, <span class="number">1</span>))(x)</span><br><span class="line"> x = Flatten()(x)</span><br><span class="line"></span><br><span class="line"> <span class="comment"># 576 -> 128</span></span><br><span class="line"> x = Dense(<span class="number">128</span>, name=<span class="string">'conv4'</span>)(x)</span><br><span class="line"> x = PReLU( name=<span class="string">'prelu4'</span>)(x)</span><br><span class="line"></span><br><span class="line"> <span class="comment"># 128 -> 2</span></span><br><span class="line"> classifier = Dense(<span class="number">2</span>, activation=<span class="string">'softmax'</span>, name=<span class="string">'conv5-1'</span>)(x)</span><br><span class="line"> <span class="comment"># 128 -> 4</span></span><br><span class="line"> bbox_regress = Dense(<span class="number">4</span>, name=<span class="string">'conv5-2'</span>)(x)</span><br><span class="line"></span><br><span class="line"> model = Model([inputs], [classifier, bbox_regress])</span><br><span class="line"> model.load_weights(weight_path, by_name=<span class="literal">True</span>)</span><br><span class="line"> <span class="keyword">return</span> model</span><br></pre></td></tr></table></figure><h3 id="4-O-Net">4. O-Net</h3><h4 id="原理-4">原理</h4><p>O-Net与R-Net工作流程类似,全称为Output Network,基本结构是一个较为复杂的卷积神经网络,相对于R-Net来说多了一个卷积层。O-Net的效果与R-Net的区别在于这一层结构会通过更多的监督来识别面部的区域,而且会对人的面部特征点进行回归,最终输出五个人脸面部特征点。</p><h4 id="代码-4">代码</h4><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># 精修框并定位五点</span></span><br><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">create_Onet</span>(<span class="params">weight_path</span>):</span></span><br><span class="line"> inputs = Input(shape = [<span class="number">48</span>,<span class="number">48</span>,<span class="number">3</span>])</span><br><span class="line"> <span class="comment"># 48,48,3 -> 46,46,32 -> 23,23,32</span></span><br><span class="line"> x = Conv2D(<span class="number">32</span>, (<span class="number">3</span>, <span class="number">3</span>), strides=<span class="number">1</span>, padding=<span class="string">'valid'</span>, name=<span class="string">'conv1'</span>)(inputs)</span><br><span class="line"> x = PReLU(shared_axes=[<span class="number">1</span>,<span class="number">2</span>],name=<span class="string">'prelu1'</span>)(x)</span><br><span class="line"> x = MaxPool2D(pool_size=<span class="number">3</span>, strides=<span class="number">2</span>, padding=<span class="string">'same'</span>)(x)</span><br><span class="line"></span><br><span class="line"> <span class="comment"># 23,23,32 -> 21,21,64 -> 10,10,64</span></span><br><span class="line"> x = Conv2D(<span class="number">64</span>, (<span class="number">3</span>, <span class="number">3</span>), strides=<span class="number">1</span>, padding=<span class="string">'valid'</span>, name=<span class="string">'conv2'</span>)(x)</span><br><span class="line"> x = PReLU(shared_axes=[<span class="number">1</span>,<span class="number">2</span>],name=<span class="string">'prelu2'</span>)(x)</span><br><span class="line"> x = MaxPool2D(pool_size=<span class="number">3</span>, strides=<span class="number">2</span>)(x)</span><br><span class="line"></span><br><span class="line"> <span class="comment"># 8,8,64 -> 4,4,64</span></span><br><span class="line"> x = Conv2D(<span class="number">64</span>, (<span class="number">3</span>, <span class="number">3</span>), strides=<span class="number">1</span>, padding=<span class="string">'valid'</span>, name=<span class="string">'conv3'</span>)(x)</span><br><span class="line"> x = PReLU(shared_axes=[<span class="number">1</span>,<span class="number">2</span>],name=<span class="string">'prelu3'</span>)(x)</span><br><span class="line"> x = MaxPool2D(pool_size=<span class="number">2</span>)(x)</span><br><span class="line"></span><br><span class="line"> <span class="comment"># 4,4,64 -> 3,3,128</span></span><br><span class="line"> x = Conv2D(<span class="number">128</span>, (<span class="number">2</span>, <span class="number">2</span>), strides=<span class="number">1</span>, padding=<span class="string">'valid'</span>, name=<span class="string">'conv4'</span>)(x)</span><br><span class="line"> x = PReLU(shared_axes=[<span class="number">1</span>,<span class="number">2</span>],name=<span class="string">'prelu4'</span>)(x)</span><br><span class="line"></span><br><span class="line"> <span class="comment"># 3,3,128 -> 128,12,12</span></span><br><span class="line"> x = Permute((<span class="number">3</span>,<span class="number">2</span>,<span class="number">1</span>))(x)</span><br><span class="line"> x = Flatten()(x)</span><br><span class="line"></span><br><span class="line"> <span class="comment"># 1152 -> 256</span></span><br><span class="line"> x = Dense(<span class="number">256</span>, name=<span class="string">'conv5'</span>) (x)</span><br><span class="line"> x = PReLU(name=<span class="string">'prelu5'</span>)(x)</span><br><span class="line"></span><br><span class="line"> <span class="comment"># 256 -> 2 </span></span><br><span class="line"> classifier = Dense(<span class="number">2</span>, activation=<span class="string">'softmax'</span>,name=<span class="string">'conv6-1'</span>)(x)</span><br><span class="line"> <span class="comment"># 256 -> 4 </span></span><br><span class="line"> bbox_regress = Dense(<span class="number">4</span>,name=<span class="string">'conv6-2'</span>)(x)</span><br><span class="line"> <span class="comment"># 256 -> 10 </span></span><br><span class="line"> landmark_regress = Dense(<span class="number">10</span>,name=<span class="string">'conv6-3'</span>)(x)</span><br><span class="line"></span><br><span class="line"> model = Model([inputs], [classifier, bbox_regress, landmark_regress])</span><br><span class="line"> model.load_weights(weight_path, by_name=<span class="literal">True</span>)</span><br><span class="line"> <span class="keyword">return</span> model</span><br></pre></td></tr></table></figure><h1>FaceNet特征提取</h1><h2 id="FaceNet概述">FaceNet概述</h2><p>谷歌人脸识别算法,发表于 CVPR 2015,利用相同人脸在不同角度等姿态的照片下有高内聚性,不同人脸有低耦合性,提出使用 CNN + Triplet mining 方法,在 LFW 数据集上准确度达到 99.63%。</p><p>通过 CNN 将人脸映射到欧式空间的特征向量上,实质上:不同图片人脸特征的距离较大;通过相同个体的人脸的距离,总是小于不同个体的人脸这一先验知识训练网络。</p><p>测试时只需要计算人脸特征Embedding,然后计算距离使用阈值即可判定两张人脸照片是否属于相同的个体。</p><h2 id="FaceNet实现">FaceNet实现</h2><p>FaceNet的主干网络起到提取特征的作用,传统的FaceNet以Inception-ResNetV1为主干特征提取网络。</p><p>MobilenetV1模型是Google针对手机等嵌入式设备提出的一种轻量级的深层神经网络,其使用的核心思想便是depthwise separable convolution(深度可分离卷积块)。</p><p>深度可分离卷积块由两个部分组成,分别是深度可分离卷积和1x1普通卷积,深度可分离卷积的卷积核大小一般是3x3的,便于理解的话我们可以把它当作是特征提取,1x1的普通卷积可以完成通道数的调整。</p><p><img src="https://gitee.com/sg2019/picgo/raw/master/20191030154355407.png" alt="20191030154355407"></p><blockquote><p>**深度可分离卷积块的目的是使用更少的参数来代替普通的3x3卷积。**与普通卷积相比,深度可分离卷积结构块可以减少模型的参数。</p></blockquote><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">import</span> math</span><br><span class="line"><span class="keyword">import</span> numpy <span class="keyword">as</span> np</span><br><span class="line"><span class="keyword">import</span> tensorflow <span class="keyword">as</span> tf</span><br><span class="line"></span><br><span class="line"><span class="keyword">from</span> keras <span class="keyword">import</span> backend</span><br><span class="line"><span class="keyword">from</span> keras <span class="keyword">import</span> backend <span class="keyword">as</span> K</span><br><span class="line"><span class="keyword">from</span> keras.preprocessing <span class="keyword">import</span> image</span><br><span class="line"><span class="keyword">from</span> keras.models <span class="keyword">import</span> Model</span><br><span class="line"><span class="keyword">from</span> keras.layers.normalization <span class="keyword">import</span> BatchNormalization</span><br><span class="line"><span class="keyword">from</span> keras.layers <span class="keyword">import</span> Conv2D, Add, ZeroPadding2D, GlobalAveragePooling2D, Dropout, Dense, Lambda</span><br><span class="line"><span class="keyword">from</span> keras.layers <span class="keyword">import</span> MaxPooling2D,Activation,DepthwiseConv2D,Input,GlobalMaxPooling2D</span><br><span class="line"><span class="keyword">from</span> keras.applications <span class="keyword">import</span> imagenet_utils</span><br><span class="line"><span class="keyword">from</span> keras.applications.imagenet_utils <span class="keyword">import</span> decode_predictions</span><br><span class="line"><span class="keyword">from</span> keras.utils.data_utils <span class="keyword">import</span> get_file</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">_conv_block</span>(<span class="params">inputs, filters, kernel=(<span class="params"><span class="number">3</span>, <span class="number">3</span></span>), strides=(<span class="params"><span class="number">1</span>, <span class="number">1</span></span>)</span>):</span></span><br><span class="line"> x = Conv2D(filters, kernel,</span><br><span class="line"> padding=<span class="string">'same'</span>,</span><br><span class="line"> use_bias=<span class="literal">False</span>,</span><br><span class="line"> strides=strides,</span><br><span class="line"> name=<span class="string">'conv1'</span>)(inputs)</span><br><span class="line"> x = BatchNormalization(name=<span class="string">'conv1_bn'</span>)(x)</span><br><span class="line"> <span class="keyword">return</span> Activation(relu6, name=<span class="string">'conv1_relu'</span>)(x)</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">_depthwise_conv_block</span>(<span class="params">inputs, pointwise_conv_filters,</span></span></span><br><span class="line"><span class="function"><span class="params"> depth_multiplier=<span class="number">1</span>, strides=(<span class="params"><span class="number">1</span>, <span class="number">1</span></span>), block_id=<span class="number">1</span></span>):</span></span><br><span class="line"></span><br><span class="line"> x = DepthwiseConv2D((<span class="number">3</span>, <span class="number">3</span>),</span><br><span class="line"> padding=<span class="string">'same'</span>,</span><br><span class="line"> depth_multiplier=depth_multiplier,</span><br><span class="line"> strides=strides,</span><br><span class="line"> use_bias=<span class="literal">False</span>,</span><br><span class="line"> name=<span class="string">'conv_dw_%d'</span> % block_id)(inputs)</span><br><span class="line"> </span><br><span class="line"> x = BatchNormalization(name=<span class="string">'conv_dw_%d_bn'</span> % block_id)(x)</span><br><span class="line"> x = Activation(relu6, name=<span class="string">'conv_dw_%d_relu'</span> % block_id)(x)</span><br><span class="line"> </span><br><span class="line"> x = Conv2D(pointwise_conv_filters, (<span class="number">1</span>, <span class="number">1</span>),</span><br><span class="line"> padding=<span class="string">'same'</span>,</span><br><span class="line"> use_bias=<span class="literal">False</span>,</span><br><span class="line"> strides=(<span class="number">1</span>, <span class="number">1</span>),</span><br><span class="line"> name=<span class="string">'conv_pw_%d'</span> % block_id)(x)</span><br><span class="line"> x = BatchNormalization(name=<span class="string">'conv_pw_%d_bn'</span> % block_id)(x)</span><br><span class="line"> <span class="keyword">return</span> Activation(relu6, name=<span class="string">'conv_pw_%d_relu'</span> % block_id)(x)</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">relu6</span>(<span class="params">x</span>):</span></span><br><span class="line"> <span class="keyword">return</span> K.relu(x, max_value=<span class="number">6</span>)</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">MobileNet</span>(<span class="params">inputs, embedding_size=<span class="number">128</span>, dropout_keep_prob=<span class="number">0.8</span>, alpha=<span class="number">1.0</span>, depth_multiplier=<span class="number">1</span></span>):</span></span><br><span class="line"> x = _conv_block(inputs, <span class="number">32</span>, strides=(<span class="number">2</span>, <span class="number">2</span>))</span><br><span class="line"> x = _depthwise_conv_block(x, <span class="number">64</span>, depth_multiplier, block_id=<span class="number">1</span>)</span><br><span class="line"></span><br><span class="line"> x = _depthwise_conv_block(x, <span class="number">128</span>, depth_multiplier, strides=(<span class="number">2</span>, <span class="number">2</span>), block_id=<span class="number">2</span>)</span><br><span class="line"> x = _depthwise_conv_block(x, <span class="number">128</span>, depth_multiplier, block_id=<span class="number">3</span>)</span><br><span class="line"> </span><br><span class="line"> x = _depthwise_conv_block(x, <span class="number">256</span>, depth_multiplier, strides=(<span class="number">2</span>, <span class="number">2</span>), block_id=<span class="number">4</span>)</span><br><span class="line"> x = _depthwise_conv_block(x, <span class="number">256</span>, depth_multiplier, block_id=<span class="number">5</span>)</span><br><span class="line"> </span><br><span class="line"> x = _depthwise_conv_block(x, <span class="number">512</span>, depth_multiplier, strides=(<span class="number">2</span>, <span class="number">2</span>), block_id=<span class="number">6</span>)</span><br><span class="line"> x = _depthwise_conv_block(x, <span class="number">512</span>, depth_multiplier, block_id=<span class="number">7</span>)</span><br><span class="line"> x = _depthwise_conv_block(x, <span class="number">512</span>, depth_multiplier, block_id=<span class="number">8</span>)</span><br><span class="line"> x = _depthwise_conv_block(x, <span class="number">512</span>, depth_multiplier, block_id=<span class="number">9</span>)</span><br><span class="line"> x = _depthwise_conv_block(x, <span class="number">512</span>, depth_multiplier, block_id=<span class="number">10</span>)</span><br><span class="line"> x = _depthwise_conv_block(x, <span class="number">512</span>, depth_multiplier, block_id=<span class="number">11</span>)</span><br><span class="line"> </span><br><span class="line"> x = _depthwise_conv_block(x, <span class="number">1024</span>, depth_multiplier, strides=(<span class="number">2</span>, <span class="number">2</span>), block_id=<span class="number">12</span>)</span><br><span class="line"> x = _depthwise_conv_block(x, <span class="number">1024</span>, depth_multiplier, block_id=<span class="number">13</span>)</span><br></pre></td></tr></table></figure><p><img src="https://upload-images.jianshu.io/upload_images/147042-b88cbde9287e4ce1.png?imageMogr2/auto-orient/strip%7CimageView2/2/format/webp" alt="img"></p><p>FaceNet总体训练流程如下:</p><ul><li>将图像通过深度卷积神经网络映射到128维的特征空间(欧几里得空间)中,得到对应的128维特征向量</li><li>对特征向量进行L2正则化,筛选出有效特征</li><li>使用正则化后的特征向量,计算Triplet Loss</li></ul><p>本项目采用<a href="https://drive.google.com/open?id=1pwQ3H4aJ8a6yyJHZkTwtjcL4wYWQb7bn">Keras FaceNet 预训练模型</a>,可以从官网下载训练。</p><h3 id="1-根据初步特征获得128维特征向量">1. 根据初步特征获得128维特征向量</h3><h4 id="原理-5">原理</h4><p>利用主干特征提取网络获得特征层,shape为<code>(batch_size, h, w, channels)</code>,可以将其取全局平均池化,方便后续的处理<code>(batch_size, channels)</code>。将平铺后的特征层进行神经元个数为128的全连接,此时相当于利用128维特征向量代替输入图片,128维特征向量即为输入图片的特征浓缩。</p><h4 id="代码-5">代码</h4><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">x = GlobalAveragePooling2D()(x)</span><br><span class="line">x = Dropout(<span class="number">1.0</span> - dropout_keep_prob, name=<span class="string">'Dropout'</span>)(x)</span><br><span class="line">x = Dense(classes, use_bias=<span class="literal">False</span>, name=<span class="string">'Bottleneck'</span>)(x)</span><br><span class="line">x = BatchNormalization(momentum=<span class="number">0.995</span>, epsilon=<span class="number">0.001</span>, scale=<span class="literal">False</span>,</span><br><span class="line"> name=<span class="string">'BatchNorm_Bottleneck'</span>)(x)</span><br></pre></td></tr></table></figure><h3 id="2-L2标准化">2. L2标准化</h3><h4 id="原理-6">原理</h4><p>在获得128维特征向量后,进行L2标准化处理,使得不同人脸的特征向量方便比较。在Keras中L2标准化很容易实现。</p><h4 id="代码-6">代码</h4><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">x= Lambda(<span class="keyword">lambda</span> x: K.l2_normalize(x, axis=-<span class="number">1</span>))(x)</span><br><span class="line"><span class="comment"># 创建模型</span></span><br><span class="line">model = Model(inputs, x, name=<span class="string">'inception_resnet_v1'</span>)</span><br></pre></td></tr></table></figure><h3 id="3-构建分类器">3. 构建分类器</h3><h4 id="原理-7">原理</h4><p>仅考虑Triplet Loss会使得整个网络难以收敛,结合Cross-Entropy Loss和Triplet Loss作为总体loss。</p><ul><li>Triplet Loss用于进行不同人的人脸特征向量欧几里得距离的扩张,同一个人的不同状态的人脸特征向量欧几里得距离的缩小。</li><li>Cross-Entropy Loss用于人脸分类,辅助Triplet Loss收敛。</li></ul><blockquote><p><strong>关于Triplet Loss</strong></p><p>其输入是一个三元组(a, p, n):</p><ul><li><p>a:anchor,基准图片获得的128维人脸特征向量</p></li><li><p>p:positive,与基准图片属于同一张人脸的图片获得的128维人脸特征向量</p></li><li><p>n:negative,与基准图片不属于同一张人脸的图片获得的128维人脸特征向量</p></li></ul><p>将anchor和positive求欧几里得距离,并使其尽量小;将negative和positive求欧几里得距离,并使其尽量大。</p><p>公式为:</p><p><span class="katex-display"><span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><semantics><mrow><mi>L</mi><mo>=</mo><mi>m</mi><mi>a</mi><mi>x</mi><mo stretchy="false">(</mo><mi>d</mi><mo stretchy="false">(</mo><mi>a</mi><mo separator="true">,</mo><mi>p</mi><mo stretchy="false">)</mo><mtext>−</mtext><mi>d</mi><mo stretchy="false">(</mo><mi>a</mi><mo separator="true">,</mo><mi>n</mi><mo stretchy="false">)</mo><mo>+</mo><mi>m</mi><mi>a</mi><mi>r</mi><mi>g</mi><mi>i</mi><mi>n</mi><mo separator="true">,</mo><mn>0</mn><mo stretchy="false">)</mo></mrow><annotation encoding="application/x-tex">L=max(d(a,p)−d(a,n)+margin,0)</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.68333em;vertical-align:0em;"></span><span class="mord mathnormal">L</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span><span class="mrel">=</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span></span><span class="base"><span class="strut" style="height:1em;vertical-align:-0.25em;"></span><span class="mord mathnormal">m</span><span class="mord mathnormal">a</span><span class="mord mathnormal">x</span><span class="mopen">(</span><span class="mord mathnormal">d</span><span class="mopen">(</span><span class="mord mathnormal">a</span><span class="mpunct">,</span><span class="mspace" style="margin-right:0.16666666666666666em;"></span><span class="mord mathnormal">p</span><span class="mclose">)</span><span class="mord">−</span><span class="mord mathnormal">d</span><span class="mopen">(</span><span class="mord mathnormal">a</span><span class="mpunct">,</span><span class="mspace" style="margin-right:0.16666666666666666em;"></span><span class="mord mathnormal">n</span><span class="mclose">)</span><span class="mspace" style="margin-right:0.2222222222222222em;"></span><span class="mbin">+</span><span class="mspace" style="margin-right:0.2222222222222222em;"></span></span><span class="base"><span class="strut" style="height:1em;vertical-align:-0.25em;"></span><span class="mord mathnormal">m</span><span class="mord mathnormal">a</span><span class="mord mathnormal" style="margin-right:0.02778em;">r</span><span class="mord mathnormal" style="margin-right:0.03588em;">g</span><span class="mord mathnormal">i</span><span class="mord mathnormal">n</span><span class="mpunct">,</span><span class="mspace" style="margin-right:0.16666666666666666em;"></span><span class="mord">0</span><span class="mclose">)</span></span></span></span></span></p><p>d(a, p)是anchor和positive的欧几里得距离,d(a, n)是negative和positive的欧几里得距离,margin是常数。</p></blockquote><p>对第2步获得的结果再次进行一个全连接用于分类。</p><h4 id="代码-7">代码</h4><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">facenet</span>(<span class="params">input_shape, num_classes=<span class="literal">None</span>, backbone=<span class="string">"mobilenet"</span>, mode=<span class="string">"train"</span></span>):</span></span><br><span class="line"> inputs = Input(shape=input_shape)</span><br><span class="line"> <span class="keyword">if</span> backbone==<span class="string">"mobilenet"</span>:</span><br><span class="line"> model = MobileNet(inputs)</span><br><span class="line"> <span class="keyword">elif</span> backbone==<span class="string">"inception_resnetv1"</span>:</span><br><span class="line"> model = InceptionResNetV1(inputs)</span><br><span class="line"> <span class="keyword">else</span>:</span><br><span class="line"> <span class="keyword">raise</span> ValueError(<span class="string">'Unsupported backbone - `{}`, Use mobilenet, inception_resnetv1.'</span>.<span class="built_in">format</span>(backbone))</span><br><span class="line"></span><br><span class="line"> <span class="keyword">if</span> mode == <span class="string">"train"</span>:</span><br><span class="line"> x = Dense(num_classes)(model.output)</span><br><span class="line"> x = Activation(<span class="string">"softmax"</span>, name = <span class="string">"Softmax"</span>)(x)</span><br><span class="line"> combine_model = Model(inputs,[x, model.output])</span><br><span class="line"> <span class="keyword">return</span> combine_model</span><br><span class="line"> <span class="keyword">elif</span> mode == <span class="string">"predict"</span>:</span><br><span class="line"> <span class="keyword">return</span> model</span><br><span class="line"> <span class="keyword">else</span>:</span><br><span class="line"> <span class="keyword">raise</span> ValueError(<span class="string">'Unsupported mode - `{}`, Use train, predict.'</span>.<span class="built_in">format</span>(mode))</span><br></pre></td></tr></table></figure><h2 id="FaceNet使用">FaceNet使用</h2><p>FaceNet的使用步骤可以简化为如下四步:</p><ol><li>输入一张人脸图片</li><li>通过深度卷积网络提取特征</li><li>L2标准化</li><li>得到一个长度为128特征向量</li></ol><h1>MTCNN人脸识别</h1><h2 id="数据库初始化">数据库初始化</h2><p>在人脸识别前,需要将存放已知人脸的数据库进行初始化。具体执行过程为:</p><ol><li>遍历数据库中所有的图片</li><li>检测每个图片中的人脸位置</li><li>利用MTCNN将人脸截取下载</li><li>将获取到的人脸进行对齐</li><li>利用FaceNet将人脸进行编码</li><li>将所有人脸编码的结果存入列表</li></ol><p>之后<strong>获得的实时图片中的人脸</strong>与<strong>已知人脸进行比对</strong>,即可计算门限值,从而得到得分最高的人脸。</p><h2 id="实时图片处理">实时图片处理</h2><h3 id="1-人脸截取与对齐">1. 人脸截取与对齐</h3><h4 id="原理-8">原理</h4><p>本项目通过双眼坐标进行旋正,需要用到两个参数,分别是:</p><ol><li>眼睛连线相对于水平线的倾斜角。</li><li>图片的中心。</li></ol><p>通过上述两个参数,可以计算出<strong>图片旋转的角度及中心</strong>,<code>landmark</code>是五个人脸特征点的位置。</p><h4 id="代码-8">代码</h4><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">Alignment_1</span>(<span class="params">img,landmark</span>):</span></span><br><span class="line"></span><br><span class="line"> <span class="keyword">if</span> landmark.shape[<span class="number">0</span>]==<span class="number">68</span>:</span><br><span class="line"> x = landmark[<span class="number">36</span>,<span class="number">0</span>] - landmark[<span class="number">45</span>,<span class="number">0</span>]</span><br><span class="line"> y = landmark[<span class="number">36</span>,<span class="number">1</span>] - landmark[<span class="number">45</span>,<span class="number">1</span>]</span><br><span class="line"> <span class="keyword">elif</span> landmark.shape[<span class="number">0</span>]==<span class="number">5</span>:</span><br><span class="line"> x = landmark[<span class="number">0</span>,<span class="number">0</span>] - landmark[<span class="number">1</span>,<span class="number">0</span>]</span><br><span class="line"> y = landmark[<span class="number">0</span>,<span class="number">1</span>] - landmark[<span class="number">1</span>,<span class="number">1</span>]</span><br><span class="line"> <span class="comment"># 眼睛连线相对于水平线的倾斜角</span></span><br><span class="line"> <span class="keyword">if</span> x==<span class="number">0</span>:</span><br><span class="line"> angle = <span class="number">0</span></span><br><span class="line"> <span class="keyword">else</span>: </span><br><span class="line"> <span class="comment"># 计算它的弧度制</span></span><br><span class="line"> angle = math.atan(y/x)*<span class="number">180</span>/math.pi</span><br><span class="line"></span><br><span class="line"> center = (img.shape[<span class="number">1</span>]//<span class="number">2</span>, img.shape[<span class="number">0</span>]//<span class="number">2</span>)</span><br><span class="line"> </span><br><span class="line"> RotationMatrix = cv2.getRotationMatrix2D(center, angle, <span class="number">1</span>)</span><br><span class="line"> <span class="comment"># 仿射函数</span></span><br><span class="line"> new_img = cv2.warpAffine(img,RotationMatrix,(img.shape[<span class="number">1</span>],img.shape[<span class="number">0</span>])) </span><br><span class="line"></span><br><span class="line"> RotationMatrix = np.array(RotationMatrix)</span><br><span class="line"> new_landmark = []</span><br><span class="line"> <span class="keyword">for</span> i <span class="keyword">in</span> <span class="built_in">range</span>(landmark.shape[<span class="number">0</span>]):</span><br><span class="line"> pts = [] </span><br><span class="line"> pts.append(RotationMatrix[<span class="number">0</span>,<span class="number">0</span>]*landmark[i,<span class="number">0</span>]+RotationMatrix[<span class="number">0</span>,<span class="number">1</span>]*landmark[i,<span class="number">1</span>]+RotationMatrix[<span class="number">0</span>,<span class="number">2</span>])</span><br><span class="line"> pts.append(RotationMatrix[<span class="number">1</span>,<span class="number">0</span>]*landmark[i,<span class="number">0</span>]+RotationMatrix[<span class="number">1</span>,<span class="number">1</span>]*landmark[i,<span class="number">1</span>]+RotationMatrix[<span class="number">1</span>,<span class="number">2</span>])</span><br><span class="line"> new_landmark.append(pts)</span><br><span class="line"></span><br><span class="line"> new_landmark = np.array(new_landmark)</span><br><span class="line"></span><br><span class="line"> <span class="keyword">return</span> new_img, new_landmark</span><br></pre></td></tr></table></figure><h3 id="2-FaceNet编码矫正的人脸">2. FaceNet编码矫正的人脸</h3><h4 id="原理-9">原理</h4><p>将第1步获得的对齐人脸传入facenet模型,可以得到每个人脸的特征向量。将所有特征向量保存在一个列表中,在第3步进行比对。</p><h4 id="代码-9">代码</h4><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br></pre></td><td class="code"><pre><span class="line">height,width,_ = np.shape(draw)</span><br><span class="line">draw_rgb = cv2.cvtColor(draw,cv2.COLOR_BGR2RGB)</span><br><span class="line"></span><br><span class="line"><span class="comment"># 检测人脸</span></span><br><span class="line">rectangles = self.mtcnn_model.detectFace(draw_rgb, self.threshold)</span><br><span class="line">print(np.shape(rectangles))</span><br><span class="line"><span class="keyword">if</span> <span class="built_in">len</span>(rectangles)==<span class="number">0</span>:</span><br><span class="line"> <span class="keyword">return</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># 转化成正方形</span></span><br><span class="line">rectangles = utils.rect2square(np.array(rectangles,dtype=np.int32))</span><br><span class="line">rectangles[:,<span class="number">0</span>] = np.clip(rectangles[:,<span class="number">0</span>],<span class="number">0</span>,width)</span><br><span class="line">rectangles[:,<span class="number">1</span>] = np.clip(rectangles[:,<span class="number">1</span>],<span class="number">0</span>,height)</span><br><span class="line">rectangles[:,<span class="number">2</span>] = np.clip(rectangles[:,<span class="number">2</span>],<span class="number">0</span>,width)</span><br><span class="line">rectangles[:,<span class="number">3</span>] = np.clip(rectangles[:,<span class="number">3</span>],<span class="number">0</span>,height)</span><br><span class="line"></span><br><span class="line">face_encodings = []</span><br><span class="line"><span class="keyword">for</span> rectangle <span class="keyword">in</span> rectangles:</span><br><span class="line"> <span class="comment"># 获取landmark坐标</span></span><br><span class="line"> landmark = (np.reshape(rectangle[<span class="number">5</span>:<span class="number">15</span>],(<span class="number">5</span>,<span class="number">2</span>)) - np.array([<span class="built_in">int</span>(rectangle[<span class="number">0</span>]),<span class="built_in">int</span>(rectangle[<span class="number">1</span>])]))/(rectangle[<span class="number">3</span>]-rectangle[<span class="number">1</span>])*<span class="number">160</span></span><br><span class="line"> <span class="comment"># 截取图像</span></span><br><span class="line"> crop_img = draw_rgb[<span class="built_in">int</span>(rectangle[<span class="number">1</span>]):<span class="built_in">int</span>(rectangle[<span class="number">3</span>]), <span class="built_in">int</span>(rectangle[<span class="number">0</span>]):<span class="built_in">int</span>(rectangle[<span class="number">2</span>])]</span><br><span class="line"> crop_img = cv2.resize(crop_img,(<span class="number">160</span>,<span class="number">160</span>))</span><br><span class="line"> <span class="comment"># 对齐</span></span><br><span class="line"> new_img,_ = utils.Alignment_1(crop_img,landmark)</span><br><span class="line"> new_img = np.expand_dims(new_img,<span class="number">0</span>)</span><br><span class="line"> <span class="comment"># 计算128维特征向量</span></span><br><span class="line"> face_encoding = utils.calc_128_vec(self.facenet_model,new_img)</span><br><span class="line"> face_encodings.append(face_encoding)</span><br></pre></td></tr></table></figure><h3 id="3-比对实时图片与数据库的人脸特征">3. 比对实时图片与数据库的人脸特征</h3><h4 id="原理-10">原理</h4><p>比对过程大致如下:</p><ol><li>获取每一张实时图片的人脸特征</li><li>将每一张图片的人脸特征和数据库中所有的人脸特征进行比较,计算距离</li><li>如果距离小于门限值,则认为其具有一定的相似度</li><li>获得每一张人脸在数据库中最相似的人脸的序号</li><li>判断这个序号对应的人脸距离是否小于门限,是则认为人脸识别成功,否则认为无法识别(Unkown)</li></ol><h4 id="代码-10">代码</h4><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line">face_names = []</span><br><span class="line"><span class="keyword">for</span> face_encoding <span class="keyword">in</span> face_encodings:</span><br><span class="line"> <span class="comment"># 取出一张脸并与数据库中所有的人脸进行对比,计算得分</span></span><br><span class="line"> matches = utils.compare_faces(self.known_face_encodings, face_encoding, tolerance = <span class="number">0.9</span>)</span><br><span class="line"> name = <span class="string">"Unknown"</span></span><br><span class="line"> <span class="comment"># 找出距离最近的人脸</span></span><br><span class="line"> face_distances = utils.face_distance(self.known_face_encodings, face_encoding)</span><br><span class="line"> <span class="comment"># 取出这个最近人脸的评分</span></span><br><span class="line"> best_match_index = np.argmin(face_distances)</span><br><span class="line"> <span class="keyword">if</span> matches[best_match_index]:</span><br><span class="line"> name = self.known_face_names[best_match_index]</span><br><span class="line"> face_names.append(name)</span><br></pre></td></tr></table></figure><h1>Flask 实现 RESTful API</h1><h2 id="Flask概述">Flask概述</h2><p>flask是一个使用Python编写的轻量级<strong>Web应用框架</strong>,WSGI工具箱采用Werkzeug,<strong>模板引擎</strong>则使用Jinja2。它没有默认使用的数据库、窗体验证工具,但保留了扩增的弹性,可以用flask-extension加入这些功能。由于其书写简单,扩展性强,成为了python最受欢迎的web框架之一。</p><h2 id="RESTful-API">RESTful API</h2><p>REST 是 Representational State Transfer的缩写,如果一个架构符合REST原则,就称它为RESTful架构。</p><ul><li>RESTful 架构可以充分的利用 HTTP 协议的各种功能,是 HTTP 协议的最佳实践</li><li>RESTful API 是一种软件架构风格、设计风格,可以让软件更加清晰,更简洁,更有层次,可维护性更好</li></ul><h2 id="Flask-RESTful-API-实现">Flask RESTful API 实现</h2><h3 id="1-微信小程序数据转码">1. 微信小程序数据转码</h3><h4 id="原理-11">原理</h4><p>微信小程序调用摄像头获取视频帧,以数据流的形式存入<code>json</code>格式的接口,数据流采用<code>base64</code>算法编码。后端接收数据流后,需要先对<code>base64</code>格式的数据进行解码,再将解码得到的字符串转换为<code>numpy</code>列表,最后编码为<code>opencv</code>常用的<code>BGR</code>格式。</p><h4 id="代码-11">代码</h4><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">base64_to_image</span>(<span class="params">base64_code</span>):</span></span><br><span class="line"> img_data = base64.b64decode(base64_code)</span><br><span class="line"> img_array = np.fromstring(img_data, np.uint8)</span><br><span class="line"> img = cv2.imdecode(img_array, cv2.COLOR_RGB2BGR)</span><br><span class="line"></span><br><span class="line"> <span class="keyword">return</span> img</span><br></pre></td></tr></table></figure><h3 id="2-上传图片-API">2. 上传图片 API</h3><h4 id="原理-12">原理</h4><p>如果要将图片上传至服务端,需要判断图片格式是否符合要求,进而获取图片存储路径,上传图片。</p><h4 id="代码-12">代码</h4><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">allowed_file</span>(<span class="params">filename</span>):</span></span><br><span class="line"> <span class="keyword">return</span> <span class="string">'.'</span> <span class="keyword">in</span> filename <span class="keyword">and</span> \</span><br><span class="line"> filename.rsplit(<span class="string">'.'</span>, <span class="number">1</span>)[<span class="number">1</span>] <span class="keyword">in</span> ALLOWED_EXTENSIONS</span><br><span class="line"></span><br><span class="line"> </span><br><span class="line"><span class="meta">@app.route(<span class="params"><span class="string">'/api/upload'</span>, methods=[<span class="string">'POST'</span>, <span class="string">'GET'</span>]</span>)</span></span><br><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">upload</span>():</span></span><br><span class="line"> <span class="keyword">if</span> request.method == <span class="string">'POST'</span>:</span><br><span class="line"> pic = request.files.get(<span class="string">'pic'</span>)</span><br><span class="line"> base_path = os.path.dirname(__file__)</span><br><span class="line"></span><br><span class="line"> <span class="keyword">if</span> pic <span class="keyword">and</span> allowed_file(pic.filename):</span><br><span class="line"> filename = secure_filename(pic.filename)</span><br><span class="line"></span><br><span class="line"> upload_path = os.path.join(base_path, app.config[<span class="string">'UPLOAD_FOLDER'</span>], filename)</span><br><span class="line"> upload_path = os.path.abspath(upload_path)</span><br><span class="line"></span><br><span class="line"> pic.save(upload_path)</span><br><span class="line"> <span class="keyword">return</span> <span class="string">"{} Upload Success!"</span>.<span class="built_in">format</span>(filename)</span><br><span class="line"> <span class="keyword">return</span> <span class="string">'''</span></span><br><span class="line"><span class="string"> <!DOCTYPE html></span></span><br><span class="line"><span class="string"> <title>Upload new File</title></span></span><br><span class="line"><span class="string"> <h1>Upload new File</h1></span></span><br><span class="line"><span class="string"> <form action="" method=post enctype=multipart/form-data></span></span><br><span class="line"><span class="string"> <p><input type=file name=file></span></span><br><span class="line"><span class="string"> <input type=submit value=Upload></p></span></span><br><span class="line"><span class="string"> </form></span></span><br><span class="line"><span class="string"> '''</span></span><br></pre></td></tr></table></figure><h3 id="3-人脸特征提取-API">3. 人脸特征提取 API</h3><h4 id="原理-13">原理</h4><p>通过以上实现的MTCNN + FaceNet,先进行人脸对齐,再对人脸特征进行提取,获得128维特征向量。最终,将提取的128维人脸特征向量转化为<code>json</code>格式,返回至前端。</p><h4 id="代码-13">代码</h4><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">@app.route(<span class="params"><span class="string">'/api/base64/align'</span>, methods=[<span class="string">'POST'</span>, <span class="string">'GET'</span>]</span>)</span></span><br><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">base64_align</span>():</span></span><br><span class="line"> <span class="keyword">if</span> request.method == <span class="string">'POST'</span>:</span><br><span class="line"> pic = request.data.get(<span class="string">'photo'</span>)</span><br><span class="line"> pic = base64_to_image(pic)</span><br><span class="line"> <span class="keyword">return</span> json.dump(align.img_128_vec(pic))</span><br><span class="line"> <span class="keyword">return</span> <span class="string">'''</span></span><br><span class="line"><span class="string"> WeiXin Camera data get failed</span></span><br><span class="line"><span class="string"> '''</span></span><br></pre></td></tr></table></figure><h1>部分项目结果展示</h1><p><img src="https://gitee.com/sg2019/picgo/raw/master/image-20210427222808499.png" alt="image-20210427222808499"></p>]]></content>
<categories>
<category> 技术 </category>
<category> 计算机视觉 </category>
</categories>
<tags>
<tag> Flask </tag>
<tag> python </tag>
<tag> MTCNN </tag>
<tag> 人脸识别 </tag>
<tag> 神经网络 </tag>
<tag> FaceNet </tag>
<tag> Keras </tag>
</tags>
</entry>
<entry>
<title>Hexo博客配置说说——插件HexoPlusPlus Talk详解</title>
<link href="posts/33452/"/>
<url>posts/33452/</url>
<content type="html"><![CDATA[<script src="\assets\js\APlayer.min.js"> </script><p>相关配置:给<a href="https://butterfly.js.org/">hexo-theme-butterfly</a>添加<a href="https://hexoplusplus.js.org/">hexoplusplus</a>说说</p><p>(超链接均为原项目博客)</p><blockquote><p><strong>GitHub地址</strong>:<a href="https://github.com/jerryc127/butterfly-plugins/tree/main/hexo-butterfly-hpptalk">https://github.com/jerryc127/butterfly-plugins/tree/main/hexo-butterfly-hpptalk</a></p></blockquote><h2 id="安装插件">安装插件</h2><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">npm install hexo-butterfly-hpptalk</span><br></pre></td></tr></table></figure>]]></content>
<categories>
<category> 技术 </category>
<category> 博客 </category>
</categories>
<tags>
<tag> 博客 </tag>
<tag> Hexo </tag>
<tag> hpptalk </tag>
</tags>
</entry>
<entry>
<title>C++实现Markdown解析器</title>
<link href="posts/48225/"/>
<url>posts/48225/</url>
<content type="html"><![CDATA[<script src="\assets\js\APlayer.min.js"> </script><p>项目地址:<a href="https://gitee.com/sg2019/markdown-parser">https://gitee.com/sg2019/markdown-parser</a></p>]]></content>
<categories>
<category> 技术 </category>
<category> C++ </category>
</categories>
<tags>
<tag> C++ </tag>
<tag> Markdown </tag>
<tag> DFS </tag>
</tags>
</entry>
<entry>
<title>C++指针、引用、const</title>
<link href="posts/14155/"/>
<url>posts/14155/</url>
<content type="html"><![CDATA[<script src="\assets\js\APlayer.min.js"> </script><h2 id="指针">指针</h2><h3 id="指针和指针变量">指针和指针变量</h3><p><strong>指针</strong>:内存地址,用于间接访问内存单元<br><strong>指针变量</strong>:用于存放地址的变量,指针变量是有类型的</p><h3 id="指针变量的算术运算">指针变量的算术运算</h3><p><strong>指针与整数的加减运算</strong>:指针p加上或减去n,等于指针当前指向位置的前方或后方第n个数据对象的地址,这种运算的结果值取决于指针指向对象的<strong>数据类型</strong>。</p><p><strong>指针加1,减,1运算</strong>:指向后一个或前一个数据对象的地址</p><p>注:<code>*</code>和<code>++</code>、<code>--</code>优先级相同,自右向左运算</p><figure class="highlight cpp"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">*px++ = *(px++)</span><br></pre></td></tr></table></figure><h3 id="指针变量的关系运算">指针变量的关系运算</h3><p>指向<strong>相同类型数据</strong>的指针变量之间可以进行各种关系运算</p><p>指针可以和零之间进行等于或不等于的关系运算,例如: <code>p==0</code> 或 <code>p!=0</code>(相当于<code>NULL</code>)</p><h3 id="指针变量的赋值运算">指针变量的赋值运算</h3><p>向指针变量赋的值必须是<strong>地址常量或变量</strong>,不能是普通整数。但可以赋值为整数 0 ,表示空指针。</p>]]></content>
<categories>
<category> 技术 </category>
<category> C++ </category>
</categories>
<tags>
<tag> C++ </tag>
<tag> 指针 </tag>
<tag> 引用 </tag>
<tag> const </tag>
</tags>
</entry>
<entry>
<title>HTML5基础</title>
<link href="posts/13914/"/>
<url>posts/13914/</url>
<content type="html"><![CDATA[<script src="\assets\js\APlayer.min.js"> </script><h2 id="HTML概述">HTML概述</h2><p>HTML(超文本标记语言)是一种用于创建网页的标准标记语言。 HTML 不需要编译,可以直接由浏览器执行,它的解析依赖于浏览器的内核。 它不是一种编程语言,而是一种标记语言。</p><blockquote><p>前端语言常常见到ML,这是Markup Language(标记语言)的缩写。我们所熟知的HTML就是Hyper Text Markup Language的缩写,意为“超文本标记语言”。</p></blockquote><h3 id="HTML网页结构">HTML网页结构</h3><figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta"><!DOCTYPE <span class="meta-keyword">html</span>></span></span><br><span class="line"><span class="tag"><<span class="name">html</span>></span></span><br><span class="line"> <span class="tag"><<span class="name">head</span>></span></span><br><span class="line"> <span class="tag"><<span class="name">title</span>></span>HTML 简介<span class="tag"></<span class="name">title</span>></span></span><br><span class="line"> <span class="tag"></<span class="name">head</span>></span></span><br><span class="line"> <span class="tag"><<span class="name">body</span>></span><span class="tag"></<span class="name">body</span>></span></span><br><span class="line"><span class="tag"></<span class="name">html</span>></span></span><br></pre></td></tr></table></figure><ul><li><code><!DOCTYPE html></code> 是文档声明头,告诉浏览器,本文档处理的是 HTML 文档。</li><li><code>html</code> 标签即根元素,此处表示文档的开始。</li><li><code>head</code> 标签是网页的头部,设置网页的相关信息。</li><li><code>title</code> 标签设置网页标题。</li><li><code>body</code> 标签定义文档的主体,也即主要内容。</li></ul><h3 id="HTML注释">HTML注释</h3><p>在 HTML 中满足以下格式的内容即为注释,被注释的内容将不会被渲染和显示。</p><figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"><!-- 在此处写注释 --></span></span><br></pre></td></tr></table></figure><h2 id="HTML常用标签">HTML常用标签</h2><p>HTML 标签是 HTML 语言中最基本的单位。HTML 标签的大小写无关,例如 <code><body></code>和 <code><BODY></code> 表示的意思是一样的,推荐使用小写。</p><h4 id="双标签(双标记)">双标签(双标记)</h4><p>双标记也称体标记,是指由开始和结束两个标记符组成的标记。其基本语法格式如下:</p><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><标记名></标记名></span><br></pre></td></tr></table></figure><p>常见的双标签有:</p><figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag"><<span class="name">html</span>></span><span class="tag"></<span class="name">html</span>></span></span><br><span class="line"><span class="tag"><<span class="name">head</span>></span><span class="tag"></<span class="name">head</span>></span></span><br><span class="line"><span class="tag"><<span class="name">title</span>></span><span class="tag"></<span class="name">title</span>></span></span><br><span class="line"><span class="tag"><<span class="name">body</span>></span><span class="tag"></<span class="name">body</span>></span></span><br><span class="line"><span class="tag"><<span class="name">h1</span>></span><span class="tag"></<span class="name">h1</span>></span></span><br><span class="line"><span class="tag"><<span class="name">p</span>></span><span class="tag"></<span class="name">p</span>></span></span><br><span class="line"><span class="tag"><<span class="name">div</span>></span><span class="tag"></<span class="name">div</span>></span></span><br><span class="line"><span class="tag"><<span class="name">span</span>></span><span class="tag"></<span class="name">span</span>></span></span><br><span class="line"><span class="tag"><<span class="name">a</span>></span><span class="tag"></<span class="name">a</span>></span></span><br><span class="line"><span class="tag"><<span class="name">ul</span>></span><span class="tag"></<span class="name">ul</span>></span></span><br></pre></td></tr></table></figure><h4 id="单标签(单标记)">单标签(单标记)</h4><p>单标记也称空标记,是指用一个标记符号即可完整地描述某个功能的标记。其基本语法格式如下:</p><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><标记名/></span><br></pre></td></tr></table></figure><p>常见的单标签有:</p><figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag"><<span class="name">br</span> /></span></span><br><span class="line"><span class="comment"><!--换行--></span></span><br><span class="line"><span class="tag"><<span class="name">hr</span> /></span></span><br><span class="line"><span class="comment"><!--水平分隔线--></span></span><br><span class="line"><span class="tag"><<span class="name">meta</span> /></span></span><br><span class="line"><span class="tag"><<span class="name">img</span> /></span></span><br></pre></td></tr></table></figure><h4 id="标签的关系">标签的关系</h4><ul><li>嵌套关系</li></ul><figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag"><<span class="name">head</span>></span></span><br><span class="line"> <span class="tag"><<span class="name">title</span>></span> <span class="tag"></<span class="name">title</span>></span></span><br><span class="line"><span class="tag"></<span class="name">head</span>></span></span><br></pre></td></tr></table></figure><ul><li>并列关系</li></ul><figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag"><<span class="name">head</span>></span><span class="tag"></<span class="name">head</span>></span></span><br><span class="line"><span class="tag"><<span class="name">body</span>></span><span class="tag"></<span class="name">body</span>></span></span><br></pre></td></tr></table></figure><h3 id="HTML元素">HTML元素</h3><p>HTML 元素指的是从开始标签(start tag)到结束标签(end tag)的所有代码。</p><h3 id="HTML标签">HTML标签</h3><h4 id="h-系类标签">h 系类标签</h4><p><code>h</code> 标签有六种 <code>h1</code>,<code>h2</code>,<code>h3</code>,<code>h4</code>,<code>h5</code>,<code>h6</code>,代表不同层级的标题。</p><figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta"><!DOCTYPE <span class="meta-keyword">html</span>></span></span><br><span class="line"><span class="tag"><<span class="name">html</span>></span></span><br><span class="line"> <span class="tag"><<span class="name">body</span>></span></span><br><span class="line"> <span class="tag"><<span class="name">h1</span>></span>一级标题<span class="tag"></<span class="name">h1</span>></span></span><br><span class="line"> <span class="tag"><<span class="name">h2</span>></span>二级标题<span class="tag"></<span class="name">h2</span>></span></span><br><span class="line"> <span class="tag"><<span class="name">h3</span>></span>三级标题<span class="tag"></<span class="name">h3</span>></span></span><br><span class="line"> <span class="tag"><<span class="name">h4</span>></span>四级标题<span class="tag"></<span class="name">h4</span>></span></span><br><span class="line"> <span class="tag"><<span class="name">h5</span>></span>五级标题<span class="tag"></<span class="name">h5</span>></span></span><br><span class="line"> <span class="tag"><<span class="name">h6</span>></span>六级标题<span class="tag"></<span class="name">h6</span>></span></span><br><span class="line"> <span class="tag"></<span class="name">body</span>></span></span><br><span class="line"><span class="tag"></<span class="name">html</span>></span></span><br></pre></td></tr></table></figure><!DOCTYPE html><html> <body> <h1>一级标题</h1> <h2>二级标题</h2> <h3>三级标题</h3> <h4>四级标题</h4> <h5>五级标题</h5> <h6>六级标题</h6> </body></html><h4 id="p-标签">p 标签</h4><p><code>p</code> 标签是文本标签,通常用来表示段落。</p><figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta"><!DOCTYPE <span class="meta-keyword">html</span>></span></span><br><span class="line"><span class="tag"><<span class="name">html</span>></span></span><br><span class="line"> <span class="tag"><<span class="name">body</span>></span></span><br><span class="line"> <span class="tag"><<span class="name">p</span>></span>段落文字<span class="tag"></<span class="name">p</span>></span></span><br><span class="line"> <span class="tag"><<span class="name">p</span>></span>段落文字<span class="tag"></<span class="name">p</span>></span></span><br><span class="line"> <span class="tag"></<span class="name">body</span>></span></span><br><span class="line"><span class="tag"></<span class="name">html</span>></span></span><br></pre></td></tr></table></figure><!DOCTYPE html><html> <body> <p>段落文字</p> <p>段落文字</p> </body></html>]]></content>
<categories>
<category> 技术 </category>
<category> 基础 </category>
</categories>
<tags>
<tag> 基础 </tag>
<tag> Web </tag>
<tag> HTML </tag>
</tags>
</entry>
<entry>
<title>C++ 1x基础</title>
<link href="posts/30775/"/>
<url>posts/30775/</url>
<content type="html"><![CDATA[<script src="\assets\js\APlayer.min.js"> </script><p><strong>提示</strong>:本篇博客代码至少需要开启 <code>-std=c++11</code> 选项来支持 C++ 11 相关特性, C++ 14 特性的相关代码需要开启 <code>-std=c++14</code> 的编译选项。</p><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">$ g++ main.cpp -std=c++11</span><br><span class="line"></span><br><span class="line">$ g++ main.cpp -std=c++14</span><br></pre></td></tr></table></figure>]]></content>
<categories>
<category> 技术 </category>
<category> C++ </category>
</categories>
<tags>
<tag> 基础 </tag>
<tag> C++ </tag>
</tags>
</entry>
<entry>
<title>Qt5基础——用户界面</title>
<link href="posts/17245/"/>
<url>posts/17245/</url>
<content type="html"><![CDATA[<script src="\assets\js\APlayer.min.js"> </script><h2 id="开始Qt">开始Qt</h2><h3 id="Linux下安装Qt开发环境">Linux下安装Qt开发环境</h3><ul><li><p>更新软件</p><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">sudo apt update</span><br></pre></td></tr></table></figure></li><li><p>安装C++环境(若已安装可跳过)</p><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">sudo apt install build-essential</span><br></pre></td></tr></table></figure></li><li><p>安装Qt</p><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">sudo apt install -y qtcreator qt5-default</span><br></pre></td></tr></table></figure></li></ul><h3 id="新建Qt工程">新建Qt工程</h3>]]></content>
<categories>
<category> 技术 </category>
<category> C++ </category>
</categories>
<tags>
<tag> 基础 </tag>
<tag> C++ </tag>
<tag> Qt </tag>
</tags>
</entry>
<entry>
<title>毛泽东概思想概论——邓小平理论</title>
<link href="posts/12565/"/>
<url>posts/12565/</url>
<content type="html"><![CDATA[<script src="\assets\js\APlayer.min.js"> </script><h1>邓小平理论</h1><h2 id="一、邓小平理论的形成">一、邓小平理论的形成</h2><h4 id="1-邓小平理论的形成过程">1. 邓小平理论的形成过程</h4><p>①<strong>时代背景</strong>:和平与发展成为时代主题</p><p>②<strong>历史根据</strong>:社会主义建设的经验教训</p><p>③<strong>现实根据</strong>:我国改革开放和现代化建设的时间</p><h4 id="2-邓小平理论的形成过程">2. 邓小平理论的形成过程</h4><p>①1982年,党的十二大,邓小平理论的<strong>主题形成</strong>(<strong>中国特色社会主义</strong>)。</p><p>②1987年,党的十三大,邓小平理论的<strong>轮廓形成</strong>。</p><p>③1992年,邓小平南方谈话,邓小平理论<strong>逐步走向成熟</strong>。</p><p>④1997年,党的十五大,<strong>正式提出</strong>“邓小平理论”概念,确立为党的指导思想并写入党章。</p><h2 id="二、邓小平理论的基本问题和主要内容">二、邓小平理论的基本问题和主要内容</h2><h3 id="(一)邓小平理论回答的基本问题">(一)邓小平理论回答的基本问题</h3><h4 id="1-什么是社会主义、怎样建设社会主义,是邓小平理论的首要的基本的理论问题">1. 什么是社会主义、怎样建设社会主义,是邓小平理论的首要的基本的理论问题</h4><h4 id="2-对社会主义本质的科学概括">2. 对社会主义本质的科学概括</h4><p>社会主义的本质:解放生产力,发展生产力,消灭剥削,消除两极分化,最终达到共同富裕。</p><h4 id="3-社会主义本质科学概括的意义">3. 社会主义本质科学概括的意义</h4><p>①</p><p>②</p><p>③</p><h3 id="(二)邓小平理论的主要内容">(二)邓小平理论的主要内容</h3><h4 id="1-解放思想、实事求是的思想路线">1. 解放思想、实事求是的思想路线</h4><p><strong>解放思想、实事求是的思想路线</strong>,是邓小平理论的<strong>活的灵魂</strong>,是邓小平理论的<strong>精髓</strong>。</p><h4 id="2-社会主义初级阶段理论">2. 社会主义初级阶段理论</h4><p>党的十三大系统地论述了社会主义初级阶段理论。</p><p>①社会主义初级阶段:我国在生产力落后,商品经济不发达条件下建设社会主义必然要经历的特定阶段,即从我国进入社会主义到基本实现社会主义现代化的整个历史阶段。</p><p>②社会主义初级阶段的论断包括两层含义:</p><ul><li>我国已经进入社会主义社会,必须坚持不能离开社会主义</li><li>我国社会主义社会还处于不发达阶段,必须正视而不能超越初级阶段</li></ul><p>党的十五大进一步阐述了社会主义初级阶段的基本特征。</p><div class="mermaid">graph LRid0(半殖民地半封建社会) --> id1(新民主主义社会)id1 --> id2(社会主义初级阶段)</div>]]></content>
<categories>
<category> 思想 </category>
<category> 毛泽东思想概论 </category>
</categories>
<tags>
<tag> 毛泽东思想概论 </tag>
<tag> 邓小平理论 </tag>
</tags>
</entry>
<entry>
<title>分类算法的数学原理</title>
<link href="posts/27818/"/>
<url>posts/27818/</url>
<content type="html"><![CDATA[<script src="\assets\js\APlayer.min.js"> </script><h2 id="向量-距离">向量 & 距离</h2><h3 id="向量的范数">向量的范数</h3><p>向量的范数表示向量自身的一种性质。在线性代数、泛函分析及相关的数学领域,范数是一个函数,其为向量空间内的所有向量赋予非零的正长度或大小。</p><p>常用的几种向量范数如下:(均以向量<span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi mathvariant="bold-italic">a</mi></mrow><annotation encoding="application/x-tex">\boldsymbol{a}</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.44444em;vertical-align:0em;"></span><span class="mord"><span class="mord"><span class="mord boldsymbol">a</span></span></span></span></span></span>为例)</p><table><thead><tr><th>范数</th><th>意义</th><th>表示</th></tr></thead><tbody><tr><td>0范数</td><td>向量中非零元素的个数</td><td>$${\left|\boldsymbol{a}\right |}_{0}$$</td></tr><tr><td>1范数</td><td>向量中所有元素绝对值之和</td><td>$${\left|\boldsymbol{a}\right |}<em>{1}=\sum\limits</em>{i}{</td></tr><tr><td>2范数(欧几里得范数)</td><td>向量的模长</td><td>$${\left|\boldsymbol{a}\right |}<em>{2}=\sqrt{\sum\limits</em>{i}{a_i^2}}$$</td></tr><tr><td><span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi mathvariant="normal">∞</mi></mrow><annotation encoding="application/x-tex">\infin</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.43056em;vertical-align:0em;"></span><span class="mord">∞</span></span></span></span>范数</td><td>想两种元素的最大值</td><td></td></tr><tr><td><span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mo>−</mo><mi mathvariant="normal">∞</mi></mrow><annotation encoding="application/x-tex">-\infin</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.66666em;vertical-align:-0.08333em;"></span><span class="mord">−</span><span class="mord">∞</span></span></span></span>范数</td><td></td><td></td></tr><tr><td><span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>p</mi></mrow><annotation encoding="application/x-tex">p</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.625em;vertical-align:-0.19444em;"></span><span class="mord mathnormal">p</span></span></span></span>范数</td><td></td><td></td></tr></tbody></table><h3 id="距离度量">距离度量</h3>]]></content>
<categories>
<category> 数学 </category>
<category> 机器学习 </category>
</categories>
<tags>
<tag> 算法 </tag>
<tag> 机器学习 </tag>
<tag> SVM </tag>
<tag> AdaBoost </tag>
<tag> PCA </tag>
</tags>
</entry>
<entry>
<title>Git & GitHub基本操作</title>
<link href="posts/53149/"/>
<url>posts/53149/</url>
<content type="html"><![CDATA[<script src="\assets\js\APlayer.min.js"> </script>]]></content>
<categories>
<category> 技术 </category>
<category> Git </category>
</categories>
<tags>
<tag> Git </tag>
<tag> GitHub </tag>
</tags>
</entry>
<entry>
<title>C++基础</title>
<link href="posts/44178/"/>
<url>posts/44178/</url>
<content type="html"><![CDATA[<script src="\assets\js\APlayer.min.js"> </script>]]></content>
<categories>
<category> 技术 </category>
<category> 基础 </category>
</categories>
<tags>
<tag> C++ </tag>
</tags>
</entry>
<entry>
<title>Flask Web开发基础</title>
<link href="posts/8955/"/>
<url>posts/8955/</url>
<content type="html"><![CDATA[<script src="\assets\js\APlayer.min.js"> </script>]]></content>
<categories>
<category> 技术 </category>
<category> Flask </category>
</categories>
<tags>
<tag> Flask </tag>
<tag> python </tag>
</tags>
</entry>
<entry>
<title>计算机组成原理笔记</title>
<link href="posts/4830/"/>
<url>posts/4830/</url>
<content type="html"><![CDATA[<script src="\assets\js\APlayer.min.js"> </script>]]></content>
<categories>
<category> 专业课 </category>
<category> 计算机组成原理 </category>
</categories>
<tags>
<tag> 计算机组成原理 </tag>
</tags>
</entry>
<entry>
<title>日常高频词根</title>
<link href="posts/29864/"/>
<url>posts/29864/</url>
<content type="html"><![CDATA[<script src="\assets\js\APlayer.min.js"> </script><h3 id="1-cent-i-hundred-百">1. cent(i) = hundred 百</h3><table><thead><tr><th>词汇</th><th>词义</th><th>联想</th><th>相关</th></tr></thead><tbody><tr><td>cent</td><td>美分</td><td></td><td></td></tr><tr><td>centigrade</td><td>摄氏的</td><td>centi + grade(级)</td><td>minus 3 degrees centigrade 零下三度</td></tr><tr><td>percent</td><td>百分比</td><td>per(每)+ cent</td><td><strong>percentile</strong> 百分率的</td></tr><tr><td>percentage</td><td>百分率</td><td>per(每)+ cent + age</td><td>What percentage of … ? …百分之几?</td></tr><tr><td>centimeter</td><td>厘米</td><td>centi + meter(米)</td><td></td></tr><tr><td><strong>centennial</strong></td><td>a. 百年纪念的</br>n. 百年纪念</td><td>cent + enn(年)+ ial</td><td>centenary 一百年</br>centennially 每百年一次</td></tr></tbody></table><h3 id="2-circ-cycl-ring-circle-圆,环">2. circ, cycl = ring, circle 圆,环</h3><table><thead><tr><th>词汇</th><th>词义</th><th>联想</th><th>相关</th></tr></thead><tbody><tr><td>circle</td><td>n. 圆,界,阶层</br>v. 围着</td><td>circ + le</td><td>upper circle 贵宾席</td></tr><tr><td>circlet</td><td>n. 小环</td><td>circ + let(小)</td><td></td></tr><tr><td></td><td></td><td></td><td></td></tr><tr><td></td><td></td><td></td><td></td></tr><tr><td></td><td></td><td></td><td></td></tr><tr><td></td><td></td><td></td><td></td></tr><tr><td></td><td></td><td></td><td></td></tr><tr><td></td><td></td><td></td><td></td></tr><tr><td></td><td></td><td></td><td></td></tr><tr><td></td><td></td><td></td><td></td></tr></tbody></table>]]></content>
<categories>
<category> 英语 </category>
<category> 词汇 </category>
</categories>
<tags>
<tag> 词根 </tag>
</tags>
</entry>
<entry>
<title>python3基础</title>
<link href="posts/38365/"/>
<url>posts/38365/</url>
<content type="html"><![CDATA[<script src="\assets\js\APlayer.min.js"> </script><blockquote><p>本文借鉴自:</p><p><em>Python for you and me</em> : <a href="http://pymbook.readthedocs.io/en/latest/">http://pymbook.readthedocs.io/en/latest/</a></p><p><em>Python tutorial</em> : <a href="http://www.pythondoc.com/pythontutorial3/index.html">http://www.pythondoc.com/pythontutorial3/index.html</a></p></blockquote><h2 id="开始Python">开始Python</h2><h3 id="解释器">解释器</h3><p>在终端键入<code>python</code>或<code>python3</code>进入交互模式:</p><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">>>> </span>print(<span class="string">"Hello World"</span>)</span><br><span class="line">Hello World</span><br></pre></td></tr></table></figure><p>退出解释器:快捷键<code>Ctrl + D</code>或键入<code>exit()</code>。</p><h3 id="脚本文件">脚本文件</h3><p>可以使用任何编辑器来编辑.py文件,这里以Vim为例:</p><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">vim helloworld.py</span><br></pre></td></tr></table></figure><p>即可用Vim创建并打开新的脚本文件。</p><p><img src="https://gitee.com/sg2019/picgo/raw/master/document-uid731737labid7100timestamp1531381084391.png" alt="document-uid731737labid7100timestamp1531381084391"></p><p><code>i</code>键进入插入模式,键入代码,<code>Esc + :wq</code>即可保存退出。</p><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">#!/usr/bin/env python3</span></span><br><span class="line">print(<span class="string">"Hello World"</span>)</span><br></pre></td></tr></table></figure><p><strong>注意</strong>:为了让shell使用Python解释器执行,要在代码前加<code>#!</code>,称为_Shebang_。</p><p>运行前用<code>chmod</code>命令来变更文件或目录的权限,否则会提示权限不足,可执行权限<code>+x</code>,即:</p><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">$</span><span class="bash"> chmod +x helloworld.py</span></span><br></pre></td></tr></table></figure><p>然后即可正常执行脚本文件:</p><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">./helloworld.py</span><br></pre></td></tr></table></figure><p><strong>注意</strong>:如果程序中没有<code>#!/usr/bin/env python3</code>,则需要键入<code>python3 helloworld.py</code>执行,否则会执行bash脚本报错。</p><h3 id="代码风格">代码风格</h3><p>不正确的空格缩进Python解释器会抛出错误:</p><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">>>> </span>a = <span class="number">1</span></span><br><span class="line"><span class="meta">>>> </span> a = <span class="number">1</span></span><br><span class="line"> File <span class="string">"<stdin>"</span>, line <span class="number">1</span></span><br><span class="line"> a = <span class="number">1</span></span><br><span class="line"> ^</span><br><span class="line">IndentationError: unexpected indent</span><br></pre></td></tr></table></figure><ul><li>空格和制表符不要混用</li><li>函数间空一行,类之间空两行</li><li>赋值运算符、比较运算符周围要加空格,<code>,</code>、<code>:</code>(字典)后要加空格</li></ul><h3 id="注释">注释</h3><p>单行注释以<code>#</code>开头(并注意后加空格),多行注释位于<code>```</code>之间。</p><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># FIXME -- fix these code later</span></span><br><span class="line"><span class="comment"># TODO -- in future you have to do this</span></span><br></pre></td></tr></table></figure><h2 id="变量和数据类型">变量和数据类型</h2><h3 id="关键字和标识符">关键字和标识符</h3><p>在解释器中可查看:</p><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">>>> </span><span class="built_in">help</span>()</span><br><span class="line"><span class="built_in">help</span>> keywords</span><br></pre></td></tr></table></figure><h3 id="从键盘读入">从键盘读入</h3><p>函数<code>input()</code>用于从键盘读取输入,<code>print()</code>用于输出。</p><h3 id="字符串格式化">字符串格式化</h3><p><code>str.format()</code>函数用于格式化字符串,其中<code>str</code>是需要格式化的字符串,其中可以加<code>{}</code>,<code>{}</code>和其中的替换字段会被替换为参数。</p><p>比如:</p><ul><li><p><code>{:5d}</code>场宽为5的整数</p></li><li><p><code>{:3.2f}</code>场宽为3,保留2位的浮点数</p></li></ul><h3 id="单行定义多个变量赋值">单行定义多个变量赋值</h3><p>Python中元组(<em>tuple</em>)这一数据类型,使得多个变量可以同时赋值。赋值语句的右值进行了封装,左值进行了拆封。既然左值和右值都可以为多个变量(使用<code>,</code>创建元组),那么经典的交换就直接写为:</p><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">a, b = b, a <span class="comment"># 交换两个数值</span></span><br></pre></td></tr></table></figure><h2 id="运算符和表达式">运算符和表达式</h2><h3 id="运算符">运算符</h3><ul><li><p>只要有任意一个操作数是浮点数,结果就是浮点数</p></li><li><p><code>/</code>除不尽时,结果为浮点数</p></li><li><p>整除符号<code>//</code>,求余<code>%</code></p></li><li><p><code>divmod(a, b)</code>返回元组<code>a//b, a%b</code>,可以用<code>*</code>运算符拆封元组</p></li></ul><p>关系运算符不变,逻辑运算符使用关键字<code>and</code>、<code>or</code>、<code>not</code>,也是短路运算符。例如:</p><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">>>> </span><span class="number">0</span> <span class="keyword">or</span> <span class="number">3</span></span><br><span class="line"><span class="number">3</span></span><br><span class="line"><span class="meta">>>> </span><span class="number">0</span> <span class="keyword">and</span> <span class="number">3</span></span><br><span class="line"><span class="number">0</span></span><br></pre></td></tr></table></figure><h3 id="类型转换">类型转换</h3><p>Python是强类型语言,有如下类型转换函数:整数<code>int()</code>,浮点数<code>float()</code>,字符串<code>str()</code>。注意如果<code>int()</code>参数为浮点数的字符串会报错。</p><h2 id="控制流-if-else">控制流 if - else</h2><h3 id="if语句">if语句</h3><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">if</span> exp1:</span><br><span class="line">A</span><br><span class="line"><span class="keyword">elif</span> exp2:</span><br><span class="line">B</span><br><span class="line"><span class="keyword">else</span></span><br><span class="line">C</span><br></pre></td></tr></table></figure><p>注意<code>else if</code>简写为<code>elif</code>。</p><h3 id="真值检测">真值检测</h3><p><code>if x:</code>比<code>if x == True</code>要更好,因为Python中许多值都具有布尔意义。</p><h2 id="循环">循环</h2><h3 id="while循环">while循环</h3><p>举例说明,打印100以内Fibonacci数列的值:</p><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">#!/usr/bin/env python3</span></span><br><span class="line">a, b = <span class="number">0</span>, <span class="number">1</span></span><br><span class="line"><span class="keyword">while</span> b < <span class="number">100</span>:</span><br><span class="line"> print(b)</span><br><span class="line"> a, b = b, a + b</span><br></pre></td></tr></table></figure><p>如果不想每次循环时都换行,可以改变<code>print()</code>的另一个参数<code>end</code>:</p><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">print(b, end = <span class="string">' '</span>)</span><br></pre></td></tr></table></figure><p>这样Fibonacci数项间将以空格隔开。如果要打印分割线,则:</p><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">print(<span class="string">'-'</span> * <span class="number">40</span>)</span><br></pre></td></tr></table></figure><p>字符串与整数相乘表示,字符串复制多次拼接,得到新的字符串。</p><p>可以在循环中加入控制流,用<code>break</code>语句跳出循环,或者用<code>continue</code>语句进入下一次循环。有时可能会看到<code>pass</code>语句,它位于循环末尾,只起占位符的作用。</p><h3 id="列表">列表</h3><p>列表很像数组,但列表的元素可以是不同类型。它可以写成中括号中间一列逗号分隔开的值的形式:</p><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">arr = [<span class="string">"sg2019"</span>, <span class="number">2021</span>, <span class="number">2.23</span>, <span class="literal">True</span>]</span><br></pre></td></tr></table></figure><p>列表的索引从0开始编号,但索引可以为负数,表示从末尾向前数。</p><h3 id="切片">切片</h3><p>切片用于取出列表的一个子列表,比如以上面的列表为例:</p><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">>>> </span>arr[<span class="number">0</span>:-<span class="number">1</span>]</span><br><span class="line">[<span class="string">"sg2019"</span>, <span class="number">2021</span>, <span class="number">2.23</span>]</span><br><span class="line"><span class="meta">>>> </span>arr[:]</span><br><span class="line">[<span class="string">"sg2019"</span>, <span class="number">2021</span>, <span class="number">2.23</span>, <span class="literal">True</span>]</span><br></pre></td></tr></table></figure><p>切片表示一个左闭右开的区间,比如说<code>arr[0:-1]</code>,就等价于<code>arr[0:4]</code>,即左闭右开区间<span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mo stretchy="false">[</mo><mn>0</mn><mo separator="true">,</mo><mn>4</mn><mo stretchy="false">)</mo></mrow><annotation encoding="application/x-tex">[0,4)</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:1em;vertical-align:-0.25em;"></span><span class="mopen">[</span><span class="mord">0</span><span class="mpunct">,</span><span class="mspace" style="margin-right:0.16666666666666666em;"></span><span class="mord">4</span><span class="mclose">)</span></span></span></span>。</p>]]></content>
<categories>
<category> 技术 </category>
<category> 基础 </category>
</categories>
<tags>
<tag> python </tag>
</tags>
</entry>
<entry>
<title>LeetCode题型总结</title>
<link href="posts/1655/"/>
<url>posts/1655/</url>
<content type="html"><![CDATA[<script src="\assets\js\APlayer.min.js"> </script><blockquote><p>Tips:均为LeetCode免费题目,代码语言是C++</p><p>本文持续更新</p></blockquote><h2 id="贪心算法">贪心算法</h2><h3 id="分配问题">分配问题</h3><h3 id="区间问题">区间问题</h3>]]></content>
<categories>
<category> 技术 </category>
<category> 算法 </category>
</categories>
<tags>
<tag> LeetCode </tag>
<tag> 算法 </tag>
</tags>
</entry>
<entry>
<title>hexo常见指令</title>
<link href="posts/15483/"/>
<url>posts/15483/</url>
<content type="html"><![CDATA[<script src="\assets\js\APlayer.min.js"> </script><table><thead><tr><th>指令</th><th>简写</th><th>功能</th></tr></thead><tbody><tr><td>hexo init 文件名</td><td></td><td>新建hexo文件夹</td></tr><tr><td>hexo generate</td><td>hexo g</td><td>生成页面文件</td></tr><tr><td>hexo server</td><td>hexo s</td><td>启动服务预览</td></tr><tr><td>hexo serser -p 端口号</td><td>hexo s -p 端口号</td><td>指定端口运行</td></tr><tr><td>hexo deploy</td><td>hexo d</td><td>部署</td></tr><tr><td>hexo new 文章标题</td><td></td><td>新建markdown博客文件</td></tr><tr><td>hexo generate --draft</td><td>hexo g -d</td><td>将草稿部署到github</td></tr><tr><td>hexo clean</td><td></td><td>清除缓存</td></tr><tr><td>hexo version</td><td>hexo v</td><td>显示hexo版本</td></tr></tbody></table>]]></content>
<categories>
<category> 技术 </category>
<category> 博客 </category>
</categories>
<tags>
<tag> 博客 </tag>
<tag> hexo </tag>
</tags>
</entry>
</search>
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。