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

Adding median statistics #106

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ repos:
- --unsafe
- id: trailing-whitespace
- repo: https://github.com/psf/black
rev: 23.9.1
rev: 23.10.0
hooks:
- id: black
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.0.292
rev: v0.1.0
hooks:
- id: ruff
args: ["--fix"]
Expand Down
7 changes: 7 additions & 0 deletions src/chainconsumer/analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ def __init__(self, parent: ChainConsumer):
SummaryStatistic.MEAN: self.get_parameter_summary_mean,
SummaryStatistic.CUMULATIVE: self.get_parameter_summary_cumulative,
SummaryStatistic.MAX_CENTRAL: self.get_parameter_summary_max_central,
SummaryStatistic.MEDIAN: self.get_parameter_summary_median,
}

def get_latex_table(
Expand Down Expand Up @@ -465,6 +466,12 @@ def get_parameter_summary_max_central(self, chain, parameter):

return Bound(lower=xvals[0], center=x, upper=xvals[1])

def get_parameter_summary_median(self, chain, parameter):
vals = 100 * np.array([0.5 - 0.5 * chain.summary_area, 0.5, 0.5 + 0.5 * chain.summary_area])
xvals = np.percentile(chain.get_data(parameter), vals)

return Bound(lower=xvals[0], center=xvals[1], upper=xvals[2])


if __name__ == "__main__":
from .chainconsumer import ChainConsumer
4 changes: 4 additions & 0 deletions src/chainconsumer/statistics.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,7 @@ class SummaryStatistic(Enum):
MEAN = "mean"
"""As per the cumulative method, except the central value is placed in the midpoint between
the upper and lower boundary. Not recommended, but was requested."""

MEDIAN = "median"
"""The central point is set to median of the pdf, and the upper and the upper
and lower bounds are determined by the percentiles of the pdf."""