【BOOKS】新The UNIX SuperText 改訂増補版【上】【下】

☆新The UNIX SuperText 改訂増補版【上】

2003年2月28日発売 山口和紀,古瀬一隆 監修 B5判/896ページ 定価(本体3,480円+税)
サポートページ https://gihyo.jp/book/2003/4-7741-1682-3/support

5159BB4A 4041 41DE A4BF E7F579ACDD2F

☆新The UNIX SuperText 改訂増補版【下】

2003年2月28日発売 山口和紀,古瀬一隆 監修 B5判/1,040ページ 定価(本体3,680円+税)
サポートページ https://gihyo.jp/book/2003/4-7741-1683-1/support

61907D98 6818 4536 9FF4 180A2FCB6016

現在在庫切れ
Amazonで中古本が購入できます

https://www.amazon.co.jp/o/ASIN/4774116823/gihyojp-22
https://www.amazon.co.jp/o/ASIN/4774116831/gihyojp-22

TheUNIXSuperTextp98

TheUNIXSuperTextp101

初版1992年
私が初めて手にしたのは東工大時代の1995年
情報科学科の友人が使っている本を見て感激
以来25年間使い続けています
いまだ2000ページすべてに目を通したことはありません

この本に書かれてあることは現在のubuntuでも実行できます
UNIXの仕組みをきちんと知ることができる本です
UNIXの仕組みを知れば知るほど面白くなり、感動することでしょう

UNIXはこの2冊あればこれから20年間使い続けられます
中古本は安く手に入るのでこの機会にぜひ手元に置いておきましょう

なお、UNIXまたはLINUXの参考書はたくさんあります
ぜひ自分が気に入った本を探してみてください

Markdown+WordPress+KaTeX

WordPressでTeXコードによる数式表示を実現するには
Markdownを使えるようにするプラグインをインストールすればいい
ただ他のプラグインとの関係など実際にインストールして使ってみないと使い勝手がわからない
私が選んだのは

WP Editor.md

スクリーンショット 166

KaTeXのセッティングをすればMarsEditの中にLaTeXコードを作文できる
スクリーンショット 169

MarsEdit

MarsEditで本投稿を作文しているところ
スクリーンショット 168

$$\frac{2x}{\sqrt{\pi}}-\frac{2x^3}{3\sqrt{\pi}}+\frac{x^5}{5\sqrt{\pi}}-\frac{x^7}{21\sqrt{\pi}}+\frac{x^9}{108\sqrt{\pi}}+\operatorname{O}\left(x^{10}\right)$$

\frac{2x}{\sqrt{\pi}}-\frac{2x^3}{3\sqrt{\pi}}+\frac{x^5}{5\sqrt{\pi}}-\frac{x^7}{21\sqrt{\pi}}+\frac{x^9}{108\sqrt{\pi}}+\operatorname{O}\left(x^{10}\right)

$$\zeta(2)=\sum_{n=1}^{\infty}\frac{1}{n^2}=\prod_{p:prime}\frac{1}{1-\frac{1}{p^2}}$$

\zeta(2)=\sum_{n=1}^{\infty}\frac{1}{n^2}=\prod_{p:prime}\frac{1}{1-\frac{1}{p^2}}

Jupyter Notebook+WordPress+MarsEdit

Jupyter Notebook hoge.ipynbをWordPressに貼り付ける手順

準備 外観→追加CSSに以下を追記

Web上にはいくつかのCSSが見つかる
その中から選んだCSS
https://andrewchallis.co.uk/articles/php-nbconvert-a-wordpress-plugin-for-jupyter-notebooks/

************** Jupyter Notebook CSS ************************/
div .dataframe {
  border:none;
  margin: 0 auto;
}
div.output_stdout pre {
  max-height:300px;
}

div.output_stderr pre
{
  background: #fdd;
  margin:0;
  max-height:300px;
}
div.hl-ipython3 pre {
  margin:0
}
.dataframe thead tr:only-child th {
  text-align: right;
  text-transform: capitalize;
}
.dataframe thead th {
  text-align: left;
}
.dataframe tbody tr th {
  vertical-align: top;
}

