|
| 1 | +(ns verify-pair-frequency-logistic-v2 |
| 2 | + (:require [clojure.java.io :as io] |
| 3 | + [clojure.pprint :as pprint] |
| 4 | + [language-learning.vocabulary-estimation.pair-frequency-logistic-v2 :as v2])) |
| 5 | + |
| 6 | +(def fixture-resource |
| 7 | + "language_learning/vocabulary_estimation/pair_frequency_fixture_v1.tsv") |
| 8 | + |
| 9 | +(def output-path |
| 10 | + "resources/language_learning/vocabulary_estimation/pair_frequency_logistic_v2_grid_check.edn") |
| 11 | + |
| 12 | +(defn fixture [] |
| 13 | + (let [pairs (-> (io/resource fixture-resource) |
| 14 | + slurp |
| 15 | + v2/parse-fixture |
| 16 | + v2/validate-fixture) |
| 17 | + {:keys [pairs] :as transformed} (v2/frequency-transform pairs)] |
| 18 | + (assoc transformed :pairs |
| 19 | + (mapv #(assoc %1 :pair-index %2) pairs (range))))) |
| 20 | + |
| 21 | +(defn check-grid [] |
| 22 | + (let [{:keys [pairs]} (fixture) |
| 23 | + xs (mapv :x pairs) |
| 24 | + selected (->> (v2/selection-schedule pairs 8 v2/default-seed) |
| 25 | + (take 6) |
| 26 | + (mapcat identity) |
| 27 | + (mapv :pair-index)) |
| 28 | + threshold (v2/threshold-for-total xs 1.5 4000.0) |
| 29 | + observations (v2/simulate-responses |
| 30 | + xs selected {:threshold threshold :width 1.5} |
| 31 | + 2026071303) |
| 32 | + coarse-posterior (v2/posterior-grid xs observations) |
| 33 | + coarse-summary (v2/posterior-predictive-summary |
| 34 | + xs observations coarse-posterior 20000 2026071304) |
| 35 | + doubled (v2/doubled-grid v2/default-grid) |
| 36 | + doubled-posterior (v2/posterior-grid xs observations doubled |
| 37 | + v2/default-prior) |
| 38 | + doubled-summary (v2/posterior-predictive-summary |
| 39 | + xs observations doubled-posterior 20000 2026071304) |
| 40 | + result {:fixture-id v2/fixture-id |
| 41 | + :fixture-sha256 v2/fixture-sha256 |
| 42 | + :observations (mapv #(select-keys % [:pair-index :response]) |
| 43 | + observations) |
| 44 | + :default-grid v2/default-grid |
| 45 | + :doubled-grid doubled |
| 46 | + :posterior-draws 20000 |
| 47 | + :seed 2026071304 |
| 48 | + :coarse coarse-summary |
| 49 | + :doubled doubled-summary |
| 50 | + :convergence (v2/grid-convergence coarse-summary |
| 51 | + doubled-summary)}] |
| 52 | + (io/make-parents output-path) |
| 53 | + (spit output-path (with-out-str (pprint/pprint result))) |
| 54 | + result)) |
| 55 | + |
| 56 | +(prn (select-keys (check-grid) [:coarse :doubled :convergence])) |
0 commit comments