2022/03,江端さんの忘備録

ここ最近、コーディング(プログラミング)に嵌っています。

Recently, I've been into coding (programming).

色々検討した結果、ここ2月ほど検討してきた方法が、間違っていることが分かってきて、現在、絶賛やりなおし中です(丸々無駄という訳でもなかったのですが)。

After much deliberation, I've come to realize that the method I've been considering for the past two months is wrong, and I'm currently in the process of redoing it (though it wasn't a total waste).

「pythonで遺伝的アルゴリズム(GA)を実装して巡回セールスマン問題(TSP)をとく」の交叉(部分的交叉)のアルゴリズムをgolangで書き直してみた

現在、トライアル中のモノは「予測できない変化をリアルタイムで組み込んで、動的に変化しつづける推論エンジン」でして これが、結構難しい。

The one we I currently trialing is an inference engine that incorporates unpredictable changes in real time and keeps changing dynamically.

状況を固定させた状態での研究は腐るほどあるのですが、実際の環境を組み込みながら動くエンジンの研究は、ほとんどありません。

There is a plethora of research that has been done with fixed situations, but there is very little research on engines that work while incorporating real environments.

まあ、これは、実際にコーディングをやってみれば分かります。

Well, you can find this out by actually doing some coding.

『現状の計画を大きく変更させないようにして、新しい情報を組みつつ、行動を変える』という、人間が普通にやっていることを、プログラムに組み込むのことは、結構難しいのです。

It is quite difficult to incorporate into a program what we normally do, which is to "change our behavior while incorporating new information without significantly altering our current plans.

それでも、私が踏ん張っているのは、『多分、大掛かりなプログラムとしては、これが現役(というか人生)ラストコード(プログラミング)になるだろう』という予感があるからです。

Still, I'm holding on because I have a feeling that this will probably be the last code (programming) I'll ever use in my life as a large-scale program.

-----

私は、テレビやスマホのゲームを楽しめない性格です。

I am a person who does not enjoy playing games on TV or on my phone.

しかし、ゲームに嵌っている人の状況と、コーディングに嵌っている私の状況は、良く似ているかもしれないなぁ、と思っています。

However, I think that the situation of people who are addicted to games and my situation of being addicted to coding may be very similar.

- 興奮状態が続き、眠れなくなる。

- The excitement lasts and makes it difficult to sleep.

- 目を瞑っても、アルゴリズムが頭の中を走り回る

- Even when I close my eyes, algorithms run through my head.

- 夢の中でバグに気がつき、その後、寝付けなくなる

- Noticing a bug in a dream and then not being able to sleep

昔は、この時点で「大量のアルコールを投入して、強制的に睡眠に入る/維持する」ということをやっていたのですが ―― その結果が、アルコール依存症の予備軍(いや、正規軍か?)になってしまいました。

In the past, I used to "throw in a lot of alcohol" at this point to force/maintain sleep -- and the result was a reserve army of alcoholics (or is it a regular army?).

今は、アルコールではなく、精神安定剤に、スイッチしただけですが。

Now, I just switched to tranquilizers instead of alcohol.

それでも、毎日のアルコールの鯨飲よりは、処方通りの安定剤の方が、はるかに健康的だとは思います。

Still, I believe that stabilizers as prescribed are much healthier than whaling on alcohol daily.

体調もいいですし。

I'm in good physical condition.

それはさておき。

That's beside the point.

-----

一般的に、プログラムはパラメータの値に実際の値を使わずに、変数にしておいて、外部から入力するようにします。

In general, programs do not use actual values for parameters. The parameter values are kept as variables and are input from outside.

(3.52)^3 + 3.52^2 + 3.52 の値(=543.9174828032)としてプログラムに書き込むのではなく、x^3 + x^2 + x と記述しておけば、プログラムの起動時に、xの値を自由に変えることができて、便利だからです。

Instead of writing it into the program as the value of (3.52)^3 + 3.52^2 + 3.52 (=543.9174828032), it is convenient to write it as x^3 + x^2 + x, so that you can freely change the value of x when the program starts.

直接、値を書き込むコーディングは、「ハードコーディング」と言われて、(実験や検証用途を除けば)やってはならないプログラミングとされています。

