cellmil.statistics

class cellmil.statistics.StatsPrinter(config: StatsPrinterConfig)[source]

Bases: object

FEATURES_KEY = 'FEATURES'
GNNS_KEY = 'GNNs'
MILS_KEY = 'MILs'
GNN_KEY = 'GNN'
MIL_KEY = 'MIL'
COLUMN_EXPERIMENT_ID = 'EXPERIMENT_ID'
COLUMN_TASK = 'TASK'
METRICS = ['f1', 'recall', 'precision', 'auroc']
__init__(config: StatsPrinterConfig)[source]
_get_run_config(experiment_id: str) dict[str, int][source]

Get the run configuration associated with a given experiment ID as one-hot encoded features. Excludes base configuration options.

Parameters:

experiment_id – The ID of the experiment

Returns:

A dictionary with one-hot encoded columns for each configuration option (excluding base config)

_fit_frequentist_models(metric: str, config_columns: list[str]) dict[str, dict[str, Any]][source]

Fit frequentist Linear Mixed Effects models for each task.

Parameters:

config_columns – List of configuration column names

Returns:

Dictionary mapping task names to their model results

_fit_bayesian_models(metric: str, config_columns: list[str]) dict[str, dict[str, Any]][source]

Fit Bayesian hierarchical models for each task using Bambi.

Parameters:

config_columns – List of configuration column names

Returns:

Dictionary mapping task names to their model results

create(metric: str)[source]

Perform both frequentist and Bayesian analyses, then generate a comprehensive report.

_generate_report(metric: str, config_columns: list[str], frequentist_results: dict[str, dict[str, Any]], bayesian_results: dict[str, dict[str, Any]]) str[source]

Generate a comprehensive markdown report with both frequentist and Bayesian results.

Parameters:
  • config_columns – List of configuration column names

  • frequentist_results – Results from frequentist LME models

  • bayesian_results – Results from Bayesian hierarchical models

Returns:

Complete markdown report as a string

_format_frequentist_results(metric: str, result: dict[str, Any]) list[str][source]

Format frequentist LME results for the markdown report.

_format_bayesian_results(result: dict[str, Any]) list[str][source]

Format Bayesian hierarchical model results for the markdown report.

_generate_pdf_from_markdown(markdown_content: str, output_file: str)[source]

Convert markdown content to PDF using markdown_it and weasyprint.

Parameters:
  • markdown_content – The markdown text to convert

  • output_file – Path to the output PDF file

Modules