Skip to content

Commit 7b9305c

Browse files
committed
Add UInt8 classification
This adds a classification into UInt8 buckets because we don't need the full accuracy of Float. This is a good compromise between flexibility and size of the output data.
1 parent 5961ad0 commit 7b9305c

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

src/rqatrend.jl

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,23 @@ rqatrend(xout, xin, thresh)
4848
Compute the RQA trend metric for the non-missing time steps of xin, and save it to xout.
4949
`thresh` specifies the epsilon threshold of the Recurrence Plot computation
5050
"""
51-
function rqatrend(pix_trend, pix, thresh=2)
52-
pix_trend .= rqatrend_impl(pix; thresh)
51+
function rqatrend(pix_trend, pix, thresh=2, lowerbound=-5., upperbound=-0.5)
52+
pix_trend .= classify_rqatrend(rqatrend_impl(pix; thresh); lowerbound, upperbound)
5353
end
5454

55+
function classify_rqatrend(trend, lowerbound=Float32(-5.0), upperbound=Float32(-0.5))
56+
ctrend = clamp(trend, lowerbound, upperbound)
57+
rlength = upperbound - lowerbound
58+
return round(UInt8, 255-((ctrend - lowerbound) / rlength) * 255)
59+
end
60+
61+
@testitem "classify_rqatrend" begin
62+
@test RQADeforestation.classify_rqatrend(-4.999) === UInt8(255)
63+
@test RQADeforestation.classify_rqatrend(1) === UInt8(0)
64+
@test RQADeforestation.classify_rqatrend(-0.52) === UInt8(1)
65+
@test RQADeforestation.classify_rqatrend(-6) === UInt8(255)
66+
@test isempty( AllocCheck.check_allocs(RQADeforestation.classify_rqatrend, (Float32, Float32, Float32)))
67+
end
5568

5669
function rqatrend_impl(data; thresh=2, border=10, theiler=1, metric=CheckedEuclidean())
5770
# simplified implementation of https://stats.stackexchange.com/a/370175 and https://github.com/joshday/OnlineStats.jl/blob/b89a99679b13e3047ff9c93a03c303c357931832/src/stats/linreg.jl

0 commit comments

Comments
 (0)