Coding that directly writes values is called "hard coding" and is considered programming that should not be done (except for experiments and verification purposes).

"goto"と同じように。

Just like "goto".

Golangでgotoを使ってみた

しかし、興奮状態が納まらず、睡眠障害が発生し、疲労が取れない、この私のコーディングこそが「ハードコーディング」と呼びに相応しい、と思っています。

However, I think that my current coding is worthy of being called "hard coding", as I can't stop the excitement, sleep disturbance, and fatigue.

そして、体力的にも、精神的にも、今が、このような「ハードコーディング」ができるラストチャンスだろうと、腹を括っています。

And I' believe the fact that this will be my last chance to do this kind of "hard coding", both physically and mentally.

2022/02,江端さんの忘備録

本日は、コラムがリリースされた日なので、日記はお休みです。

Today, new my column is released, so I take a day off.

 

「お金に愛されないエンジニア」のための新行動論(1)

"A New Theory of Action for Engineers Who Are Not Loved by Money".

定年がうっすら見えてきたエンジニアが突き付けられた「お金がない」という現実

The reality of "no money" confronts an engineer whose retirement is just around the corner

 

-----

===== EE Times Japan編集部 担当者Mさんからメール ここから ======

===== Email from Ms. M, EE Times Japan Editor, from here ======

お世話になっております。大変お待たせ致しました。Web稿を作成しましたので、28日(月)の正午をメドに、ご確認をお願いできますでしょうか。

Thank you for your cooperation. We have prepared a web draft, which should be ready for your review by noon on Monday the 28th.

※連載名ですが、「「お金に愛されないエンジニア」のための新行動論」のみとしました。

I've changed the name of the series to just "A New Theory of Action for Engineers Who Are Not Loved by Money".

「世界で『数字』を~~~」を頭につけると、コンテンツ生成システムから「長すぎて入らん」と怒られまして…(涙)。

When I put "numbers in the world~~" at the beginning, the content generation system got angry and said it was too long to fit... (tears)

なので、新シリーズというより、完全なる新連載という形で行こうと思います。

So, rather than a new series, I think we'll go with a completely new series.

===== ここまで =====

===== to here =====

―― えっ? 新連載なの?

"What? Is this a new series?"

という感じで、なし崩し的に、始まってしまいました、新連載。

And so, in an uncontrolled process, the new series has begun.

システムからの要求だけでなく、『気合入れて書けよ』という、Mさんの内なる声も入っているような"気"を感じます。

I can feel the "spirit" of Mr. M, not only from the system's requirements, but also from her inner voice that says, "Put your heart and soul into your writing.

2022/02,江端さんの技術メモ

GAを使った推論エンジンを、無限ループで回し続けながら(止めないで)、変数の変更やら、パラメータの変更を突っ込みたいんだけど、その「割り込み」方法が思いつきませんでした。たしか select, caseを使ったやり方があって、defaultの使い方がキモだったようなものがあったような気がして、ちょっとテストプログラム書いてみましたところ、動いたみたいなので、メモの残しておきます。

// go run main2.go

package main

import (
	"fmt"
	"time"
)

var ch1 chan interface{}
var ch2 chan interface{}

func main() {

	ch1 = make(chan interface{}) // チャネルの初期化
	ch2 = make(chan interface{}) // チャネルの初期化(ここでは使っていない)

	go loop()

	for i := 0; i < 5; i++ {
		time.Sleep(3 * time.Second) // 3秒待つ
		fmt.Println("send")
		ch1 <- i
	}
}

func loop() {

	for {
		time.Sleep(1 * time.Second) // 1秒待つ
		fmt.Println("loop")

		//チャネルからメッセージの到着を確認する
		select {
		case i := <-ch1:
			fmt.Println("ch1:", i)

		case <-ch2:
			fmt.Println("ch2")

		default:
			//fmt.Println("No value")
		}
	}
}

で、この最後の"default"をコメントアウトすると、selectが無限待ちになってしまう(チャネルからメッセージが飛んでこないとロックしてしまう)ので注意して下さい。
コメントアウトした結果↓

 

# チャネルからイベント入ったら、初期設定のルーチンまで強制的に飛ばしてしまおうと思っているのですが、golangに、"goto"ってあるのかなぁ・・・

