Skip to content

Commit 5aa1055

Browse files
committed
add docs about constructor trait
1 parent 7b7128f commit 5aa1055

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

docs/src/model_wrappers.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,21 @@ EnsembleModel(model=tree, n=100)
2727

2828
This is the only case in MLJ where positional arguments in a model constructor are
2929
allowed.
30+
31+
## Handling generic constructors
32+
33+
Model wrappers frequently have a public facing constructor with a name different from that
34+
of the model type constructed. For example, `TunedModel(model, ...)` is a constructor that
35+
will construct either an instance of `DeterministicTunedModel` or
36+
`ProbabilisticTunedModel`, depending on the type of `model`. In this case it is necessary
37+
to overload the `constructor` trait, which in that case looks like this:
38+
39+
```julia
40+
MLJModelInterface.constructor(::Type{<:Union{
41+
DeterministicTunedModel,
42+
ProbabilisticTunedModel,
43+
}}) = TunedModel
44+
```
45+
46+
This allows the MLJ Model Registry to correctly associate model metadata to the
47+
constructor, rather than the (private) types.

0 commit comments

Comments
 (0)