From ee0dbdb04e4073b4c2ed73a656917e7160a7bc7c Mon Sep 17 00:00:00 2001 From: Datseris Date: Mon, 10 Jun 2024 16:52:59 +0100 Subject: [PATCH] propagate isless in ordinal encoding Closes #378 --- src/encoding_implementations/ordinal_pattern.jl | 2 +- test/encodings/encodings/ordinal_pattern_encoding.jl | 11 ++++++++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/encoding_implementations/ordinal_pattern.jl b/src/encoding_implementations/ordinal_pattern.jl index 603a62e9b..1c106413c 100644 --- a/src/encoding_implementations/ordinal_pattern.jl +++ b/src/encoding_implementations/ordinal_pattern.jl @@ -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 diff --git a/test/encodings/encodings/ordinal_pattern_encoding.jl b/test/encodings/encodings/ordinal_pattern_encoding.jl index c457f1995..4df124d17 100644 --- a/test/encodings/encodings/ordinal_pattern_encoding.jl +++ b/test/encodings/encodings/ordinal_pattern_encoding.jl @@ -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)) @@ -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