2022/02,江端さんの忘備録

実家に帰ると、萩尾望都先生の「銀の三角」を読みます。そして、時間が消失してしまいます。

When I go back to my parents' house, I read "Silver Triangle" by Ms. Moto Hagio. And time disappears.

当時、高校生としては、かなりの高価だったと思うのですが、「銀の三角」はハードブックで購入しました。

I bought "Silver Triangle" as a hard book, although I think it was quite expensive for a high school student at the time.

「銀の三角」の内容を、どう解説すれば良いのか分かりません。

I don't know how to explain the contents of the "Silver Triangle".

ただ、このストーリを言語で説明するのであれば、必要なモノは相対性理論・・・違うな。量子論とも違う。

But if I want to explain this story in language, I need the theory of relativity...No no. It's not quantum theory either.

少なくとも、「時空間コンテンツ」の最高傑作であり、江端の最高評価、ということだけは言えるのですが。

At least, I can say that it is the best of "space-time contents" and Ebata's highest evaluation.

これまで、百回以上は読み直したかと思いますが、今でも、よく分からないのです。

I must have reread it a hundred times or more, but I still don't understand it.

「銀の三角」は、万人受けする作品ではないのかもしれません。

"Silver Triangle" may not be a work for everyone.

思うに、これは『私たちが作品を選ぶのではなく、作品が私たちを選ぶ』という作品なのだと思うのです。

I think this is the book that "we don't choose the book, the book chooses us".

-----

光瀬 龍先生の原作の「百億の昼と千億の夜」は、量子論の2つ目の解釈「エヴェレットの多世界解釈」の一つの形として完成した作品であると思います。

I believe that the original work "Ten Billion Days and One Hundred Billion Nights" by Mr. Ryu Mitsuse is a completed work as a form of the second interpretation of quantum theory, Everett's Many Worlds Interpretation.

「ウは宇宙船のウ」「スターレッド」「11人いる!」「恐るべき子どもたち」「半神」「メッシュ」「エッグ・スタンド」「偽王」

"R is for Rocket", "Start Red," "There are 11 of Us!" "Terrible Children", "Half-Blood", "Mesh", "Egg Stand", "The False King".

おお、凄い。

Well, I am great.

こんなにも、スラスラとタイトルが出てくるとは思わなかった。

I didn't expect the title of the book to come out so sloppily.

-----

以前「スターレッド」をテーブルに出しておいたのですが、家族に読まれた形跡がありません。

I left "Star Red" out on the table before, but there was no sign of it being read by my family.

どうやら、我が家において「選ばれし読者」は、私だけのようです。

Apparently, I am the only "chosen reader" in my family.

未分類

私、知財(知的財産法)四法については詳しいです。どの記述がどの条文に書かれているのか知っているレベルです。

加えて、知財に関する国際条約についても、かなり知っている方だと自負しています。

憲法は、高等教育のレベルで知っているくらいです。

民法は、ちょっと怪しくなってきます。

刑法、刑事訴訟法については、ボロボロです。

-----

今回の、「ロシアによるウクライナ侵攻」について、多くの人が、「国際法違反」と言っているようですが、その根拠となる法令について、どこを捜せばいいのか、まったくサッパリ分かりません。

また、我が国においては、憲法98条2項に「国際法優位説」と読める記載があり、現時点では「国内法と国際法がバッティングした時は、国際法が優位である」という考え方が、定説です。

ちなみに、特許法の場合は、「国際法優位」が、ばっちり明文化されていて、疑義の生じる余地がありません(第26条)。

で、何が言いたいかというと、私は『戦争に関する国際法』については、完全にド素人である、ということです。

-----

以上を踏まえまして、読者の皆様に2つお願いがあります。

(1)「ロシアによるウクライナ侵攻」を国際法違反と断じる、国際法の根拠条約と条文の場所(URL)を教えて下さい

(2)「ロシア」の法体系が、「国際法優先」か「国内法優先」のどちらに寄っているかについて、論じられているコンテンツの場所(URL)を、ご紹介下さい(論文でもいいけど、できれば、簡易に記載されているコラムで、日本語なら、なお嬉しいです)

