2023,江端さんの技術メモ

現在時刻を入れた、agoopデータ形式のcsvファイルをGolangで作る

// C:\Users\ebata\yamaguchi\src_try2\others\main9.csv

/*
	このデータ形式のcsvを作成する

	Dailyid,Year,Month,Day,Hour,Minute,Second,Latitude,Longitude
	14,2017,12,1,8,17,5,33.749583,132.709375
*/

package main

import (
	"encoding/csv"
	"fmt"
	"log"
	"os"
	"time"
)

func main() {

	const STATIONS_PATH string = "test.csv"

	// csvファイル
	csvFile, err := os.Create(STATIONS_PATH)
	if err != nil {
		log.Fatal(err)
	}
	defer csvFile.Close()

	// CSVファイルの中身を読み込み
	w := csv.NewWriter(csvFile)

	//str := "Dailyid,Year,Day,Hour,Minute,Second,Latitude,Longitude"
	str := []string{"Dailyid", "Year", "Day", "Hour", "Minute", "Second", "Latitude", "Longitude"}
	fmt.Println(str)

	if err = w.Write(str); err != nil {
		log.Fatal(err)
	}

	/////

	id := 1
	dt := time.Now()
	year := dt.Year()
	day := dt.Day()
	hour := dt.Hour()
	minute := dt.Minute()
	second := dt.Second()
	latitude := 33.749583
	longitude := 132.709375

	str = []string{fmt.Sprint(id), fmt.Sprint(year), fmt.Sprint(day), fmt.Sprint(hour), fmt.Sprint(minute), fmt.Sprint(second), fmt.Sprint(latitude), fmt.Sprint(longitude)}

	if err = w.Write(str); err != nil {
		log.Fatal(err)
	}

	w.Flush() // バッファに残っているデータを書き込む

}

2023,江端さんの技術メモ

単純だけど、これでオブジェクトを書いたり消したりすれば、実現できるかな?

 

<!doctype html>
<html>
<head>
    <title>Many Points with  leaflet Canvas</title>
    <meta charset="utf-8">

    <style>
        
        #map {
            position: absolute;
            height: 100%;
            width: 100%;
            background-color: #333;
        }
    </style>

</head>
<body>
    <div id="map"></div>
    <link rel="stylesheet" href="http://cdn.leafletjs.com/leaflet-0.7.2/leaflet.css" />
    <script src="http://cdn.leafletjs.com/leaflet-0.7.2/leaflet.js"></script>
    <script src="L.CanvasOverlay.js"></script>
    <script src="http://www.sumbera.com/gist/data.js" charset="utf-8"></script>


    <script>

        var points = data; // data loaded from data.js
        var leafletMap = L.map('map').setView([50.00, 14.44], 9);
        L.tileLayer("http://{s}.sm.mapstack.stamen.com/(toner-lite,$fff[difference],$fff[@23],$fff[hsl-saturation@20])/{z}/{x}/{y}.png")
            .addTo(leafletMap);

        L.canvasOverlay()
            .drawing(drawingOnCanvas)
            .addTo(leafletMap);

        function drawingOnCanvas(canvasOverlay, params) {
            var ctx = params.canvas.getContext('2d');
            ctx.clearRect(0, 0, params.canvas.width, params.canvas.height);
            ctx.fillStyle = "rgba(255,116,0, 0.2)";


            //for (var i = 0; i < data.length; i++) {
            for (var i = 0; i < data.length; i=i+300) {
                var d = data[i];
                if (params.bounds.contains([d[0], d[1]])) {
                    dot = canvasOverlay._map.latLngToContainerPoint([d[0], d[1]]);
                    ctx.beginPath();
                    //ctx.arc(dot.x, dot.y, 3, 0, Math.PI * 2);
                    ctx.arc(dot.x, dot.y, 10, 0, Math.PI * 2);
                    ctx.fill();
                    ctx.closePath();
                }
            }

            //for (var i = 0; i < data.length ; i++) {
            for (var i = 0; i < data.length ; i=i+10) {
                var d = data[i];
                if (params.bounds.contains([d[0], d[1]])) {
                    dot = canvasOverlay._map.latLngToContainerPoint([d[0], d[1]]);
					//ctx.beginPath();
					ctx.clearRect(dot.x-10, dot.y-10, dot.x+0, dot.y+0);
                    //ctx.closePath();
                }
            }


        };
    </script>
