From a29b511dc90900ffcc297aaf8d88d6b1e015c8bc Mon Sep 17 00:00:00 2001
From: STEVAN Antoine <antoine.stevan@isae-supaero.fr>
Date: Tue, 28 May 2024 14:06:22 +0000
Subject: [PATCH] include the standard deviation of "inbreeding" measurements
 (dragoon/komodo!119)

this adds `$.diversity.e` to the output of `inbreeding load` and input of `inbreeding plot` to show errors bars in the final plot.

these can be discarded by running something similar to
```bash
inbreeding load $experiment
    | reject diversity.e
    | inbreeding plot --options { k: $OPTS.k }
```
---
 bins/inbreeding/load.nu | 8 +++++---
 bins/inbreeding/plot.nu | 6 +-----
 2 files changed, 6 insertions(+), 8 deletions(-)

diff --git a/bins/inbreeding/load.nu b/bins/inbreeding/load.nu
index 7f79a949..b0437ca6 100644
--- a/bins/inbreeding/load.nu
+++ b/bins/inbreeding/load.nu
@@ -13,7 +13,7 @@ def get-experiments []: nothing -> list<string> {
 
 export def main [
     experiment: string@get-experiments, # something of the form '<seed>-<env>'
-]: nothing -> table<strategy: string, diversity: table<x: int, y: float>> {
+]: nothing -> table<strategy: string, diversity: table<x: int, y: float, e: float>> {
     let exp = $experiment | parse "{seed}-{env}" | into record
     if $exp == {} {
         error throw {
@@ -46,8 +46,10 @@ export def main [
                 | parse "{x}, {y}"
                 | into float y
                 | group-by x --to-table
-                | update items { get y | math avg }
-                | rename --column { group: "x", items: "y" }
+                | insert y { get items.y | math avg }
+                | insert e { get items.y | math stddev }
+                | rename --column { group: "x" }
+                | reject items
                 | into int x # NOTE: $.x needs to be converted to int here because
                              # `group-by --to-table` converts the grouping key to
                              # string
diff --git a/bins/inbreeding/plot.nu b/bins/inbreeding/plot.nu
index 11ca0f71..cd2bcddf 100644
--- a/bins/inbreeding/plot.nu
+++ b/bins/inbreeding/plot.nu
@@ -43,7 +43,7 @@ def get-color []: int -> string {
 export def main [
     --save: path,
     --options: record<k: int>
-]: table<strategy: string, diversity: table<x: int, y: float>> -> nothing {
+]: table<strategy: string, diversity: table<x: int, y: float, e: float>> -> nothing {
     let data = $in
     let l = $data.diversity.0 | length
 
@@ -71,10 +71,6 @@ export def main [
                 "double" => $"($it.strategy.p)? ($it.strategy.n) ; ($it.strategy.m)"
             }
         }
-        | update diversity {|it|
-            let l = $it.diversity | length
-            $it.diversity | insert e 0 | rename --column { t: "x", diversity: "y" }
-        }
         | rename --column { diversity: "points" }
         | insert style {|it|
             let color = match $it.strategy.type {
-- 
GitLab