Skip to content

Commit

Permalink
propagate isless in ordinal encoding
Browse files Browse the repository at this point in the history
Closes #378
  • Loading branch information
Datseris committed Jun 10, 2024
1 parent dd1c61d commit ee0dbdb
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/encoding_implementations/ordinal_pattern.jl
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ function encode(encoding::OrdinalPatternEncoding{m}, χ::AbstractVector) where {
if m != length(χ)
throw(ArgumentError("Permutation order and length of input must match!"))
end
perm = sortperm!(encoding.perm, χ)
perm = sortperm!(encoding.perm, χ; lt = encoding.lt)
return permutation_to_integer(perm)
end

Expand Down
11 changes: 10 additions & 1 deletion test/encodings/encodings/ordinal_pattern_encoding.jl
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ end
@test missing_outcomes(OrdinalPatterns(; m, τ), x) == 0
end

@testset "Pretty printing" begin
@testset "Pretty printing" begin
o = OrdinalPatterns{3}()
@test occursin("OrdinalPatterns{3}", repr(o))
@test occursin("encoding = OrdinalPatternEncoding(perm = [0, 0, 0], lt = isless_rand), τ = 1", repr(o))
Expand All @@ -67,3 +67,12 @@ end
s = "[OrdinalPatterns{3}(encoding = OrdinalPatternEncoding(perm = [0, 0, 0], lt = isless_rand), τ = 1), OrdinalPatterns{3}(encoding = OrdinalPatternEncoding(perm = [0, 0, 0], lt = isless_rand), τ = 1), OrdinalPatterns{3}(encoding = OrdinalPatternEncoding(perm = [0, 0, 0], lt = isless_rand), τ = 1)]"
@test occursin(s, repr(os))
end

@testset "usage of isless" begin
o = OrdinalPatternEncoding{2}() # random is less
res = [encode(o, [1,1]) for i in 1:1000]
@test unique(res) == [1, 2]
o = OrdinalPatternEncoding{2}(isless) # random is less
res = [encode(o, [1,1]) for i in 1:1000]
@test unique(res) == [1]
end

0 comments on commit ee0dbdb

Please sign in to comment.