-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
rely on tuple indexing to simplify
categorise
(#15)
- `categorise` is now an impure function since it indexes a `NamedTuple` with cutoffs - benchmarking suggests that 1 microsecond is lost due to the lookup that this incurs (50% slowdown) - the remaining time is mostly spent in `weight`, and likely even in building the type-unstable `Tuple` with `getproperty.(Ref(x), components(x)`. Not sure how to solve this yet, and eventually might revisit this code to speed it up.
- Loading branch information
1 parent
6d77962
commit 2dc8b17
Showing
18 changed files
with
171 additions
and
120 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,3 +3,4 @@ | |
.vscode/ | ||
/**/.DS_Store | ||
node_modules | ||
*_files/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,63 +1,41 @@ | ||
""" | ||
categorise(x::ContinuousComposite) | ||
categorise(::Type{T}, s::Real) where {T<:ContinuousComposite} | ||
Convert `x` to a discrete value. | ||
Convert score `s` to a discrete value using `SDAI` thresholds. | ||
The same functionality exists for other `ContinuousComposites`. | ||
# Examples | ||
```jldoctest | ||
julia> DAS28ESR(tjc=4, sjc=5, pga=12u"mm", apr=44u"mm/hr") |> categorise | ||
"Moderate" | ||
julia> categorise(SDAI, 3.6) | ||
"low" | ||
``` | ||
""" | ||
function categorise(::Type{DAS28ESR}, v) | ||
out = v < cont_cutoff.DAS28ESR.remission ? "Remission" : | ||
v <= cont_cutoff.DAS28ESR.low ? "Low" : | ||
v <= cont_cutoff.DAS28ESR.moderate ? "Moderate" : | ||
"High" | ||
return out | ||
function categorise(::Type{T}, s::Real) where {T<:ContinuousComposite} | ||
return seq_check(s, getproperty(cont_cutoff_funs, Symbol(T))) | ||
end | ||
|
||
function categorise(::Type{DAS28CRP}, v) | ||
out = v < cont_cutoff.DAS28CRP.remission ? "Remission" : | ||
v <= cont_cutoff.DAS28CRP.low ? "Low" : | ||
v <= cont_cutoff.DAS28CRP.moderate ? "Moderate" : | ||
"High" | ||
return out | ||
end | ||
|
||
function categorise(::Type{SDAI}, v) | ||
out = v < cont_cutoff.SDAI.remission ? "Remission" : | ||
v <= cont_cutoff.SDAI.low ? "Low" : | ||
v <= cont_cutoff.SDAI.moderate ? "Moderate" : | ||
"High" | ||
return out | ||
end | ||
|
||
function categorise(::Type{CDAI}, v) | ||
out = v < cont_cutoff.CDAI.remission ? "Remission" : | ||
v <= cont_cutoff.CDAI.low ? "Low" : | ||
v <= cont_cutoff.CDAI.moderate ? "Moderate" : | ||
"High" | ||
return out | ||
end | ||
|
||
categorise(x::ContinuousComposite) = categorise(typeof(x), score(x)) | ||
# This implementation is roughly half as 2.5 times slower than hard coding | ||
# cutoffs into each categorise function | ||
# If performance is ever critical, I should change to the more verbose but faster version | ||
|
||
""" | ||
categorise(::Type{SDAI}, v) | ||
Convert `v` to a discrete value using `SDAI` thresholds. | ||
The same functionality exists for other `ContinuousComposites`. | ||
categorise(x::ContinuousComposite) | ||
See also [`DAS28ESR`](@ref), [`DAS28CRP`](@ref). | ||
Convert `x` to a discrete value. | ||
# Examples | ||
```jldoctest | ||
julia> categorise(SDAI, 3.6) | ||
"Low" | ||
julia> DAS28ESR(tjc=4, sjc=5, pga=12u"mm", apr=44u"mm/hr") |> categorise | ||
"moderate" | ||
``` | ||
""" | ||
categorise(x::ContinuousComposite) = categorise(typeof(x), score(x)) | ||
|
||
""" | ||
categorise(x::Faceted{<:ContinuousComposite}) | ||
Convert the `root` composite of `x` to a discrete value. | ||
""" | ||
categorise(x::Faceted{<:ContinuousComposite}) = categorise(typeof(x.root), score(x.root)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.