Skip to content

Commit

Permalink
add exclusion zone option
Browse files Browse the repository at this point in the history
  • Loading branch information
baggepinnen committed Sep 14, 2023
1 parent 527ad36 commit e1fec2f
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Distances = "0.7, 0.8, 0.9, 0.10"
LoopVectorization = "0.7.4, 0.8, 0.9, 0.10, 0.11, 0.12"
ProgressMeter = "1.2, 1.3"
RecipesBase = "0.8, 1.0"
SlidingDistancesBase = "0.2, 0.3"
SlidingDistancesBase = "0.2, 0.3.5"
julia = "1"

[extras]
Expand Down
8 changes: 5 additions & 3 deletions src/MatrixProfile.jl
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,15 @@ struct Profile{TT,TP,QT}
end

"""
profile = matrix_profile(T, m, [dist = ZEuclidean()]; showprogress=true)
profile = matrix_profile(T, m, [dist = ZEuclidean()]; showprogress=true, exclusion_zone = 0)
Return the matrix profile and the profile indices of time series `T` with window length `m`. See fields `profile.P, profile.I`. You can also plot the profile. If `dist = ZEuclidean()` the STOMP algorithm will be used.
- `exclusion_zone` denotes an integer number of samples around the trivial match to avoid. The paper suggests using `exclusion_zone = m ÷ 4`. This is likely most beneficial for time-series dominated by low frequencies.
Reference: [Matrix profile II](https://www.cs.ucr.edu/~eamonn/STOMP_GPU_final_submission_camera_ready.pdf).
"""
function matrix_profile(T::AbstractVector{<:Number}, m::Int; showprogress=true)
function matrix_profile(T::AbstractVector{<:Number}, m::Int; showprogress=true, kwargs...)
n = lastlength(T)
l = n-m+1
n > 2m+1 || throw(ArgumentError("Window length too long, maximum length is $((n+1)÷2)"))
Expand All @@ -47,7 +49,7 @@ function matrix_profile(T::AbstractVector{<:Number}, m::Int; showprogress=true)
# The expression with fastmath appears to be both more accurate and faster than both muladd and fma
end
QT[1] = QT₀[i]
distance_profile!(D, ZEuclidean(), QT, μ, σ, m, i)
distance_profile!(D, ZEuclidean(), QT, μ, σ, m, i; kwargs...)
update_min!(P, I, D, i)
showprogress && i % 5 == 0 && next!(prog)
end
Expand Down
11 changes: 11 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,17 @@ end
@test m[1] < 1e-6
@test m[2] == 51 || m[2] == 112

profileez = @inferred matrix_profile(T, length(y0), exclusion_zone=10)
Pez,Iez = profileez.P, profileez.I
@test_nowarn plot(profileez)
# plot(T, layout=2)
# plot!(P, sp=2)

m = findmin(Pez)
@test m[1] < 1e-6
@test m[2] == 51 || m[2] == 112
@test all(Pez .>= P .- 1e-12)


# Test Euclidean between two series
profile3 = @inferred matrix_profile(T, T, length(y0))
Expand Down

0 comments on commit e1fec2f

Please sign in to comment.