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

split "inbreeding" load and plot (dragoon/komodo!118)

plotting "inbreeding" results is now done in two steps
- `load` the data from raw experiment files with `inbreeding load`
- `plot` the results by piping this data into `inbreeding plot`
parent bb626120
No related branches found
No related tags found
No related merge requests found
......@@ -34,5 +34,8 @@ inbreeding build
```
```bash
inbreeding run --options $OPTS --prng-seed $PRNG_SEED
inbreeding plot ... --options { k: $OPTS.K }
```
```bash
let experiment = $"($PRNG_SEED)-($OPTS.environment)"
inbreeding load $experiment | inbreeding plot --options { k: $OPTS.k }
```
use consts.nu
def get-experiments []: nothing -> list<string> {
$consts.CACHE
| path join '*' '*' '*'
| into glob
| ls $in
| get name
| path split
| each { last 3 | reject 1 | str join "-" }
| uniq
}
export def main [
experiment: string@get-experiments, # something of the form '<seed>-<env>'
]: nothing -> table<strategy: string, diversity: table<x: int, y: float>> {
let exp = $experiment | parse "{seed}-{env}" | into record
if $exp == {} {
error throw {
err: "invalid experiment",
label: $"should have format '<seed>-<env>', found ($experiment)",
span: (metadata $experiment).span,
}
}
let experiment_path = [$consts.CACHE, $exp.seed, '*', $exp.env, '*' ]
| path join
| into glob
let experiment_files = try {
ls $experiment_path
} catch {
error throw {
err: "invalid experiment",
label: $"experiment '($experiment)' does not appear to have data files",
span: (metadata $experiment).span,
}
}
$experiment_files
| insert strategy { get name | path split | last }
| select name strategy
| insert diversity {
ls $in.name
| each { get name | open | lines }
| flatten
| parse "{x}, {y}"
| into float y
| group-by x --to-table
| update items { get y | math avg }
| rename --column { group: "x", items: "y" }
| into int x # NOTE: $.x needs to be converted to int here because
# `group-by --to-table` converts the grouping key to
# string
}
| reject name
| group-by strategy --to-table
| update items {|it|
let d = $it.items.diversity
$d | skip 1 | reduce --fold $d.0 {|it, acc| $acc | append $it}
}
| rename --column { group: "strategy", items: "diversity" }
}
export use build.nu
export use run.nu
export use load.nu
export use plot.nu
......@@ -3,6 +3,7 @@ use std repeat
use consts.nu
use ../../.nushell/plot.nu gplt
use ../../.nushell/color.nu *
use ../../.nushell/error.nu "error throw"
def "parse strategy" []: string -> record<type: string> {
let s = $in
......@@ -39,41 +40,11 @@ def get-color []: int -> string {
}
}
def get-experiments []: nothing -> list<string> {
$consts.CACHE
| path join '*' '*' '*'
| into glob
| ls $in
| get name
| path split
| each { last 3 | str join "-" }
}
export def main [
experiment: string@get-experiments, # something of the form '<seed>-<timestamp>-<env>'
--save: path,
--options: record<k: int>
] {
let data = [$consts.CACHE, ($experiment | str replace --all '-' (char path_sep)), '*' ]
| path join
| into glob
| ls $in
| insert strategy { get name | path split | last }
| select name strategy
| insert diversity {
ls $in.name
| each { get name | open | lines }
| flatten
| parse "{x}, {y}"
| into float y
| group-by x --to-table
| update items { get y | math avg }
| rename --column { group: "x", items: "y" }
| into int x # NOTE: $.x needs to be converted to int here because
# `group-by --to-table` converts the grouping key to
# string
}
| reject name
]: table<strategy: string, diversity: table<x: int, y: float>> -> nothing {
let data = $in
let l = $data.diversity.0 | length
$data
......
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