@@ -2,6 +2,84 @@ using Statistics
22using StatsBase
33
44
5+ """
6+ Bounds given metric between -1.0 and 1.0, where 1.0 is perfect fit.
7+
8+ Suitable for use with any metric that ranges from 1 to -∞.
9+
10+ # References
11+ 1. Mathevet, T., Michel, C., Andréassian, V., Perrin, C., 2006.
12+ A bounded version of the Nash-Sutcliffe criterion for better model
13+ assessment on large sets of basins.
14+ IAHS-AISH Publication 307, 211–219.
15+ https://iahs.info/uploads/dms/13614.21--211-219-41-MATHEVET.pdf
16+
17+ # Example
18+ ```julia
19+ julia> import Streamfall: @bound, KGE
20+ julia> @bound KGE([1,2], [3,2])
21+ -0.35653767993482094
22+ ```
23+ """
24+ macro bound (metric)
25+ tmp = :($ metric)
26+ return :($ tmp / (2.0 - $ tmp))
27+ end
28+
29+
30+ """
31+ Normalizes given metric between 0.0 and +∞, where 0.0 is perfect fit.
32+
33+ Suitable for use with any metric that ranges from 1 to -∞.
34+
35+ # References
36+ 1. Nossent, J., Bauwens, W., 2012.
37+ Application of a normalized Nash-Sutcliffe efficiency to improve the
38+ accuracy of the Sobol’ sensitivity analysis of a hydrological model.
39+ EGU General Assembly Conference Abstracts 237.
40+
41+ # Example
42+ ```julia
43+ julia> import Streamfall: @normalize, KGE
44+ julia> @normalize KGE([1,2], [3,2])
45+ 0.1111111111111111
46+ ```
47+ """
48+ macro normalize (metric)
49+ return :(1.0 / (2.0 - $ metric))
50+ end
51+
52+
53+ """
54+ Applies mean inverse approach to a metric.
55+
56+ Suitable for use with any metric that ranges from 1 to -∞.
57+
58+ If using with other macros such as `@normalize` or `@bound`,
59+ these must come first.
60+
61+ # References
62+ 1. Garcia, F., Folton, N., Oudin, L., 2017.
63+ Which objective function to calibrate rainfall–runoff
64+ models for low-flow index simulations?
65+ Hydrological Sciences Journal 62, 1149–1166.
66+ https://doi.org/10.1080/02626667.2017.1308511
67+
68+ # Example
69+ ```julia
70+ julia> import Streamfall: @normalize, @mean_inverse, KGE
71+ julia> @normalize @mean_inverse KGE [1,2] [3,2]
72+ 0.3193505947991363
73+ ```
74+ """
75+ macro mean_inverse (metric, obs, sim)
76+ obj, o, s = eval (metric), eval (obs), eval (sim)
77+ q = obj (o, s)
78+ q2 = obj (1.0 ./ o, 1.0 ./ s)
79+ return mean ([q, q2])
80+ end
81+
82+
583""" The Nash-Sutcliffe Efficiency score"""
684NSE (obs, sim) = 1.0 - sum ((obs .- sim). ^ 2 ) / sum ((obs .- mean (obs)). ^ 2 )
785
@@ -182,7 +260,7 @@ Also known as KGE prime (KGE').
182260# Arguments
183261- `obs::Vector`: observations
184262- `sim::Vector` : modeled results
185- - `scaling::Tuple` : scaling factors in order of timing (r), magnitude (β), variability (γ).
263+ - `scaling::Tuple` : scaling factors in order of timing (r), magnitude (β), variability (γ).
186264 Defaults to (1,1,1).
187265
188266# References
@@ -274,7 +352,7 @@ mean_NmKGE(obs, sim; scaling=nothing) = mean([Streamfall.NmKGE(obs, sim; scaling
274352
275353# Arguments
276354- `obs::Vector` : observations
277- - `sim::Vector` : modeled
355+ - `sim::Vector` : modeled
278356- `scaling::Tuple` : scaling factors for timing (s), variability (α), magnitude (β)
279357
280358# References
0 commit comments