</body>
</html>

 

2023,江端さんの忘備録

「劇場版 PSYCHO-PASS サイコパス PROVIDENCE」も、ちゃんと見にいくつもりです。

I am going to watch "PSYCHO-PASS PROVIDENCE THE MOVIE" as well.

このアニメのおかげで、随分勉強をさせられたものです。

Thanks to this animation, I have learned a lot.

江端:「というように、『みんなが幸せになること』に潜む矛盾の中でも、特に分かりやすい事例を、一通り網羅的に教えてくれる、大変お得なアニメが『PSYCHO-PASS サイコパス』だ」

まあ、それはさておき。

Well, let's leave that aside.

-----

私が法学のゼミに通っていた時、民法の一部である特別法(特許法)の「工業所有権法(産業財産権法)逐条解説」などを読み込み、その講義を受け、さまざまな法律とその運用における解釈が、複数あることに驚きました。

When I was attending a law seminar, I read the "Industrial Property Law (Industrial Property Law) Verbatim Commentary" and other lectures on special laws (patent law), which are part of the Civil Code, and was amazed at the multiple interpretations of the various laws and their operation.

そして、様々なユースケースに対して、もっとも妥当で、多くの法律学者や、法律の運用者によって支持されているものが、「定説」と呼ばれるものになる、というプロセスにも感動しました。

I was also impressed by the process by which what is most reasonable and supported by many legal scholars and practitioners of the law for various use cases becomes what is called "settled law.

―― 法律とは、「数学の証明」あるいは「システムのプログラミング」と同じである

"Law is like "mathematical proof" or "programming a system"

と気がついた時に、生れて初めて、『法律を「美しい」』と思いました。

When I realized that, for the first time in my life, I thought that the law was "beautiful".

私の「法治」という考え方の信頼は、あの時から発生したと思うのです ―― それは、すでに40歳近い年齢でしたが。

I think my faith in the idea of the "rule of law" occurred at that time -- even though I was already almost 40 years old.

-----

PSYCHO-PASSの主人公の常守 朱(つねもり あかね)も、「法の支配」に対する絶対的な信念を持っているようです。

Akane Tsunemori, the protagonist of PSYCHO-PASS, also seems to have an absolute belief in the "rule of law".

しかし、その信念の発生のプロセスが、よく分からない ―― というか、アニメや映画の中では描かれていないように思えます。

However, I'm not sure about the process by which this belief arises -- or it doesn't seem to be depicted in the animation or film.

常守 朱は、エリート中のエリートですから、私のような泥くさい勉強を経なくても、「法治の美学」を理解できていた、という可能性はあります。

Since Akane Tsunemori is one of the elite of the elite, she might have been able to understand the "aesthetics of the rule of law" without going through the muddled study process that I went through.

しかし、私のように、勉強というプロセスでしか対象を理解できないような凡庸にとっては、この部分が分からないと、今一つ、主人公の気持ちに寄り添えないのです。

However, for a mediocre like me, who can only understand the subject through the process of study, if I don't understand this part of the story, I can't get close to the feelings of the main character at the moment.

-----

もしかしたら、小説の方を読めば、分かるのかもしれません。

Perhaps if I read the novel, I might understand that.

という訳で、先程、ポチっとしてみました。

So I pushed the button to order it.

2019,江端さんの忘備録

長女:「パパみたいに、社会問題に対して興味を持てるようになるには、どうしたらいいかな」

Senior daughter(SD): "How can I become interested in social issues like you ?"

