Skip to content

Commit

Permalink
work on types
Browse files Browse the repository at this point in the history
  • Loading branch information
baggepinnen committed Jun 30, 2020
1 parent 2126631 commit 48b0596
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 17 deletions.
4 changes: 2 additions & 2 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "MatrixProfile"
uuid = "24e37439-14ec-4097-bda3-6a65822e2305"
authors = ["Fredrik Bagge Carlson"]
version = "0.1.2"
version = "0.1.3"

[deps]
Distances = "b4f34e82-e78d-54a5-968a-f98e89d6e8f7"
Expand All @@ -17,7 +17,7 @@ Distances = "0.7, 0.8, 0.9"
LoopVectorization = "0.7.4, 0.8"
ProgressMeter = "1.2, 1.3"
RecipesBase = "0.8, 1.0"
SlidingDistancesBase = "0.1.4"
SlidingDistancesBase = "0.2"
julia = "1"

[extras]
Expand Down
2 changes: 1 addition & 1 deletion examples/mixed_bag.jl
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ plot(mot)
using DynamicAxisWarping

dist = DTW(3)
normalizer = Val(ZNormalizer)
normalizer = ZNormalizer
profile2 = matrix_profile(T, 50, dist, normalizer=normalizer)


Expand Down
8 changes: 4 additions & 4 deletions src/mpdist.jl
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,14 @@ end
All MP distance profiles between subsequences of length `S` in `T` using internal window length `m`.
"""
function mpdist_profile(T::AbstractVector,S::Int, m::Int, d::DT = ZEuclidean()) where DT
function mpdist_profile(T::AbstractVector{TT},S::Int, m::Int, d::DT = ZEuclidean()) where {TT,DT}
S >= m || throw(ArgumentError("S should be > m"))
SlidingDistancesBase.DSP.FFTW.set_num_threads(1)
n = lastlength(T)
n = length(T)
pad = S * ceil(Int, n / S) - n
T = [T;zeros(eltype(T), pad)]
append!(T,zeros(TT, pad)) # vcat was not type stable
N = S-m+1
D = Matrix{float(eltype(T))}(undef, lastlength(T)-m+1, N)
D = Matrix{float(TT)}(undef, length(T)-m+1, N)
sliding_means = similar(D)
m_profile = similar(D, 2N)

Expand Down
21 changes: 11 additions & 10 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ end
T = [randn(50); y0; randn(50); y0; randn(50)]
A = sign.([randn(50); y0; randn(50); y0; randn(50)])[1:end÷2] .+ 0.01.*randn.()

profile = matrix_profile(T, length(y0))
profile = @inferred matrix_profile(T, length(y0))
P,I = profile.P, profile.I
@test_nowarn plot(profile)
# plot(T, layout=2)
Expand All @@ -40,7 +40,7 @@ end


# Test Euclidean between two series
profile3 = matrix_profile(T, T, length(y0))
profile3 = @inferred matrix_profile(T, T, length(y0))
@test all(profile3.P .< 1e-6)


Expand All @@ -52,14 +52,14 @@ end


profile7n = naive_matrix_profile(T, A, length(y0))
profile7n2 = matrix_profile(T, A, length(y0), normdist)
profile7n2 = @inferred matrix_profile(T, A, length(y0), normdist)
profile7 = matrix_profile(T, A, length(y0))
@test profeq(profile7, profile7n)
@test profeq(profile7n, profile7n2)

profile8n = naive_matrix_profile(A, T, length(y0))
profile8n2 = matrix_profile(A, T, length(y0), normdist)
profile8 = matrix_profile(A, T, length(y0))
profile8n2 = @inferred matrix_profile(A, T, length(y0), normdist)
profile8 = @inferred matrix_profile(A, T, length(y0))
@test profeq(profile8, profile8n)
@test profeq(profile8n, profile8n2)

Expand All @@ -68,14 +68,14 @@ end
@info "Testing Generic matrix profile"

# Test generic one serie
profile2 = matrix_profile(T, length(y0), normdist)
profile2 = @inferred matrix_profile(T, length(y0), normdist)
@test profile2.P profile.P
@test all(eachindex(profile.I)) do i
profile2.I[i] (51,112) || profile2.I[i] == profile.I[i]
end

# Test generic between two series
profile4 = matrix_profile(T, T, length(y0), normdist)
profile4 = @inferred matrix_profile(T, T, length(y0), normdist)
@test all(profile4.P .< 1e-6)
end

Expand Down Expand Up @@ -123,13 +123,14 @@ end
# partialsort([p1.P; p2.P], 20)
# plot(p1)
# plot!(p2)
@test mpdist(A,B, m) > 0
@test @inferred(mpdist(A,B, m)) > 0
@test mpdist(A,A, m) < 10sqrt(eps())
@test mpdist(B,B, m) < 10sqrt(eps())
p = mpdist_profile([A; B], 50, 5)
T = [A; B]
p = mpdist_profile(T, 50, 5)
@test_nowarn plot(p)

snips = snippets([A; B], 2, 50, m=5)
snips = snippets(T, 2, 50, m=5)
@test_nowarn plot(snips)

end
Expand Down

0 comments on commit 48b0596

Please sign in to comment.