Skip to content

Commit

Permalink
add docs about constructor trait
Browse files Browse the repository at this point in the history
  • Loading branch information
ablaom committed Aug 2, 2024
1 parent 7b7128f commit 5aa1055
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions docs/src/model_wrappers.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,21 @@ EnsembleModel(model=tree, n=100)

This is the only case in MLJ where positional arguments in a model constructor are
allowed.

## Handling generic constructors

Model wrappers frequently have a public facing constructor with a name different from that
of the model type constructed. For example, `TunedModel(model, ...)` is a constructor that
will construct either an instance of `DeterministicTunedModel` or
`ProbabilisticTunedModel`, depending on the type of `model`. In this case it is necessary
to overload the `constructor` trait, which in that case looks like this:

```julia
MLJModelInterface.constructor(::Type{<:Union{
DeterministicTunedModel,
ProbabilisticTunedModel,
}}) = TunedModel
```

This allows the MLJ Model Registry to correctly associate model metadata to the
constructor, rather than the (private) types.

0 comments on commit 5aa1055

Please sign in to comment.