Ebata: "If you watch the animation " PSYCHO-PASS Psycho-Pass ", I think that the basic ideas about social issues can be covered in general."

長女:「そうなの?」

SD: "Is that so?"

江端:「んー、そうだなぁ。例えば「社会の究極的な目的」は何だと思う?」

Ebata: "Hmm, let me think. For example, what do you think is the ultimate goal of society? "

長女:「普通に考えれば、『みんなが幸せになること』だと思う」

SD: "If I think normally, I think that "everyone will be happy""

江端:「『みんなが幸せになること』の"幸せ"の内容は、いったん置いておくとして、『みんなが幸せになるアプローチ』についてはどうかな。例えば、最小の努力で"幸せ"に達成できる世界は、正しいと思うか」

Ebata:"Firstly we forget the contents of" happiness "in "everyone will be happy," let us think "what about the "approach that makes everyone happy"? For example, How do you think that the world that can achieve "happy" with minimum effort?"

長女:「正しと思う」

SD: "I think it's correct."

江端:「確実に最短距離への"幸せ"のアプローチを示してくれるものがあれば、その存在を受けいれるか?」

Ebata: "Can I accept the existence of something that surely shows the "happiness" approach to the shortest distance?"

長女:「受け入れる」

SD: "I can"

江端:「試行錯誤をくりかえさず、自分の様々な可能性を自分で試すこともなく、超高度の計算機が導いた答を受けいれる社会は、『みんなが幸せになること』の実現だと思うか」

Ebata: "Do you think it is the realization of "everyone will be happy," which is derived from the super-high-level calculator without your trial and error by yourself or trying the possibilities ?"

長女:「思う」

SD: "I think so"

江端:「では、1人を犠牲にして99人が100%幸せになる社会と、誰も犠牲にせずに100人が50%の幸せにしか至れない社会は、『みんなが幸せになること』という観点から見て、どっちを選ぶべきだと思うか」

Ebata: "Well, From the point of view that "everyone will be happy", which one do you think should choose (A) A society where 99 people become 100% happy at the expense of one, or (B)A society where 100 people can only achieve 50% happiness without sacrificing anyone.

長女:「うっ・・」

SD: "Hmm ..."

江端:「超高度のコンピュータが、『90%以上の確率で犯罪者になる』ということが、完全に数理学的に算出でき、それに間違いがないとして、そのような場合、いわゆる『犯罪予備』という可能性だけで、その人を社会から隔離することは、正しいと思うか」

Ebata: "A super-high-level calculator can mathematically calculate that a human will become a criminal as a" 90% or more possibility. Of course, the result has absolutely no mistake. In such a case, do you think it would be right to isolate that person from society just by the possibility of so-called "crime reserves"? "

長女:「えーっと・・・」

SD: "....Let me think for a moment"

江端:「というように、『みんなが幸せになること』に潜む矛盾の中でも、特に分かりやすい事例を、一通り網羅的に教えてくれる、大変お得なアニメが『PSYCHO-PASS サイコパス』だ」

Ebata:""PSYCHO-PASS" is very reasonable animation, that give us easy several examples of contradictions hidden in "everyone will be happy"

長女:「・・・」

SD: "..."

江端:「見たいなら、準備するけど」

Ebata: "If you want to see, I will prepare."

(続く)

(To be continued)

未分類

ちょっとコードいじって、表示場所を替えてみた

使っている(らしい)API

https://github.com/Sumbera/gLayers.Leaflet

 

2023,江端さんの技術メモ

https://prideout.net/emulating-double-precision の ざっくり翻訳

