flexpyirt 0.0.1__tar.gz
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.
- flexpyirt-0.0.1/.gitignore +13 -0
- flexpyirt-0.0.1/CONTRIBUTING.ja.md +137 -0
- flexpyirt-0.0.1/CONTRIBUTING.md +150 -0
- flexpyirt-0.0.1/LICENSE +21 -0
- flexpyirt-0.0.1/PKG-INFO +204 -0
- flexpyirt-0.0.1/README.ja.md +165 -0
- flexpyirt-0.0.1/README.md +172 -0
- flexpyirt-0.0.1/benchmarks/README.ja.md +107 -0
- flexpyirt-0.0.1/benchmarks/README.md +109 -0
- flexpyirt-0.0.1/benchmarks/__init__.py +1 -0
- flexpyirt-0.0.1/benchmarks/data.py +310 -0
- flexpyirt-0.0.1/benchmarks/report.py +378 -0
- flexpyirt-0.0.1/benchmarks/results/2026-11-21-apple-m5.json +1801 -0
- flexpyirt-0.0.1/benchmarks/results/2026-11-21-apple-m5.md +56 -0
- flexpyirt-0.0.1/benchmarks/run_flexpyirt.py +431 -0
- flexpyirt-0.0.1/benchmarks/run_mirt.R +247 -0
- flexpyirt-0.0.1/docs/API.ja.md +159 -0
- flexpyirt-0.0.1/docs/API.md +172 -0
- flexpyirt-0.0.1/docs/DESIGN.ja.md +1071 -0
- flexpyirt-0.0.1/docs/DESIGN.md +1530 -0
- flexpyirt-0.0.1/docs/ROADMAP.ja.md +50 -0
- flexpyirt-0.0.1/docs/ROADMAP.md +67 -0
- flexpyirt-0.0.1/docs/VALIDATION.ja.md +552 -0
- flexpyirt-0.0.1/docs/VALIDATION.md +685 -0
- flexpyirt-0.0.1/docs/guide.ja.md +857 -0
- flexpyirt-0.0.1/docs/guide.md +924 -0
- flexpyirt-0.0.1/docs/index.ja.md +57 -0
- flexpyirt-0.0.1/docs/index.md +59 -0
- flexpyirt-0.0.1/docs/javascripts/mathjax.js +19 -0
- flexpyirt-0.0.1/docs/reference.ja.md +748 -0
- flexpyirt-0.0.1/docs/reference.md +820 -0
- flexpyirt-0.0.1/mkdocs.yml +94 -0
- flexpyirt-0.0.1/pyproject.toml +117 -0
- flexpyirt-0.0.1/scripts/check_pr.py +87 -0
- flexpyirt-0.0.1/scripts/mkdocs_hooks.py +22 -0
- flexpyirt-0.0.1/scripts/release_version.py +82 -0
- flexpyirt-0.0.1/src/flexpyirt/__init__.py +48 -0
- flexpyirt-0.0.1/src/flexpyirt/_compile.py +1594 -0
- flexpyirt-0.0.1/src/flexpyirt/_core.py +1387 -0
- flexpyirt-0.0.1/src/flexpyirt/_dif.py +198 -0
- flexpyirt-0.0.1/src/flexpyirt/_itemfit.py +244 -0
- flexpyirt-0.0.1/src/flexpyirt/_json.py +1539 -0
- flexpyirt-0.0.1/src/flexpyirt/_linking.py +535 -0
- flexpyirt-0.0.1/src/flexpyirt/_m2.py +367 -0
- flexpyirt-0.0.1/src/flexpyirt/_newton.py +96 -0
- flexpyirt-0.0.1/src/flexpyirt/_precision.py +44 -0
- flexpyirt-0.0.1/src/flexpyirt/_scoring.py +789 -0
- flexpyirt-0.0.1/src/flexpyirt/errors.py +57 -0
- flexpyirt-0.0.1/src/flexpyirt/fit.py +389 -0
- flexpyirt-0.0.1/src/flexpyirt/items.py +910 -0
- flexpyirt-0.0.1/src/flexpyirt/latent.py +963 -0
- flexpyirt-0.0.1/src/flexpyirt/linking.py +815 -0
- flexpyirt-0.0.1/src/flexpyirt/method.py +47 -0
- flexpyirt-0.0.1/src/flexpyirt/model.py +621 -0
- flexpyirt-0.0.1/src/flexpyirt/priors.py +275 -0
- flexpyirt-0.0.1/src/flexpyirt/py.typed +0 -0
- flexpyirt-0.0.1/src/flexpyirt/quadrature.py +135 -0
- flexpyirt-0.0.1/src/flexpyirt/result.py +1230 -0
- flexpyirt-0.0.1/tests/__init__.py +0 -0
- flexpyirt-0.0.1/tests/_reference.py +77 -0
- flexpyirt-0.0.1/tests/conftest.py +25 -0
- flexpyirt-0.0.1/tests/reference/v11_3pl.json +4329 -0
- flexpyirt-0.0.1/tests/reference/v11_4pl.json +4193 -0
- flexpyirt-0.0.1/tests/reference/v12_irtpars.json +1462 -0
- flexpyirt-0.0.1/tests/reference/v13_fscores.json +5586 -0
- flexpyirt-0.0.1/tests/reference/v14_mirt2d.json +5568 -0
- flexpyirt-0.0.1/tests/reference/v14_mirt_map.json +945 -0
- flexpyirt-0.0.1/tests/reference/v14_mirt_mlwle.json +5039 -0
- flexpyirt-0.0.1/tests/reference/v15_sx2.json +76 -0
- flexpyirt-0.0.1/tests/reference/v15_sx2_multigroup.json +251 -0
- flexpyirt-0.0.1/tests/reference/v16_lsat7_common_slope.json +147 -0
- flexpyirt-0.0.1/tests/reference/v16_mixed_constraints.json +1641 -0
- flexpyirt-0.0.1/tests/reference/v16_twogroup_common_slope.json +1251 -0
- flexpyirt-0.0.1/tests/reference/v17_dif.json +69 -0
- flexpyirt-0.0.1/tests/reference/v18_m2.json +3027 -0
- flexpyirt-0.0.1/tests/reference/v19_davidian_2pl_k3.json +3103 -0
- flexpyirt-0.0.1/tests/reference/v19_davidian_fipc_k3.json +2813 -0
- flexpyirt-0.0.1/tests/reference/v19_davidian_grm_k2.json +3272 -0
- flexpyirt-0.0.1/tests/reference/v1_lsat7_2pl.json +123 -0
- flexpyirt-0.0.1/tests/reference/v1_sim_2pl.json +1142 -0
- flexpyirt-0.0.1/tests/reference/v20_linking.json +28499 -0
- flexpyirt-0.0.1/tests/reference/v21_mirt_multigroup.json +3767 -0
- flexpyirt-0.0.1/tests/reference/v22_mixture_2pl_k2.json +2175 -0
- flexpyirt-0.0.1/tests/reference/v22_mixture_gpcm_k3.json +3627 -0
- flexpyirt-0.0.1/tests/reference/v22_mixture_grm_k2.json +2594 -0
- flexpyirt-0.0.1/tests/reference/v23_nominal_2d.json +2515 -0
- flexpyirt-0.0.1/tests/reference/v23_nominal_mixed.json +2501 -0
- flexpyirt-0.0.1/tests/reference/v23_nominal_science.json +609 -0
- flexpyirt-0.0.1/tests/reference/v23_nominal_sim.json +3381 -0
- flexpyirt-0.0.1/tests/reference/v23_nominal_unordered.json +2566 -0
- flexpyirt-0.0.1/tests/reference/v2_lsat7_rasch.json +123 -0
- flexpyirt-0.0.1/tests/reference/v2_sim_rasch.json +1122 -0
- flexpyirt-0.0.1/tests/reference/v3_science_grm.json +221 -0
- flexpyirt-0.0.1/tests/reference/v4_twogroup_2pl.json +2409 -0
- flexpyirt-0.0.1/tests/reference/v5_fipc_2pl.json +1593 -0
- flexpyirt-0.0.1/tests/reference/v6_fipc_eh.json +2918 -0
- flexpyirt-0.0.1/tests/reference/v6_twogroup_fipc_eh.json +122631 -0
- flexpyirt-0.0.1/tests/reference/v7_2pl_lnorm_map.json +1148 -0
- flexpyirt-0.0.1/tests/reference/v7_2pl_map.json +1146 -0
- flexpyirt-0.0.1/tests/reference/v7_3pl_map.json +1219 -0
- flexpyirt-0.0.1/tests/reference/v8_science_gpcm.json +224 -0
- flexpyirt-0.0.1/tests/reference/v8_sim_gpcm.json +3109 -0
- flexpyirt-0.0.1/tests/reference/v8_sim_pcm.json +3006 -0
- flexpyirt-0.0.1/tests/reference/v9_missing_2pl.json +1929 -0
- flexpyirt-0.0.1/tests/test_benchmarks.py +78 -0
- flexpyirt-0.0.1/tests/test_core.py +288 -0
- flexpyirt-0.0.1/tests/test_docs.py +129 -0
- flexpyirt-0.0.1/tests/test_m2_units.py +225 -0
- flexpyirt-0.0.1/tests/test_m3_3pl_4pl.py +410 -0
- flexpyirt-0.0.1/tests/test_m3_eh.py +592 -0
- flexpyirt-0.0.1/tests/test_m3_gpcm.py +413 -0
- flexpyirt-0.0.1/tests/test_m3_priors.py +639 -0
- flexpyirt-0.0.1/tests/test_m3_squarem.py +363 -0
- flexpyirt-0.0.1/tests/test_m4_json.py +1152 -0
- flexpyirt-0.0.1/tests/test_m4_mirt.py +660 -0
- flexpyirt-0.0.1/tests/test_m4_result.py +568 -0
- flexpyirt-0.0.1/tests/test_m4_scoring.py +576 -0
- flexpyirt-0.0.1/tests/test_m5_davidian.py +536 -0
- flexpyirt-0.0.1/tests/test_m5_dif.py +194 -0
- flexpyirt-0.0.1/tests/test_m5_equal_items.py +277 -0
- flexpyirt-0.0.1/tests/test_m5_linking.py +1031 -0
- flexpyirt-0.0.1/tests/test_m5_m2.py +467 -0
- flexpyirt-0.0.1/tests/test_m5_mixture.py +561 -0
- flexpyirt-0.0.1/tests/test_m5_nominal.py +474 -0
- flexpyirt-0.0.1/tests/test_mirt_m1.py +167 -0
- flexpyirt-0.0.1/tests/test_mirt_m2.py +244 -0
- flexpyirt-0.0.1/tests/test_mirt_m3.py +168 -0
- flexpyirt-0.0.1/tests/test_mirt_m3_gpcm.py +195 -0
- flexpyirt-0.0.1/tests/test_mirt_m3_priors.py +269 -0
- flexpyirt-0.0.1/tests/test_mirt_m4_irtpars.py +249 -0
- flexpyirt-0.0.1/tests/test_mirt_m4_mirt.py +375 -0
- flexpyirt-0.0.1/tests/test_mirt_m4_multigroup.py +245 -0
- flexpyirt-0.0.1/tests/test_mirt_m4_scoring.py +239 -0
- flexpyirt-0.0.1/tests/test_mirt_m5_davidian.py +285 -0
- flexpyirt-0.0.1/tests/test_mirt_m5_dif.py +100 -0
- flexpyirt-0.0.1/tests/test_mirt_m5_equal_items.py +219 -0
- flexpyirt-0.0.1/tests/test_mirt_m5_itemfit.py +122 -0
- flexpyirt-0.0.1/tests/test_mirt_m5_itemfit_multigroup.py +121 -0
- flexpyirt-0.0.1/tests/test_mirt_m5_linking.py +338 -0
- flexpyirt-0.0.1/tests/test_mirt_m5_m2.py +249 -0
- flexpyirt-0.0.1/tests/test_mirt_m5_mixture.py +299 -0
- flexpyirt-0.0.1/tests/test_mirt_m5_nominal.py +458 -0
- flexpyirt-0.0.1/tests/test_mirt_v6_eh.py +235 -0
- flexpyirt-0.0.1/tests/test_oakes.py +325 -0
- flexpyirt-0.0.1/tests/test_quadrature_gh.py +146 -0
- flexpyirt-0.0.1/tests/test_reference_meta.py +202 -0
- flexpyirt-0.0.1/tests/test_release_version.py +136 -0
- flexpyirt-0.0.1/tests/test_scaffold.py +94 -0
- flexpyirt-0.0.1/validation/r/m1_reference.R +97 -0
- flexpyirt-0.0.1/validation/r/m2_reference.R +153 -0
- flexpyirt-0.0.1/validation/r/m3_eh_reference.R +135 -0
- flexpyirt-0.0.1/validation/r/m3_gpcm_reference.R +141 -0
- flexpyirt-0.0.1/validation/r/m3_priors_reference.R +477 -0
- flexpyirt-0.0.1/validation/r/m3_reference.R +139 -0
- flexpyirt-0.0.1/validation/r/m4_irtpars_reference.R +293 -0
- flexpyirt-0.0.1/validation/r/m4_mirt_map_reference.R +76 -0
- flexpyirt-0.0.1/validation/r/m4_mirt_mlwle_reference.R +84 -0
- flexpyirt-0.0.1/validation/r/m4_mirt_multigroup_reference.R +108 -0
- flexpyirt-0.0.1/validation/r/m4_mirt_reference.R +315 -0
- flexpyirt-0.0.1/validation/r/m4_scoring_reference.R +372 -0
- flexpyirt-0.0.1/validation/r/m5_davidian_reference.R +524 -0
- flexpyirt-0.0.1/validation/r/m5_dif_reference.R +63 -0
- flexpyirt-0.0.1/validation/r/m5_equal_items_reference.R +145 -0
- flexpyirt-0.0.1/validation/r/m5_itemfit_multigroup_reference.R +105 -0
- flexpyirt-0.0.1/validation/r/m5_itemfit_reference.R +68 -0
- flexpyirt-0.0.1/validation/r/m5_linking_reference.R +655 -0
- flexpyirt-0.0.1/validation/r/m5_m2_reference.R +246 -0
- flexpyirt-0.0.1/validation/r/m5_mixture_reference.R +514 -0
- flexpyirt-0.0.1/validation/r/m5_nominal_reference.R +499 -0
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
# 開発フロー
|
|
2
|
+
|
|
3
|
+
[English](CONTRIBUTING.md) | 日本語
|
|
4
|
+
|
|
5
|
+
## ブランチ
|
|
6
|
+
|
|
7
|
+
| ブランチ | 役割 | 作り方 / マージ先 |
|
|
8
|
+
|---|---|---|
|
|
9
|
+
| `main` | リリース済みの状態だけを置く。直接 push しない | `develop` からのリリース PR だけを受け付ける |
|
|
10
|
+
| `develop` | 統合ブランチ。次のリリースに入る変更が集まる | `feature/*` と `fix/*` の PR を受け付ける |
|
|
11
|
+
| `feature/<slug>` | 機能追加・ドキュメント・リファクタリングなど | `develop` から切り、`develop` へ PR |
|
|
12
|
+
| `fix/<issue番号>-<slug>` | バグ修正。**必ず issue に対応させる** | `develop` から切り、`develop` へ PR |
|
|
13
|
+
|
|
14
|
+
- `<slug>` は小文字・数字・`.`・`_`・`-` だけ(例: `feature/grm-docs`, `fix/12-oakes-se`)。
|
|
15
|
+
- fix ブランチの PR 説明には `Closes #<issue番号>` を書く。issue は open でなければならない。
|
|
16
|
+
(`develop` は既定ブランチではないので、issue はマージ時ではなく**リリース時**にワークフローが閉じる。)
|
|
17
|
+
- これらは PR ごとに `PR rules` チェック(`scripts/check_pr.py`)が検査する。
|
|
18
|
+
|
|
19
|
+
## PR とレビュー
|
|
20
|
+
|
|
21
|
+
- すべての変更は PR で入れる。`main` と `develop` はルールセットで保護され、CI(`test (3.11/3.12/3.13)`)と
|
|
22
|
+
`pr-rules` が通らないとマージできない。
|
|
23
|
+
- PR はリポジトリのオーナーがレビューしてからマージする(自動マージしない)。
|
|
24
|
+
- 数値計算に関わる変更は、R mirt との照合テスト([docs/VALIDATION.ja.md](docs/VALIDATION.ja.md))が通ることが前提。
|
|
25
|
+
|
|
26
|
+
## リリース
|
|
27
|
+
|
|
28
|
+
バージョンは **git タグ**(`vX.Y.Z`)から決まる(hatch-vcs)。`pyproject.toml` にはバージョンを書かず、
|
|
29
|
+
リリースはタグを打つことで行う。タグのない開発中のコミットは `0.0.2.dev3+g1a2b3c4` のような開発版になる。
|
|
30
|
+
|
|
31
|
+
1. `develop` → `main` の PR を作る。**タイトルでバージョンの上げ方を決める**:
|
|
32
|
+
- `release(major): ...` / `release(minor): ...` / `release(patch): ...`
|
|
33
|
+
- PR は**マージコミット**でマージする(`main` のルールセットはマージコミットだけを許可)。
|
|
34
|
+
2. マージされると `.github/workflows/release.yml` が動く:
|
|
35
|
+
1. `plan` ジョブ: PR タイトルと最新の `vX.Y.Z` タグから次のバージョンを決める。
|
|
36
|
+
2. `publish` ジョブ: **`release` 環境の承認待ちになる**。オーナーが Actions 画面で承認すると、
|
|
37
|
+
`main` にタグ `vX.Y.Z` を打って `uv build` し、GitHub Release を作成する(wheel / sdist 添付、
|
|
38
|
+
リリースノート自動生成)。このリリースに含まれる fix PR が `Closes` していた issue を閉じる。
|
|
39
|
+
3. `pypi` ジョブ: 同じ wheel / sdist を **PyPI に公開する**(`pypi` 環境、Trusted Publishing。
|
|
40
|
+
API トークンは使わない)。
|
|
41
|
+
4. 同じ `main` への push で `.github/workflows/docs.yml` がドキュメントサイトを GitHub Pages に公開する。
|
|
42
|
+
3. **最初のリリース**(`v*` タグがまだない)は、タイトルの上げ方に関係なく **v0.0.1**。
|
|
43
|
+
4. 手動実行(`workflow_dispatch`)は dry run 専用で、次のバージョンの計算とビルドだけを行う。
|
|
44
|
+
|
|
45
|
+
`main` へのマージコミットは `develop` に戻さない(`develop` は保護されていて、ボットは push できない)。
|
|
46
|
+
このため `develop` 上の開発版の番号は直前のリリースタグを参照しないことがあるが、リリースには影響しない。
|
|
47
|
+
|
|
48
|
+
バージョンは [Semantic Versioning](https://semver.org/lang/ja/) に従う。1.0.0 までは公開 API が変わりうる。
|
|
49
|
+
|
|
50
|
+
## セキュリティ(誰がリリースできるか)
|
|
51
|
+
|
|
52
|
+
- **`main` を更新できるのはリポジトリ管理者だけ**(ルールセット `main-release-gate`)。PR と CI の要件
|
|
53
|
+
(ルールセット `main`)は管理者にも適用される。リリースを起こせるのは develop → main を
|
|
54
|
+
マージできる管理者だけ。
|
|
55
|
+
- **`publish` ジョブは `release` 環境で動き、指定レビュアー(オーナー)の承認が必要**。環境は `main` からしか
|
|
56
|
+
デプロイできないので、他のブランチやフォークからはタグも Release も作れない。
|
|
57
|
+
- **PyPI への公開は Trusted Publishing**(OIDC)。PyPI 側には「リポジトリ `takuizum/flexpyirt`、
|
|
58
|
+
ワークフロー `release.yml`、環境 `pypi`」だけを信頼する publisher を登録しているので、API トークンは
|
|
59
|
+
リポジトリに置かない。`pypi` 環境もデプロイ元を `main` に限定しておく。PyPI に一度上げた番号は
|
|
60
|
+
削除しても再利用できない。
|
|
61
|
+
- ワークフローの `GITHUB_TOKEN` は既定で読み取り専用(`permissions: contents: read`)。書き込みは
|
|
62
|
+
`publish` ジョブだけ。フォークからの PR は読み取り専用トークンで CI と PR rules だけが走る。
|
|
63
|
+
- 協力者を追加するときは write 権限にとどめる。管理者を増やすとリリースできる人が増える。
|
|
64
|
+
|
|
65
|
+
## ローカル開発
|
|
66
|
+
|
|
67
|
+
Python 環境は `uv` だけで管理する(pip は使わない)。
|
|
68
|
+
|
|
69
|
+
```bash
|
|
70
|
+
uv sync --all-extras --dev
|
|
71
|
+
uv run ruff check . && uv run ruff format --check . && uv run mypy && uv run pytest
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
テストは pytest-xdist で並列に走る(`-n auto`)。直列にしたいときは `-n 0` を付ける。
|
|
75
|
+
10 秒程度を超えるテストには `@pytest.mark.slow` を付ける。PR の CI はこれを飛ばし(`-m "not slow"`)、
|
|
76
|
+
`develop`/`main` への push では全テストを走らせる。手元で素早く確かめるなら `uv run pytest -m "not slow"`。新しく 10 秒を超えるテストを書いたら `slow` を付ける。
|
|
77
|
+
|
|
78
|
+
mirt の参照値を作り直すとき(R 4.4+ と mirt が必要):
|
|
79
|
+
|
|
80
|
+
```bash
|
|
81
|
+
Rscript validation/r/m1_reference.R
|
|
82
|
+
Rscript validation/r/m2_reference.R
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
R `mirt` との wall time ベンチマークを再実行するとき(詳細と `--quick` モードは
|
|
86
|
+
[benchmarks/README.ja.md](benchmarks/README.ja.md) を参照):
|
|
87
|
+
|
|
88
|
+
```bash
|
|
89
|
+
uv run python benchmarks/data.py
|
|
90
|
+
uv run python benchmarks/run_flexpyirt.py
|
|
91
|
+
Rscript benchmarks/run_mirt.R
|
|
92
|
+
uv run python benchmarks/report.py
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
## 命名
|
|
96
|
+
|
|
97
|
+
名前は PEP 8 に従い、R ではなく Python として読めるものにする(DESIGN.md §15.46)。`ruff` が `N` 規則を検査する。
|
|
98
|
+
|
|
99
|
+
- 関数・メソッド・引数・変数は `snake_case`、クラスは `CapWords`、モジュール定数は `UPPER_SNAKE_CASE`。
|
|
100
|
+
- R/mirt の引数名をそのまま使わない。Python の綴りにし、対応する mirt の名前は docstring に書く:
|
|
101
|
+
`n_categories`(`n_cat` ではない)、`min_cell`(mirt の `mincell`)、`mean_log`/`sd_log`(R の `meanlog`/`sdlog`)、
|
|
102
|
+
`bounds=(lower, upper)`(mirt の `theta_lim`)。
|
|
103
|
+
- 公開名は略さない(`is_eh` ではなく `is_empirical_histogram`)。定着した略語は使ってよい: モデル名(`TwoPL`, `GRM`,
|
|
104
|
+
`GPCM`)、個数を表す接頭辞 `n_`、`se`, `vcov`, `loglik`, `theta`, `eta`。よく使う別名とぶつかる略語は避ける
|
|
105
|
+
(`pd` は pandas、`df` は自由度と DataFrame で紛らわしい)。
|
|
106
|
+
- 同じ概念には API 全体で同じ名前を使う(`n_points`, `n_factors`, `n_categories`)。同じ系統のクラスは接尾辞を揃える
|
|
107
|
+
(`NormalPrior`, `LogNormalPrior`, `BetaPrior`)。
|
|
108
|
+
- `Literal` の文字列の選択肢は小文字の `snake_case`(`"slope_intercept"`, `"stocking_lord"`)。定着した頭字語は大文字のまま
|
|
109
|
+
(`"EAP"`, `"MAP"`, `"BH"`)。
|
|
110
|
+
- DESIGN.md の数式に対応する場所では数式記号を使ってよい: jit されるカーネル内の大文字の記号(`G`, `Q`, `D`, `K_f`。
|
|
111
|
+
このため ruff の `N803`/`N806` は無視している)や、`LinkResult.A`/`B` のような標準的な定数。
|
|
112
|
+
- ローカルのクロージャは役割で名付ける(`objective`, `backtrack_body`, `interp_weights`。`obj` や `tmp` は使わない)。
|
|
113
|
+
mirt のコードを行ごとに移植した箇所(例: `_itemfit.collapse_cells`)は照合のため mirt の局所変数名を残してよく、
|
|
114
|
+
その旨をコメントに書く。
|
|
115
|
+
- `FitResult` の JSON に保存される名前を変えるときは `schema_version` を上げ、古いファイルも読めるようにする
|
|
116
|
+
(読み込み時に旧キーを置き換える)。
|
|
117
|
+
|
|
118
|
+
## ドキュメント
|
|
119
|
+
|
|
120
|
+
すべての文書は英語版(`*.md`)と日本語版(`*.ja.md`)があり、内容は同じ。片方を変えたら両方を直す。
|
|
121
|
+
`.github/` の PR・issue テンプレートは、GitHub が既定のテンプレートを 1 つしか使わないため、英日を併記した
|
|
122
|
+
1 つのファイルにしている。
|
|
123
|
+
|
|
124
|
+
`docs/` の文書はそのまま英日 2 言語のサイト(<https://takuizum.github.io/flexpyirt/>、日本語は `/ja/`)
|
|
125
|
+
にもなる(MkDocs、`mkdocs.yml`)。サイトは `main` から公開されるので、リリース済みの状態を表す。
|
|
126
|
+
ローカルでの確認:
|
|
127
|
+
|
|
128
|
+
```bash
|
|
129
|
+
uv run --group docs mkdocs serve # プレビュー
|
|
130
|
+
uv run --group docs mkdocs build --strict # CI と同じ検査(リンク切れ・アンカー切れで失敗)
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
- 文書内のリンクは相対リンクで書く(GitHub でもサイトでも動く)。`docs/` の外を指すリンクは、サイトでは
|
|
134
|
+
GitHub 上のファイルに書き換わる(`scripts/mkdocs_hooks.py`)。
|
|
135
|
+
- `README.md` / `README.ja.md` は PyPI のプロジェクトページにも表示されるので、リンクは絶対 URL で書く
|
|
136
|
+
(文書はサイトの URL、それ以外は GitHub の URL)。
|
|
137
|
+
- `docs/` に文書を足したら `mkdocs.yml` の `nav`(と日本語の `nav_translations`)にも足す。
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
# Contributing
|
|
2
|
+
|
|
3
|
+
English | [日本語](CONTRIBUTING.ja.md)
|
|
4
|
+
|
|
5
|
+
## Branches
|
|
6
|
+
|
|
7
|
+
| Branch | Role | Created from / merged into |
|
|
8
|
+
|---|---|---|
|
|
9
|
+
| `main` | Released states only. No direct pushes | Accepts release PRs from `develop` only |
|
|
10
|
+
| `develop` | Integration branch; collects what goes into the next release | Accepts PRs from `feature/*` and `fix/*` |
|
|
11
|
+
| `feature/<slug>` | Features, documentation, refactoring and so on | From `develop`, PR into `develop` |
|
|
12
|
+
| `fix/<issue number>-<slug>` | Bug fixes. **Always tied to an issue** | From `develop`, PR into `develop` |
|
|
13
|
+
|
|
14
|
+
- `<slug>` uses lowercase letters, digits, `.`, `_` and `-` only (e.g. `feature/grm-docs`,
|
|
15
|
+
`fix/12-oakes-se`).
|
|
16
|
+
- A fix branch's PR description contains `Closes #<issue number>`, and the issue must be open.
|
|
17
|
+
(`develop` is not the default branch, so the workflow closes the issue **at release time**, not at
|
|
18
|
+
merge time.)
|
|
19
|
+
- The `PR rules` check (`scripts/check_pr.py`) enforces these on every PR.
|
|
20
|
+
|
|
21
|
+
## PRs and reviews
|
|
22
|
+
|
|
23
|
+
- Every change goes in through a PR. `main` and `develop` are protected by rulesets and cannot be
|
|
24
|
+
merged into until CI (`test (3.11/3.12/3.13)`) and `pr-rules` pass.
|
|
25
|
+
- The repository owner reviews PRs before merging them (no automatic merging).
|
|
26
|
+
- Changes to numerical code must pass the agreement tests against R mirt
|
|
27
|
+
([docs/VALIDATION.md](docs/VALIDATION.md)).
|
|
28
|
+
|
|
29
|
+
## Releases
|
|
30
|
+
|
|
31
|
+
The version comes from **git tags** (`vX.Y.Z`, via hatch-vcs). `pyproject.toml` holds no version;
|
|
32
|
+
releasing means tagging. Untagged development commits get versions like `0.0.2.dev3+g1a2b3c4`.
|
|
33
|
+
|
|
34
|
+
1. Open a PR from `develop` into `main`. **Its title decides the version bump**:
|
|
35
|
+
- `release(major): ...` / `release(minor): ...` / `release(patch): ...`
|
|
36
|
+
- Merge it with a **merge commit** (the `main` ruleset allows merge commits only).
|
|
37
|
+
2. The merge runs `.github/workflows/release.yml`:
|
|
38
|
+
1. `plan` job: computes the next version from the PR title and the latest `vX.Y.Z` tag.
|
|
39
|
+
2. `publish` job: **waits for approval in the `release` environment**. Once the owner approves
|
|
40
|
+
it on the Actions page, it tags `main` with `vX.Y.Z`, runs `uv build` and creates a GitHub
|
|
41
|
+
Release (wheel and sdist attached, release notes generated). It then closes the issues that
|
|
42
|
+
fix PRs in this release `Closes`d.
|
|
43
|
+
3. `pypi` job: **publishes the same wheel and sdist to PyPI** (`pypi` environment, Trusted
|
|
44
|
+
Publishing; no API token).
|
|
45
|
+
4. The same push to `main` runs `.github/workflows/docs.yml`, which deploys the documentation
|
|
46
|
+
site to GitHub Pages.
|
|
47
|
+
3. **The first release** (no `v*` tag yet) is **v0.0.1**, whatever bump the title asks for.
|
|
48
|
+
4. Manual runs (`workflow_dispatch`) are dry runs only: they compute the next version and build.
|
|
49
|
+
|
|
50
|
+
Merge commits on `main` are not merged back into `develop` (`develop` is protected and the bot
|
|
51
|
+
cannot push to it). So development version numbers on `develop` may not refer to the latest release
|
|
52
|
+
tag; releases are not affected.
|
|
53
|
+
|
|
54
|
+
Versions follow [Semantic Versioning](https://semver.org/). The public API may change before 1.0.0.
|
|
55
|
+
|
|
56
|
+
## Security (who can release)
|
|
57
|
+
|
|
58
|
+
- **Only repository admins can update `main`** (ruleset `main-release-gate`). The PR and CI
|
|
59
|
+
requirements (ruleset `main`) apply to admins too. Only an admin who can merge develop into main
|
|
60
|
+
can start a release.
|
|
61
|
+
- **The `publish` job runs in the `release` environment and needs the designated reviewer's (the
|
|
62
|
+
owner's) approval.** The environment deploys from `main` only, so other branches and forks cannot
|
|
63
|
+
create tags or Releases.
|
|
64
|
+
- **PyPI uploads use Trusted Publishing** (OIDC). PyPI trusts only the publisher "repository
|
|
65
|
+
`takuizum/flexpyirt`, workflow `release.yml`, environment `pypi`", so no API token lives in the
|
|
66
|
+
repository. Restrict the `pypi` environment to deployments from `main` as well. A version
|
|
67
|
+
number uploaded to PyPI can never be reused, even after deleting it.
|
|
68
|
+
- Workflow `GITHUB_TOKEN`s are read-only by default (`permissions: contents: read`); only the
|
|
69
|
+
`publish` job writes. PRs from forks get a read-only token and run only CI and PR rules.
|
|
70
|
+
- Give new collaborators write access only. Every additional admin is another person who can
|
|
71
|
+
release.
|
|
72
|
+
|
|
73
|
+
## Local development
|
|
74
|
+
|
|
75
|
+
Manage Python environments with `uv` only (no pip).
|
|
76
|
+
|
|
77
|
+
```bash
|
|
78
|
+
uv sync --all-extras --dev
|
|
79
|
+
uv run ruff check . && uv run ruff format --check . && uv run mypy && uv run pytest
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
Tests run in parallel (pytest-xdist, `-n auto`); pass `-n 0` to run serially. Tests that take
|
|
83
|
+
more than about 10 s are marked `@pytest.mark.slow`. PR CI skips them (`-m "not slow"`); pushes
|
|
84
|
+
to `develop`/`main` run the full suite. Run `uv run pytest -m "not slow"` locally for a quick
|
|
85
|
+
check, and mark any new test that takes more than ~10 s as `slow`.
|
|
86
|
+
|
|
87
|
+
To regenerate the mirt reference values (needs R 4.4+ and mirt):
|
|
88
|
+
|
|
89
|
+
```bash
|
|
90
|
+
Rscript validation/r/m1_reference.R
|
|
91
|
+
Rscript validation/r/m2_reference.R
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
To rerun the wall-time benchmarks against R `mirt` (see [benchmarks/README.md](benchmarks/README.md)
|
|
95
|
+
for details and `--quick` mode):
|
|
96
|
+
|
|
97
|
+
```bash
|
|
98
|
+
uv run python benchmarks/data.py
|
|
99
|
+
uv run python benchmarks/run_flexpyirt.py
|
|
100
|
+
Rscript benchmarks/run_mirt.R
|
|
101
|
+
uv run python benchmarks/report.py
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
## Naming
|
|
105
|
+
|
|
106
|
+
Names follow PEP 8 and read as Python, not as R (DESIGN.md §15.46). `ruff` checks the `N` rules.
|
|
107
|
+
|
|
108
|
+
- `snake_case` for functions, methods, arguments and variables; `CapWords` for classes;
|
|
109
|
+
`UPPER_SNAKE_CASE` for module constants.
|
|
110
|
+
- Do not copy R/mirt argument names. Use the Python spelling and mention mirt's name in the
|
|
111
|
+
docstring: `n_categories` (not `n_cat`), `min_cell` (mirt `mincell`), `mean_log`/`sd_log` (R
|
|
112
|
+
`meanlog`/`sdlog`), `bounds=(lower, upper)` (mirt `theta_lim`).
|
|
113
|
+
- Spell public names out (`is_empirical_histogram`, not `is_eh`). Well-known abbreviations are
|
|
114
|
+
fine: model names (`TwoPL`, `GRM`, `GPCM`), the `n_` prefix for counts, and `se`, `vcov`,
|
|
115
|
+
`loglik`, `theta`, `eta`. Avoid abbreviations that collide with common aliases, such as `pd`
|
|
116
|
+
(pandas) or `df` (degrees of freedom vs DataFrame).
|
|
117
|
+
- Use one name for one concept across the whole API (`n_points`, `n_factors`, `n_categories`).
|
|
118
|
+
Members of a family share a suffix (`NormalPrior`, `LogNormalPrior`, `BetaPrior`).
|
|
119
|
+
- `Literal` string options are lowercase `snake_case` (`"slope_intercept"`, `"stocking_lord"`).
|
|
120
|
+
Established acronyms stay upper case (`"EAP"`, `"MAP"`, `"BH"`).
|
|
121
|
+
- Mathematical notation is allowed where it mirrors the formulas in DESIGN.md: upper-case symbols
|
|
122
|
+
inside jitted kernels (`G`, `Q`, `D`, `K_f`; ruff `N803`/`N806` are ignored for this) and
|
|
123
|
+
standard constants such as `LinkResult.A`/`B`.
|
|
124
|
+
- Name local closures by their role (`objective`, `backtrack_body`, `interp_weights`), not `obj`
|
|
125
|
+
or `tmp`. Line-by-line ports of mirt code (e.g. `_itemfit.collapse_cells`) may keep mirt's local
|
|
126
|
+
names so they can be compared; say so in a comment.
|
|
127
|
+
- Renaming anything that is stored in `FitResult` JSON needs a new `schema_version`, and older
|
|
128
|
+
files must still load (rename the old keys on read).
|
|
129
|
+
|
|
130
|
+
## Documentation
|
|
131
|
+
|
|
132
|
+
Every document exists in English (`*.md`) and Japanese (`*.ja.md`) with the same content. Update
|
|
133
|
+
both when you change one. The PR and issue templates under `.github/` are single bilingual files
|
|
134
|
+
(English and Japanese side by side), because GitHub uses one default template.
|
|
135
|
+
|
|
136
|
+
The files in `docs/` also make up the bilingual documentation site
|
|
137
|
+
(<https://takuizum.github.io/flexpyirt/>, Japanese under `/ja/`; MkDocs, `mkdocs.yml`). The site is
|
|
138
|
+
deployed from `main`, so it shows the released state. To check it locally:
|
|
139
|
+
|
|
140
|
+
```bash
|
|
141
|
+
uv run --group docs mkdocs serve # preview
|
|
142
|
+
uv run --group docs mkdocs build --strict # the CI check (fails on broken links and anchors)
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
- Write links between documents as relative links (they work on GitHub and on the site). On the
|
|
146
|
+
site, links that leave `docs/` point to the file on GitHub (`scripts/mkdocs_hooks.py`).
|
|
147
|
+
- `README.md` / `README.ja.md` are also shown on the PyPI project page, so their links are absolute
|
|
148
|
+
(site URLs for documents, GitHub URLs for everything else).
|
|
149
|
+
- When you add a document to `docs/`, add it to `nav` in `mkdocs.yml` (and to the Japanese
|
|
150
|
+
`nav_translations`).
|
flexpyirt-0.0.1/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 takuizum
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
flexpyirt-0.0.1/PKG-INFO
ADDED
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: flexpyirt
|
|
3
|
+
Version: 0.0.1
|
|
4
|
+
Summary: Bock–Aitkin EM estimation for item response theory models, built on JAX.
|
|
5
|
+
Project-URL: Homepage, https://github.com/takuizum/flexpyirt
|
|
6
|
+
Project-URL: Documentation, https://takuizum.github.io/flexpyirt/
|
|
7
|
+
Project-URL: Repository, https://github.com/takuizum/flexpyirt
|
|
8
|
+
Project-URL: Issues, https://github.com/takuizum/flexpyirt/issues
|
|
9
|
+
Project-URL: Releases, https://github.com/takuizum/flexpyirt/releases
|
|
10
|
+
Author: takuizum
|
|
11
|
+
License-Expression: MIT
|
|
12
|
+
License-File: LICENSE
|
|
13
|
+
Keywords: EM algorithm,IRT,JAX,item response theory,marginal maximum likelihood,psychometrics
|
|
14
|
+
Classifier: Development Status :: 3 - Alpha
|
|
15
|
+
Classifier: Intended Audience :: Science/Research
|
|
16
|
+
Classifier: Operating System :: OS Independent
|
|
17
|
+
Classifier: Programming Language :: Python :: 3
|
|
18
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
22
|
+
Classifier: Topic :: Scientific/Engineering :: Mathematics
|
|
23
|
+
Classifier: Typing :: Typed
|
|
24
|
+
Requires-Python: >=3.11
|
|
25
|
+
Requires-Dist: jax>=0.4.30
|
|
26
|
+
Requires-Dist: numpy>=1.26
|
|
27
|
+
Requires-Dist: pandas>=2.1
|
|
28
|
+
Requires-Dist: scipy>=1.11
|
|
29
|
+
Provides-Extra: polars
|
|
30
|
+
Requires-Dist: polars>=1.0; extra == 'polars'
|
|
31
|
+
Description-Content-Type: text/markdown
|
|
32
|
+
|
|
33
|
+
# flexpyirt
|
|
34
|
+
|
|
35
|
+
English | [日本語](https://github.com/takuizum/flexpyirt/blob/main/README.ja.md)
|
|
36
|
+
|
|
37
|
+
Item response theory (IRT) estimation in Python, built on JAX. At its core is marginal maximum
|
|
38
|
+
likelihood estimation (MMLE) with the Bock–Aitkin EM algorithm, including multiple-group
|
|
39
|
+
calibration and fixed item parameter calibration (FIPC).
|
|
40
|
+
|
|
41
|
+
- **Verified against R `mirt`**: every supported feature is checked numerically against mirt
|
|
42
|
+
(parameters, log-likelihood and standard errors agree to about 1e-8; see
|
|
43
|
+
[validation](https://takuizum.github.io/flexpyirt/VALIDATION/)).
|
|
44
|
+
- **Automatic differentiation**: M-step gradients and Hessians and the standard errors (Oakes'
|
|
45
|
+
identity) all come from JAX autodiff. A new item model only needs its log-probability for
|
|
46
|
+
estimation, standard errors and scoring to work.
|
|
47
|
+
- **ParameterTable**: a table like mirt's `pars = "values"` for editing fixed values, equality
|
|
48
|
+
constraints and starting values.
|
|
49
|
+
|
|
50
|
+
> Under development (0.x). The public API may change before 1.0.0.
|
|
51
|
+
|
|
52
|
+
**Documentation: <https://takuizum.github.io/flexpyirt/>**
|
|
53
|
+
|
|
54
|
+
## Features
|
|
55
|
+
|
|
56
|
+
| Feature | Details | mirt check |
|
|
57
|
+
|---|---|---|
|
|
58
|
+
| Item models | 2PL, Rasch (latent variance estimated), 3PL, 4PL, GRM (graded response model), GPCM, PCM (latent variance estimated), Nominal (nominal response model; validated for one and two factors, three factors unit-tested only) | V1, V2, V3, V8, V11, V23 |
|
|
59
|
+
| Priors and MAP | `NormalPrior`, `LogNormalPrior`, `BetaPrior` on item parameters (`Model.prior()`), natural scale, `FitResult.log_posterior` | V7 |
|
|
60
|
+
| Multiple groups | Group-specific item parameters, anchor items equal across groups, focal-group mean and variance estimated | V4 |
|
|
61
|
+
| Equality across items | Common parameters across items and item models (`Model.equal_across_items()`, e.g. one common slope), combined with across-group equalities | V16 |
|
|
62
|
+
| FIPC | Fix some items at item-bank values; estimate the other items and the latent distribution | V5 |
|
|
63
|
+
| Missing data | Responses missing at random (MAR) | V9 |
|
|
64
|
+
| Standard errors | Oakes' identity (default) or the Hessian of the marginal log-likelihood / log posterior, plus delta-method SEs for display IRT thresholds (`b_se` / `bk_se`) | V7, V10, V12, V14 |
|
|
65
|
+
| Scoring | EAP, MAP, ML and WLE (1–3 factors, with standard errors) and plausible values (`PV`, 1–3 factors, explicit JAX PRNG `key`), using each group's latent distribution as the prior where applicable | V1–V5, V7–V9, V11, V13, V14 |
|
|
66
|
+
| Multidimensional models | Confirmatory 2–3 factor MIRT (`Model.with_factors()`, also with multiple groups) with cross-loadings, correlated or orthogonal MVN factors, product quadrature grids, Oakes/Hessian SEs, and EAP / MAP / ML / WLE scoring | V14, V21 |
|
|
67
|
+
| Empirical histogram | `EmpiricalHistogram()` latent distributions (Woods, 2007) for skewed or multimodal traits; reference group standardized to mean 0 / variance 1 by an exact constrained M-step, free under FIPC; weights reported with moments up to the 4th | V6 |
|
|
68
|
+
| Davidian curves | `DavidianCurve(degree)` seminonparametric latent distributions (Zhang & Davidian, 2001; Woods & Lin, 2009) for single-group unidimensional models; analytically standardized to exact continuous `mean`/`var` (optional `free_mean`/`free_var` for Rasch, PCM, FIPC) with joint Oakes/Hessian SEs and EAP/PV scoring | V19 |
|
|
69
|
+
| Normal mixtures | `NormalMixture(n_components)` latent densities (Mislevy, 1984) with one common set of items for single-group unidimensional models; mirt's `dentype = "mixture-k"` class parameterization analytically standardized to exact continuous `mean`/`var`, standardized components (`pi_c`, `mean_c`, `var_c`) with delta-method SEs, joint Oakes/Hessian SEs, EAP/PV scoring, degenerate-solution warnings | V22 |
|
|
70
|
+
| Saving results | `FitResult.to_json()` / `FitResult.from_json()` (strict schema, no pickle) | — |
|
|
71
|
+
| EM acceleration | SQUAREM (scheme S3) with a monotonicity safeguard, `BAEM(squarem=True)`; agreement with mirt holds with and without it | V1–V5, V7–V9, V11, V14 |
|
|
72
|
+
| Item fit | Orlando–Thissen S-X2 (`FitResult.item_fit()`, per group for multiple groups) with mirt's cell collapsing, df, RMSEA and p-values | V15 |
|
|
73
|
+
| Limited-information fit | Maydeu-Olivares & Joe M2 / M2* (`FitResult.m2()`) with df, p-value, RMSEA + CI, SRMSR and dichotomous TLI / CFI | V18 |
|
|
74
|
+
| DIF | Multiple-group likelihood-ratio DIF tests (`FitResult.dif()`, mirt's `DIF()` schemes `add` / `drop`, AIC/SABIC/HQ/BIC differences, Holm or BH adjusted p-values) | V17 |
|
|
75
|
+
| Scale linking | Differentiable characteristic-curve linking (`link()`, `LinkResult`: Haebara and Stocking–Lord, non-symmetric and symmetric, Ogasawara delta-method SEs, transformed items and $\theta$ scores; validated for 2PL, 3PL, GRM, GPCM and mixed 2PL + GPCM common items) | V20 |
|
|
76
|
+
| Identification checks | Unidentified specifications raise `IdentificationError` before fitting | — |
|
|
77
|
+
|
|
78
|
+
See the [roadmap](https://takuizum.github.io/flexpyirt/ROADMAP/) for what comes next.
|
|
79
|
+
|
|
80
|
+
## Installation
|
|
81
|
+
|
|
82
|
+
Python 3.11 or later.
|
|
83
|
+
|
|
84
|
+
```bash
|
|
85
|
+
pip install flexpyirt # or: uv add flexpyirt
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
For polars input, install `flexpyirt[polars]`. For GPUs, install a CUDA build of `jax` first
|
|
89
|
+
(see the [JAX installation guide](https://docs.jax.dev/en/latest/installation.html)).
|
|
90
|
+
|
|
91
|
+
flexpyirt computes in **64-bit floating point**. The JAX setting belongs to you, so the library
|
|
92
|
+
does not change it; enable it before fitting (otherwise `fit()` raises `PrecisionError`).
|
|
93
|
+
|
|
94
|
+
```python
|
|
95
|
+
import jax
|
|
96
|
+
|
|
97
|
+
jax.config.update("jax_enable_x64", True)
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
## Quick start
|
|
101
|
+
|
|
102
|
+
As an example, simulate 2PL data and fit it. With real data, pass a DataFrame with one column per
|
|
103
|
+
item and one row per respondent (values 0/1, missing as NaN).
|
|
104
|
+
|
|
105
|
+
```python
|
|
106
|
+
import numpy as np
|
|
107
|
+
import pandas as pd
|
|
108
|
+
|
|
109
|
+
from flexpyirt import Model, TwoPL, fit
|
|
110
|
+
|
|
111
|
+
rng = np.random.default_rng(1)
|
|
112
|
+
n_persons, n_items = 1000, 10
|
|
113
|
+
a = rng.lognormal(0.0, 0.3, n_items) # slopes
|
|
114
|
+
d = rng.normal(0.0, 1.0, n_items) # intercepts
|
|
115
|
+
theta = rng.normal(0.0, 1.0, n_persons)
|
|
116
|
+
p = 1.0 / (1.0 + np.exp(-(np.outer(theta, a) + d)))
|
|
117
|
+
df = pd.DataFrame(
|
|
118
|
+
(rng.random(p.shape) < p).astype(int),
|
|
119
|
+
columns=[f"q{j:02d}" for j in range(1, n_items + 1)],
|
|
120
|
+
)
|
|
121
|
+
|
|
122
|
+
spec = Model.uniform(TwoPL(), items=df.columns)
|
|
123
|
+
res = fit(spec, df)
|
|
124
|
+
|
|
125
|
+
print(res) # log-likelihood, number of parameters, convergence
|
|
126
|
+
print(res.items.head()) # item, model, a, d, a_se, d_se, b (= -d/a), b_se
|
|
127
|
+
print(res.loglik, res.aic, res.bic)
|
|
128
|
+
scores = res.score(df) # EAP (theta) and posterior SD (se) per respondent
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
Parameters use mirt's slope–intercept form $P(y=1\mid\theta)=\sigma(a\theta+d)$; `items` also
|
|
132
|
+
shows the difficulty $b=-d/a$ for display.
|
|
133
|
+
|
|
134
|
+
## Examples
|
|
135
|
+
|
|
136
|
+
See the [user guide](https://takuizum.github.io/flexpyirt/guide/) for details and the [API reference](https://takuizum.github.io/flexpyirt/reference/) for
|
|
137
|
+
each function.
|
|
138
|
+
|
|
139
|
+
**Rasch model** (slopes fixed at 1, latent variance estimated)
|
|
140
|
+
|
|
141
|
+
```python
|
|
142
|
+
from flexpyirt import Rasch
|
|
143
|
+
|
|
144
|
+
rasch = fit(Model.uniform(Rasch(), items=df.columns), df)
|
|
145
|
+
print(rasch.latent) # group, mean (fixed at 0), var (estimated), mean_se, var_se
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
**Multiple groups (linked by anchor items)**
|
|
149
|
+
|
|
150
|
+
```python
|
|
151
|
+
from flexpyirt import Normal
|
|
152
|
+
|
|
153
|
+
group = np.repeat(["ref", "focal"], n_persons // 2)
|
|
154
|
+
spec2 = (
|
|
155
|
+
Model.uniform(TwoPL(), items=df.columns)
|
|
156
|
+
.with_groups(ref=Normal.standard(), focal=Normal.free()) # the first group is the reference
|
|
157
|
+
.equal_across_groups(items=["q01", "q02", "q03", "q04"]) # anchor items
|
|
158
|
+
)
|
|
159
|
+
res2 = fit(spec2, df, group=group)
|
|
160
|
+
print(res2.latent) # the focal group's mean and variance are estimated
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
**FIPC (fix items at bank values and calibrate new items)**
|
|
164
|
+
|
|
165
|
+
```python
|
|
166
|
+
bank = pd.DataFrame({"item": ["q01", "q02", "q03"], "a": a[:3], "d": d[:3]})
|
|
167
|
+
spec3 = Model.uniform(TwoPL(), items=df.columns).fix_from(bank).with_latent(Normal.free())
|
|
168
|
+
res3 = fit(spec3, df)
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
## Performance
|
|
172
|
+
|
|
173
|
+
Wall-time benchmarks against R `mirt` (default settings, `TOL = 1e-4`, 61 quadrature points on CPU)
|
|
174
|
+
are in [benchmarks/](https://github.com/takuizum/flexpyirt/blob/main/benchmarks/README.md) with committed Apple M5 results in
|
|
175
|
+
[benchmarks/results/2026-11-21-apple-m5.md](https://github.com/takuizum/flexpyirt/blob/main/benchmarks/results/2026-11-21-apple-m5.md).
|
|
176
|
+
After the first-call JAX/XLA compilation (a cold EM fit takes ~0.8–1.1 s), warm CPU fits are faster
|
|
177
|
+
than `mirt` across all tested cases (`0.12×–0.60×` of `mirt` time), while `mirt` is faster for a
|
|
178
|
+
single cold fit without standard errors.
|
|
179
|
+
|
|
180
|
+
## Documentation
|
|
181
|
+
|
|
182
|
+
- [User guide](https://takuizum.github.io/flexpyirt/guide/) — specifying models, multiple groups, FIPC, editing the
|
|
183
|
+
ParameterTable, estimation options
|
|
184
|
+
- [API reference](https://takuizum.github.io/flexpyirt/reference/) — public classes and functions and their arguments
|
|
185
|
+
- [Validation](https://takuizum.github.io/flexpyirt/VALIDATION/) — how results are checked against R mirt, tolerances, known
|
|
186
|
+
differences
|
|
187
|
+
- [Design](https://takuizum.github.io/flexpyirt/DESIGN/) — formulas, algorithms and implementation decisions
|
|
188
|
+
- [Roadmap](https://takuizum.github.io/flexpyirt/ROADMAP/)
|
|
189
|
+
- [Contributing](https://github.com/takuizum/flexpyirt/blob/main/CONTRIBUTING.md) — branches, reviews, releases
|
|
190
|
+
|
|
191
|
+
Every document is also available in Japanese ([日本語サイト](https://takuizum.github.io/flexpyirt/ja/)).
|
|
192
|
+
|
|
193
|
+
## Development
|
|
194
|
+
|
|
195
|
+
```bash
|
|
196
|
+
uv sync --all-extras --dev
|
|
197
|
+
uv run ruff check . && uv run ruff format --check . && uv run mypy && uv run pytest
|
|
198
|
+
```
|
|
199
|
+
|
|
200
|
+
See [CONTRIBUTING.md](https://github.com/takuizum/flexpyirt/blob/main/CONTRIBUTING.md) for the branch flow and releases.
|
|
201
|
+
|
|
202
|
+
## License
|
|
203
|
+
|
|
204
|
+
MIT
|