これは、純粋に調査に供する事項であり、「正論」「正義」「理念」「倫理」などの観点は、(今回は)必要ありません。

ご教示頂けましたら、幸いです。

ご利用頂けるメールアドレスは"until20220310@kobore.net"です。

ご協力のほど、何卒、よろしくお願い致します。

 

江端

2022/02,江端さんの技術メモ

"goto"を使う ―― とても、感慨深いです。

"goto"追放キャンペーンが発生したのは、私が大学院在学中の頃でしょうか。そして、現在も"goto"に対する差別的扱いは、変っていません。"goto"なんか使ったら、それだけで『無能』扱いされ、仕事の依頼を打ち切られるような空気すらあります。

まあ、"goto"に、そこまで言われるだけの弊害があるのは確かです。特に「可読性は最悪」ですし、放置された変数が、どんな悪さをするか分かったもんではありません。メモリリークは確実で、スレッドとか使っていたら高い確率でクラッシュします。

しかし、私、学生のころ、N-BASICで"goto"使い倒していましたけど、『あれは、あれで便利でした』。

実際、プログラミング初心者には、とても便利なモノでした。初学者には、"goto"で、ラクラクプログラミングを楽しんでもらっていいんじゃないかな、私は思うのです。


ところで、調べてみたら、golangに、"goto"が実装されていました。C/C++にもありました。Pythonにもありました。Javaにもあるみたいですが、動かないようです(?)。

「使うな」と言われている割に、一応準備だけはされているのが、なかなか興味深いです。

ちゃんと動きましたので、書き残しておきます。

// go run main2.go

package main

import (
	"fmt"
	"time"
)

var ch1 chan interface{}
var ch2 chan interface{}

func main() {

	ch1 = make(chan interface{}) // チャネルの初期化
	ch2 = make(chan interface{}) // チャネルの初期化(ここでは使っていない)

	go loop()

	for i := 0; i < 5; i++ {
		time.Sleep(3 * time.Second) // 3秒待つ
		fmt.Println("send")
		ch1 <- i
	}
}

func loop() {

L:
	fmt.Println("先頭からやりなおし")

	for {
		time.Sleep(1 * time.Second) // 1秒待つ
		fmt.Println("loop")

		//チャネルからメッセージの到着を確認する
		select {
		case i := <-ch1:
			fmt.Println("ch1:", i)
			goto L

		case <-ch2:
			fmt.Println("ch2")

		default:
			//fmt.Println("No value")
		}
	}
}

以上

2020/08,江端さんの技術メモ



