Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add number of failed states metric to comparative analysis board (Fixes #43) #69

Merged
merged 6 commits into from
Mar 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion covid19_drdfm/streamlit/Dashboard.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# TODO: Fix Dashboard to use h5ad file
import json
import time
from pathlib import Path
Expand Down
37 changes: 28 additions & 9 deletions covid19_drdfm/streamlit/pages/2_Comparative_Run_Analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import arviz as az
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
import plotly.io as pio
import plotly_express as px
import pymc as pm
Expand All @@ -15,14 +16,15 @@


def center_title(text):
return st.markdown(f"<h1 style='text-align: center; color: grey;'>{text}</h1>", unsafe_allow_html=True)
txt = f"<h1 style='text-align: center; color: grey;'>{text}</h1>"
return st.markdown(txt, unsafe_allow_html=True)


center_title("Comparative Run Analysis")

# Parameter to runs
path_to_results = Path(st.text_input("Path directory of runs", value="./covid19_drdfm/data/example-data"))
df = parse_multiple_runs(path_to_results)
run_dir = Path(st.text_input("Path directory of runs", value="./covid19_drdfm/data/example-data"))
df = parse_multiple_runs(run_dir)


def create_plot(df):
Expand Down Expand Up @@ -54,15 +56,32 @@ def create_plot(df):
return metric


def get_summary(df):
def num_failures(run_dir: Path, run_name: str):
"""Count the number of failed states for a specific run"""
failed_file_path = run_dir / run_name / "failed.txt"
if not failed_file_path.exists():
return 0
with open(failed_file_path) as failed_file:
return len(failed_file.readlines())


def delta_failures(run_dir: Path, run_name: str):
"""Calculate deviation from the run with the least failed states"""
min_failures = min([num_failures(run_dir, run_name) for run_name in run_dir.iterdir()])
return min_failures - num_failures(run_dir, run_name)


def get_summary(df: pd.DataFrame):
# Median metrics
col1, col2, col3 = st.columns(3)
col1.metric("Median Log Likelihood", df["Log Likelihood"].median())
col2.metric("Median AIC", df["AIC"].median())
col3.metric("Median EM Iterations", df["EM Iterations"].median())
run_name = df.Run.iloc[0]
col1, col2, col3, col4 = st.columns(4)
col1.metric("Number of Failed States", num_failures(run_dir, run_name), delta_failures(run_dir, run_name))
col2.metric("Median Log Likelihood", df["Log Likelihood"].median())
col3.metric("Median AIC", df["AIC"].median())
col4.metric("Median EM Iterations", df["EM Iterations"].median())


def show_summary(df):
def show_summary(df: pd.DataFrame):
run = st.selectbox("Select a run", df["Run"].unique())
filtered_df = df[(df["Run"] == run)]
return get_summary(filtered_df)
Expand Down
Loading