2026年4月21日火曜日

micro:bitを使ってニューラルネットワークの基礎を学ぶ

 アルゼンチンのDr. Leandro Batlle(Sadosky Foundationという教育関係財団に所属)から、教育用に「micro:bitを使ったニューラルネット」を作り、いくつかのアプリを公開したとの知らせをいただきました。そのきっかけとなったのが、私が以前に書いたブログ記事だとのことでした。ブログ記事を書いていて良かった!という一つの事例ですので、簡単にご紹介します。

 以下のGitHubにあります。スペイン語ですので、日本語または英語に翻訳してご覧ください。
https://github.com/fundacion-sadosky/microbitML

 謝辞を日本語に訳すと以下のようです:
「この活動は、2024年にそのフレームワークの開発を促し、その名称「microbitML」は、ネイティブのBLE機能を拡張するものであり、もともと機械学習のために考案されたことに由来します。また、Fujio Yamamoto 教授の論文「MicrobitネットワークによるMLPのエミュレーションの構築」に基づいています。

 そして、私が書いたブロブ記事は以下の2件でした。

🟢 micro:bitsで、Forward Propagation
https://sparse-dense.blogspot.com/2018/06/microbittwo-layer-perceptronxor.html

🟢 micro:bitsで、Back Propagation
https://sparse-dense.blogspot.com/2018/06/backpropagation-in-neural-network-with.html


2026年4月10日金曜日

