---
title: "ani_sm"
output: html_document
date: '2023-05-24'
---

```{r lib}
library(ggplot2)
library(dplyr)
library(tidyr)
```

```{r setwd}
setwd('~/git/dashing2-experiments/jirange/vs_sm')
```

```{r cars}
dft <- read.csv('results.csv', header=T)
stopifnot(nrow(dft) > 0)
```

```{r pivot}
df <- dft %>% pivot_longer(cols=c('sm_ani', 'd2_ani', 'd2f_ani', 'd2w_ani'))
df$diff <- df$value - df$fastani_ani
df$anibin <- as.integer((df$fastani_ani - 1e-9)*20)
df$anibin <- pmax(df$anibin, 16)
```

```{r ani_violin}
ggplot(df, aes(y=diff, x=name, color=name)) + geom_violin() + theme_bw() + facet_wrap(~anibin, scales='free')
```

```{r plot}
ggplot(df, aes(x=fastani_ani, y=value, color=name)) + geom_point() + theme_bw()
```

```{r plot_diff}
ggplot(df %>% filter(diff^2 > 0.1), aes(x=fastani_ani, y=I(diff^2), color=name)) + geom_point() + theme_bw()
```
```{r sse}
df %>% group_by(k, name, anibin) %>% 
  summarise(sse=sum(diff ^ 2), n=n()) %>% 
  mutate(anibin=ifelse(anibin <= 16, "<=85%", paste0((anibin)*5, "--", (anibin+1)*5, "%"))) %>%
  pivot_wider(values_from=sse)
```
```{r violin}
ggplot(df %>% filter(diff > -0.1), aes(x=name, y=diff, color=name)) + geom_violin() + theme_bw()
```
