@nahisaho/satori 0.22.0 → 0.23.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +33 -17
- package/package.json +1 -1
- package/src/.github/skills/scientific-active-learning/SKILL.md +289 -0
- package/src/.github/skills/scientific-advanced-visualization/SKILL.md +310 -0
- package/src/.github/skills/scientific-automl/SKILL.md +264 -0
- package/src/.github/skills/scientific-ensemble-methods/SKILL.md +263 -0
- package/src/.github/skills/scientific-interactive-dashboard/SKILL.md +346 -0
- package/src/.github/skills/scientific-missing-data-analysis/SKILL.md +312 -0
- package/src/.github/skills/scientific-transfer-learning/SKILL.md +298 -0
- package/src/.github/skills/scientific-uncertainty-quantification/SKILL.md +286 -0
package/README.md
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
|
|
8
8
|
## Overview
|
|
9
9
|
|
|
10
|
-
このディレクトリには、Exp-01〜13 で蓄積した科学データ解析技法を Agent Skills として体系化した **
|
|
10
|
+
このディレクトリには、Exp-01〜13 で蓄積した科学データ解析技法を Agent Skills として体系化した **174 個**のスキルを格納しています。Copilot がプロンプトの文脈に応じて適切なスキルを自動ロードし、各実験で確立した解析パターンを再利用します。131 のスキルは [ToolUniverse](https://github.com/mims-harvard/ToolUniverse) SMCP 経由で 1,200 以上の外部科学データベースツールとも連携可能です。
|
|
11
11
|
|
|
12
12
|
### パイプラインフロー
|
|
13
13
|
|
|
@@ -286,8 +286,8 @@ SATORI Skill (方法論・判断) ToolUniverse SMCP (データ取得・
|
|
|
286
286
|
| 中区分 | スキル数 | 概要 |
|
|
287
287
|
|---|:---:|---|
|
|
288
288
|
| A. 基盤・ワークフロー | 17 | パイプライン構築・前処理・データ生成・図表・執筆・仮説立案・批判的レビュー・SI 生成・LaTeX 変換・引用検証・査読対応・改訂追跡・論文品質・系統的レビュー・BioThings ID マッピング・データ投稿・CrossRef メタデータ |
|
|
289
|
-
| B. 統計・探索的解析 |
|
|
290
|
-
| C. 機械学習・モデリング |
|
|
289
|
+
| B. 統計・探索的解析 | 6 | EDA・仮説検定・次元削減・記号数学・欠損データ解析・高度可視化 |
|
|
290
|
+
| C. 機械学習・モデリング | 6 | 回帰・分類・特徴量重要度・アクティブラーニング・AutoML・アンサンブル学習 |
|
|
291
291
|
| D. 実験計画・プロセス最適化 | 2 | DOE・応答曲面法・ベイズ最適化 |
|
|
292
292
|
| E. 信号・スペクトル・時系列 | 4 | スペクトル解析・生体信号・時系列分解・神経電気生理学 |
|
|
293
293
|
| F. 生命科学・オミクス | 28 | バイオインフォ・メタボロ・ゲノム配列・マルチオミクス・ネットワーク・プロテオミクス・トランスクリプトミクス・パスウェイ濃縮・代謝物 DB・HPA・ゲノム配列ツール・非コード RNA・オントロジー・EBI DB 群・Ensembl ゲノミクス・STRING/BioGRID PPI・発現比較・モデル生物 DB・GEO 発現プロファイル・寄生虫ゲノミクス・ArrayExpress 発現アーカイブ・GTEx 組織発現・UniProt プロテオーム・Reactome パスウェイ・HGNC 命名法・代謝ネットワーク・糖鎖解析・リピドミクス |
|
|
@@ -298,11 +298,11 @@ SATORI Skill (方法論・判断) ToolUniverse SMCP (データ取得・
|
|
|
298
298
|
| K. 構造生物学・タンパク質工学 | 7 | PDB/AlphaFold 構造解析・de novo タンパク質設計・PPI ネットワーク・ドメイン/ファミリー・構造プロテオミクス・AlphaFold DB 構造予測・RCSB PDB 構造検索 |
|
|
299
299
|
| L. 精密医療・臨床意思決定 | 6 | 変異解釈 (ACMG/AMP)・エビデンスベース臨床意思決定・バリアント効果予測・CIViC 臨床エビデンス・gnomAD バリアント・ClinGen キュレーション |
|
|
300
300
|
| M. 実験室自動化・データ管理 | 3 | 液体ハンドリング・プロトコル管理・ELN/LIMS 連携・ラボデータ管理・CRISPR gRNA 設計 |
|
|
301
|
-
| N. 科学プレゼンテーション・図式 |
|
|
301
|
+
| N. 科学プレゼンテーション・図式 | 3 | 科学スライド・ポスター・ワークフロー図・科学図式・インタラクティブダッシュボード |
|
|
302
302
|
| O. 研究計画・グラント・規制 | 3 | 助成金申請書・研究方法論・倫理審査・規制科学 |
|
|
303
303
|
| P. ファーマコビジランス・薬理ゲノミクス | 4 | FAERS 不均衡分析・MedDRA 階層・安全性シグナル検出・PGx 代謝型・PharmGKB 臨床アノテーション・臨床薬理学 PopPK/PBPK |
|
|
304
304
|
| Q. 腫瘍学・疾患研究 | 10 | 精密腫瘍学 (CIViC/OncoKB)・疾患-遺伝子関連 (GWAS/Orphanet)・がんゲノミクス (COSMIC/DepMap)・希少疾患遺伝学・細胞株リソース・ICGC がんゲノムデータ・Open Targets 遺伝学・DepMap 依存性・Monarch オントロジー・GDC ポータル |
|
|
305
|
-
| R. 量子・先端計算 |
|
|
305
|
+
| R. 量子・先端計算 | 9 | 量子計算・GNN・ベイズ統計・説明可能 AI・深層学習・ヘルスケア AI・強化学習・転移学習・不確実性定量化 |
|
|
306
306
|
| S. 医用イメージング | 1 | DICOM/NIfTI・WSI 病理画像・Radiomics・MONAI |
|
|
307
307
|
| T. シングルセル・空間・エピゲノミクス | 13 | scRNA-seq・Visium・MERFISH・CELLxGENE・RNA velocity・エピゲノミクス・レギュラトリーゲノミクス・摂動解析・scVI 統合・scATAC-seq/Signac・GPU シングルセル・ENCODE/SCREEN・Human Cell Atlas・高度 Squidpy 空間解析・空間マルチオミクス・CELLxGENE Census |
|
|
308
308
|
| U. 免疫・感染症 | 2 | 免疫情報学・MHC 結合予測・病原体ゲノミクス・AMR・IEDB |
|
|
@@ -340,9 +340,9 @@ SATORI Skill (方法論・判断) ToolUniverse SMCP (データ取得・
|
|
|
340
340
|
| 119 | [scientific-data-submission](scientific-data-submission/SKILL.md) | GenBank/SRA/GEO/BioProject/BioSample データ投稿・FAIR 原則準拠 | 汎用 |
|
|
341
341
|
| 139 | [scientific-crossref-metadata](scientific-crossref-metadata/SKILL.md) | CrossRef REST API DOI 解決・論文メタデータ・引用数・ジャーナル情報 | 汎用 |
|
|
342
342
|
|
|
343
|
-
### B. 統計・探索的解析(
|
|
343
|
+
### B. 統計・探索的解析(6 種)
|
|
344
344
|
|
|
345
|
-
|
|
345
|
+
データの理解・検定・次元削減・記号数学・欠損データ解析・高度可視化を担うスキル群。
|
|
346
346
|
|
|
347
347
|
| # | Skill | 説明 | 参照 Exp |
|
|
348
348
|
|---|---|---|---|
|
|
@@ -350,16 +350,21 @@ SATORI Skill (方法論・判断) ToolUniverse SMCP (データ取得・
|
|
|
350
350
|
| 15 | [scientific-statistical-testing](scientific-statistical-testing/SKILL.md) | 仮説検定・多重比較・エンリッチメント・ベイズ推論 | 03, 04, 06, 07 |
|
|
351
351
|
| 16 | [scientific-pca-tsne](scientific-pca-tsne/SKILL.md) | PCA / t-SNE / UMAP 次元削減・クラスタリング | 02, 03, 07, 11, 13 |
|
|
352
352
|
| 105 | [scientific-symbolic-mathematics](scientific-symbolic-mathematics/SKILL.md) | SymPy 解析的微積分・ODE 求解・線形代数・科学モデリング記号計算 | 汎用 |
|
|
353
|
+
| 172 | [scientific-missing-data-analysis](scientific-missing-data-analysis/SKILL.md) | 欠損パターン診断 (MCAR/MAR/MNAR)・Little's MCAR テスト・MICE 多重代入・KNN/MissForest 補完 | 汎用 |
|
|
354
|
+
| 173 | [scientific-advanced-visualization](scientific-advanced-visualization/SKILL.md) | Plotly 3D・Altair 宣言的可視化・Parallel Coordinates・出版品質図・アニメーション | 汎用 |
|
|
353
355
|
|
|
354
|
-
### C. 機械学習・モデリング(
|
|
356
|
+
### C. 機械学習・モデリング(6 種)
|
|
355
357
|
|
|
356
|
-
|
|
358
|
+
教師あり学習・特徴量解釈・アクティブラーニング・AutoML・アンサンブル学習を担うスキル群。
|
|
357
359
|
|
|
358
360
|
| # | Skill | 説明 | 参照 Exp |
|
|
359
361
|
|---|---|---|---|
|
|
360
362
|
| 17 | [scientific-ml-regression](scientific-ml-regression/SKILL.md) | マルチターゲット回帰・モデル比較・レーダーチャート | 05, 12, 13 |
|
|
361
363
|
| 18 | [scientific-ml-classification](scientific-ml-classification/SKILL.md) | 分類 ML・ROC・PR 曲線・混同行列・PDP・Volcano | 03, 05 |
|
|
362
364
|
| 19 | [scientific-feature-importance](scientific-feature-importance/SKILL.md) | Tree-based & Permutation 特徴量重要度・PDP | 05, 12, 13 |
|
|
365
|
+
| 167 | [scientific-active-learning](scientific-active-learning/SKILL.md) | 不確実性サンプリング・QBC・バッチ AL・能動学習ループ・停止基準 | 汎用 |
|
|
366
|
+
| 168 | [scientific-automl](scientific-automl/SKILL.md) | Optuna HPO・マルチモデル AutoML・自動特徴量エンジニアリング・AutoML レポート | 汎用 |
|
|
367
|
+
| 169 | [scientific-ensemble-methods](scientific-ensemble-methods/SKILL.md) | XGBoost/LightGBM/CatBoost 比較・Stacking OOF・Voting・アンサンブル多様性 | 汎用 |
|
|
363
368
|
|
|
364
369
|
### D. 実験計画・プロセス最適化(2 種)
|
|
365
370
|
|
|
@@ -509,14 +514,15 @@ SATORI Skill (方法論・判断) ToolUniverse SMCP (データ取得・
|
|
|
509
514
|
| 72 | [scientific-lab-data-management](scientific-lab-data-management/SKILL.md) | Benchling ELN/DNA 設計・DNAnexus PaaS・OMERO バイオイメージング・Protocols.io | 汎用 |
|
|
510
515
|
| 164 | [scientific-crispr-design](scientific-crispr-design/SKILL.md) | CRISPR gRNA 設計・Cas9/Cas12a PAM 検索・オフターゲットスコアリング・sgRNA ライブラリ構築 | 汎用 |
|
|
511
516
|
|
|
512
|
-
### N. 科学プレゼンテーション・図式(
|
|
517
|
+
### N. 科学プレゼンテーション・図式(3 種)
|
|
513
518
|
|
|
514
|
-
|
|
519
|
+
学会発表用スライド・ポスター・科学図式・インタラクティブダッシュボードのデザインを担うスキル群。
|
|
515
520
|
|
|
516
521
|
| # | Skill | 説明 | 参照 Exp |
|
|
517
522
|
|---|---|---|---|
|
|
518
523
|
| 45 | [scientific-presentation-design](scientific-presentation-design/SKILL.md) | 15 スライド構成テンプレート・tikzposter・matplotlib ワークフロー図・アクセシビリティ | 汎用 |
|
|
519
524
|
| 73 | [scientific-scientific-schematics](scientific-scientific-schematics/SKILL.md) | CONSORT フロー図・NN アーキテクチャ図・パスウェイ図・TikZ/SVG | 汎用 |
|
|
525
|
+
| 174 | [scientific-interactive-dashboard](scientific-interactive-dashboard/SKILL.md) | Streamlit/Dash/Panel 科学データダッシュボード・パラメータ探索 UI・リアルタイム解析 | 汎用 |
|
|
520
526
|
|
|
521
527
|
### O. 研究計画・グラント・規制(3 種)
|
|
522
528
|
|
|
@@ -556,9 +562,9 @@ SATORI Skill (方法論・判断) ToolUniverse SMCP (データ取得・
|
|
|
556
562
|
| 149 | [scientific-monarch-ontology](scientific-monarch-ontology/SKILL.md) | Monarch Initiative 疾患-遺伝子-表現型オントロジー・HPO・エンティティ検索 | 汎用 |
|
|
557
563
|
| 150 | [scientific-gdc-portal](scientific-gdc-portal/SKILL.md) | NCI Genomic Data Commons REST API・プロジェクト/ケース/SSM 検索 | 汎用 |
|
|
558
564
|
|
|
559
|
-
### R. 量子・先端計算(
|
|
565
|
+
### R. 量子・先端計算(9 種)
|
|
560
566
|
|
|
561
|
-
量子計算・GNN・ベイズ統計・XAI・深層学習・ヘルスケア AI
|
|
567
|
+
量子計算・GNN・ベイズ統計・XAI・深層学習・ヘルスケア AI・強化学習・転移学習・不確実性定量化など次世代計算手法を担うスキル群。
|
|
562
568
|
|
|
563
569
|
| # | Skill | 説明 | 参照 Exp |
|
|
564
570
|
|---|---|---|---|
|
|
@@ -569,6 +575,8 @@ SATORI Skill (方法論・判断) ToolUniverse SMCP (データ取得・
|
|
|
569
575
|
| 55 | [scientific-deep-learning](scientific-deep-learning/SKILL.md) | Lightning/timm/Transformers・CNN/ViT/BERT Fine-tune・Optuna HPO・ONNX エクスポート | 汎用 |
|
|
570
576
|
| 96 | [scientific-healthcare-ai](scientific-healthcare-ai/SKILL.md) | PyHealth 臨床 ML パイプライン・フローサイトメトリー・EHR 処理 | 汎用 |
|
|
571
577
|
| 104 | [scientific-reinforcement-learning](scientific-reinforcement-learning/SKILL.md) | Stable-Baselines3/PufferLib RL エージェント訓練・分子設計/実験最適化 RL | 汎用 |
|
|
578
|
+
| 170 | [scientific-transfer-learning](scientific-transfer-learning/SKILL.md) | Vision/NLP ファインチューニング・Few-shot・知識蒸留・ドメイン適応 | 汎用 |
|
|
579
|
+
| 171 | [scientific-uncertainty-quantification](scientific-uncertainty-quantification/SKILL.md) | Conformal Prediction・MC Dropout・深層アンサンブル・Calibration・ECE | 汎用 |
|
|
572
580
|
|
|
573
581
|
### S. 医用イメージング(1 種)
|
|
574
582
|
|
|
@@ -731,12 +739,17 @@ Skills は `.github/skills/` に配置されているため、Copilot が自動
|
|
|
731
739
|
│ ├── scientific-eda-correlation/
|
|
732
740
|
│ ├── scientific-statistical-testing/
|
|
733
741
|
│ ├── scientific-pca-tsne/
|
|
734
|
-
│
|
|
742
|
+
│ ├── scientific-symbolic-mathematics/
|
|
743
|
+
│ ├── scientific-missing-data-analysis/
|
|
744
|
+
│ └── scientific-advanced-visualization/
|
|
735
745
|
│
|
|
736
746
|
│── [C] 機械学習・モデリング
|
|
737
747
|
│ ├── scientific-ml-regression/
|
|
738
748
|
│ ├── scientific-ml-classification/
|
|
739
|
-
│
|
|
749
|
+
│ ├── scientific-feature-importance/
|
|
750
|
+
│ ├── scientific-active-learning/
|
|
751
|
+
│ ├── scientific-automl/
|
|
752
|
+
│ └── scientific-ensemble-methods/
|
|
740
753
|
│
|
|
741
754
|
│── [D] 実験計画・プロセス最適化
|
|
742
755
|
│ ├── scientific-doe/
|
|
@@ -839,7 +852,8 @@ Skills は `.github/skills/` に配置されているため、Copilot が自動
|
|
|
839
852
|
│
|
|
840
853
|
├── [N] 科学プレゼンテーション・図式
|
|
841
854
|
│ ├── scientific-presentation-design/
|
|
842
|
-
│
|
|
855
|
+
│ ├── scientific-scientific-schematics/
|
|
856
|
+
│ └── scientific-interactive-dashboard/
|
|
843
857
|
│
|
|
844
858
|
└── [O] 研究計画・グラント・規制
|
|
845
859
|
├── scientific-grant-writing/
|
|
@@ -871,7 +885,9 @@ Skills は `.github/skills/` に配置されているため、Copilot が自動
|
|
|
871
885
|
│ ├── scientific-explainable-ai/
|
|
872
886
|
│ ├── scientific-deep-learning/
|
|
873
887
|
│ ├── scientific-healthcare-ai/
|
|
874
|
-
│
|
|
888
|
+
│ ├── scientific-reinforcement-learning/
|
|
889
|
+
│ ├── scientific-transfer-learning/
|
|
890
|
+
│ └── scientific-uncertainty-quantification/
|
|
875
891
|
│
|
|
876
892
|
└── [S] 医用イメージング
|
|
877
893
|
└── scientific-medical-imaging/
|
package/package.json
CHANGED
|
@@ -0,0 +1,289 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: scientific-active-learning
|
|
3
|
+
description: |
|
|
4
|
+
アクティブラーニング (能動学習) スキル。不確実性サンプリング・
|
|
5
|
+
Query-by-Committee・期待モデル変化・プール型/ストリーム型・
|
|
6
|
+
バッチアクティブラーニング・停止基準判定・
|
|
7
|
+
モデル改善パイプライン。
|
|
8
|
+
---
|
|
9
|
+
|
|
10
|
+
# Scientific Active Learning
|
|
11
|
+
|
|
12
|
+
ラベル付けコストを最小化しながらモデル精度を最大化する
|
|
13
|
+
アクティブラーニング戦略の設計・実行・評価パイプラインを提供する。
|
|
14
|
+
|
|
15
|
+
## When to Use
|
|
16
|
+
|
|
17
|
+
- 少量のラベル付きデータで効率的にモデルを改善するとき
|
|
18
|
+
- ラベル付けコストが高い実験データを扱うとき
|
|
19
|
+
- 不確実性サンプリングでモデルの弱点を特定するとき
|
|
20
|
+
- Query-by-Committee で意見が分かれるサンプルを選択するとき
|
|
21
|
+
- バッチアクティブラーニングで複数サンプルを同時取得するとき
|
|
22
|
+
- 停止基準 (パフォーマンス収束) を判定するとき
|
|
23
|
+
|
|
24
|
+
---
|
|
25
|
+
|
|
26
|
+
## Quick Start
|
|
27
|
+
|
|
28
|
+
## 1. 不確実性サンプリング
|
|
29
|
+
|
|
30
|
+
```python
|
|
31
|
+
import numpy as np
|
|
32
|
+
import pandas as pd
|
|
33
|
+
from sklearn.base import clone
|
|
34
|
+
from sklearn.ensemble import RandomForestClassifier
|
|
35
|
+
from sklearn.metrics import accuracy_score
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
def uncertainty_sampling(model, X_pool, strategy="entropy"):
|
|
39
|
+
"""
|
|
40
|
+
不確実性ベース サンプリング。
|
|
41
|
+
|
|
42
|
+
Parameters:
|
|
43
|
+
model: fitted sklearn classifier
|
|
44
|
+
X_pool: np.ndarray — ラベルなしプール
|
|
45
|
+
strategy: str — "entropy" / "margin" / "least_confident"
|
|
46
|
+
Returns:
|
|
47
|
+
indices: np.ndarray — 不確実性降順のインデックス
|
|
48
|
+
"""
|
|
49
|
+
proba = model.predict_proba(X_pool)
|
|
50
|
+
|
|
51
|
+
if strategy == "entropy":
|
|
52
|
+
scores = -np.sum(proba * np.log(proba + 1e-10), axis=1)
|
|
53
|
+
elif strategy == "margin":
|
|
54
|
+
sorted_p = np.sort(proba, axis=1)
|
|
55
|
+
scores = 1.0 - (sorted_p[:, -1] - sorted_p[:, -2])
|
|
56
|
+
elif strategy == "least_confident":
|
|
57
|
+
scores = 1.0 - np.max(proba, axis=1)
|
|
58
|
+
else:
|
|
59
|
+
raise ValueError(f"Unknown strategy: {strategy}")
|
|
60
|
+
|
|
61
|
+
indices = np.argsort(scores)[::-1]
|
|
62
|
+
print(f"Uncertainty ({strategy}): top score = {scores[indices[0]]:.4f}")
|
|
63
|
+
return indices
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
def query_by_committee(models, X_pool, n_members=5):
|
|
67
|
+
"""
|
|
68
|
+
Query-by-Committee サンプリング。
|
|
69
|
+
|
|
70
|
+
Parameters:
|
|
71
|
+
models: list — 学習済み分類器リスト
|
|
72
|
+
X_pool: np.ndarray — ラベルなしプール
|
|
73
|
+
n_members: int — 委員会メンバ数
|
|
74
|
+
"""
|
|
75
|
+
predictions = np.array([m.predict(X_pool) for m in models[:n_members]])
|
|
76
|
+
# Vote entropy
|
|
77
|
+
n_samples = X_pool.shape[0]
|
|
78
|
+
n_classes = len(np.unique(predictions))
|
|
79
|
+
scores = np.zeros(n_samples)
|
|
80
|
+
|
|
81
|
+
for i in range(n_samples):
|
|
82
|
+
votes = predictions[:, i]
|
|
83
|
+
_, counts = np.unique(votes, return_counts=True)
|
|
84
|
+
proba = counts / len(votes)
|
|
85
|
+
scores[i] = -np.sum(proba * np.log(proba + 1e-10))
|
|
86
|
+
|
|
87
|
+
indices = np.argsort(scores)[::-1]
|
|
88
|
+
print(f"QBC: top disagreement = {scores[indices[0]]:.4f}")
|
|
89
|
+
return indices
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
## 2. バッチアクティブラーニング
|
|
93
|
+
|
|
94
|
+
```python
|
|
95
|
+
def batch_active_learning(model, X_pool, batch_size=10,
|
|
96
|
+
strategy="entropy", diversity_weight=0.5):
|
|
97
|
+
"""
|
|
98
|
+
多様性を考慮したバッチアクティブラーニング。
|
|
99
|
+
|
|
100
|
+
Parameters:
|
|
101
|
+
model: fitted classifier
|
|
102
|
+
X_pool: np.ndarray — ラベルなしプール
|
|
103
|
+
batch_size: int — バッチサイズ
|
|
104
|
+
strategy: str — 不確実性戦略
|
|
105
|
+
diversity_weight: float — 多様性重み (0-1)
|
|
106
|
+
"""
|
|
107
|
+
from sklearn.metrics.pairwise import euclidean_distances
|
|
108
|
+
|
|
109
|
+
# 不確実性スコア
|
|
110
|
+
indices = uncertainty_sampling(model, X_pool, strategy)
|
|
111
|
+
|
|
112
|
+
# 候補プール (上位 batch_size * 3)
|
|
113
|
+
candidate_size = min(batch_size * 3, len(indices))
|
|
114
|
+
candidates = indices[:candidate_size]
|
|
115
|
+
|
|
116
|
+
# 多様性ベース選択 (k-center greedy)
|
|
117
|
+
selected = [candidates[0]]
|
|
118
|
+
for _ in range(batch_size - 1):
|
|
119
|
+
remaining = [c for c in candidates if c not in selected]
|
|
120
|
+
if not remaining:
|
|
121
|
+
break
|
|
122
|
+
|
|
123
|
+
dists = euclidean_distances(
|
|
124
|
+
X_pool[remaining], X_pool[selected])
|
|
125
|
+
min_dists = dists.min(axis=1)
|
|
126
|
+
|
|
127
|
+
# 不確実性ランクを正規化
|
|
128
|
+
uncertainty_ranks = np.array([
|
|
129
|
+
np.where(indices == r)[0][0] for r in remaining])
|
|
130
|
+
uncertainty_scores = 1.0 - uncertainty_ranks / len(indices)
|
|
131
|
+
|
|
132
|
+
# 複合スコア
|
|
133
|
+
combined = (diversity_weight * min_dists / (min_dists.max() + 1e-10)
|
|
134
|
+
+ (1 - diversity_weight) * uncertainty_scores)
|
|
135
|
+
|
|
136
|
+
best_idx = remaining[np.argmax(combined)]
|
|
137
|
+
selected.append(best_idx)
|
|
138
|
+
|
|
139
|
+
print(f"Batch AL: selected {len(selected)} diverse-uncertain samples")
|
|
140
|
+
return np.array(selected)
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
## 3. アクティブラーニングループ
|
|
144
|
+
|
|
145
|
+
```python
|
|
146
|
+
def active_learning_loop(X_labeled, y_labeled, X_pool, y_pool_true,
|
|
147
|
+
X_test, y_test,
|
|
148
|
+
model=None, n_rounds=20, batch_size=10,
|
|
149
|
+
strategy="entropy"):
|
|
150
|
+
"""
|
|
151
|
+
アクティブラーニング実験ループ。
|
|
152
|
+
|
|
153
|
+
Parameters:
|
|
154
|
+
X_labeled: np.ndarray — 初期ラベル付きデータ
|
|
155
|
+
y_labeled: np.ndarray — 初期ラベル
|
|
156
|
+
X_pool: np.ndarray — ラベルなしプール
|
|
157
|
+
y_pool_true: np.ndarray — プールの真ラベル (Oracle)
|
|
158
|
+
X_test: np.ndarray — テストデータ
|
|
159
|
+
y_test: np.ndarray — テストラベル
|
|
160
|
+
model: sklearn classifier (default: RF)
|
|
161
|
+
n_rounds: int — ラウンド数
|
|
162
|
+
batch_size: int — バッチサイズ
|
|
163
|
+
strategy: str — サンプリング戦略
|
|
164
|
+
"""
|
|
165
|
+
if model is None:
|
|
166
|
+
model = RandomForestClassifier(n_estimators=100, random_state=42)
|
|
167
|
+
|
|
168
|
+
X_l = X_labeled.copy()
|
|
169
|
+
y_l = y_labeled.copy()
|
|
170
|
+
X_p = X_pool.copy()
|
|
171
|
+
y_p = y_pool_true.copy()
|
|
172
|
+
|
|
173
|
+
history = []
|
|
174
|
+
for rnd in range(n_rounds):
|
|
175
|
+
m = clone(model).fit(X_l, y_l)
|
|
176
|
+
acc = accuracy_score(y_test, m.predict(X_test))
|
|
177
|
+
history.append({
|
|
178
|
+
"round": rnd,
|
|
179
|
+
"n_labeled": len(y_l),
|
|
180
|
+
"accuracy": round(acc, 4),
|
|
181
|
+
"pool_size": len(y_p),
|
|
182
|
+
})
|
|
183
|
+
|
|
184
|
+
if len(X_p) == 0:
|
|
185
|
+
break
|
|
186
|
+
|
|
187
|
+
# バッチ選択
|
|
188
|
+
selected = batch_active_learning(
|
|
189
|
+
m, X_p, batch_size, strategy)
|
|
190
|
+
|
|
191
|
+
# Oracle に問い合わせ
|
|
192
|
+
X_l = np.vstack([X_l, X_p[selected]])
|
|
193
|
+
y_l = np.concatenate([y_l, y_p[selected]])
|
|
194
|
+
|
|
195
|
+
mask = np.ones(len(X_p), dtype=bool)
|
|
196
|
+
mask[selected] = False
|
|
197
|
+
X_p = X_p[mask]
|
|
198
|
+
y_p = y_p[mask]
|
|
199
|
+
|
|
200
|
+
df = pd.DataFrame(history)
|
|
201
|
+
improvement = df["accuracy"].iloc[-1] - df["accuracy"].iloc[0]
|
|
202
|
+
print(f"AL loop: {n_rounds} rounds, "
|
|
203
|
+
f"acc {df['accuracy'].iloc[0]:.3f} → {df['accuracy'].iloc[-1]:.3f} "
|
|
204
|
+
f"(+{improvement:.3f})")
|
|
205
|
+
return df
|
|
206
|
+
|
|
207
|
+
|
|
208
|
+
def compare_strategies(X_labeled, y_labeled, X_pool, y_pool_true,
|
|
209
|
+
X_test, y_test, n_rounds=20, batch_size=10):
|
|
210
|
+
"""
|
|
211
|
+
複数アクティブラーニング戦略の比較。
|
|
212
|
+
|
|
213
|
+
Parameters: (同上)
|
|
214
|
+
"""
|
|
215
|
+
strategies = ["entropy", "margin", "least_confident"]
|
|
216
|
+
results = {}
|
|
217
|
+
|
|
218
|
+
for strat in strategies:
|
|
219
|
+
history = active_learning_loop(
|
|
220
|
+
X_labeled, y_labeled, X_pool, y_pool_true,
|
|
221
|
+
X_test, y_test,
|
|
222
|
+
n_rounds=n_rounds, batch_size=batch_size,
|
|
223
|
+
strategy=strat)
|
|
224
|
+
results[strat] = history
|
|
225
|
+
|
|
226
|
+
# ランダムベースライン
|
|
227
|
+
np.random.seed(42)
|
|
228
|
+
random_history = active_learning_loop(
|
|
229
|
+
X_labeled, y_labeled,
|
|
230
|
+
X_pool[np.random.permutation(len(X_pool))],
|
|
231
|
+
y_pool_true[np.random.permutation(len(y_pool_true))],
|
|
232
|
+
X_test, y_test,
|
|
233
|
+
n_rounds=n_rounds, batch_size=batch_size,
|
|
234
|
+
strategy="least_confident")
|
|
235
|
+
results["random"] = random_history
|
|
236
|
+
|
|
237
|
+
print(f"Strategy comparison: {len(strategies) + 1} methods evaluated")
|
|
238
|
+
return results
|
|
239
|
+
```
|
|
240
|
+
|
|
241
|
+
## 4. 停止基準判定
|
|
242
|
+
|
|
243
|
+
```python
|
|
244
|
+
def stopping_criterion(history_df, patience=5, min_improvement=0.001):
|
|
245
|
+
"""
|
|
246
|
+
アクティブラーニング停止基準判定。
|
|
247
|
+
|
|
248
|
+
Parameters:
|
|
249
|
+
history_df: pd.DataFrame — AL 履歴
|
|
250
|
+
patience: int — 改善なしラウンド数
|
|
251
|
+
min_improvement: float — 最小改善幅
|
|
252
|
+
"""
|
|
253
|
+
accs = history_df["accuracy"].values
|
|
254
|
+
if len(accs) < patience + 1:
|
|
255
|
+
return False, "insufficient rounds"
|
|
256
|
+
|
|
257
|
+
recent = accs[-patience:]
|
|
258
|
+
best_before = accs[:-patience].max()
|
|
259
|
+
improvement = recent.max() - best_before
|
|
260
|
+
|
|
261
|
+
if improvement < min_improvement:
|
|
262
|
+
return True, (f"converged: improvement {improvement:.5f} "
|
|
263
|
+
f"< threshold {min_improvement}")
|
|
264
|
+
|
|
265
|
+
return False, f"continuing: improvement {improvement:.5f}"
|
|
266
|
+
```
|
|
267
|
+
|
|
268
|
+
---
|
|
269
|
+
|
|
270
|
+
## パイプライン統合
|
|
271
|
+
|
|
272
|
+
```
|
|
273
|
+
eda-correlation → active-learning → ml-classification
|
|
274
|
+
(データ探索) (サンプル選択) (モデル構築)
|
|
275
|
+
│ │ ↓
|
|
276
|
+
missing-data ─────────┘ ensemble-methods
|
|
277
|
+
(欠損値処理) (アンサンブル)
|
|
278
|
+
↓
|
|
279
|
+
uncertainty-quantification
|
|
280
|
+
(不確実性定量化)
|
|
281
|
+
```
|
|
282
|
+
|
|
283
|
+
## パイプライン出力
|
|
284
|
+
|
|
285
|
+
| ファイル | 説明 | 次スキル |
|
|
286
|
+
|---------|------|---------|
|
|
287
|
+
| `al_history.csv` | AL ラウンド履歴 | → 停止判定 |
|
|
288
|
+
| `selected_samples.csv` | 選択サンプル | → ラベル付け |
|
|
289
|
+
| `strategy_comparison.csv` | 戦略比較 | → advanced-visualization |
|