• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

nz-gravity / LogPSplinePSD / 17934599025

23 Sep 2025 03:07AM UTC coverage: 86.608% (+2.6%) from 83.977%
17934599025

push

github

avivajpeyi
remove sparcity comments

274 of 308 branches covered (88.96%)

Branch coverage included in aggregate %.

2274 of 2634 relevant lines covered (86.33%)

1.73 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

95.12
/src/log_psplines/plotting/diagnostics.py
1
import arviz as az
2✔
2
import matplotlib.pyplot as plt
2✔
3
import numpy as np
2✔
4

5

6
def plot_diagnostics(
2✔
7
    idata: az.InferenceData,
8
    outdir: str,
9
    # variables: list = ["phi", "delta", "weights"],
10
    figsize: tuple = (12, 8),
11
) -> None:
12
    """
13
    Plot MCMC diagnostics using arviz.
14

15
    Parameters
16
    ----------
17
    idata : az.InferenceData
18
        Inference data from adaptive MCMC
19
    variables : list
20
        Variables to plot
21
    figsize : tuple
22
        Figure size
23
    """
24

25
    try:
2✔
26

27
        # Trace plots
28
        az.plot_trace(idata, figsize=figsize) #, var_names=variables)
2✔
29
        plt.suptitle("Trace plots - Adaptive MCMC")
2✔
30
        plt.tight_layout()
2✔
31
        plt.savefig(f"{outdir}/trace_plots.png")
2✔
32

33
        # Acceptance rate plot
34
        if "acceptance_rate" in idata.sample_stats:
2✔
35
            fig, ax = plt.subplots(figsize=(10, 4))
2✔
36
            accept_rates = idata.sample_stats.acceptance_rate.values.flatten()
2✔
37
            ax.plot(accept_rates, alpha=0.7)
2✔
38
            ax.axhline(
2✔
39
                idata.attrs.get("target_accept_rate", 0.44),
40
                color="red",
41
                linestyle="--",
42
                label="Target",
43
            )
44
            ax.set_xlabel("Iteration")
2✔
45
            ax.set_ylabel("Acceptance Rate")
2✔
46
            ax.set_title("Acceptance Rate Over Time")
2✔
47
            ax.legend()
2✔
48
            ax.grid(True, alpha=0.3)
2✔
49
            plt.tight_layout()
2✔
50
            plt.savefig(f"{outdir}/acceptance_rate.png")
2✔
51

52
        # Step size evolution
53
        if "step_size_mean" in idata.sample_stats:
2✔
54
            fig, (ax1, ax2) = plt.subplots(1, 2, figsize=(12, 4))
2✔
55

56
            step_means = idata.sample_stats.step_size_mean.values.flatten()
2✔
57
            step_stds = idata.sample_stats.step_size_std.values.flatten()
2✔
58

59
            ax1.plot(step_means, alpha=0.7)
2✔
60
            ax1.set_xlabel("Iteration")
2✔
61
            ax1.set_ylabel("Mean Step Size")
2✔
62
            ax1.set_title("Step Size Evolution")
2✔
63
            ax1.grid(True, alpha=0.3)
2✔
64

65
            ax2.plot(step_stds, alpha=0.7, color="orange")
2✔
66
            ax2.set_xlabel("Iteration")
2✔
67
            ax2.set_ylabel("Step Size Std")
2✔
68
            ax2.set_title("Step Size Variability")
2✔
69
            ax2.grid(True, alpha=0.3)
2✔
70

71
            plt.tight_layout()
2✔
72
            plt.savefig(f"{outdir}/step_size_evolution.png")
2✔
73

74
    except Exception as e:
×
75
        print(f"Error generating adaptive MCMC diagnostics: {e}")
×
76

77

78
    # NUTS-specific plots
79
    ## ... unsure what diagnostics we should add...
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc