Home > Back-end >  Manipulating task objects by reference: How does this work?
Manipulating task objects by reference: How does this work?

Time:11-27

I struggle to understand what exactly happens if I use commands like x <- task. As an example, here is what I do:

  1. I have a lists of tasks, learners and resamplings and I combine them for benchmarking. As I do the matchin manually, my list of tasks consists of multiple repeats of the same task, e.g. the second and third entry of my list are the same. So, I have no problem to understand what happens in the following lines:

Step 1

This is understandable. As I refer to the same object, the third entry of my list must change as I manipulate the second (yes, they are the same object)

  1. Now, I use this lists to generate a benchmark design and execute the resampling:
design = data.table(
  task = list_of_tasks,
  learner = list_of_learners,
  resampling = list_of_resamplings
)

bmr = benchmark(design) 

tab = bmr$aggregate(c(msr("classif.acc"))) 

The resulting tab has a column with resample results that I can inspect and manipulate. These resample results include my original tasks (at least this is what I understand). Manipulating the "tasks within the resample results" works exactly as in step 1 and has the same effects (again, no surprise):

step 2

  1. But now, what happens here (I execute the following lines next)? It seems that the "tasks within the resample results" are the same object for lines 2 and 3 but not in the original list:

step 3

There seems to be something that I am missing. But how can I understand this?

CodePudding user response:

The tasks, learners and resamplings are cloned when calling benchmark() i.e. a copy of each object is created. The entries in design and tab do not refer to the same objects in memory. Therefore, changing tab$resample_result[[2]]$task does not change list_of_tasks[[2]].

  • Related