頂点変換の精度を向上させる
WebGLとOpenGL ESは64ビット演算をサポートしていませんが、頂点シェーダーで少し足掻くだけでエミュレートできます。
まず、この記事に興味を持たれた方は、Patrick CozziとKevin Ringが出版した「3D Engine Design for Virtual Globes」というとても素晴らしい本に興味を持たれたのではないでしょうか。この本には、精度についての章があり、その他にも多くのことが書かれています。
地図画像を読み込むと、以下の2つのインタラクティブなWebGLキャンバスが表示されます。青い十字線は、バークレー・マリーナのすぐ北にあるセザール・チャベス公園の展望台です。ここは、私の2人の子供たちのお気に入りの場所で、十分に拡大すると見ることができます。Googleマップと同じように、ズームやパンをしてみてください。
子供たちが見えるくらいまで拡大すると、左のキャンバスでは十字線が揺れていますが、右のキャンバスでは揺れていないことに気がつくかもしれません。左のキャンバスでは従来のモデル・ビュー・プロジェクション・マトリックスを使用していますが、右のキャンバスでは MVP を計算する際にカメラが (0,0,0) にあるように見せかけ、バーテックスシェーダーで手動で変換を行っています。このためのGLSLを以下に示します。
ハイパートとローパートの2つのユニフォームを使って、目の位置をGPUに送信していることに注意してください。この2つのパーツを抽出するために、以下のCPUサイドのコードを使用することができます:
C言語ではなくJavaScriptを使用している場合、Float32Arrayを使用して、上記のスニペットで見られるdouble-to-floatキャストを行うことができるかもしれません。
64ビット頂点
これまで、64ビットのカメラ位置の扱い方について説明してきましたが、これは上記のデモで十分です。では、64ビットの頂点が必要な場合はどうでしょうか。この場合も、GPUに送る前に各2倍を2つの浮動小数点に分割することができます。この場合、VBOが2倍になり、バーテックスシェーダが少し複雑になるため、よりコストがかかります。
私はこれを完全にテストしたわけではありませんが、ドナルド・クヌース(Donald Knuth)の研究に基づく古い数学精度ライブラリであるDSFUN90で使用されている「ダブル・シングル」ルーチンをGLSLで移植したものがあります!
いくつかの脚注
このページの地図デモは、私が取り組んでいる小さなC99ライブラリを使い、MODULARIZE=1、PRECISE_F32=1のフラグを付けてEmscriptenで実行したものです。PRECISE_F32を使用しない場合、Emscriptenはfloat変数でもdoubleを使用するため、split_doubleのコードが壊れてしまいます。
デモ用のマップテクスチャを得るために、mapbox.comの本当に素晴らしいStatic maps APIを使用しました。

2023,江端さんの忘備録

以前、ワールドカップのニュースが、私に全く入ってこないというお話をしました。

I have told you before that the news of the World Cup has not been getting to me at all.

―― ワールドカップの日本の1次リーグ突破のニュースが一つも表示されない

今回も、WBCの情報は全く入ってきませんでした。

Again, I received no information about the WBC.

「WBCで日本が優勝した」という一次情報源は、嫁さんでした。

The primary source of information that "Japan won the WBC" was my wife.

-----

これこそがWebターゲティングの真髄だとは思いますが、考えれば、結構怖い話だとも思います。

I think this is the essence of web targeting, but I also think it's a pretty scary story when I think about it.

これを別の案件から考えて見ると、

Looking at this from a different perspective, I can envision a situation in which I do not receive news about

―― 「外食チェーン店への客による迷惑行為動画」ニュースは勿論、最悪のケースでは「日本国土にミサイルが飛来する」とかの情報も入ってこない

"videos of customers causing trouble at restaurant chains" or, in the worst case scenario, "missiles flying over Japan"

という事態が想定されるのです。

『情報格差』という言葉がありますが、これも、その一態様のように思えます。

The term "information gap" seems to be another example of this.

―― 公衆の衛生を害するような動画を投稿したら、社会的に制裁を喰らう(というか、社会的リンチ(*)といいましょうか)

"If you post a video that is harmful to public health, you will be socially sanctioned (or perhaps we should say socially lynched(*)"

という事件は、これまでも、腐るほどありました。

Such incidents have been and are rotten.

(*)リンチとは私刑ですので、「社会的リンチ」は形容矛盾です。

(*) Lynching is a private punishment, so "social lynching" is a figurative contradiction.

