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

Alternative implementation of the scatter index #142

Merged
merged 4 commits into from
Oct 12, 2022
Merged
Changes from 2 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
20 changes: 20 additions & 0 deletions fmskill/metrics.py
Original file line number Diff line number Diff line change
@@ -410,6 +410,26 @@ def si(obs: np.ndarray, model: np.ndarray) -> float:
def scatter_index(obs: np.ndarray, model: np.ndarray) -> float:
"""Scatter index (SI)

Which is the same as the unbiased-RMSE normalized by the absolute mean of the observations.

.. math::
\\frac{ \\sqrt{ \\frac{1}{n} \\sum_{i=1}^n \\left( (model_i - \\overline {model}) - (obs_i - \\overline {obs}) \\right)^2} }
{\\frac{1}{n} \\sum_{i=1}^n | obs_i | }

Range: [0, \\infty); Best: 0
"""
assert obs.size == model.size
if len(obs) == 0:
return np.nan

residual = obs.ravel() - model.ravel()
residual = residual - residual.mean() # unbiased
return np.sqrt(np.mean(residual**2)) / np.mean(np.abs(obs.ravel()))


def scatter_index2(obs: np.ndarray, model: np.ndarray) -> float:
"""Alternative formulation of the scatter index (SI)

.. math::
\\sqrt {\\frac{\\sum_{i=1}^n \\left( (model_i - \\overline {model}) - (obs_i - \\overline {obs}) \\right)^2}
{\\sum_{i=1}^n obs_i^2}}