ある確率分布に従う質量(あるいは確率)を、別の確率分布に移動させるために必要なコストを最小化するような輸送方法を求める問題です。
「離散的なスナップショットデータから連続的な変化プロセスを推定できる」
実際には時系列ではないデータ(異なる状態の独立したサンプル)に対して、連続性を仮定することで、状態間の滑らかな遷移経路を数学的に復元できます。これにより、観測されていない「中間プロセス」を理論的に推定し、変化のメカニズムを解明できるのが最適輸送解析の革新的な価値です。
各データポイントが早期状態から中期状態、そして2つの後期状態への最適経路に沿って遷移する様子を示すアニメーション
状態の変化パターンを密度分布と等高線で可視化。データポイントの集中度と分散パターンが明確に表示されます
初期状態
中間状態
最終状態1
最終状態2
State A→State B→State Cの全体的な分岐パターンを示す静的図表(Cluster: A1, B1, C1, C2)
State AからState Bへの最適輸送パターンと矢印による移動経路の可視化
# A→B輸送解析のRコード (mvp_simple.Rより)
# PNG 2: A→B Transport using ggplot2
cat("Creating transport_ab.png with ggplot2...\n")
# Prepare A→B data
ab_data <- data.frame(
PC1 = c(pca_A$data[,1], pca_B$data[,1]),
PC2 = c(pca_A$data[,2], pca_B$data[,2]),
State = factor(c(rep("State A", nrow(pca_A$data)),
rep("State B", nrow(pca_B$data))),
levels = c("State A", "State B"))
)
# Prepare ALL transport arrows (not sampled)
ab_arrows <- data.frame()
if(nrow(transport_AB$plan) > 0) {
for (i in 1:nrow(transport_AB$plan)) {
if (transport_AB$plan[i, 3] > 1e-6) {
ab_arrows <- rbind(ab_arrows, data.frame(
x = pca_A$data[transport_AB$plan[i, 1], 1],
y = pca_A$data[transport_AB$plan[i, 1], 2],
xend = pca_B$data[transport_AB$plan[i, 2], 1],
yend = pca_B$data[transport_AB$plan[i, 2], 2],
weight = transport_AB$plan[i, 3]
))
}
}
}
p2 <- ggplot(ab_data, aes(x = PC1, y = PC2)) +
geom_segment(data = ab_arrows, aes(x = x, y = y, xend = xend, yend = yend),
arrow = arrow(length = unit(0.15, "cm")),
color = "gray40", linewidth = 0.5, alpha = 0.4) +
geom_point(aes(color = State), size = 3, shape = 16, alpha = 0.8) +
scale_color_manual(values = c("State A" = "blue", "State B" = "darkgreen")) +
labs(title = "State A->State B Transport Analysis\n(Horizontal Movement Pattern)",
x = "PC1", y = "PC2") +
annotate("text", x = min(ab_data$PC1), y = max(ab_data$PC2),
label = paste("Wasserstein Cost:", round(transport_AB$cost, 4)),
hjust = 0, vjust = 1, size = 4, fontface = "bold", color = "darkblue") +
theme_minimal() +
theme(
plot.title = element_text(size = 16, hjust = 0.5, face = "bold"),
axis.title = element_text(size = 12),
legend.position = "right",
legend.title = element_text(size = 11),
legend.text = element_text(size = 10),
panel.grid.minor = element_blank()
) +
guides(color = guide_legend(title = "State", override.aes = list(size = 4)))
ggsave("transport_ab.png", plot = p2, width = 10, height = 8, dpi = 150, bg = "white")
cat("✅ Generated: transport_ab.png with ggplot2 (all arrows displayed)\n")
State BからState Cへの分岐輸送パターンと色分けされた矢印による移動経路の可視化
# B→C輸送解析のRコード (mvp_simple.Rより)
# PNG 3: B→C Transport using ggplot2
cat("Creating transport_bc.png with ggplot2...\n")
# Create BC_data with cluster information
BC_data <- data.frame(
PC1 = c(pca_B$data[,1], pca_C$data[,1]),
PC2 = c(pca_B$data[,2], pca_C$data[,2]),
State = factor(c(rep("State B", nrow(pca_B$data)),
rep("State C", nrow(pca_C$data))),
levels = c("State B", "State C")),
Cluster = c(rep("B", nrow(pca_B$data)),
rep(paste0("C", pca_C$cluster), nrow(pca_C$data)))
)
# Prepare ALL transport arrows for B→C
bc_arrows <- data.frame()
if(nrow(transport_BC$plan) > 0) {
for (i in 1:nrow(transport_BC$plan)) {
if (transport_BC$plan[i, 3] > 1e-6) {
target_cluster <- pca_C$cluster[transport_BC$plan[i, 2]]
bc_arrows <- rbind(bc_arrows, data.frame(
x = pca_B$data[transport_BC$plan[i, 1], 1],
y = pca_B$data[transport_BC$plan[i, 1], 2],
xend = pca_C$data[transport_BC$plan[i, 2], 1],
yend = pca_C$data[transport_BC$plan[i, 2], 2],
weight = transport_BC$plan[i, 3],
target_cluster = paste0("C", target_cluster)
))
}
}
}
p3 <- ggplot(BC_data, aes(x = PC1, y = PC2)) +
geom_segment(data = bc_arrows, aes(x = x, y = y, xend = xend, yend = yend, color = target_cluster),
arrow = arrow(length = unit(0.15, "cm")),
linewidth = 0.6, alpha = 0.7) +
geom_point(aes(color = Cluster, shape = State), size = 3, alpha = 0.9) +
scale_color_manual(values = c("B" = "darkgreen", "C1" = "red", "C2" = "orange")) +
scale_shape_manual(values = c("State B" = 16, "State C" = 17)) +
labs(title = "State B->State C Transport Analysis\n(Branching to Two Clusters)",
x = "PC1", y = "PC2") +
annotate("text", x = min(BC_data$PC1), y = max(BC_data$PC2),
label = paste("Wasserstein Cost:", round(transport_BC$cost, 4)),
hjust = 0, vjust = 1, size = 4, fontface = "bold", color = "darkred") +
theme_minimal() +
theme(
plot.title = element_text(size = 16, hjust = 0.5, face = "bold"),
axis.title = element_text(size = 12),
legend.position = "right",
legend.title = element_text(size = 11),
legend.text = element_text(size = 10),
panel.grid.minor = element_blank()
) +
guides(
color = guide_legend(title = "Cluster", override.aes = list(size = 4)),
shape = guide_legend(title = "State", override.aes = list(size = 4))
)
ggsave("transport_bc.png", plot = p3, width = 10, height = 8, dpi = 150, bg = "white")
cat("✅ Generated: transport_bc.png with ggplot2 (branching transport displayed)\n")
| 指標 | 値 | 説明 |
|---|---|---|
| データポイント数 | 30 per state | 各状態のサンプルサイズ |
| PC1分散寄与率 | 84% | 第1主成分の説明力 |
| PC2分散寄与率 | 14% | 第2主成分の説明力 |
| クラスター分離 | 3.4 units | C1とC2クラスター中心間の距離 |
| 輸送パス | ワッサースタイン距離 | 輸送接続数 | 解釈 |
|---|---|---|---|
| A→B輸送 | 1.7512 | 30 | 水平移動の最適輸送コスト |
| B→C輸送 | 2.0985 | 30 | 分岐輸送の最適コスト |
| 総輸送コスト | 3.8497 | 60 | A→B→C全体の輸送コスト |
| 分岐コスト増加 | 0.3473 | - | B→C分岐による追加コスト |
| 分岐先 | データポイント数 | 分岐比率 | 平均座標 (PC1, PC2) |
|---|---|---|---|
| クラスターC1 | 15 | 50.0% | (8.2, 3.5) |
| クラスターC2 | 15 | 50.0% | (8.1, 0.6) |
| クラスター間距離 | - | - | 3.4 units |
| 分岐角度 | - | - | 約90°(垂直分岐) |
概念: 状態Aから状態Bへの単純な水平移動に必要な最小エネルギー
わかりやすく言うと:30人の集団が全員同じ方向に3歩分移動する時の「疲労度」の総計
概念: 中間状態から2つの異なる最終状態への分岐移動に必要な最小エネルギー
わかりやすく言うと:30人の集団が道の分岐点で半分ずつ異なる方向に進む時の「移動エネルギー」の総計
概念: 初期状態から最終状態までの完全な遷移プロセスに必要な総エネルギー
わかりやすく言うと:30人の集団が出発地から最終目的地まで移動する「総旅行コスト」
概念: 単純な水平移動と比較した場合の分岐移動による追加エネルギー
わかりやすく言うと:集団が「一緒に移動」ではなく「別々の道に分かれる」ことで生じる「追加の手間」
| 比較項目 | 値 | 解釈 |
|---|---|---|
| 分岐コスト / 水平コスト | 1.20倍 | 分岐移動は水平移動より20%困難 |
| 追加コスト / 全体コスト | 9.0% | 全体の9%が分岐による追加負担 |
| 効率性指標 | 91.0% | 分岐しても比較的効率的な遷移 |
Geoffrey Schiebinger et al.
"Optimal-Transport Analysis of Single-Cell Gene Expression Identifies Developmental Trajectories in Reprogramming"
Cell, Volume 176, Issue 6, 7 March 2019, Pages 1517
この研究は単一細胞遺伝子発現データに最適輸送理論を適用し、細胞の発生軌跡を推定する手法を確立しました。本解析では、この手法を状態データに応用し、状態遷移パターンの解明を行っています。
最適輸送理論を用いた単一細胞データの軌跡推定手法の概念図。異なる時点のデータから連続的な発生プロセスを復元し、細胞分化の経路を明らかにする革新的なアプローチを示しています。