Skip to content

Commit 7bc22a4

Browse files
Merge pull request #410 from jamiepratt/codex/pair-frequency-logistic-v2
Publish pair-frequency model validation
2 parents bfbf4f6 + 3cf930d commit 7bc22a4

22 files changed

Lines changed: 13510 additions & 20 deletions

deps.edn

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
{:paths ["src"]
1+
{:paths ["src" "resources"]
22

33
:deps
44
{org.clojure/clojure {:mvn/version "1.12.3"}
@@ -100,4 +100,11 @@
100100
org.scicloj/kindly-advice {:local/root "../kindly-advice"}
101101
org.scicloj/kindly-render {:local/root "../kindly-render"}}}
102102
:neil {:project {:name io.github.timothypratley/clojurecivitas}}
103-
:dev {:jvm-opts ["--add-opens=java.base/java.nio=ALL-UNNAMED"]}}}
103+
:dev {:jvm-opts ["--add-opens=java.base/java.nio=ALL-UNNAMED"]}
104+
:test-clj {:extra-paths ["test"]
105+
:main-opts ["-m" "language-learning.vocabulary-estimation.test-runner"]}
106+
:test-cljs {:extra-paths ["test"]
107+
:extra-deps {org.clojure/clojurescript {:mvn/version "1.12.42"}}
108+
:main-opts ["-m" "cljs.main"
109+
"-re" "node"
110+
"-m" "language-learning.vocabulary-estimation.cljs-test-runner"]}}}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
(ns generate-pair-frequency-fixture
2+
(:require [clojure.java.io :as io]
3+
[clojure.string :as str]))
4+
5+
(def source-path
6+
(or (first *command-line-args*)
7+
"/Users/jamiep/Documents/subtlex/data/database-import/surface_form_lemma_pair_frequency_ranks.tsv"))
8+
9+
(def target-path
10+
(or (second *command-line-args*)
11+
"resources/language_learning/vocabulary_estimation/pair_frequency_fixture_v1.tsv"))
12+
13+
(def source-columns
14+
["surface_form_lemma_pair_frequency_rank_id"
15+
"surface_form_id"
16+
"lemma_id"
17+
"pair_frequency_sn_sum"
18+
"pair_frequency_sn_sum_rank"])
19+
20+
(defn select-row [indexes line]
21+
(let [fields (str/split line #"\t" -1)]
22+
(str/join "\t" (map #(nth fields %) indexes))))
23+
24+
(with-open [reader (io/reader source-path)]
25+
(let [[header & rows] (line-seq reader)
26+
columns (str/split header #"\t" -1)
27+
indexes (mapv #(.indexOf columns %) source-columns)
28+
selected (take 8000 rows)]
29+
(when (some neg? indexes)
30+
(throw (ex-info "Required source column missing"
31+
{:required source-columns :actual columns})))
32+
(when-not (= 8000 (count selected))
33+
(throw (ex-info "Source has fewer than 8,000 data rows" {})))
34+
(io/make-parents target-path)
35+
(spit target-path
36+
(str (str/join "\t" source-columns) "\n"
37+
(str/join "\n" (map #(select-row indexes %) selected))
38+
"\n"))))
39+
40+
(println target-path)
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
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

Comments
 (0)