Skip to content

v1.7.0

Compare
Choose a tag to compare
@MilesCranmer MilesCranmer released this 08 Feb 20:45
· 46 commits to master since this release
40f90bc

What's Changed

New Features

  • Parametric Template Expressions: You can now add learnable parameters to template expressions! It's easiest to set this up with the new @template_spec macro: (#394)
    @template_spec(expressions=(f, g), parameters=(amplitude=2, phase=2, offset=1)) do x, class
        amplitude[class] * cos(f(x) + phase[class]) + g(x)^2 + offset[1]
    end
  • Loss Functions on AbstractExpression objects: New loss_function_expression parameter enables custom loss functions that operate directly on TemplateExpression and other expression objects. (#408)
  • Expression specifications: Rather than setting both expression_type and expression_options, there is now a unified expression_spec argument for Options and SRRegressor. Use ParametricExpressionSpec for parametric expressions, and TemplateExpressionSpec for template expressions. (Though the latter has the @template_spec shorthand)

Small changes

  • Added support for comparison operators (>, <, >=, <=) within templates as well as in the operators. (#407)

Deprecations

  • The expression_type and expression_options parameters are now deprecated in favor of the unified expression_spec interface.

Example Usage

Class-Conditional Model with Learnable Parameters

# Define template with class-specific parameters
model_template = @template_spec(
    expressions=(base, modifier),
    parameters=(coeff=5,)
) do x, class
    coeff[class] * (base(x) + modifier(x^2))
end

# Set up search
model = SRRegressor(
    expression_spec=model_template,
    binary_operators=[+, *],
    unary_operators=[cos],
    niterations=500
)

# X contains features x and class labels
X = (x=rand(100) .* 10, class=rand(1:5, 100))
coeffs = [2.0, -0.5, 4.0, 0.2, 1.0]
y = [coeffs[X.class[i]] * (cos(X.x[i]) - X.x[i]^2) for i in 1:100]

using MLJBase: fit!, machine
fit!(machine(model, X, y))

Full Changelog: v1.6.0...v1.7.0