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

Analysis refactor #36

Merged
merged 8 commits into from
Jan 7, 2025
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 scripts/dir_exp_analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,3 @@ def main(output_path: str):

if __name__ == "__main__":
CLI(main)
CLI(main)
2 changes: 1 addition & 1 deletion scripts/experiment_analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
plot_vectors,
single_model_analysis,
)
from arc_spice.eval.analysis_utils import brier_score
from arc_spice.analysis.utils import brier_score


def main(
Expand Down
42 changes: 2 additions & 40 deletions scripts/propagation_analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,7 @@

from jsonargparse import CLI

from arc_spice.eval.analysis_utils import (
collect_pipeline_dict,
exp_analysis,
test_train_split_res,
)
from arc_spice.eval.prop_models import (
eval_lin_models,
eval_mult_prop,
fit_uncertainty_model,
)
from arc_spice.utils import open_json_path
from arc_spice.analysis.analysis_functions import propagation_analysis


def main(experiment_path: str):
Expand All @@ -26,35 +16,7 @@ def main(experiment_path: str):
Args:
experiment_path: path experiment directory
"""
model_keys = ["ocr", "translator", "classifier"]

# collect and collate results
pipeline_results = open_json_path(f"{experiment_path}/full_pipeline.json")
pipe_results = collect_pipeline_dict(pipeline_results)

# no model results, rename keys
no_mod_res = exp_analysis(pipe_results, model_keys)
no_mod_res["recognition"] = no_mod_res.pop("ocr")
no_mod_res["translation"] = no_mod_res.pop("translator")
no_mod_res["classification"] = no_mod_res.pop("classifier")

# multplication model resuls
multi_mod_res = eval_mult_prop(pipe_results)

# fitted model results
train_res, test_res = test_train_split_res(pipe_results)
fitted_uq_models = fit_uncertainty_model(train_res)
fit_mod_res = eval_lin_models(fitted_uq_models, test_res)

# collate results
out_res = {}
for key, itm in fit_mod_res.items():
out_res[key] = {
"no_model": no_mod_res[key],
"mult_model": multi_mod_res[key],
"fitted_model": itm,
}

out_res = propagation_analysis(experiment_path)
# save results
with open(f"{experiment_path}/prop_model_analysis.json", "w") as save_file:
json.dump(out_res, save_file, indent=2)
Expand Down
60 changes: 54 additions & 6 deletions src/arc_spice/analysis/analysis_functions.py
J-Dymond marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -1,11 +1,60 @@
import matplotlib.pyplot as plt
import numpy as np

from arc_spice.analysis.utils import fitted_lin_model, multiplication_prop
from arc_spice.eval.analysis_utils import exp_analysis, exp_vectors
from arc_spice.analysis.prop_models import (
eval_lin_models,
eval_mult_prop,
fit_uncertainty_model,
fitted_lin_model,
multiplication_prop,
)
from arc_spice.analysis.utils import (
collect_pipeline_dict,
exp_analysis,
exp_vectors,
test_train_split_res,
)
from arc_spice.utils import open_json_path


def propagation_analysis(experiment_path: str):
"""Run analysis of a given pipeline experiment using the different propagation
models

Args:
experiment_path: path experiment directory
"""
model_keys = ["ocr", "translator", "classifier"]

# collect and collate results
pipeline_results = open_json_path(f"{experiment_path}/full_pipeline.json")
pipe_results = collect_pipeline_dict(pipeline_results)

# no model results, rename keys
no_mod_res = exp_analysis(pipe_results, model_keys)
no_mod_res["recognition"] = no_mod_res.pop("ocr")
no_mod_res["translation"] = no_mod_res.pop("translator")
no_mod_res["classification"] = no_mod_res.pop("classifier")

# multplication model resuls
multi_mod_res = eval_mult_prop(pipe_results)

# fitted model results
train_res, test_res = test_train_split_res(pipe_results)
fitted_uq_models = fit_uncertainty_model(train_res)
fit_mod_res = eval_lin_models(fitted_uq_models, test_res)

# collate results
out_res = {}
for key, itm in fit_mod_res.items():
out_res[key] = {
"no_model": no_mod_res[key],
"mult_model": multi_mod_res[key],
"fitted_model": itm,
}
return out_res


def single_model_analysis(
experiment_path: str,
):
Expand Down Expand Up @@ -108,6 +157,7 @@ def plot_vectors(
plt.legend()
plt.xlim(0, 1)
plt.savefig(f"{save_directory}/figures/recognition_confidence_histogram.pdf")
plt.close()

# Translation
fig, (ax1, ax2) = plt.subplots(2, 1, figsize=(8, 12))
Expand Down Expand Up @@ -208,6 +258,7 @@ def plot_vectors(
ax1.set_xlim(0, 1)
ax2.set_xlim(0, 1)
plt.savefig(f"{save_directory}/figures/translation_confidence_histogram.pdf")
plt.close()

fig, (ax1, ax2) = plt.subplots(2, 1, figsize=(8, 12))

Expand Down Expand Up @@ -290,7 +341,4 @@ def plot_vectors(
ax1.set_xlim(0, 1)
ax2.set_xlim(0, 1)
plt.savefig(f"{save_directory}/figures/classification_confidence_histogram.pdf")

ax1.set_xlim(0, 1)
ax2.set_xlim(0, 1)
plt.savefig(f"{save_directory}/figures/classification_confidence_histogram.pdf")
plt.close()
Loading
Loading