16  Nodes, Edges and Graphs

POs are combined into Graphs.

POs are identified by their $id. Note that the operations all modify the object in-place and return the object itself. Therefore, multiple modifications can be chained.

For this example we use the pca PO defined above and a new PO named “mutate”. The latter creates a new feature from existing variables. Additionally, we use the filter PO again.

mutate = po("mutate")

filter = po("filter",
  filter = mlr3filters::flt("variance"),
  param_vals = list(filter.frac = 0.5))

The recommended way to construct a graph is to use the %>>% operator to chain POs or Graphs.

graph = mutate %>>% filter

To illustrate how this sugar operator works under the surface we will include an example of the manual way (= hard way) to construct a Graph. This is done by creating an empty graph first. Then one fills the empty graph with POs, and connects edges between the POs. Conceptually, this may look like this:

graph = Graph$new()$
  add_edge("mutate", "variance") # add connection mutate -> filter

The constructed Graph can be inspected using its $plot() function:


Chaining multiple POs of the same kind

If multiple POs of the same kind should be chained, it is necessary to change the id to avoid name clashes. This can be done by either accessing the $id slot or during construction:

graph$add_pipeop(po("pca", id = "pca2"))