Software environment to make the small world

Japanese

In the last post, I said that I want to make a world in which I can experiment with evolution. In this post, I’d like to talk about the software environment to do that.

I think the best language for doing this task is Python because the task would eventually require doing machine learning (including deep learning) with multiple agents. Python has a framework like OpenAI Gym that makes machine learning easy. It is also the most powerful language for deep learning because of the vast amount of libraries. In terms of pure speed, it is also competitive if you use modules like Numpy or Numba. (I tested running Conway’s game of life using Matlab, Python, and Julia and compared the speed. If you optimize, the speeds of Python and Julia were similar. Matlab was a bit slower (~x2) than the other two. I would omit the details of these experiments, but let me know if you are interested. I may write a post for that.)

I will use PyCharm to write the code. I was torn between VSCode and PyCharm, but PyCharm seemed to be easier for debugging. I also thought about Vim, but there were too many plugins to be installed to make it practical. More plugins mean more maintenance, so I skipped it this time. These are not final decisions.

I would try making my own environment and register it to OpenAI Gym, then combine it with one of the existing deep learning frameworks. I’m using a bit old Intel Mac, so I thought about using PlaidML + Keras to use CPU graphics for computational resources. However, I got errors when combined with OpenAI Gym (discussed in this thread), and couldn’t fix it. (I could run the PlaidML benchmark on my CPU. That was fast.) I thought my current computer would not be used for the long-term, so I decided to use just a CPU for now.

In near future, I would build a reasonable computer with a GPU and run the calculation on that. I would write another post on the hardware environment, but I’m not thinking that it is not the greatest time to write about hardware right now. At least, I should wait until the details of Apple Silicon Macs and AMD’s Ryzen 5000 series are known.

This is a relatively short post without any code. In the next post, I will probably start deciding what the world’s rules are, and register them to Open AI Gym.

世界を作るための準備(ソフトウェア環境編)

English

前回の投稿で進化の実験ができる世界を作りたいと言いました。今回はその実現のためのソフトウェア環境について考察します。

将来的には深層学習を含めた複数エージェントの機械学習をすることになりますので、現時点で最適な言語は Python だと言えると思います。 OpenAI Gym などの機械学習のフレームワークが確立されている他、深層学習では強力なライブラリ群によってほぼ独壇場のシェアがあります。速度面でも Numpy や Numba をうまく使えば他の言語と遜色なく、フレキシブルに使える分 Python に利があるとも言えます。(Matlab と Julia でライフゲームの速度比較をしたのですが、Python も Julia もきちんと最適化をすればほぼ同等の性能が出ました。Matlabだけはどうしてもそこまで速度を上げることができませんでした。これらの実験の詳細は割愛します。もし興味がある方がいらっしゃれば、一報いただければ記事を書こうと思います。)

エディタは PyCharm を使うつもりです。VSCode も評価が高く、考慮はしたのですが、デバッグが PyCharm の方が簡単そうだったのでこちらにしました。 Vim も選択肢にはありましたが、実用的なレベルになるまでに必要なプラグインの数が多いこと(結果メンテナンスの量が増える)もあって、諦めました。無理してVimを使うよりは、PyCharm の Vim mode を使った方が短期的には楽になる気がしたので。このあたりは様子を見ながら色々試してみたいと思っています。

今回は OpenAI Gym に自作の環境(世界)を登録して、既存の深層学習ライブラリと組み合わせて計算することを試みます。やや古い Intel Mac を使っているので、PlaidML + Keras を使って Intel CPU のグラフィック機能を計算資源にできないかと思ったのですが、強化学習のフレームワークと相性が悪く、直す方法もわからなかったので大人しく CPU で計算することにしました。(こちらでとりあげられている問題が発生し、PlaidML側の反応としては、Kerasの方が何とかならないと難しい、とのことでした。PlaidMLのベンチマーク自体は走らせることができました。)

