@nahisaho/satori 0.22.0 → 0.24.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 CHANGED
@@ -7,7 +7,7 @@
7
7
 
8
8
  ## Overview
9
9
 
10
- このディレクトリには、Exp-01〜13 で蓄積した科学データ解析技法を Agent Skills として体系化した **166 個**のスキルを格納しています。Copilot がプロンプトの文脈に応じて適切なスキルを自動ロードし、各実験で確立した解析パターンを再利用します。131 のスキルは [ToolUniverse](https://github.com/mims-harvard/ToolUniverse) SMCP 経由で 1,200 以上の外部科学データベースツールとも連携可能です。
10
+ このディレクトリには、Exp-01〜13 で蓄積した科学データ解析技法を Agent Skills として体系化した **182 個**のスキルを格納しています。Copilot がプロンプトの文脈に応じて適切なスキルを自動ロードし、各実験で確立した解析パターンを再利用します。131 のスキルは [ToolUniverse](https://github.com/mims-harvard/ToolUniverse) SMCP 経由で 1,200 以上の外部科学データベースツールとも連携可能です。
11
11
 
12
12
  ### パイプラインフロー
13
13
 
@@ -286,10 +286,10 @@ SATORI Skill (方法論・判断) ToolUniverse SMCP (データ取得・
286
286
  | 中区分 | スキル数 | 概要 |
287
287
  |---|:---:|---|
288
288
  | A. 基盤・ワークフロー | 17 | パイプライン構築・前処理・データ生成・図表・執筆・仮説立案・批判的レビュー・SI 生成・LaTeX 変換・引用検証・査読対応・改訂追跡・論文品質・系統的レビュー・BioThings ID マッピング・データ投稿・CrossRef メタデータ |
289
- | B. 統計・探索的解析 | 4 | EDA・仮説検定・次元削減・記号数学 |
290
- | C. 機械学習・モデリング | 3 | 回帰・分類・特徴量重要度 |
289
+ | B. 統計・探索的解析 | 9 | EDA・仮説検定・次元削減・記号数学・欠損データ解析・高度可視化・データプロファイリング・地理空間解析・ネットワーク可視化 |
290
+ | C. 機械学習・モデリング | 9 | 回帰・分類・特徴量重要度・アクティブラーニング・AutoML・アンサンブル学習・異常検知・因果 ML・モデル監視 |
291
291
  | D. 実験計画・プロセス最適化 | 2 | DOE・応答曲面法・ベイズ最適化 |
292
- | E. 信号・スペクトル・時系列 | 4 | スペクトル解析・生体信号・時系列分解・神経電気生理学 |
292
+ | E. 信号・スペクトル・時系列 | 5 | スペクトル解析・生体信号・時系列分解・神経電気生理学・ML 時系列予測 |
293
293
  | F. 生命科学・オミクス | 28 | バイオインフォ・メタボロ・ゲノム配列・マルチオミクス・ネットワーク・プロテオミクス・トランスクリプトミクス・パスウェイ濃縮・代謝物 DB・HPA・ゲノム配列ツール・非コード RNA・オントロジー・EBI DB 群・Ensembl ゲノミクス・STRING/BioGRID PPI・発現比較・モデル生物 DB・GEO 発現プロファイル・寄生虫ゲノミクス・ArrayExpress 発現アーカイブ・GTEx 組織発現・UniProt プロテオーム・Reactome パスウェイ・HGNC 命名法・代謝ネットワーク・糖鎖解析・リピドミクス |
294
294
  | G. 化学・材料・イメージング | 9 | ケモインフォ・材料特性評価・画像形態解析・計算材料科学・ChEMBL アッセイマイニング・MD シミュレーション・高度イメージング・深層化学・STITCH 化学-タンパク質ネットワーク |
295
295
  | H. 臨床・疫学・メタ科学 | 7 | 生存解析・因果推論・メタアナリシス・臨床試験解析・臨床レポート・バイオバンク大規模コホート・臨床標準用語 |
@@ -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. 科学プレゼンテーション・図式 | 2 | 科学スライド・ポスター・ワークフロー図・科学図式 |
301
+ | N. 科学プレゼンテーション・図式 | 4 | 科学スライド・ポスター・ワークフロー図・科学図式・インタラクティブダッシュボード・再現可能レポート |
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. 量子・先端計算 | 7 | 量子計算・GNN・ベイズ統計・説明可能 AI・深層学習・ヘルスケア AI・強化学習 |
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. 統計・探索的解析(4 種)
343
+ ### B. 統計・探索的解析(9 種)
344
344
 
345
- データの理解・検定・次元削減・記号数学を担うスキル群。
345
+ データの理解・検定・次元削減・記号数学・欠損データ解析・高度可視化・データプロファイリング・地理空間解析・ネットワーク可視化を担うスキル群。
346
346
 
347
347
  | # | Skill | 説明 | 参照 Exp |
348
348
  |---|---|---|---|
@@ -350,16 +350,27 @@ 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・出版品質図・アニメーション | 汎用 |
355
+ | 179 | [scientific-data-profiling](scientific-data-profiling/SKILL.md) | ydata-profiling 自動 EDA・データ品質スコア (5 次元)・Great Expectations バリデーション | 汎用 |
356
+ | 180 | [scientific-geospatial-analysis](scientific-geospatial-analysis/SKILL.md) | GeoPandas 地理空間処理・Moran's I/LISA 空間自己相関・Kriging 補間・Folium 地図 | 汎用 |
357
+ | 181 | [scientific-network-visualization](scientific-network-visualization/SKILL.md) | NetworkX グラフ構築・Louvain/Leiden コミュニティ検出・中心性分析・PyVis インタラクティブ | 汎用 |
353
358
 
354
- ### C. 機械学習・モデリング(3 種)
359
+ ### C. 機械学習・モデリング(9 種)
355
360
 
356
- 教師あり学習と特徴量解釈を担うスキル群。
361
+ 教師あり学習・特徴量解釈・アクティブラーニング・AutoML・アンサンブル学習・異常検知・因果 ML・モデル監視を担うスキル群。
357
362
 
358
363
  | # | Skill | 説明 | 参照 Exp |
359
364
  |---|---|---|---|
360
365
  | 17 | [scientific-ml-regression](scientific-ml-regression/SKILL.md) | マルチターゲット回帰・モデル比較・レーダーチャート | 05, 12, 13 |
361
366
  | 18 | [scientific-ml-classification](scientific-ml-classification/SKILL.md) | 分類 ML・ROC・PR 曲線・混同行列・PDP・Volcano | 03, 05 |
362
367
  | 19 | [scientific-feature-importance](scientific-feature-importance/SKILL.md) | Tree-based & Permutation 特徴量重要度・PDP | 05, 12, 13 |
368
+ | 167 | [scientific-active-learning](scientific-active-learning/SKILL.md) | 不確実性サンプリング・QBC・バッチ AL・能動学習ループ・停止基準 | 汎用 |
369
+ | 168 | [scientific-automl](scientific-automl/SKILL.md) | Optuna HPO・マルチモデル AutoML・自動特徴量エンジニアリング・AutoML レポート | 汎用 |
370
+ | 169 | [scientific-ensemble-methods](scientific-ensemble-methods/SKILL.md) | XGBoost/LightGBM/CatBoost 比較・Stacking OOF・Voting・アンサンブル多様性 | 汎用 |
371
+ | 175 | [scientific-anomaly-detection](scientific-anomaly-detection/SKILL.md) | Isolation Forest/LOF/OCSVM アンサンブル異常検知・Autoencoder 異常・SPC 管理図 | 汎用 |
372
+ | 176 | [scientific-causal-ml](scientific-causal-ml/SKILL.md) | DoWhy 因果推論・EconML Double ML/Causal Forest・S/T/X-Learner メタラーナー | 汎用 |
373
+ | 177 | [scientific-model-monitoring](scientific-model-monitoring/SKILL.md) | データドリフト検出 (KS/PSI/Wasserstein)・性能劣化検出・A/B テスト統計 | 汎用 |
363
374
 
364
375
  ### D. 実験計画・プロセス最適化(2 種)
365
376
 
@@ -370,7 +381,7 @@ SATORI Skill (方法論・判断) ToolUniverse SMCP (データ取得・
370
381
  | 20 | [scientific-doe](scientific-doe/SKILL.md) | 田口直交表・CCD/Box-Behnken・ANOVA 因子効果・ベイズ最適化 | 汎用 |
371
382
  | 21 | [scientific-process-optimization](scientific-process-optimization/SKILL.md) | 応答曲面法 (ML-RSM)・パレート最適化・プロセスウィンドウ | 12, 13 |
372
383
 
373
- ### E. 信号・スペクトル・時系列(4 種)
384
+ ### E. 信号・スペクトル・時系列(5 種)
374
385
 
375
386
  波形・周波数領域・神経電気生理学の解析を担うスキル群。
376
387
 
@@ -380,6 +391,7 @@ SATORI Skill (方法論・判断) ToolUniverse SMCP (データ取得・
380
391
  | 23 | [scientific-biosignal-processing](scientific-biosignal-processing/SKILL.md) | ECG R波/HRV・EEG バンドパワー/ERP・EMG バースト・Poincaré | 08 |
381
392
  | 24 | [scientific-time-series](scientific-time-series/SKILL.md) | STL 分解・SARIMA 予測・変化点検出・FFT 周期解析・Granger 因果 | 汎用 |
382
393
  | 67 | [scientific-neuroscience-electrophysiology](scientific-neuroscience-electrophysiology/SKILL.md) | SpikeInterface/Kilosort4 スパイクソート・MNE EEG/ERP・NeuroKit2 HRV/EDA・脳機能結合 | 汎用 |
394
+ | 178 | [scientific-time-series-forecasting](scientific-time-series-forecasting/SKILL.md) | Prophet/NeuralProphet ML 予測・時系列特徴量エンジニアリング・バックテストフレームワーク | 汎用 |
383
395
 
384
396
  ### F. 生命科学・オミクス(28 種)
385
397
 
@@ -509,14 +521,16 @@ SATORI Skill (方法論・判断) ToolUniverse SMCP (データ取得・
509
521
  | 72 | [scientific-lab-data-management](scientific-lab-data-management/SKILL.md) | Benchling ELN/DNA 設計・DNAnexus PaaS・OMERO バイオイメージング・Protocols.io | 汎用 |
510
522
  | 164 | [scientific-crispr-design](scientific-crispr-design/SKILL.md) | CRISPR gRNA 設計・Cas9/Cas12a PAM 検索・オフターゲットスコアリング・sgRNA ライブラリ構築 | 汎用 |
511
523
 
512
- ### N. 科学プレゼンテーション・図式(2 種)
524
+ ### N. 科学プレゼンテーション・図式(4 種)
513
525
 
514
- 学会発表用スライド・ポスター・科学図式のデザインを担うスキル群。
526
+ 学会発表用スライド・ポスター・科学図式・インタラクティブダッシュボード・再現可能レポートのデザインを担うスキル群。
515
527
 
516
528
  | # | Skill | 説明 | 参照 Exp |
517
529
  |---|---|---|---|
518
530
  | 45 | [scientific-presentation-design](scientific-presentation-design/SKILL.md) | 15 スライド構成テンプレート・tikzposter・matplotlib ワークフロー図・アクセシビリティ | 汎用 |
519
531
  | 73 | [scientific-scientific-schematics](scientific-scientific-schematics/SKILL.md) | CONSORT フロー図・NN アーキテクチャ図・パスウェイ図・TikZ/SVG | 汎用 |
532
+ | 174 | [scientific-interactive-dashboard](scientific-interactive-dashboard/SKILL.md) | Streamlit/Dash/Panel 科学データダッシュボード・パラメータ探索 UI・リアルタイム解析 | 汎用 |
533
+ | 182 | [scientific-reproducible-reporting](scientific-reproducible-reporting/SKILL.md) | Quarto 科学文書・Jupyter Book 多章構成・Papermill パラメトリック実行・nbconvert 自動変換 | 汎用 |
520
534
 
521
535
  ### O. 研究計画・グラント・規制(3 種)
522
536
 
@@ -556,9 +570,9 @@ SATORI Skill (方法論・判断) ToolUniverse SMCP (データ取得・
556
570
  | 149 | [scientific-monarch-ontology](scientific-monarch-ontology/SKILL.md) | Monarch Initiative 疾患-遺伝子-表現型オントロジー・HPO・エンティティ検索 | 汎用 |
557
571
  | 150 | [scientific-gdc-portal](scientific-gdc-portal/SKILL.md) | NCI Genomic Data Commons REST API・プロジェクト/ケース/SSM 検索 | 汎用 |
558
572
 
559
- ### R. 量子・先端計算(7 種)
573
+ ### R. 量子・先端計算(9 種)
560
574
 
561
- 量子計算・GNN・ベイズ統計・XAI・深層学習・ヘルスケア AI・強化学習など次世代計算手法を担うスキル群。
575
+ 量子計算・GNN・ベイズ統計・XAI・深層学習・ヘルスケア AI・強化学習・転移学習・不確実性定量化など次世代計算手法を担うスキル群。
562
576
 
563
577
  | # | Skill | 説明 | 参照 Exp |
564
578
  |---|---|---|---|
@@ -569,6 +583,8 @@ SATORI Skill (方法論・判断) ToolUniverse SMCP (データ取得・
569
583
  | 55 | [scientific-deep-learning](scientific-deep-learning/SKILL.md) | Lightning/timm/Transformers・CNN/ViT/BERT Fine-tune・Optuna HPO・ONNX エクスポート | 汎用 |
570
584
  | 96 | [scientific-healthcare-ai](scientific-healthcare-ai/SKILL.md) | PyHealth 臨床 ML パイプライン・フローサイトメトリー・EHR 処理 | 汎用 |
571
585
  | 104 | [scientific-reinforcement-learning](scientific-reinforcement-learning/SKILL.md) | Stable-Baselines3/PufferLib RL エージェント訓練・分子設計/実験最適化 RL | 汎用 |
586
+ | 170 | [scientific-transfer-learning](scientific-transfer-learning/SKILL.md) | Vision/NLP ファインチューニング・Few-shot・知識蒸留・ドメイン適応 | 汎用 |
587
+ | 171 | [scientific-uncertainty-quantification](scientific-uncertainty-quantification/SKILL.md) | Conformal Prediction・MC Dropout・深層アンサンブル・Calibration・ECE | 汎用 |
572
588
 
573
589
  ### S. 医用イメージング(1 種)
574
590
 
@@ -731,12 +747,23 @@ Skills は `.github/skills/` に配置されているため、Copilot が自動
731
747
  │ ├── scientific-eda-correlation/
732
748
  │ ├── scientific-statistical-testing/
733
749
  │ ├── scientific-pca-tsne/
734
- └── scientific-symbolic-mathematics/
750
+ ├── scientific-symbolic-mathematics/
751
+ │ ├── scientific-missing-data-analysis/
752
+ │ ├── scientific-advanced-visualization/
753
+ │ ├── scientific-data-profiling/
754
+ │ ├── scientific-geospatial-analysis/
755
+ │ └── scientific-network-visualization/
735
756
 
736
757
  │── [C] 機械学習・モデリング
737
758
  │ ├── scientific-ml-regression/
738
759
  │ ├── scientific-ml-classification/
739
- └── scientific-feature-importance/
760
+ ├── scientific-feature-importance/
761
+ │ ├── scientific-active-learning/
762
+ │ ├── scientific-automl/
763
+ │ ├── scientific-ensemble-methods/
764
+ │ ├── scientific-anomaly-detection/
765
+ │ ├── scientific-causal-ml/
766
+ │ └── scientific-model-monitoring/
740
767
 
741
768
  │── [D] 実験計画・プロセス最適化
742
769
  │ ├── scientific-doe/
@@ -746,7 +773,8 @@ Skills は `.github/skills/` に配置されているため、Copilot が自動
746
773
  │ ├── scientific-spectral-signal/
747
774
  │ ├── scientific-biosignal-processing/
748
775
  │ ├── scientific-time-series/
749
- └── scientific-neuroscience-electrophysiology/
776
+ ├── scientific-neuroscience-electrophysiology/
777
+ │ └── scientific-time-series-forecasting/
750
778
 
751
779
  │── [F] 生命科学・オミクス
752
780
  │ ├── scientific-bioinformatics/
@@ -839,7 +867,9 @@ Skills は `.github/skills/` に配置されているため、Copilot が自動
839
867
 
840
868
  ├── [N] 科学プレゼンテーション・図式
841
869
  │ ├── scientific-presentation-design/
842
- └── scientific-scientific-schematics/
870
+ ├── scientific-scientific-schematics/
871
+ │ ├── scientific-interactive-dashboard/
872
+ │ └── scientific-reproducible-reporting/
843
873
 
844
874
  └── [O] 研究計画・グラント・規制
845
875
  ├── scientific-grant-writing/
@@ -871,7 +901,9 @@ Skills は `.github/skills/` に配置されているため、Copilot が自動
871
901
  │ ├── scientific-explainable-ai/
872
902
  │ ├── scientific-deep-learning/
873
903
  │ ├── scientific-healthcare-ai/
874
- └── scientific-reinforcement-learning/
904
+ ├── scientific-reinforcement-learning/
905
+ │ ├── scientific-transfer-learning/
906
+ │ └── scientific-uncertainty-quantification/
875
907
 
876
908
  └── [S] 医用イメージング
877
909
  └── scientific-medical-imaging/
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nahisaho/satori",
3
- "version": "0.22.0",
3
+ "version": "0.24.0",
4
4
  "description": "SATORI — Agent Skills for Science. GitHub Copilot Agent Skills collection for scientific data analysis.",
5
5
  "main": "index.js",
6
6
  "bin": {
@@ -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 |