この程度の情報なら、普通にテレビでニュースを見ていれば、誰だって知り得ることです。

This level of information is something that anyone who watches the news on TV would know.

それにもかかわらず、何度も、同じような事件が繰り返されていることに首をかしげている人も多いかと思います。

Nevertheless, many people are scratching their heads at the fact that, time and again, similar incidents are being repeated.

私は、別段に不思議には思っていません。

I am not wondering otherwise.

-----

今回の回転寿司事件では、4名の人物が特定され、逮捕されています。

Four individuals have been identified and arrested in the recent Kaiten Sushi case.

比して、現在の高校生は330万人、大学生は292万人います。ざっくり620万人としましょう。

In comparison, there are 3.3 million high school students and 2.92 million college students today. Let's say roughly 6.2 million.

4 ÷ 6200000 = 0.0000065 です。

4 ÷ 6200000 = 0.0000065.

今回の事件を起こした人物の比率は、155万人に対して1人です。

The ratio of the person who caused this incident is one to 1.55 million.

つまり、回転寿司事件を起こした4人の彼らは、「155万人に1人の『超低能エリート』」といえるエクセレントでアメージングな存在なのです。

In other words, the four of them who caused the Kaiten Sushi incident are EXCELLENT and AMAZING, the "1 in 1,550,000 'super low elite'".

そんな、超エリートの行為に対して、620万人の若者全体を判断するのは ―― それは、いくらなんでも、若者に対して失礼と言えましょう。

To judge the entire 6.2 million young people for the actions of such a super-elite -- that is, to any degree, disrespectful to the young people.

逆に言えば、我が国の若者の社会的常識は、極めて健全であると断言できます。

Conversely, I can assure you that the social common sense of our country's youth is extremely sound.

このような事件がニュースになること自体、彼らの高いモラルを、褒め称えてもいいくらいです。

The fact that such incidents make the news is in itself a compliment to their high moral character.

それはさておき。

That aside.

-----

これは仮説ですが『事件を起こした彼らは、新聞はもちろん、テレビのニュースすら見ていなかったのではないか?』ということです。

This is a hypothesis, but 'they who caused the incident, did they not even watch the newspapers, or even the TV news?' This is what I mean.

なお、『バズる』という、新しい貨幣(数値で換算できる価値)については、以下で述べていますので、今回は省略します。

The new currency (value that can be converted into numerical values) called "buzz" is described below, so I will omit it this time.

「江端家ファクトチェックシステム」

つまり、

In short,

『炎上事件を起こした彼らと、WBCの日本優勝を知らなかった私の間には、"情報格差"という観点では、大差はないのではないか』

"I think there is not much difference in terms of "information gap" between them, who caused the fire incident, and me, who did not know that Japan won the WBC"

ということです。

まあ、私の場合は単なる「無知」で済みますが、彼らは、そこに「犯罪者(*)」が加わる点が、決定的に異なると言えますが。

Well, in my case, it would be mere "ignorance", but they are decidedly different in that they add "criminal(*)" to the mix.

(*)刑事事件として起訴されて有罪判決が確定した後にですが。

(*) After being indicted and convicted in a criminal case, though.

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

の後で、「一体、江端は何を考えているんだ」と思われるかもしれませんが、『宇都宮ライトレールの利用を拒否させるような、ダイクストラをどうやって作ろうか』と考えています ―― しかも、できるだけ手を抜いて。https://wp.kobore.net/%e6%b1%9f%e7%ab%af%e3%81%95%e3%82%93%e3%81%ae%e6%8a%80%e8%a1%93%e3%83%a1%e3%83%a2/post-6473/

ところで、今、いくつかDBを作っていますが、混乱しかけているので、メモを残しておきます。

utsu_tram_db  : 道路と鉄道の強制結合
utsu_tram_db2: 鉄道のコストを下げて、宇都宮ライトレールを優先的に選ばれるようにした
utsu_tram_db3: 宇都宮ライトレールを単線にして、取り扱いをラクにした