Variational Quantum Algorithmによる幾何学的最適化

 量子コンピューティングによって、「アメーバ」のような形の閉曲線に内接する正五角形を見つけ出そう!(→英語版はこちらです。

🟠閉曲線の内接正五角形を探す
 どんな単純閉曲線の上にも、正方形の4頂点となる点の組が存在することが(一部の例外を除いて)、すでに証明されています。これは内接正方形問題として知られています。では、正方形ではなく、正五角形(およびそれ以上の角数の正多角形)は必ず存在するのか?実は、それは未だ数学的に明らかにされていないようです。ここでは、量子コンピューティングの手法によって、具体的にそのような5角形を探します。もちろん、数学的証明ではなく、数値的に一定の誤差の範囲内でそれを求めます。

🟠変分量子アルゴリズム(VQA)の応用
 今回は、量子・古典ハイブリッドアルゴリズムであるVQA (Variational Quantum Algorithm)を採用します。概要は以下のとおりです。

・Ansatz (量子回路): 
 5つの頂点を表す変数(その値は、曲線を一周する 0〜2π)を、量子回路の回転ゲート(Ryなど)のパラメータとします。
・コスト関数 (古典側): 
 5辺の長さが等しいこと(隣接する点間の距離の分散を最小化)と、5本の対角線の長さが等しいこと(対角線距離の分散を最小化)を表現します。
・最適化: 
 量子回路側からの勾配を要求しない、古典オプティマイザ(COBYLA等)を用いて、量子回路の期待値が最小(正五角形にできるだけ近づくよう)になるようパラメータを更新します。
・実装:
 Qiskit 2.xの Sampler を使い、量子回路の状態を座標に直接対応させ、Ansatzにより、5つの量子ビットの回転角θiを、曲線上のパラメータ tiとみなします。そして、古典側で、Samplerでの実測から、期待値の近似値、すなわち、得られた準位(状態)から現在の幾何学的配置を評価します。

 VQA以外に、QAOAという方法もあります。QAOAの方は曲線上の点を離散化して、そのうちの最適な5点の組み合わせを求めるのに対して、今回のVQAは「連続的な探索」に特徴があります。さらに詳しいことは、別記事で書きたいと思います。

🟠VQAの動作の可視化
 最初に、下図のアニメーションをご覧ください。閉曲線がアメーバのように動き回る中で、VQAは正五角形を追い続けている様子が分かります。これを眺めていると、量子アルゴリズムは、化学計算や金融最適化だけでなく、こうした純粋幾何学の探索においても強力なツールとなるように思えます。
 さらに、閉曲線を一つ固定して、VQAがどのように正五角形を探索しているかを見ることにします。以下のアニメーションがその一例です。
🟠VQAが求めてた正五角形の精度
 以下の図に、VQAで求めた、正三角形、正方形、正五角形の精度を示します。角数が増えると、次第に高精度を求めることが難しくなって行きます。それでも、左下の正五角形の場合、かなり高い精度になっています。具体的には、5つの辺の長さの平均値=1.096、標準偏差=0.00016でした。また、5つの対角線の長さについても、平均値=1.773、標準偏差=0.00043です。

🟠量子コンピュータ実機を使う場合
 今回は、Qiskitによるシミュレータでの実行でした。実機でもやってみたいのですが、無料ユーザ(Open Plan)はsession機能を使えないので、上記のような量子/古典ハイブリッドジョブをそのまま投入することができません。そのため、かなりの部分をシミュレータで実行して、それを利用して、最後の1回か2回程度の評価をジョブとして実機に投入する、などの工夫が必要になります。この件も、後日報告したいと思います。

Geometric Optimization with a Variational Quantum Algorithm

Let’s use quantum computing to find a regular pentagon inscribed in an “amoeba-shaped” closed curve! (→日本語版はこちらです

🟠 Searching for an Inscribed Regular Pentagon
It has already been proven (with some exceptions) that for any simple closed curve, there exists a set of four points that form a square. This is known as the inscribed square problem. But what about a regular pentagon—or regular polygons with even more sides? Do they always exist on any closed curve? In fact, this question has not yet been fully resolved in mathematics.
    In this article, instead of pursuing a formal proof, we take a computational approach. Using quantum computing techniques, we attempt to numerically find such a pentagon—within a certain tolerance of error.

🟠 Applying a Variational Quantum Algorithm (VQA)
We use a hybrid quantum-classical method known as a Variational Quantum Algorithm (VQA). The basic idea is as follows:

Ansatz (quantum circuit):
We represent the five vertices of the pentagon by parameters 𝑡𝑖∈[0,2π], which correspond to positions along the curve. These parameters are encoded as rotation angles (e.g., 𝑅𝑦 gates) in a quantum circuit.

Cost function (classical side):
We define a function that enforces the geometry of a regular pentagon:
All five edges should have equal length (minimize the variance of distances between adjacent points)
All five diagonals should also have equal length (minimize the variance of diagonal distances)

Optimization:
A gradient-free classical optimizer (such as COBYLA) updates the circuit parameters to minimize the cost function—i.e., to make the shape as close as possible to a regular pentagon.

Implementation:
Using the Qiskit 2.x Sampler, we interpret the quantum circuit state as geometric coordinates. The Ansatz produces five angles 𝜃𝑖, which are treated as curve parameters 𝑡𝑖. From measurement results, we estimate expectation values and evaluate the current geometric configuration on the classical side.

🟠 Why VQA (and not QAOA)?
Another approach would be QAOA (Quantum Approximate Optimization Algorithm). QAOA would discretize the curve and search for the best combination of five points. In contrast, VQA performs a continuous search over the curve. This continuous nature is a key advantage of VQA in this setting. I plan to discuss this distinction in more detail in a future article.

🟠 Visualizing the VQA Process
First, take a look at the animation below.
    As the closed curve moves and deforms like an amoeba, the VQA continuously tracks and updates the candidate pentagon. Watching this process, one gets the impression that quantum algorithms are not only useful for chemistry or finance, but also for exploring problems in pure geometry.
    Next, we fix a single closed curve and observe how the VQA searches for a regular pentagon. The following animation shows a representative example.
🟠 Accuracy of the Discovered Pentagon
The figure below shows the accuracy achieved by VQA for an equilateral triangle, square, and regular pentagon.
    As the number of sides increases, achieving high precision becomes more difficult. Nevertheless, the pentagon case still reaches a high level of accuracy. 

For the edges:
Mean edge length: 1.096
Standard deviation: 0.00016

For the diagonals:
Mean length: 1.773
Standard deviation: 0.00043

    These results indicate that the obtained shape is very close to a true regular pentagon.

🟠 Running on Real Quantum Hardware
In this work, all experiments were performed using the Qiskit simulator. Running this on real quantum hardware is more challenging. For example, under the free-tier Open Plan, session-based execution is not available. This makes it difficult to directly run hybrid quantum-classical loops like VQA. So, a practical workaround is:
Perform most of the optimization on a simulator, Then submit only the final few evaluations as jobs to real hardware. I plan to report on this approach in a future post.

2026年4月3日金曜日

利尻山に朝日と満月が同時に

 時々、全国何ヶ所かのライブカメラを楽しんでいます。そのうちのお気に入りの一つは北海道利尻山です。こちらのwebカメラです。本日の朝(2026-04-03の06:30頃)、珍しく、太陽と満月が、ちょうど山頂にはっきり現れているところに出会いました!
利尻山の朝日と満月(利尻町webカメラから引用)
 天候条件やカメラ更新タイミングもあり、こんな場面に出会うのは稀ですね。でも、この現象自体はそんなに珍しいものではなく、天文計算で出現は予測できるでしょう。実際、それをCharGPTに聞いてみたところ、以下の回答がありました。確かに、本日のこの現象とほぼ合致します。あと、2、3日は、早起きすれば楽しめそうです!

#実は、この翌日の4月4日(土)はダメでした。天文計算では[最良]との予測でしたが、日の出頃に分厚い雲に覆われたためです。ですから、上記写真は貴重な1枚となりました!

🌕 2026年「ベスト日程(利尻山)」(満月:4月2日)
 ■ 4月3日(金)
 日の出:約 05:13
 月の入り:約05:30〜05:40(推定)
 👉 約15〜25分 同時に見える
 👉 山頂+朝日+西空の月が成立

 ■ 4月4日(土)【★最良】
 日の出:約 05:11
 月の入り:06時台
 👉 約1時間近く同時に見える
 👉 撮影としては最も余裕あり

 ■ 4月5日(日)
 日の出:約 05:09
 月の入り:さらに遅い
 👉 月が高く残る
 👉 構図自由度が最大