Skip to content

Commit

Permalink
Fixed issue with max_prob parameter in plot_posterior
Browse files Browse the repository at this point in the history
  • Loading branch information
tomasstolker committed Mar 7, 2024
1 parent f0e46a2 commit c897514
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions species/plot/plot_mcmc.py
Original file line number Diff line number Diff line change
Expand Up @@ -472,8 +472,6 @@ def plot_posterior(
samples[:, param_index] *= 1e3 # (um) -> (nm)

if box.prob_sample is not None:
par_val = tuple(box.prob_sample.values())

print("\nSample with highest probability:")
for key, value in box.prob_sample.items():
print(f" - {key} = {value:.2e}")
Expand Down Expand Up @@ -700,7 +698,11 @@ def plot_posterior(

# Remove abundances

if not inc_abund and box.attributes["chemistry"] == "free":
if (
not inc_abund
and "chemistry" in box.attributes
and box.attributes["chemistry"] == "free"
):
index_del = []
item_del = []

Expand Down Expand Up @@ -749,6 +751,12 @@ def plot_posterior(

samples = samples.reshape((-1, ndim))

# Get parameter values of maximum likelihood

if max_prob:
max_idx = np.argmax(box.ln_prob)
max_sample = samples[max_idx, :]

if isinstance(title_fmt, list) and len(title_fmt) != ndim:
raise ValueError(
f"The number of items in the list of 'title_fmt' ({len(title_fmt)}) is "
Expand Down Expand Up @@ -855,12 +863,12 @@ def plot_posterior(
ax.set_xlim(limits[j])

if max_prob:
ax.axvline(par_val[j], color="tomato")
ax.axvline(max_sample[j], color="tomato")

if i > j:
if max_prob:
ax.axhline(par_val[i], color="tomato")
ax.plot(par_val[j], par_val[i], "s", color="tomato")
ax.axhline(max_sample[i], color="tomato")
ax.plot(max_sample[j], max_sample[i], "s", color="tomato")

if limits is not None:
ax.set_ylim(limits[i])
Expand Down

0 comments on commit c897514

Please sign in to comment.