ただ、今、ここで、バスが宇都宮ライトレールの上を驀進するようになってきましたので、これを何とかしないといけなくなりました。

ここで逆転の発想で、

utsu_tram_db4: 宇都宮ライトレールを誰も使いたくなくなるくらいに、コストを爆上げしてやればいい

と気がつきました。

で、utsu_tram_db3と、utsu_tram_db4を併用してやれば良い、と気がつきました。


この続きを記載したのですが、反映に失敗したようです。

という訳で簡単に説明しますと、utsu_tram_db3のコスト(現在0.2倍)を、逆に100倍にしたものをutsu_tram_db4として作成しました。現在上手く動いています(色々失敗もしましたが、それを書き残す気力は、もうありません。この週末、20時間以上コーディングしていて、フラフラです)


ちなみに、上記の作業で作ったデータベースを、他の人に渡す為に、以下の作業を行いました。

# pg_dump -U postgres -p 15432 utsu_tram_db3 > utsu_tram_db3.sql
# pg_dump -U postgres -p 15432 utsu_tram_db4 > utsu_tram_db4.sql

で作った、2つのデータベースのダンプ(utsu_tram_db3.sqlと、utsu_tram_db4.sql)を圧縮したのが、こちら。

utsu_tram_db.zip

まず、
create database utsu_tram_db3;
\c utsu_tram_db3
create extension postgis;
create extension pgrouting;
(utsu_tram_db4についても同じ)

としておいてから

これをutsu_tram_db.zipを解凍して、

# psql -U postgres -p 15432 utsu_tram_db3 < utsu_tram_db3.sql
# psql -U postgres -p 15432 utsu_tram_db4 < utsu_tram_db4.sql

で、PostgreSQLにインポートできます(source番号なども完全一致する(はず))。

2023,江端さんの忘備録

今日は、江端家の結婚記念日です。

Today is the Ebata family's wedding anniversary. Hence,

- 午前の発表会出席のオーダーを却下したのも、

- I also rejected the order to attend the presentation in the morning,

- 午後の会議を途中で抜け出すのも、

- I will get out of an afternoon meeting in the middle of the day,

- 稟議のサポートや報告書でドタバタしているのも、

- I'm also slammed with support for approvals and reports,

- 研究ゼミ生の卒業式や謝恩会に出席できないのも、

- It is also impossible to attend graduation ceremonies and thank-you parties for research seminar students,

ぜんぶ結婚記念日のせいです。

It's all because of our wedding anniversary.

-----

ちなみに、私の嫁さんは、

By the way, my wife always says,

『記念日に、宝飾品なぞ買う金があるなら、高いメシを食うほうがいいに決まっている』

"If you have money to buy jewelry on your anniversary, it's better to eat expensive meals"

という同じポリシーを持つ、長年の同志です。

Hence, she is a long-time comrade who shares the same policy.

2023,江端さんの技術メモ

■wsl2は通常状態ではdockerにアクセスできない。
→ Docker Desktopで、wsl2を使えるようにチェックを付ける

■wsl2からpsqlを使えるようにできるように、"sudo apt psql なんとか"で、psqlをインストールしておく
→ 要するに、wsl2からDBアクセスできなければ、お話にならない
こんなエラーで面倒な目にあった(なんか色々やっているうちに動くようになった)

psql: error: connection to server at "localhost" (::1), port 15432 failed: Connection refused (0x0000274D/10061)
Is the server running on that host and accepting TCP/IP connections?
connection to server at "localhost" (127.0.0.1), port 15432 failed: Connection refused (0x0000274D/10061)
Is the server running on that host and accepting TCP/IP connections?

とか、

psql: error: connection to server on socket "/var/run/postgresql/.s.PGSQL.5432" failed: No such file or directory

などが出てくるが、やっかいなことに、DBを3回くらい作り直すと、直っていたりするので、原因が特定できないことが多い。

T.B.D.