.rendered_html tbody tr:nth-child(odd),
.rendered_html tbody tr:nth-child(odd) td {
  background: #f5f5f5;
}
.rendered_html tr, .rendered_html th, .rendered_html td {
  text-align: right;
  vertical-align: middle;
  padding: 0.5em 0.5em;
  line-height: normal;
  white-space: normal;
  max-width: none;
  border: none;
}
div.highlight .kn, .n, .k, .nn, .s1, .ow, .p, .mi, .c, .mf, .nb, .kc, .sd, .nf {
  font-family: monospace;
  font-size:14px;
}
.input_prompt {
  color: #303F9F;
  font-weight: bold;
  float: left;
  margin-right: 5px;
  margin-top: 3px;
}
.input_area pre {
  border: 1px solid #cfcfcf;
  border-radius: 2px;
  background: #f7f7f7;
  line-height: 1.21429em;
  padding: 6px 3px 6px 6px;
}
.output_prompt{
  color:#cc0000;
  font-weight: bold;
}
.prompt{
  font-family: monospace;
  font-size: 14px;
}
.c, c1 {
  color: #408080;
  font-style: italic;
}
.k {
  color: #338822;
  font-weight: bold;
}
.kn {
  color: #338822;
  font-weight: bold;
}
.mi {
  color: #008800;
}
.mf {
  color: #008800;
}
.o {
  color: #9966ff;
}
.ow {
  color: #BA22FF;
  font-weight: bold;
}
.nb {
  color: #338822;
}
.n {
  color: #000000;
}
.s, .s1, .sd, .s2 {
  color: #cc2222;
}
.se {
  color: #cc2222;
  font-weight: bold;
}
.si {
  color: #C06688;
  font-weight: bold;
}
.nn {
  color: #4D00FF;
  font-weight: bold;
}
.output_area pre {
  background-color: #FFFFFF;
  padding-left: 5%;
}
.code_cell {
  padding-left: 1%;
}
.cell {
  margin-top: 10px;
  margin-bottom: 10px;
}
br {
  line-height: 2;
}
blockquote {
  font-size: 1em;
  text-align: left;
  font-weight: normal;
}
code {
  border: none;
  box-shadow: none;
  font-family: monospace;
}
div.rendered_html h1, h2, h3, h4 {
  margin-top: 30px;
  margin-bottom: 10px;
}
div.rendered_html p a {
  color: #4D00FF;
}

スクリーンショット 165

1. hoge.ipynb から hoge.html を生成

$ jupyter nbconvert --to html --template basic hoge.ipynb
[NbConvertApp] Converting notebook hoge.ipynb to html
[NbConvertApp] Writing 5129 bytes to hoge.html

2. hoge.html の中身をMarsEditにコピー

ここでhoge.htmlをWORDPRESSエディター上カスタムHTMLにコピーする方法を試してみると、TeXコード部分が変換されずそのままで表示されてしまう。

出力

In [12]:
# フィボナッチ数列の一般項 F_n
# F_0 = 0,  F_1 = 1
# F_{n+2} = F_n + F_{n+1} n=0,1,2,...
In [13]:
import sympy
sympy.init_printing()
sympy.var("n")
A = sympy.Matrix([[1, 1],[1, 0]])
f1 = sympy.Matrix([1, 0])
Fn = sympy.simplify(A**(n-1)*f1)
display(Fn)
print("F_n =")
display(Fn[0,0])  # F_n = Fn[0,0]
\displaystyle \left[\begin{matrix}\frac{2^{- n} \left(- \left(1 – \sqrt{5}\right)^{n} + \frac{2 \sqrt{5} \left(1 – \sqrt{5}\right)^{n}}{5} – \frac{2 \sqrt{5} \left(1 + \sqrt{5}\right)^{n}}{5} + \left(1 + \sqrt{5}\right)^{n}\right)}{-2 + \sqrt{5}}\\- \frac{2 \sqrt{5} \left(1 – \sqrt{5}\right)^{n}}{5 \left(- 2^{n} \sqrt{5} + 2^{n}\right)} + \frac{2 \sqrt{5} \left(1 + \sqrt{5}\right)^{n}}{5 \left(2^{n} + 2^{n} \sqrt{5}\right)}\end{matrix}\right]
F_n =
\displaystyle \frac{2^{- n} \left(- \left(1 – \sqrt{5}\right)^{n} + \frac{2 \sqrt{5} \left(1 – \sqrt{5}\right)^{n}}{5} – \frac{2 \sqrt{5} \left(1 + \sqrt{5}\right)^{n}}{5} + \left(1 + \sqrt{5}\right)^{n}\right)}{-2 + \sqrt{5}}
In [14]:
for i in range(10):
    print(int(Fn[0,0].subs(n, i)))
0
1
1
2
3
5
8
13
21
34
In [ ]:
 

MacPro2009でTensorflow+Kerasを使う

私のメインマシンはMacPro2009
拡張性の大きさから10年以上現役バリバリ
M1MacBook Proはサブ
他に
MacBook Pro Late 2013
MacBook Air Mid 2012
Dell OPTIPLEX 3020(Ubuntuメイン+NAS)
HP EliteBook 820(SSD分割Ubuntu+Win10)
東芝DynaBook T350(win7)
Macpc 001
これだけのマシンを駆使して
桜井進のPython・UNIX教室で使うUSBメモリーブートUbuntuシステムを作成できます
本当はテスト用に2016年〜2020年のMacBook Proが欲しい

さて本題
これらのマシンにPythonの実行環境がある
Pythonのバージョンメンテナンスで面倒なのがTensorFlow
それぞれのマシンで動くバージョンが違う(CPU、GPUの性能に異存)
Tensorflowのインストールだけでも手間がかかるのに
異存するライブラリのバージョンも関係するのでさらに面倒

なかでもメインマシンMacPro2009(10.15.6)はCPUが古いので
新しいTensorFlowは入らない
それでもTesorFlow 1.5.0なら動くことがわかった

ところが、
そこに画像認識をさせようとKerasを動かそうとするとこれが中々動いてくれない

試行錯誤の末、ようやくTnsorflow+Kerasが動く組合せを見つけた

Macにはpyenvを使ってPythonをインストール
これでPythonのバージョンを自在にコントロールできる
Python 3.6.5のインストール

$ pyenv install --list
$ pyenv install 3.6.5
$ pyenv global 3.6.5
$ pyenv rehash

同様にPython 3.6.6のインストールすると
次のように異なるバージョンのスイッチングが簡単にできて便利

$ pyenv versions
  system
* 3.6.5 (set by /Users/sakuraisusumu/.pyenv/version)
  3.6.6

TensorFlow 1.5.0 インストール

$ python -m pip install --upgrade https://storage.googleapis.com/tensorflow/mac/cpu/tensorflow-1.5.0-py3-none-any.whl

組合せその1
Python 3.6.6
TensorFlow 1.5.0
keras 2.6.0(最新)

TensorFlow OK
Tnsorflow+Keras NG

組合せその2
Python 3.6.6
TensorFlow 1.5.0
keras 2.4.3(2.3.0、2.2.1)

TensorFlow OK
Tnsorflow+Keras NG

組合せその3
Python 3.6.5
TensorFlow 1.5.0
keras 2.2.1

TensorFlow OK
Tnsorflow+Keras OK

これでMacPro2009でもTnsorflow+Keraを使った画像認識ができるようになった
本当に微妙なバージョン違いです

$ python ai.py cat.jpg
Using TensorFlow backend.
2021-09-17 03:28:56.088497: I tensorflow/core/platform/cpu_feature_guard.cc:137] Your CPU supports instructions that this TensorFlow binary was not compiled to use: SSE4.2

keras+TensorFlowによる画像認識結果
                     確率
           tabby     71.12%
    Egyptian_cat     14.72%
       tiger_cat     10.62%
        radiator     0.55%
         doormat     0.27%

桜井進のPython・UNIX教室(入門コース全3回Zoom)の第3回授業風景
Dell OPTIPLEX 3020(Ubuntuメイン+NAS)でTnsorflow+Keraを使った画像認識を実行しているところ
スクリーンショット 66