From fcb03d9c9692df5d8e756d35653f3206c1a914a1 Mon Sep 17 00:00:00 2001 From: MilesCranmer Date: Thu, 13 Feb 2025 20:57:50 +0000 Subject: [PATCH 1/3] fix: max of 6 expressions bug --- src/TemplateExpression.jl | 2 +- test/test_template_expression_string.jl | 22 ++++++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/src/TemplateExpression.jl b/src/TemplateExpression.jl index 6c4f9a36..67b45af6 100644 --- a/src/TemplateExpression.jl +++ b/src/TemplateExpression.jl @@ -561,7 +561,7 @@ end # Rather than using iterator with repeat, just make a tuple: function _colors(::Val{n}) where {n} return ntuple( - (i -> (:magenta, :green, :red, :blue, :yellow, :cyan)[mod1(i, n)]), Val(n) + (i -> (:magenta, :green, :red, :blue, :yellow, :cyan)[mod1(i, 6)]), Val(n) ) end _color_string(s::AbstractString, c::Symbol) = styled"{$c:$s}" diff --git a/test/test_template_expression_string.jl b/test/test_template_expression_string.jl index b7e71da0..be1d71f8 100644 --- a/test/test_template_expression_string.jl +++ b/test/test_template_expression_string.jl @@ -1,3 +1,25 @@ +@testitem "template expression color function" tags = [:part1, :template_colors] begin + using SymbolicRegression.TemplateExpressionModule: _colors + + # Test empty case + @test _colors(Val(0)) == () + + # Test n <= 6 cases + @test _colors(Val(1)) == (:magenta,) + @test _colors(Val(2)) == (:magenta, :green) + @test _colors(Val(6)) == (:magenta, :green, :red, :blue, :yellow, :cyan) + + # Test n > 6 cases to verify color cycling + colors_7 = _colors(Val(7)) + @test length(colors_7) == 7 + @test colors_7[1:6] == (:magenta, :green, :red, :blue, :yellow, :cyan) + @test colors_7[7] == :magenta # Should cycle back to first color + + colors_8 = _colors(Val(8)) + @test length(colors_8) == 8 + @test colors_8[7:8] == (:magenta, :green) # Should cycle colors properly +end + @testitem "template expression string representation" tags = [:part1, :template_string] begin using SymbolicRegression using StyledStrings: @styled_str, annotatedstring, AnnotatedString From 85e466ecf51809dbb7c71361bdc4215945c5a175 Mon Sep 17 00:00:00 2001 From: MilesCranmer Date: Thu, 13 Feb 2025 21:01:29 +0000 Subject: [PATCH 2/3] chore: bump version with expression limit fix --- Project.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Project.toml b/Project.toml index 5e31c9d4..7380d7a9 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "SymbolicRegression" uuid = "8254be44-1295-4e6a-a16d-46603ac705cb" authors = ["MilesCranmer "] -version = "1.7.1" +version = "1.7.2" [deps] ADTypes = "47edcb42-4c32-4615-8424-f2b9edc5f35b" From 69abc941fc3a350f614d41a3b63e3d5f7f7a8987 Mon Sep 17 00:00:00 2001 From: MilesCranmer Date: Thu, 13 Feb 2025 21:31:44 +0000 Subject: [PATCH 3/3] test: allow equal best loss --- examples/parameterized_function.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/parameterized_function.jl b/examples/parameterized_function.jl index 882ffbaa..1c954d5d 100644 --- a/examples/parameterized_function.jl +++ b/examples/parameterized_function.jl @@ -104,4 +104,4 @@ ypred2 = predict(mach, (data=X, idx=idx2)) loss2 = sum(i -> abs2(ypred2[i] - y[i]), eachindex(y)) / length(y) # Should get better: -@test loss1 > loss2 +@test loss1 >= loss2