将来的には GPU を積んだ手頃な計算機を構築して、そちらで計算を回せるようにしたいところです。計算用のハードウェアの構成の考察も大変面白いので、別途記事にしますが、今は計算機を構築するのに最適な時期ではない気がするのでもう少し後に書こうと思います。少なくとも Apple Silicon Mac と、 AMD Ryzen 5000 シリーズの情報が出て来てから考えるべきだと思っています。

今回は特に紹介するコードもなく手短になりました。次回はおそらく手始めに OpenAI Gym に登録できる世界を作ってみることになると思います。お楽しみに。

電気羊は仮想空間で進化の夢を見るか?

English Version

長いこと私が心の奥の方で静かに「やりたいなぁ…」と思っていたことがあります。それは小さな世界で進化の実験をすることです。もちろん実際にやるのは難しいので計算機の上で、ということになりますが。突飛なことを、と思われるかもしれません。あるいは、現状の計算リソースでは足りないのでは? という批判もあるかもしれません。が、セル・オートマトンなどに代表されるようにごく単純なルールから複雑な事象が生まれるということは既に示されています。

もうすこし具体的にはセル・オートマトンをもう少し複雑にし、より「生命」らしくした存在を用いて観測をしてみたいと思っています。思考をし、学習をし、再生産をし、そして死ぬことができる「生命」と、それが生きる環境を用意して、自然選択に任せてどのようにそれが発達するかを見守る、といった感じの漠然としたプロジェクトです。もし条件が合えば、徐々に「知的(?)」な生命が生まれていくかもしれません。

これは簡単なことではないですし時間のかかることだと思います。おそらくたくさんの人々が過去に挑戦してきたテーマでもあるでしょう。私が個人的な趣味としてやったところで何か有益な結果が生まれるかといわれれば、それはわかりません。今までやってきた物理学と神経科学からひょっとしたら新しい知見を持ち込めるかもしれません。仮に知的生命体様のものが一切出てこなかったとしても、何かしら学ぶところがあることでしょう。とりあえずモチベーションはそれでよしとします。

当面は2つのことに注力するつもりです。1つめは個体の情報の継承と、自然選択を可能にする環境の構築。広い意味では、「遺伝的アルゴリズムの実装」と言えるかもしれませんが、目標関数だとかを設定するのではなく、あくまで「生き延びた者が次の世代を作る」というルールの実装になります。勝てば官軍とでも言いましょうか。2つめは、生きる過程でトレーニングが可能、かつ、進化によって構造自体のの変化が可能なニューラルネットワークを「生命」に持たせることです。

これから書く記事はこの探求を記録した個人的な日誌のようなものになることと思います。道は長いですが、その道中で小さなトピックを見つけて書いたり、考察した事柄をまとめたりすることになると思います。もし楽しみにしてくださる方がいらっしゃれば幸いです。

Dreaming of a virtual world with evolving electric sheep

Japanese Version

For long, I’ve been dreaming of making a small world (on a computer) where I can experiment with evolution. Too ambitious? Perhaps. We already know that order and complexity can emerge from simple ingredients (e.g. cellular automaton). How about intelligence? Will it emerge out of simple rules?

To be more specific, I want to make a slightly complicated version of a cellular automaton with a little more realistic life-like entities. I’d like to make an environment in which lives can think, act, learn, reproduce, and die. Changes caused by reproduction will make diversity of the lives, and natural selection would keep the entities that fit the current environment. The process goes on and in the end, in an ideal scenario that I’m dreaming of, progressively intelligent entities would emerge from such an environment.

I know this project will not be very easy. Probably many people had already tried and failed. Can I contribute at all by doing it as a hobby? I don’t know. Will I have a unique perspective to tackle this issue? Maybe. Even if I won’t achieve much, but it’s fine. I’ll learn something valuable through the process (at the very least, more programming skills).

There are two important factors for this. The first one is the genetic algorithm implemented by inheritance and natural selection. I won’t use a specific training function, but let them survive in the environment. If they thrive, they survive. The second one is neural networks whose structure can be changed through evolution and can be trained through the course of a single life.

Articles that I will write in this blog will be like a journal for this exploration. In each article, I’ll focus on a small topic. Let’s see how it goes. I’m excited.