go func() { defer close(done) for { _, message, err := c.ReadMessage() if err != nil { log.Println("read:", err) return } log.Printf("recv: %s", message) } }() ticker := time.NewTicker(time.Second) defer ticker.Stop() for { select { case <-done: return case t := <-ticker.C: err := c.WriteMessage(websocket.TextMessage, []byte(t.String())) if err != nil {

go func()で、defer close(done)が効いてくるまで、 case <-done:はロックされて、デッドロックになるじゃないか? と、ずっと考えて訳が分からなくなってきたところで、Go言語でチャネルとselect というページに、

チャネルに値が入っていない場合、受信はブロックする。ブロックせずに処理を行いたい場合は select を使う。

そんなSwitchの使いかた、あるかーーーー! と、叫びそうになりました(私の2時間を返せ)

2022/02,江端さんの忘備録

監督と脚本と声優の皆さんのラインナップを見て、今期、アニメ「平家物語」の視聴を決めました ―― が

I decided to watch the anime "The Tale of the Heike" this season after seeing the lineup of the director, scriptwriter, and voice actors -- however, I think

『これは、これから長い間、視聴され続けるアニメになるかもしれないなぁ』

"This may become an anime that will be watched for a long time to come"

と思っています。

滅亡する平家一族の視点から描かれる、まさしく、琵琶法師の世界観を描いたアニメで、「見事」の一言に尽きます。

It is an anime that depicts the world of Biwahoushi(lute player) from the point of view of the Heike clan that is dying out, and it is absolutely "brilliant".

声優の悠木碧さんの語る平家琵琶の迫力が凄くて、圧倒されます。

The power of the Heike Biwa, as told by the voice actress Aoi Yuuki, is amazing and overwhelming.

-----

なんだかんだいっても、私は、日本の歴史を扱うコンテンツを、楽しむ能力があると思います。

For what it's worth, I think I have the ability to enjoy content about Japanese history.

これは、やはり、入試で「日本史」を選択したのが大きいと思います。

I think this was largely due to the fact that I chose "Japanese History" for the entrance exam.

世界史は、世界史の教師の教え方が絶望的にお粗末で、大嫌いであったのに加えて、私は、複数の世界で流れる時間を、マルチタスクで理解する能力がなかったからです。

World history, not only because my world history teacher was hopelessly lousy at teaching and a total asshole, but also because I lacked the ability to multitask and understand the time that flows in multiple worlds.

とは言え、海外に打って出ようとする若者には、「世界史選択」をお勧めしたいです。

Nevertheless, I would like to recommend the "World History Option" to young people who are planning to venture abroad.

特に、世界で同時並列で存在する宗教や思想を理解するのに、世界史はもっとも役に立つ道具です。

In particular, world history is the most useful tool for understanding religions and ideas that exist simultaneously and in parallel in the world.

そういえば、世界史と日本史をミックスした、「歴史総合」という教科になる、といういう話を聞きました。大変良いことだと思います。

By the way, I heard that there will be a new subject called "Integrated History", which is a mixture of world history and Japanese history. I think this is a very good thing.

この「歴史総合」に、「数学」を入れると、さらに面白いだろうと思います。

I think it would be even more interesting to include "mathematics" in this "Integrated History" course.

国家とか、権力とか、戦争などには、発生原因と存続時間があります。

Nations, powers, wars, etc. have a cause and duration.

これらは、数値モデルで説明できると思いますが ――

It would be interesting to be able to explain these in a numerical model, but--

その前に、『歴史数学』という学問分野の確立が必要ですね。

Before that, we need to establish the discipline of "historical mathematics".

-----

一方、私のように、

On the other hand, if you're like me,

■世間とコミットしたくなくて、

- I didn't want to commit to the world.

■1人の世界でヌクヌクしていたくて、

- I just wanted to relax in my own world.

■『閉塞した世界こそが私の楽園』

- The closed world is my paradise.

という方には、「日本史」はお勧めできます。

I can recommend "Japanese History" to you.

少なくとも、「NHK大河ドラマ」と「歴史小説/アニメ」と「寺社/名所巡り」を楽しむ人生は、担保されると思います。

At the very least, you will be guaranteed a life of enjoying NHK historical dramas, historical novels/animations, and visits to temples, shrines, and famous places.

2021/12,江端さんの技術メモ

C/C++では、構造体を丸ごと送信するのに、文字列にキャストを被せて無理矢理送り込むということをやっていました。

Goの場合、チャネルに ch chan interface{}を使うと、何でも運んでくれるようなので、これで同じように「手を抜く」を考えていました。

で、色々試した結果、こういう風に使えるらしいので自分用のメモとして残しておきます

// 単一通信の構造体
type SingleCaster struct {
	//ch   chan int   // 単一通信路
	ch   chan interface{}
	lock sync.Mutex // 単一通信路のロック
}

でもって、

type locInfo struct {
	lon float64
	lat float64
}
でもって、
type PERSON struct {
    number      int     // 人間番号
    live        bool    // 存在フラグ 存在:true 消滅:false
    destination locInfo // 出発座標
    arrival     locInfo // 到着座標
    distance    float64 // 到着座標と出発座標の距離
    present     locInfo // 現在位置
}

を、こんな風に運びたい時、

sc_person.ch <- person.present

これで、元に戻ります。

case v_p := <-sc_person.ch:
			fmt.Println("catched from person send", v_p)
			//var ll locInfo
			ll := v_p.(locInfo)
			fmt.Println(ll.lon, ll.lat)

channelで構造体を送り込む方法

var ch1 chan interface{}

type PERSON struct {
	number      int     // 人間番号
	action      int     // 0:リクエスト 1:乗車 2:降車
}

func sub1(){
	 var person PERSON
	 person.number = 1
	 person.action= 2

	 ch1 <- person 
} 

func sub2(){

	 p := <-ch1

	 person := p.(PERSON)
	 fmt.Println(person) 
}