Skip to content

Commit

Permalink
feat: use ? for wildcard units instead of cdot
Browse files Browse the repository at this point in the history
  • Loading branch information
MilesCranmer committed Apr 27, 2024
1 parent 758f991 commit df86692
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 8 deletions.
4 changes: 2 additions & 2 deletions docs/src/examples.md
Original file line number Diff line number Diff line change
Expand Up @@ -215,11 +215,11 @@ fit!(mach)
```

You can observe that all expressions with a loss under
our penalty are dimensionally consistent! (The `"[]"` indicates free units in a constant,
our penalty are dimensionally consistent! (The `"[?]"` indicates free units in a constant,
which can cancel out other units in the expression.) For example,

```julia
"y[m s⁻² kg] = (M[kg] * 2.6353e-22[])"
"y[m s⁻² kg] = (M[kg] * 2.6353e-22[?])"
```

would indicate that the expression is dimensionally consistent, with
Expand Down
4 changes: 2 additions & 2 deletions src/HallOfFame.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ using ..CoreModule: MAX_DEGREE, Options, Dataset, DATA_TYPE, LOSS_TYPE, relu
using ..ComplexityModule: compute_complexity
using ..PopMemberModule: PopMember
using ..LossFunctionsModule: eval_loss
using ..InterfaceDynamicExpressionsModule: format_dimensions
using ..InterfaceDynamicExpressionsModule: format_dimensions, WILDCARD_UNIT_STRING
using Printf: @sprintf

"""
Expand Down Expand Up @@ -129,7 +129,7 @@ function string_dominating_pareto_curve(
unit_str = format_dimensions(dataset.y_sym_units)
y_prefix *= unit_str
if dataset.y_sym_units === nothing && dataset.X_sym_units !== nothing
y_prefix *= "[⋅]"
y_prefix *= WILDCARD_UNIT_STRING
end
eqn_string = y_prefix * " = " * eqn_string
base_string_length = length(@sprintf("%-10d %-8.3e %8.3e ", 1, 1.0, 1.0))
Expand Down
4 changes: 3 additions & 1 deletion src/InterfaceDynamicExpressions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,8 @@ function differentiable_eval_tree_array(
return differentiable_eval_tree_array(tree, X, options.operators; kws...)
end

const WILDCARD_UNIT_STRING = "[?]"

"""
string_tree(tree::AbstractExpressionNode, options::Options; kws...)
Expand Down Expand Up @@ -168,7 +170,7 @@ Convert an equation to a string.
tree,
options.operators;
f_variable=(feature, vname) -> string_variable(feature, vname, X_sym_units),
f_constant=(val,) -> string_constant(val, vprecision, "[⋅]"),
f_constant=(val,) -> string_constant(val, vprecision, WILDCARD_UNIT_STRING),
variable_names=display_variable_names,
kws...,
)
Expand Down
6 changes: 3 additions & 3 deletions test/test_units.jl
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ end
X_sym_units=dataset.X_sym_units,
y_sym_units=dataset.y_sym_units,
) ==
"(1[] * (x₁[m³] + ((x₂[s⁻¹ km] * x₃[kg]) * 5.32[]))) - cos(1.5[] * (x₁[m³] - 0.5[]))"
"(1[?] * (x₁[m³] + ((x₂[s⁻¹ km] * x₃[kg]) * 5.32[?]))) - cos(1.5[?] * (x₁[m³] - 0.5[?]))"

@test string_tree(
x5 * 3.2,
Expand All @@ -357,7 +357,7 @@ end
display_variable_names=dataset.display_variable_names,
X_sym_units=dataset.X_sym_units,
y_sym_units=dataset.y_sym_units,
) == "x₅ * 3.2[]"
) == "x₅ * 3.2[?]"

# Should print numeric factor in unit if given:
dataset2 = Dataset(X, y; X_units=[1.5, 1.9, 2.0, 3.0, 5.0u"m"], y_units="kg")
Expand All @@ -368,7 +368,7 @@ end
display_variable_names=dataset2.display_variable_names,
X_sym_units=dataset2.X_sym_units,
y_sym_units=dataset2.y_sym_units,
) == "x₅[5.0 m] * 3.2[]"
) == "x₅[5.0 m] * 3.2[?]"
end

@testset "Miscellaneous" begin
Expand Down

0 comments on commit df86692

Please sign in to comment.