diff --git a/bins/inbreeding/README.md b/bins/inbreeding/README.md index 32e32cac20b9bf4f710cc1b73c6f529c0b5d79e7..cb18b6b1b09f537741247fd1b46b7b6592197adb 100644 --- a/bins/inbreeding/README.md +++ b/bins/inbreeding/README.md @@ -3,53 +3,5 @@ - plot the results with [`inbreeding plot`](./src/.nushell/plot.nu) # Example -```bash -use ./bins/inbreeding -``` -```bash -const PRNG_SEED = "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff" -const OPTS = { - nb_bytes: (10 * 1_024), - k: 10, - n: 20, - nb_measurements: 10, - nb_scenarii: 100, - measurement_schedule: 1, - measurement_schedule_start: 0, - max_t: 150, - strategies: [ - "single:1", - "double:0.5:1:2", - "single:2" - "double:0.5:2:3", - "single:3" - "single:5", - "single:10", - ], - environment: "fixed:0", -} -``` -```bash -inbreeding build -``` -```bash -inbreeding run --options $OPTS --prng-seed $PRNG_SEED -``` -```bash -let experiment = $"($PRNG_SEED)-($OPTS.environment)-($OPTS.k)-($OPTS.n)-($OPTS.nb_bytes)" -inbreeding load $experiment | inbreeding plot -``` - -## plot all experiments -```bash -use bins/inbreeding/src/.nushell/consts.nu CACHE -use bins/inbreeding - -const FIGURES_DIR = ($CACHE | path join figures) - -mkdir $FIGURES_DIR - -for exp in (inbreeding list) { - inbreeding load $exp | inbreeding plot --save ($FIGURES_DIR | path join $exp) -} -``` +see [run](scripts/run.nu) +see [plot](scripts/plot.nu) diff --git a/bins/inbreeding/scripts/plot.nu b/bins/inbreeding/scripts/plot.nu new file mode 100644 index 0000000000000000000000000000000000000000..335746c281ba4c60243a13134b6faed7d6d8c5c9 --- /dev/null +++ b/bins/inbreeding/scripts/plot.nu @@ -0,0 +1,11 @@ +use ../src/.nushell/consts.nu CACHE +use ../ + +const FIGURES_DIR = ($CACHE | path join figures) + +mkdir $FIGURES_DIR + +for exp in (inbreeding list) { + let img = $FIGURES_DIR | path join $exp | path parse --extension '' | update extension "png" | path join + inbreeding load $exp | inbreeding plot --save $img +} diff --git a/bins/inbreeding/scripts/run.nu b/bins/inbreeding/scripts/run.nu new file mode 100644 index 0000000000000000000000000000000000000000..aac3c5865b79c015aa43fc30b100b7e81d2a10e8 --- /dev/null +++ b/bins/inbreeding/scripts/run.nu @@ -0,0 +1,57 @@ +use ../ + +const OPTS = { + nb_bytes: (10 * 1_024), + k: 10, + n: null, + nb_measurements: 100, + nb_scenarii: 100, + measurement_schedule: 1, + measurement_schedule_start: 0, + max_t: 150, + strategies: [ + "single:1", + "single:2", + "single:3" + "single:4" + "single:5", + "single:6", + "single:7", + "single:8", + "single:9", + "single:10", + ], + environment: null, +} + +const RHOS = [ (1 / 2), (1 / 3), (1 / 5), (1 / 10) ] + +const ENVS = [ + "fixed:0", + "random-fixed:0.1:1", + "random-fixed:0.2:1", + "random-fixed:0.3:1", + "random-fixed:0.4:1", + "random-fixed:0.5:1", + "random-fixed:0.6:1", + "random-fixed:0.7:1", + "random-fixed:0.8:1", + "random-fixed:0.9:1", + "fixed:1", +] + +def prod [a: list, b: list]: [ nothing -> list<list> ] { + $a | each { |ia| $b | each { |ib| [$ia, $ib] }} | flatten +} + +def main [ + --nb-threads: int = 8, + --prng-seed: string = "0000000000000000000000000000000000000000000000000000000000000000", +] { + inbreeding build + + prod $RHOS $ENVS | par-each --threads $nb_threads { |exp| + let opts = $OPTS | update n ($OPTS.k / $exp.0 | math round --precision 0) | update environment $exp.1 + inbreeding run --options $opts --prng-seed $prng_seed + } +} diff --git a/bins/inbreeding/scripts/show.nu b/bins/inbreeding/scripts/show.nu new file mode 100644 index 0000000000000000000000000000000000000000..15e22d991131f575ed05611f6a5651a9d2ae9f9b --- /dev/null +++ b/bins/inbreeding/scripts/show.nu @@ -0,0 +1,55 @@ +use ../src/.nushell/consts.nu CACHE +use ../src/.nushell/path.nu [ "remove-cache-prefix" ] +use ../src/.nushell/parse.nu [ "parse full-experiment" ] + +const SEED = "b239e48345ac457b492cc164f58c010d07292c88e4791e607d91796baec7f334" +let k = 10 + +# # Example +# ``nushell +# # sort files based on their file extensions +# ls | where type == file | sort-by-closure { get name | path parse | get extension } +# `` +# --- +# `` +# ─┬─────────────────── +# 0│LICENSE +# 1│Cargo.lock +# 2│CODE_OF_CONDUCT.md +# 3│CONTRIBUTING.md +# 4│README.md +# 5│toolkit.nu +# 6│Cargo.toml +# 7│Cross.toml +# 8│rust-toolchain.toml +# 9│typos.toml +# ─┴─────────────────── +# `` +def sort-by-closure [key: closure]: list -> list { + insert __key__ { do $key $in } | sort-by __key__ | reject __key__ +} + +def show [x: string] { + $CACHE + | path join figures $"($SEED)-($x).png" + | into glob + | ls $in + | sort-by-closure { + get name + | remove-cache-prefix + | path parse --extension 'png' + | reject extension + | path join + | parse full-experiment + | get n + } + | feh ...$in.name +} + +show $"fixed:0-($k)-*-*" +show $"random-fixed:0.5:1-($k)-*-*" +show $"fixed:1-($k)-*-*" +show $"*-($k)-20-*" +show $"*-($k)-30-*" +show $"*-($k)-50-*" +show $"*-($k)-100-*"