Skip to content

Commit

Permalink
Cleaning up docstrings for evaluation metrics.
Browse files Browse the repository at this point in the history
  • Loading branch information
drewoldag committed Nov 17, 2023
1 parent 7c827bd commit 9c32c8a
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 25 deletions.
8 changes: 4 additions & 4 deletions src/rail/evaluation/evaluator.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
"""
" Abstract base class defining an Evaluator
Abstract base class defining an Evaluator
The key feature is that the evaluate method.
"""

import numpy as np

from ceci.config import StageParameter as Param
from qp.metrics.pit import PIT
from rail.core.data import Hdf5Handle, QPHandle
from rail.core.stage import RailStage
from rail.core.common_params import SHARED_PARAMS

from rail.evaluation.metrics.cdeloss import CDELoss
from qp.metrics.pit import PIT
from rail.evaluation.metrics.pointestimates import PointSigmaIQR, PointBias, PointOutlierRate, PointSigmaMAD


Expand Down Expand Up @@ -112,7 +111,8 @@ def run(self):
else:
out_table[f'PIT_{pit_metric}_stat'] = [getattr(value, 'statistic', None)]
out_table[f'PIT_{pit_metric}_pval'] = [getattr(value, 'p_value', None)]
out_table[f'PIT_{pit_metric}_significance_level'] = [getattr(value, 'significance_level', None)]
out_table[f'PIT_{pit_metric}_significance_level'] = \
[getattr(value, 'significance_level', None)]

POINT_METRICS = dict(SimgaIQR=PointSigmaIQR,
Bias=PointBias,
Expand Down
46 changes: 26 additions & 20 deletions src/rail/evaluation/metrics/pointestimates.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,21 @@ class PointStatsEz(MetricEvaluator):
magnitude."""

def __init__(self, pzvec, szvec):
"""An object that takes in the vectors of the point photo-z
""" An object that takes in the vectors of the point photo-z
the spec-z, and the i-band magnitudes for calculating the
point statistics
Parameters:
pzvec: Numpy 1d array of the point photo-z values
szvec: Numpy 1d array of the spec-z values
magvec: Numpy 1d array of the i-band magnitudes
imagcut: float: i-band magnitude cut for the sample
Calculates:
ez: (pz-sz)/(1+sz), the quantity will be useful for
calculating statistics
ez = (pz - sz) / (1 + sz), the quantity will be useful for calculating
statistics
Parameters
----------
pzvec : ndarray
Array of the point photo-z values
szvec : ndarray
array of the spec-z values
"""
super().__init__(None)
self.pzs = pzvec
Expand All @@ -36,11 +40,10 @@ class PointSigmaIQR(PointStatsEz):
def evaluate(self):
"""Calculate the width of the e_z distribution
using the Interquartile range
Parameters:
imagcut: float: i-band magnitude cut for the sample
Returns:
sigma_IQR float: width of ez distribution for full sample
sigma_IQR_magcut float: width of ez distribution for magcut sample
Returns
-------
``sigma_IQR`` float. Width of ez distribution for full sample
"""
x75, x25 = np.percentile(self.ez, [75., 25.])
iqr = x75 - x25
Expand All @@ -55,8 +58,9 @@ class PointBias(PointStatsEz):
"""
def evaluate(self):
"""
Returns:
bias: median of the full ez sample
Returns
-------
``bias`` ndarray. Median of the full ez sample
"""
return np.median(self.ez)

Expand All @@ -70,14 +74,15 @@ class PointOutlierRate(PointStatsEz):

def evaluate(self):
"""
Returns:
frac: fraction of catastrophic outliers for full sample
Returns
-------
``frac`` float. Fraction of catastrophic outliers for full sample
"""
num = len(self.ez)
sig_iqr = PointSigmaIQR(self.pzs, self.szs).evaluate()
threesig = 3.0 * sig_iqr
cutcriterion = np.maximum(0.06, threesig)
mask = (np.fabs(self.ez) > cutcriterion)
mask = np.fabs(self.ez) > cutcriterion
outlier = np.sum(mask)
frac = float(outlier) / float(num)
return frac
Expand All @@ -91,8 +96,9 @@ class PointSigmaMAD(PointStatsEz):

def evaluate(self):
"""
Returns:
sigma_mad: sigma_MAD for full sample
Returns
-------
``sigma_mad`` float. Sigma median absolute deviation for full sample.
"""
tmpmed = np.median(self.ez)
tmpx = np.fabs(self.ez - tmpmed)
Expand Down
2 changes: 1 addition & 1 deletion src/rail/evaluation/stats_groups.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""Tuples that capture standard statisical quantities """
"""Tuples that capture standard statistical quantities """

from collections import namedtuple

Expand Down

0 comments on commit 9c32c8a

Please sign in to comment.