marshaling {mlr3}R Documentation

(Un)marshal a Learner

Description

Marshaling is the process of processing the model of a trained Learner so it an be successfully serialized and deserialized. The naming is inspired by the marshal package and we plan to fully migrate to this package once it is on CRAN. The current implementation should therfore be considered as a temporary solution and is likely to change in the future.

The central functions (and the only methods that are used by mlr3 internally) are:

For both marshal_model and unmarshal_model, the inplace argument determines whether in-place marshaling should be performed. This is especially relevant in the context of references semantics. If inplace is FALSE, the original input should not be modified, otherwise this is allowed. Note that the input and output can still share references, even when inplace is FALSE.

Usage

learner_unmarshal(.learner, ...)

learner_marshal(.learner, ...)

learner_marshaled(.learner)

marshal_model(model, inplace = FALSE, ...)

unmarshal_model(model, inplace = FALSE, ...)

is_marshaled_model(model)

Arguments

.learner

Learner
The learner.

...

(any)
Additional parameters, currently unused.

model

(any)
Model to marshal.

inplace

(logical(1))
Whether to marshal in-place.

Implementing Marshaling

In order to implement marshaling for a Learner, you need to overload the marshal_model and unmarshal_model methods for the class of the learner's model and tag the learner with the "marshal" property. To make marshaling accessible in an R6-manner, you should also add the public methods ⁠$marshal()⁠, ⁠$unmarshal()⁠ and the active binding ⁠$marshaled⁠. To make this as convenient as possible, the functions learner_marshal(.learner, ...), learner_unmarshal(.learner, ...) and learner_marshaled(.learner) are provided and can be called from the public methods.

You can verify whether you have correctly implemented marshaling by using the internal test helper expect_marshalable_learner(learner, task). This is also run by expect_learner() if a task is provided.

For a concrete example on how to implement marshaling, see LearnerClassifDebug.


[Package mlr3 version 1.0.1 Index]