v1.7.0
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: Newloss_function_expression
parameter enables custom loss functions that operate directly onTemplateExpression
and other expression objects. (#408) - Expression specifications: Rather than setting both
expression_type
andexpression_options
, there is now a unifiedexpression_spec
argument forOptions
andSRRegressor
. UseParametricExpressionSpec
for parametric expressions, andTemplateExpressionSpec
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
andexpression_options
parameters are now deprecated in favor of the unifiedexpression_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