Skip to content
Snippets Groups Projects
Commit ff5752a1 authored by STEVAN Antoine's avatar STEVAN Antoine :crab:
Browse files

move "inbreeding" snippets from README to real scripts (dragoon/komodo!148)

parent 447e4473
No related branches found
No related tags found
1 merge request!148move "inbreeding" snippets from README to real scripts
Pipeline #5427 passed with stages
in 2 minutes and 45 seconds
...@@ -3,53 +3,5 @@ ...@@ -3,53 +3,5 @@
- plot the results with [`inbreeding plot`](./src/.nushell/plot.nu) - plot the results with [`inbreeding plot`](./src/.nushell/plot.nu)
# Example # Example
```bash see [run](scripts/run.nu)
use ./bins/inbreeding see [plot](scripts/plot.nu)
```
```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)
}
```
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
}
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
}
}
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-*"
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment