Skip to content

Commit 6912e99

Browse files
authored
Merge pull request #11 from JuliaAI/dev
For a 01.1 release
2 parents 1d675b3 + c5488c5 commit 6912e99

File tree

7 files changed

+30
-21
lines changed

7 files changed

+30
-21
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "StatisticalMeasuresBase"
22
uuid = "c062fc1d-0d66-479b-b6ac-8b44719de4cc"
33
authors = ["Anthony D. Blaom <[email protected]>"]
4-
version = "0.1.0"
4+
version = "0.1.1"
55

66
[deps]
77
CategoricalArrays = "324d7699-5711-5eae-9e2f-1d82baa6b597"

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,15 @@ A Julia package for building production-ready measures (metrics) for statistics
77
[![Docs](https://img.shields.io/badge/docs-dev-blue.svg)](https://juliaai.github.io/StatisticalMeasuresBase.jl/dev/)
88

99
Related:
10-
[StatisticalMeasures.jl](https://github.com/JuliaAI/StatisticalMeasures.jl).
10+
[StatisticalMeasures.jl](https://juliaai.github.io/StatisticalMeasures.jl/dev/)
1111

1212

13-
## The main idea
13+
## The main idea
1414

1515
Here's an example of a simple statistical measure that can be applied to a pair of scalars:
1616

1717
```julia
18-
l1(ŷ, y) = abs(ŷ - y)
18+
l1(ŷ, y) = abs(ŷ - y)
1919
y = 5 # ground truth
2020
= 2 # prediction
2121

@@ -55,7 +55,7 @@ julia> multitarget_L1(t̂, t, weights)
5555
39
5656
```
5757

58-
Access per-observation measurements with the `measurement` method:
58+
Generate measurements *for each observation* with the `measurement` method:
5959

6060
```julia
6161
julia> measurements(multitarget_L1, t̂, t, weights)

docs/src/index.md

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
```@raw html
22
<script async defer src="https://buttons.github.io/buttons.js"></script>
3+
4+
<div style="font-size:1.4em;font-weight:bold;">
5+
<a href="tutorial"
6+
style="color: #389826;">Tutorial</a> &nbsp;|&nbsp;
7+
<a href="https://juliaai.github.io/StatisticalMeasuresBase.jl/dev/implementing_new_measures/#definitions"
8+
style="color: #9558B2;">What is a measure?</a>
9+
</div>
10+
311
<span style="color: #9558B2;font-size:4.5em;">
412
StatisticalMeasuresBase.jl</span>
513
<br>
@@ -45,18 +53,12 @@ t̂ = ŷ' |> Tables.table |> Tables.rowtable
4553
multitarget_L1(t̂, t, weights)
4654
```
4755

48-
Access per-observation measurements with the `measurement` method:
56+
Generate measurements *for each observation* with the `measurement` method:
4957

5058
```@example 01
5159
measurements(multitarget_L1, t̂, t, weights)
5260
```
5361

54-
### Quick links
55-
56-
- [Tutorial](@ref), to jump right into building new measures
57-
- [What is a measure?](@ref definitions)
58-
59-
6062
# Overview
6163

6264
This package specifies [an interface](@ref definitions) for statistical measures (metrics)
@@ -74,9 +76,9 @@ Specically, this package provides:
7476
function) that consumes single observations to measures consuming vectors, arrays or
7577
tables (multi-target measures).
7678

77-
- Other [wrappers](@ref wrappers) to add missing value support, argument checks,
78-
direct callability, or to silently treat unsupported weights as uniform (good for
79-
application of a batch of measures with mixed degrees of weight support)
79+
- Other [wrappers](@ref wrappers) to add missing value support, argument checks, or to
80+
silently treat unsupported weights as uniform (good for application of a batch of
81+
measures with mixed degrees of weight support)
8082

8183
- [`measurements`](@ref), a method to return *unaggregated* measurements
8284

src/api.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,9 @@ on data.
1111
1212
# New implementations
1313
14-
Overloading this trait is optional. A fallback returns the aggregated measure, repeated
15-
`n` times, where `n = MLUtils.numobs(y)`. It is not typically necessary to overload
14+
Overloading this function for new measure types is optional. A fallback returns the
15+
aggregated measure, repeated `n` times, where `n = MLUtils.numobs(y)` (which falls back to
16+
`length(y)` if `numobs` is not implemented). It is not typically necessary to overload
1617
`measurements` for wrapped measures. All [`multimeasure`](@ref)s provide the obvious
1718
fallback and other wrappers simply forward the `measurements` method of the atomic
1819
measure. If overloading, use the following signatures:
@@ -24,7 +25,6 @@ measure. If overloading, use the following signatures:
2425
2526
"""
2627
function measurements(measure, yhat, y, args...)
27-
consumes_multiple_observations(measure) || return measure(yhat, y, args...)
2828
m = measure(yhat, y, args...)
2929
fill(m, MLUtils.numobs(y))
3030
end

src/traits.jl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,9 @@ with the same number of observations as `y`.
9191
9292
# New implementations
9393
94-
Overloading the trait is optional and it is typically not overloaded. The general fallback
95-
returns `false` but it is `true` for any [`multimeasure`](@ref), and the value is
94+
Overload this trait for a new measure type that consumes multiple observations, unless it
95+
has been constructed using `multimeaure` or is an $API.jl wrap thereof. The general
96+
fallback returns `false` but it is `true` for any [`multimeasure`](@ref), and the value is
9697
propagated by other wrappers.
9798
9899
"""

test/api.jl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,12 @@ w = 10:10:10N
99
measurements(measure, 2.3, 3.4) == LPLossOnScalars()(2.3, 3.4)
1010
measure = MeanAbsoluteError()
1111
measurements(measure, yhat, y) == fill(measure(yhat, y), N)
12+
13+
# if a measure does not overload `consumes_multiple_observations` but really does, then
14+
# `meausurements` should nevertheless have the expected behavior:
15+
badly_implemented_rms(yhat, y) = (yhat - y).^2 |> mean |> sqrt
16+
μ = badly_implemented_rms([4, 5], [1, 1])
17+
@test measurements(badly_implemented_rms, [4, 5], [1, 1]) [μ, μ]
1218
end
1319

1420
true

test/measure.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ API.is_measure(::Measure{typeof(min)}) = true
99
@testset "calling" begin
1010
measure = Measure(min)
1111
@test measure(2, -3) == 3
12-
@test measurements(measure, 2, -3) == 3
12+
@test measurements(measure, 2, -3) == [3,]
1313
end
1414

1515
true

0 commit comments

Comments
 (0)