mlr-org / mlr3spatiotempcv
Showing 14 of 31 files from the diff.

@@ -1,4 +1,4 @@
Loading
1 -
#' @title Spatioemporal Cluster Resampling
1 +
#' @title (skmeans) Spatiotemporal clustering resampling
2 2
#'
3 3
#' @template rox_sptcv_cluto
4 4
#'
@@ -29,7 +29,6 @@
Loading
29 29
#' }
30 30
ResamplingSptCVCluto = R6Class("ResamplingSptCVCluto",
31 31
  inherit = mlr3::Resampling,
32 -
33 32
  public = list(
34 33
35 34
    #' @field time_var [character]\cr
@@ -124,18 +123,14 @@
Loading
124 123
      self$task_hash = task$hash
125 124
      self$task_nrow = task$nrow
126 125
      invisible(self)
127 -
    }
128 -
  ),
129 -
126 +
    }),
130 127
  active = list(
131 128
    #' @field iters `integer(1)`\cr
132 129
    #'   Returns the number of resampling iterations, depending on the
133 130
    #'   values stored in the `param_set`.
134 131
    iters = function() {
135 132
      self$param_set$values$folds
136 -
    }
137 -
  ),
138 -
133 +
    }),
139 134
  private = list(
140 135
    .sample = function(ids, data_matrix, clmethod, cluto_parameters, verbose) {
141 136
      vcluster_loc = check_cluto_path()
@@ -167,9 +162,7 @@
Loading
167 162
    .get_train = function(i) {
168 163
      self$instance[!list(i), "row_id", on = "fold"][[1L]]
169 164
    },
170 -
171 165
    .get_test = function(i) {
172 166
      self$instance[list(i), "row_id", on = "fold"][[1L]]
173 -
    }
174 -
  )
167 +
    })
175 168
)

@@ -1,4 +1,4 @@
Loading
1 -
#' @title Repeated "Leave-location-and-time-out" resampling.
1 +
#' @title (CAST) Repeated "leave-location-and-time-out" resampling
2 2
#'
3 3
#' @template rox_sptcv_cstf
4 4
#'
@@ -28,7 +28,6 @@
Loading
28 28
#' rrcv$instance # table
29 29
ResamplingRepeatedSptCVCstf = R6Class("ResamplingRepeatedSptCVCstf",
30 30
  inherit = mlr3::Resampling,
31 -
32 31
  public = list(
33 32
34 33
    #' @field space_var `character(1)`\cr
@@ -116,9 +115,7 @@
Loading
116 115
      self$task_hash = task$hash
117 116
      self$task_nrow = task$nrow
118 117
      invisible(self)
119 -
    }
120 -
  ),
121 -
118 +
    }),
122 119
  active = list(
123 120
124 121
    #' @field iters `integer(1)`\cr
@@ -127,12 +124,9 @@
Loading
127 124
    iters = function() {
128 125
      pv = self$param_set$values
129 126
      as.integer(pv$repeats) * as.integer(pv$folds)
130 -
    }
131 -
  ),
132 -
127 +
    }),
133 128
  private = list(
134 129
    .sample = function(task, space_var, time_var, class) {
135 -
136 130
      reps = self$param_set$values$repeats
137 131
      # declare empty list so the for-loop can write to its fields
138 132
      self$instance = vector("list", length = reps)
@@ -141,7 +135,6 @@
Loading
141 135
      data = task$data()
142 136
143 137
      for (rep in seq_len(reps)) {
144 -
145 138
        sptfolds = sample_cstf(
146 139
          self = self, task, space_var, time_var,
147 140
          class, k, data)
@@ -170,7 +163,6 @@
Loading
170 163
      }
171 164
      invisible(self)
172 165
    },
173 -
174 166
    .get_train = function(i) {
175 167
      i = as.integer(i) - 1L
176 168
      folds = as.integer(self$param_set$values$folds)
@@ -178,13 +170,11 @@
Loading
178 170
      fold = i %% folds + 1L
179 171
      self$instance[[rep]]$train[[fold]]
180 172
    },
181 -
182 173
    .get_test = function(i) {
183 174
      i = as.integer(i) - 1L
184 175
      folds = as.integer(self$param_set$values$folds)
185 176
      rep = i %/% folds + 1L
186 177
      fold = i %% folds + 1L
187 178
      self$instance[[rep]]$test[[fold]]
188 -
    }
189 -
  )
179 +
    })
190 180
)

@@ -200,7 +200,6 @@
Loading
200 200
  test_color = "#E18727",
201 201
  crs = NULL,
202 202
  ...) {
203 -
204 203
  autoplot_spatial(
205 204
    resampling = object,
206 205
    task = task,
@@ -298,7 +297,6 @@
Loading
298 297
  test_color = "#E18727",
299 298
  crs = NULL,
300 299
  ...) {
301 -
302 300
  autoplot_spatial(
303 301
    resampling = object,
304 302
    task = task,
@@ -568,7 +566,6 @@
Loading
568 566
  }
569 567
570 568
  if (!is.null(fold_id)) {
571 -
572 569
    if (length(fold_id) == 1) {
573 570
      ### only one fold
574 571
@@ -604,15 +601,15 @@
Loading
604 601
          labs(color = "Set", title = sprintf(
605 602
            "Fold %s, Repetition %s", fold_id,
606 603
            repeats_id)) +
607 -
          theme(plot.title = ggtext::element_textbox(
608 -
            size = 10,
609 -
            color = "black", fill = "#ebebeb", box.color = "black",
610 -
            height = unit(0.33, "inch"), width = unit(1, "npc"),
611 -
            linetype = 1, r = unit(5, "pt"),
612 -
            valign = 0.5, halign = 0.5,
613 -
            padding = margin(2, 2, 2, 2), margin = margin(3, 3, 3, 3))
604 +
          theme(
605 +
            plot.title = ggtext::element_textbox(
606 +
              size = 10,
607 +
              color = "black", fill = "#ebebeb", box.color = "black",
608 +
              height = unit(0.33, "inch"), width = unit(1, "npc"),
609 +
              linetype = 1, r = unit(5, "pt"),
610 +
              valign = 0.5, halign = 0.5,
611 +
              padding = margin(2, 2, 2, 2), margin = margin(3, 3, 3, 3))
614 612
          )
615 -
616 613
      } else {
617 614
        data_coords = data_coords[indicator != ""]
618 615
@@ -632,13 +629,14 @@
Loading
632 629
          labs(color = "Set", title = sprintf(
633 630
            "Fold %s, Repetition %s", fold_id,
634 631
            repeats_id)) +
635 -
          theme(plot.title = ggtext::element_textbox(
636 -
            size = 10,
637 -
            color = "black", fill = "#ebebeb", box.color = "black",
638 -
            height = unit(0.33, "inch"), width = unit(1, "npc"),
639 -
            linetype = 1, r = unit(5, "pt"),
640 -
            valign = 0.5, halign = 0.5,
641 -
            padding = margin(2, 2, 2, 2), margin = margin(3, 3, 3, 3))
632 +
          theme(
633 +
            plot.title = ggtext::element_textbox(
634 +
              size = 10,
635 +
              color = "black", fill = "#ebebeb", box.color = "black",
636 +
              height = unit(0.33, "inch"), width = unit(1, "npc"),
637 +
              linetype = 1, r = unit(5, "pt"),
638 +
              valign = 0.5, halign = 0.5,
639 +
              padding = margin(2, 2, 2, 2), margin = margin(3, 3, 3, 3))
642 640
          )
643 641
      }
644 642
    }
@@ -680,15 +678,15 @@
Loading
680 678
            labs(color = "Set", title = sprintf(
681 679
              "Fold %s, Repetition %s", .x,
682 680
              repeats_id)) +
683 -
            theme(plot.title = ggtext::element_textbox(
684 -
              size = 10,
685 -
              color = "black", fill = "#ebebeb", box.color = "black",
686 -
              height = unit(0.33, "inch"), width = unit(1, "npc"),
687 -
              linetype = 1, r = unit(5, "pt"),
688 -
              valign = 0.5, halign = 0.5,
689 -
              padding = margin(2, 2, 2, 2), margin = margin(3, 3, 3, 3))
681 +
            theme(
682 +
              plot.title = ggtext::element_textbox(
683 +
                size = 10,
684 +
                color = "black", fill = "#ebebeb", box.color = "black",
685 +
                height = unit(0.33, "inch"), width = unit(1, "npc"),
686 +
                linetype = 1, r = unit(5, "pt"),
687 +
                valign = 0.5, halign = 0.5,
688 +
                padding = margin(2, 2, 2, 2), margin = margin(3, 3, 3, 3))
690 689
            )
691 -
692 690
        } else {
693 691
          data_coords = data_coords[indicator != ""]
694 692
@@ -708,13 +706,14 @@
Loading
708 706
            labs(color = "Set", title = sprintf(
709 707
              "Fold %s, Repetition %s", .x,
710 708
              repeats_id)) +
711 -
            theme(plot.title = ggtext::element_textbox(
712 -
              size = 10,
713 -
              color = "black", fill = "#ebebeb", box.color = "black",
714 -
              height = unit(0.33, "inch"), width = unit(1, "npc"),
715 -
              linetype = 1, r = unit(5, "pt"),
716 -
              valign = 0.5, halign = 0.5,
717 -
              padding = margin(2, 2, 2, 2), margin = margin(3, 3, 3, 3))
709 +
            theme(
710 +
              plot.title = ggtext::element_textbox(
711 +
                size = 10,
712 +
                color = "black", fill = "#ebebeb", box.color = "black",
713 +
                height = unit(0.33, "inch"), width = unit(1, "npc"),
714 +
                linetype = 1, r = unit(5, "pt"),
715 +
                valign = 0.5, halign = 0.5,
716 +
                padding = margin(2, 2, 2, 2), margin = margin(3, 3, 3, 3))
718 717
            )
719 718
        }
720 719
      })
@@ -785,7 +784,7 @@
Loading
785 784
  }
786 785
}
787 786
788 -
#' @rdname autoplot.ResamplingSptCVCstf
787 +
#' @rdname autoplot.ResamplingSpCVDisc
789 788
#' @export
790 789
autoplot.ResamplingRepeatedSpCVDisc = function( # nolint
791 790
  object,
@@ -873,7 +872,6 @@
Loading
873 872
  test_color = "#E18727",
874 873
  crs = NULL,
875 874
  ...) {
876 -
877 875
  autoplot_spatial(
878 876
    resampling = object,
879 877
    task = task,
@@ -987,7 +985,6 @@
Loading
987 985
      sf_df = reorder_levels(sf_df)
988 986
989 987
      if (show_blocks) {
990 -
991 988
        if (grepl("Repeated", class(rsmp_autopl)[1])) {
992 989
          coords_resamp = coords_resamp[rep == repeats_id, ]
993 990
          blocks = rsmp_autopl$blocks[[repeats_id]]
@@ -1007,13 +1004,14 @@
Loading
1007 1004
          labs(color = "Set", title = sprintf(
1008 1005
            "Fold %s, Repetition %s", .x,
1009 1006
            repeats_id)) +
1010 -
          theme(plot.title = ggtext::element_textbox(
1011 -
            size = 10,
1012 -
            color = "black", fill = "#ebebeb", box.color = "black",
1013 -
            height = unit(0.33, "inch"), width = unit(1, "npc"),
1014 -
            linetype = 1, r = unit(5, "pt"),
1015 -
            valign = 0.5, halign = 0.5,
1016 -
            padding = margin(2, 2, 2, 2), margin = margin(3, 3, 3, 3))
1007 +
          theme(
1008 +
            plot.title = ggtext::element_textbox(
1009 +
              size = 10,
1010 +
              color = "black", fill = "#ebebeb", box.color = "black",
1011 +
              height = unit(0.33, "inch"), width = unit(1, "npc"),
1012 +
              linetype = 1, r = unit(5, "pt"),
1013 +
              valign = 0.5, halign = 0.5,
1014 +
              padding = margin(2, 2, 2, 2), margin = margin(3, 3, 3, 3))
1017 1015
          )
1018 1016
1019 1017
        if (show_labels) {
@@ -1040,13 +1038,14 @@
Loading
1040 1038
          labs(color = "Set", title = sprintf(
1041 1039
            "Fold %s, Repetition %s", .x,
1042 1040
            repeats_id)) +
1043 -
          theme(plot.title = ggtext::element_textbox(
1044 -
            size = 10,
1045 -
            color = "black", fill = "#ebebeb", box.color = "black",
1046 -
            height = unit(0.33, "inch"), width = unit(1, "npc"),
1047 -
            linetype = 1, r = unit(5, "pt"),
1048 -
            valign = 0.5, halign = 0.5,
1049 -
            padding = margin(2, 2, 2, 2), margin = margin(3, 3, 3, 3))
1041 +
          theme(
1042 +
            plot.title = ggtext::element_textbox(
1043 +
              size = 10,
1044 +
              color = "black", fill = "#ebebeb", box.color = "black",
1045 +
              height = unit(0.33, "inch"), width = unit(1, "npc"),
1046 +
              linetype = 1, r = unit(5, "pt"),
1047 +
              valign = 0.5, halign = 0.5,
1048 +
              padding = margin(2, 2, 2, 2), margin = margin(3, 3, 3, 3))
1050 1049
          )
1051 1050
      }
1052 1051
    })
@@ -1077,7 +1076,6 @@
Loading
1077 1076
    }
1078 1077
    # transform to selected crs
1079 1078
    if (show_blocks) {
1080 -
1081 1079
      blocks = sf::st_as_sf(coords_resamp)
1082 1080
    }
1083 1081
    if (!is.null(coords_resamp$blocks)) {
@@ -1286,7 +1284,6 @@
Loading
1286 1284
        )
1287 1285
1288 1286
        pl = mlr3misc::invoke(plotly::layout, .args = layout_args)
1289 -
1290 1287
      })
1291 1288
    }
1292 1289

@@ -1,4 +1,4 @@
Loading
1 -
#' @title Spatial Buffer Cross Validation Resampling
1 +
#' @title (blockCV) Spatial buffering resampling
2 2
#'
3 3
#' @template rox_spcv_buffer
4 4
#'
@@ -25,7 +25,6 @@
Loading
25 25
#' }
26 26
ResamplingSpCVBuffer = R6Class("ResamplingSpCVBuffer",
27 27
  inherit = mlr3::Resampling,
28 -
29 28
  public = list(
30 29
    #' @description
31 30
    #' Create an "Environmental Block" resampling instance.
@@ -71,18 +70,14 @@
Loading
71 70
      self$task_hash = task$hash
72 71
      self$task_nrow = task$nrow
73 72
      invisible(self)
74 -
    }
75 -
  ),
76 -
73 +
    }),
77 74
  active = list(
78 75
    #' @field iters `integer(1)`\cr
79 76
    #'   Returns the number of resampling iterations, depending on the
80 77
    #'   values stored in the `param_set`.
81 78
    iters = function() {
82 79
      as.integer(length(self$instance))
83 -
    }
84 -
  ),
85 -
80 +
    }),
86 81
  private = list(
87 82
    .sample = function(ids, response, coords, positive, crs, properties) {
88 83
@@ -131,7 +126,6 @@
Loading
131 126
          sprintf("train_fold_%s", seq_along(train_list)))
132 127
      }
133 128
    },
134 -
135 129
    .get_train = function(i) {
136 130
      if (!is.null(self$param_set$values$addBG)) {
137 131
        self$instance[[i]]$train # nocov
@@ -139,14 +133,11 @@
Loading
139 133
        self$instance[[i]]
140 134
      }
141 135
    },
142 -
143 136
    .get_test = function(i) {
144 137
      if (!is.null(self$param_set$values$addBG)) {
145 -
146 138
        self$instance[[i]]$test
147 139
      } else {
148 140
        i
149 141
      }
150 -
    }
151 -
  )
142 +
    })
152 143
)

@@ -1,4 +1,4 @@
Loading
1 -
#' @title Spatial Cross Validation Resampling
1 +
#' @title (sperrorest) Coordinate-based k-means clustering
2 2
#'
3 3
#' @template rox_spcv_coords
4 4
#'
@@ -24,7 +24,6 @@
Loading
24 24
#' rcv$instance # table
25 25
ResamplingSpCVCoords = R6Class("ResamplingSpCVCoords",
26 26
  inherit = mlr3::Resampling,
27 -
28 27
  public = list(
29 28
    #' @description
30 29
    #' Create an "coordinate-based" repeated resampling instance.
@@ -62,18 +61,14 @@
Loading
62 61
      self$task_hash = task$hash
63 62
      self$task_nrow = task$nrow
64 63
      invisible(self)
65 -
    }
66 -
  ),
67 -
64 +
    }),
68 65
  active = list(
69 66
    #' @field iters `integer(1)`\cr
70 67
    #'   Returns the number of resampling iterations, depending on the
71 68
    #'   values stored in the `param_set`.
72 69
    iters = function() {
73 70
      self$param_set$values$folds
74 -
    }
75 -
  ),
76 -
71 +
    }),
77 72
  private = list(
78 73
    .sample = function(ids, coords) {
79 74
      inds = kmeans(coords, centers = self$param_set$values$folds)
@@ -90,9 +85,7 @@
Loading
90 85
    .get_train = function(i) {
91 86
      self$instance[!list(i), "row_id", on = "fold"][[1L]]
92 87
    },
93 -
94 88
    .get_test = function(i) {
95 89
      self$instance[list(i), "row_id", on = "fold"][[1L]]
96 -
    }
97 -
  )
90 +
    })
98 91
)

@@ -1,4 +1,4 @@
Loading
1 -
#' @title "Leave-location-and-time-out" resampling.
1 +
#' @title (CAST) "Leave-location-and-time-out" resampling
2 2
#'
3 3
#' @template rox_sptcv_cstf
4 4
#'
@@ -26,7 +26,6 @@
Loading
26 26
#' rcv$instance # table
27 27
ResamplingSptCVCstf = R6Class("ResamplingSptCVCstf",
28 28
  inherit = mlr3::Resampling,
29 -
30 29
  public = list(
31 30
32 31
    #' @field space_var `character(1)`\cr
@@ -103,18 +102,14 @@
Loading
103 102
      self$task_hash = task$hash
104 103
      self$task_nrow = task$nrow
105 104
      invisible(self)
106 -
    }
107 -
  ),
108 -
105 +
    }),
109 106
  active = list(
110 107
    #' @field iters `integer(1)`\cr
111 108
    #'   Returns the number of resampling iterations, depending on the
112 109
    #'   values stored in the `param_set`.
113 110
    iters = function() {
114 111
      self$param_set$values$folds
115 -
    }
116 -
  ),
117 -
112 +
    }),
118 113
  private = list(
119 114
    .sample = function(task, space_var, time_var, class) {
120 115
      k = self$param_set$values$folds
@@ -154,9 +149,7 @@
Loading
154 149
    .get_train = function(i) {
155 150
      self$instance$train[[i]]
156 151
    },
157 -
158 152
    .get_test = function(i) {
159 153
      self$instance$test[[i]]
160 -
    }
161 -
  )
154 +
    })
162 155
)

@@ -1,4 +1,4 @@
Loading
1 -
#' @title Environmental Block Cross Validation Resampling
1 +
#' @title (blockCV) "Environmental blocking" resampling
2 2
#'
3 3
#' @template rox_spcv_env
4 4
#'
@@ -26,7 +26,6 @@
Loading
26 26
#' }
27 27
ResamplingSpCVEnv = R6Class("ResamplingSpCVEnv",
28 28
  inherit = mlr3::Resampling,
29 -
30 29
  public = list(
31 30
    #' @description
32 31
    #' Create an "Environmental Block" resampling instance.
@@ -88,18 +87,14 @@
Loading
88 87
      self$task_hash = task$hash
89 88
      self$task_nrow = task$nrow
90 89
      invisible(self)
91 -
    }
92 -
  ),
93 -
90 +
    }),
94 91
  active = list(
95 92
    #' @field iters `integer(1)`\cr
96 93
    #'   Returns the number of resampling iterations, depending on the
97 94
    #'   values stored in the `param_set`.
98 95
    iters = function() {
99 96
      as.integer(self$param_set$values$folds)
100 -
    }
101 -
  ),
102 -
97 +
    }),
103 98
  private = list(
104 99
    .sample = function(ids, data) {
105 100
      inds = stats::kmeans(data, centers = self$param_set$values$folds)
@@ -115,9 +110,7 @@
Loading
115 110
    .get_train = function(i) {
116 111
      self$instance[!list(i), "row_id", on = "fold"][[1L]]
117 112
    },
118 -
119 113
    .get_test = function(i) {
120 114
      self$instance[list(i), "row_id", on = "fold"][[1L]]
121 -
    }
122 -
  )
115 +
    })
123 116
)

@@ -1,4 +1,4 @@
Loading
1 -
#' @title Repeated Spatial Cross Validation Resampling
1 +
#' @title (blockCV) Repeated spatial block resampling
2 2
#'
3 3
#' @template rox_spcv_block
4 4
#'
@@ -32,7 +32,6 @@
Loading
32 32
#' }
33 33
ResamplingRepeatedSpCVBlock = R6Class("ResamplingRepeatedSpCVBlock",
34 34
  inherit = mlr3::Resampling,
35 -
36 35
  public = list(
37 36
38 37
    #' @field blocks `sf | list of sf objects`\cr
@@ -69,7 +68,6 @@
Loading
69 68
        param_set = ps,
70 69
        man = "mlr3spatiotempcv::mlr_resamplings_repeated_spcv_block"
71 70
      )
72 -
73 71
    },
74 72
75 73
    #' @description Translates iteration numbers to fold number.
@@ -155,9 +153,7 @@
Loading
155 153
      self$task_hash = task$hash
156 154
      self$task_nrow = task$nrow
157 155
      invisible(self)
158 -
    }
159 -
  ),
160 -
156 +
    }),
161 157
  active = list(
162 158
163 159
    #' @field iters `integer(1)`\cr
@@ -166,9 +162,7 @@
Loading
166 162
    iters = function() {
167 163
      pv = self$param_set$values
168 164
      as.integer(pv$repeats) * as.integer(pv$folds)
169 -
    }
170 -
  ),
171 -
165 +
    }),
172 166
  private = list(
173 167
    .sample = function(ids, coords, crs) {
174 168
@@ -217,9 +211,7 @@
Loading
217 211
      map_dtr(inds, function(i) {
218 212
        i$resampling
219 213
      })
220 -
221 214
    },
222 -
223 215
    .get_train = function(i) {
224 216
      i = as.integer(i) - 1L
225 217
      folds = as.integer(self$param_set$values$folds)
@@ -228,7 +220,6 @@
Loading
228 220
      ii = data.table(rep = rep, fold = seq_len(folds)[-fold])
229 221
      self$instance[ii, "row_id", on = names(ii), nomatch = 0L][[1L]]
230 222
    },
231 -
232 223
    .get_test = function(i) {
233 224
      i = as.integer(i) - 1L
234 225
      folds = as.integer(self$param_set$values$folds)
@@ -236,6 +227,5 @@
Loading
236 227
      fold = i %% folds + 1L
237 228
      ii = data.table(rep = rep, fold = fold)
238 229
      self$instance[ii, "row_id", on = names(ii), nomatch = 0L][[1L]]
239 -
    }
240 -
  )
230 +
    })
241 231
)

@@ -1,4 +1,4 @@
Loading
1 -
#' @title Spatial Block Cross Validation Resampling
1 +
#' @title (blockCV) Spatial block resampling
2 2
#'
3 3
#' @template rox_spcv_block
4 4
#'
@@ -27,7 +27,6 @@
Loading
27 27
#' }
28 28
ResamplingSpCVBlock = R6Class("ResamplingSpCVBlock",
29 29
  inherit = mlr3::Resampling,
30 -
31 30
  public = list(
32 31
33 32
    #' @field blocks `sf | list of sf objects`\cr
@@ -121,18 +120,14 @@
Loading
121 120
      self$task_hash = task$hash
122 121
      self$task_nrow = task$nrow
123 122
      invisible(self)
124 -
    }
125 -
  ),
126 -
123 +
    }),
127 124
  active = list(
128 125
    #' @field iters `integer(1)`\cr
129 126
    #'   Returns the number of resampling iterations, depending on the
130 127
    #'   values stored in the `param_set`.
131 128
    iters = function() {
132 129
      as.integer(self$param_set$values$folds)
133 -
    }
134 -
  ),
135 -
130 +
    }),
136 131
  private = list(
137 132
    .sample = function(ids, coords, crs) {
138 133
@@ -174,9 +169,7 @@
Loading
174 169
    .get_train = function(i) {
175 170
      self$instance[!list(i), "row_id", on = "fold"][[1L]]
176 171
    },
177 -
178 172
    .get_test = function(i) {
179 173
      self$instance[list(i), "row_id", on = "fold"][[1L]]
180 -
    }
181 -
  )
174 +
    })
182 175
)

@@ -1,4 +1,4 @@
Loading
1 -
#' @title Spatial "Disc" resampling with optional buffer zone
1 +
#' @title (sperrorest) Spatial "disc" resampling
2 2
#'
3 3
#' @template rox_spcv_disc
4 4
#'
@@ -24,7 +24,6 @@
Loading
24 24
#' rcv$instance # table
25 25
ResamplingSpCVDisc = R6Class("ResamplingSpCVDisc",
26 26
  inherit = mlr3::Resampling,
27 -
28 27
  public = list(
29 28
    #' @description
30 29
    #' Create a "Spatial 'Disc' resampling" resampling instance.
@@ -75,18 +74,14 @@
Loading
75 74
      self$task_hash = task$hash
76 75
      self$task_nrow = task$nrow
77 76
      invisible(self)
78 -
    }
79 -
  ),
80 -
77 +
    }),
81 78
  active = list(
82 79
    #' @field iters `integer(1)`\cr
83 80
    #'   Returns the number of resampling iterations, depending on the
84 81
    #'   values stored in the `param_set`.
85 82
    iters = function() {
86 83
      self$param_set$values$folds
87 -
    }
88 -
  ),
89 -
84 +
    }),
90 85
  private = list(
91 86
    .sample = function(ids, coords) {
92 87
@@ -103,7 +98,6 @@
Loading
103 98
      mlr3_index = 1
104 99
105 100
      for (i in index) {
106 -
107 101
        if (!is.null(self$param_set$values$buffer) |
108 102
          self$param_set$values$radius >= 0) {
109 103
          di = sqrt((coords[[1]] - as.numeric(coords[i, 1]))^2 + # nolint
@@ -113,7 +107,7 @@
Loading
113 107
        if (self$param_set$values$radius >= 0) {
114 108
          # leave-disc-out with buffer:
115 109
          test_sel = which(di <= self$param_set$values$radius)
116 -
          train_sel <- which(di > (self$param_set$values$radius + self$param_set$values$buffer))
110 +
          train_sel = which(di > (self$param_set$values$radius + self$param_set$values$buffer))
117 111
        } else {
118 112
          # leave-one-out with buffer:
119 113
          test_sel = i
@@ -140,7 +134,6 @@
Loading
140 134
141 135
      invisible(self)
142 136
    },
143 -
144 137
    .set_default_param_values = function(param) {
145 138
      if (is.null(self$param_set$values[[param]])) {
146 139
        self$param_set$values[[param]] = self$param_set$default[[param]]
@@ -152,9 +145,7 @@
Loading
152 145
    .get_train = function(i) {
153 146
      self$instance$train[[i]]
154 147
    },
155 -
156 148
    .get_test = function(i) {
157 149
      self$instance$test[[i]]
158 -
    }
159 -
  )
150 +
    })
160 151
)

@@ -1,4 +1,4 @@
Loading
1 -
#' @title Repeated Spatial "Disc" resampling with optional buffer zone
1 +
#' @title (sperrorest) Repeated spatial "disc" resampling
2 2
#'
3 3
#' @references
4 4
#' `r format_bib("brenning2012")`
@@ -28,7 +28,6 @@
Loading
28 28
#' rrcv$instance # table
29 29
ResamplingRepeatedSpCVDisc = R6Class("ResamplingRepeatedSpCVDisc",
30 30
  inherit = mlr3::Resampling,
31 -
32 31
  public = list(
33 32
    #' @description
34 33
    #' Create a "Spatial 'Disc' resampling" resampling instance.
@@ -54,7 +53,6 @@
Loading
54 53
        param_set = ps,
55 54
        man = "mlr3spatiotempcv::mlr_resamplings_repeated_spcv_disc"
56 55
      )
57 -
58 56
    },
59 57
60 58
    #' @description Translates iteration numbers to fold number.
@@ -97,9 +95,7 @@
Loading
97 95
      self$task_hash = task$hash
98 96
      self$task_nrow = task$nrow
99 97
      invisible(self)
100 -
    }
101 -
  ),
102 -
98 +
    }),
103 99
  active = list(
104 100
105 101
    #' @field iters `integer(1)`\cr
@@ -108,9 +104,7 @@
Loading
108 104
    iters = function() {
109 105
      pv = self$param_set$values
110 106
      as.integer(pv$repeats) * as.integer(pv$folds)
111 -
    }
112 -
  ),
113 -
107 +
    }),
114 108
  private = list(
115 109
    .sample = function(ids, coords) {
116 110
      reps = self$param_set$values$repeats
@@ -120,7 +114,6 @@
Loading
120 114
      # k = self$param_set$values$folds
121 115
122 116
      for (rep in seq_len(reps)) {
123 -
124 117
        index = sample.int(nrow(coords),
125 118
          size = self$param_set$values$folds,
126 119
          replace = self$param_set$values$replace,
@@ -134,7 +127,6 @@
Loading
134 127
        mlr3_index = 1
135 128
136 129
        for (i in index) {
137 -
138 130
          if (!is.null(self$param_set$values$buffer) |
139 131
            self$param_set$values$radius >= 0) {
140 132
            di = sqrt((coords[[1]] - as.numeric(coords[i, 1]))^2 + # nolint
@@ -144,7 +136,7 @@
Loading
144 136
          if (self$param_set$values$radius >= 0) {
145 137
            # leave-disc-out with buffer:
146 138
            test_sel = which(di <= self$param_set$values$radius)
147 -
            train_sel <- which(di > (self$param_set$values$radius + self$param_set$values$buffer))
139 +
            train_sel = which(di > (self$param_set$values$radius + self$param_set$values$buffer))
148 140
          } else {
149 141
            # leave-one-out with buffer:
150 142
            test_sel = i
@@ -171,13 +163,11 @@
Loading
171 163
        invisible(self)
172 164
      }
173 165
    },
174 -
175 166
    .set_default_param_values = function(param) {
176 167
      if (is.null(self$param_set$values[[param]])) {
177 168
        self$param_set$values[[param]] = self$param_set$default[[param]]
178 169
      }
179 170
    },
180 -
181 171
    .get_train = function(i) {
182 172
      i = as.integer(i) - 1L
183 173
      folds = as.integer(self$param_set$values$folds)
@@ -185,13 +175,11 @@
Loading
185 175
      fold = i %% folds + 1L
186 176
      self$instance[[rep]]$train[[fold]]
187 177
    },
188 -
189 178
    .get_test = function(i) {
190 179
      i = as.integer(i) - 1L
191 180
      folds = as.integer(self$param_set$values$folds)
192 181
      rep = i %/% folds + 1L
193 182
      fold = i %% folds + 1L
194 183
      self$instance[[rep]]$test[[fold]]
195 -
    }
196 -
  )
184 +
    })
197 185
)

@@ -1,4 +1,4 @@
Loading
1 -
#' @title Repeated Spatial Cross Validation Resampling
1 +
#' @title (sperrorest) Repeated coordinate-based k-means clustering
2 2
#'
3 3
#' @template rox_spcv_coords
4 4
#'
@@ -28,7 +28,6 @@
Loading
28 28
#' rrcv$instance # table
29 29
ResamplingRepeatedSpCVCoords = R6Class("ResamplingRepeatedSpCVCoords",
30 30
  inherit = mlr3::Resampling,
31 -
32 31
  public = list(
33 32
    #' @description
34 33
    #' Create an "coordinate-based" repeated resampling instance.
@@ -45,7 +44,6 @@
Loading
45 44
        param_set = ps,
46 45
        man = "mlr3spatiotempcv::mlr_resamplings_repeated_spcv_coords"
47 46
      )
48 -
49 47
    },
50 48
51 49
    #' @description Translates iteration numbers to fold number.
@@ -83,9 +81,7 @@
Loading
83 81
      self$task_hash = task$hash
84 82
      self$task_nrow = task$nrow
85 83
      invisible(self)
86 -
    }
87 -
  ),
88 -
84 +
    }),
89 85
  active = list(
90 86
91 87
    #' @field iters `integer(1)`\cr
@@ -94,9 +90,7 @@
Loading
94 90
    iters = function() {
95 91
      pv = self$param_set$values
96 92
      as.integer(pv$repeats) * as.integer(pv$folds)
97 -
    }
98 -
  ),
99 -
93 +
    }),
100 94
  private = list(
101 95
    .sample = function(ids, coords) {
102 96
      pv = self$param_set$values
@@ -109,7 +103,6 @@
Loading
109 103
        )
110 104
      })
111 105
    },
112 -
113 106
    .get_train = function(i) {
114 107
      i = as.integer(i) - 1L
115 108
      folds = as.integer(self$param_set$values$folds)
@@ -118,7 +111,6 @@
Loading
118 111
      ii = data.table(rep = rep, fold = seq_len(folds)[-fold])
119 112
      self$instance[ii, "row_id", on = names(ii), nomatch = 0L][[1L]]
120 113
    },
121 -
122 114
    .get_test = function(i) {
123 115
      i = as.integer(i) - 1L
124 116
      folds = as.integer(self$param_set$values$folds)
@@ -126,6 +118,5 @@
Loading
126 118
      fold = i %% folds + 1L
127 119
      ii = data.table(rep = rep, fold = fold)
128 120
      self$instance[ii, "row_id", on = names(ii), nomatch = 0L][[1L]]
129 -
    }
130 -
  )
121 +
    })
131 122
)

@@ -1,4 +1,4 @@
Loading
1 -
#' @title Repeated Spatiotemporal Cluster Resampling
1 +
#' @title (skmeans) Repeated spatiotemporal clustering resampling
2 2
#'
3 3
#' @template rox_sptcv_cluto
4 4
#'
@@ -33,7 +33,6 @@
Loading
33 33
#' }
34 34
ResamplingRepeatedSptCVCluto = R6Class("ResamplingRepeatedSptCVCluto",
35 35
  inherit = mlr3::Resampling,
36 -
37 36
  public = list(
38 37
39 38
    #' @field time_var [character]\cr
@@ -160,9 +159,7 @@
Loading
160 159
      self$task_hash = task$hash
161 160
      self$task_nrow = task$nrow
162 161
      invisible(self)
163 -
    }
164 -
  ),
165 -
162 +
    }),
166 163
  active = list(
167 164
168 165
    #' @field iters `integer(1)`\cr
@@ -171,9 +168,7 @@
Loading
171 168
    iters = function() {
172 169
      pv = self$param_set$values
173 170
      as.integer(pv$repeats) * as.integer(pv$folds)
174 -
    }
175 -
  ),
176 -
171 +
    }),
177 172
  private = list(
178 173
    .sample = function(ids, data_matrix, clmethod, cluto_parameters, verbose) {
179 174
      vcluster_loc = check_cluto_path()
@@ -202,7 +197,6 @@
Loading
202 197
        )
203 198
      })
204 199
    },
205 -
206 200
    .get_train = function(i) {
207 201
      i = as.integer(i) - 1L
208 202
      folds = as.integer(self$param_set$values$folds)
@@ -211,7 +205,6 @@
Loading
211 205
      ii = data.table(rep = rep, fold = seq_len(folds)[-fold])
212 206
      self$instance[ii, "row_id", on = names(ii), nomatch = 0L][[1L]]
213 207
    },
214 -
215 208
    .get_test = function(i) {
216 209
      i = as.integer(i) - 1L
217 210
      folds = as.integer(self$param_set$values$folds)
@@ -219,6 +212,5 @@
Loading
219 212
      fold = i %% folds + 1L
220 213
      ii = data.table(rep = rep, fold = fold)
221 214
      self$instance[ii, "row_id", on = names(ii), nomatch = 0L][[1L]]
222 -
    }
223 -
  )
215 +
    })
224 216
)

@@ -1,4 +1,4 @@
Loading
1 -
#' @title Repeated Environmental Block Cross Validation Resampling
1 +
#' @title (blockCV) Repeated "environmental blocking" resampling
2 2
#'
3 3
#' @template rox_spcv_env
4 4
#'
@@ -25,7 +25,6 @@
Loading
25 25
#' }
26 26
ResamplingRepeatedSpCVEnv = R6Class("ResamplingRepeatedSpCVEnv",
27 27
  inherit = mlr3::Resampling,
28 -
29 28
  public = list(
30 29
    #' @description
31 30
    #' Create an "coordinate-based" repeated resampling instance.
@@ -97,9 +96,7 @@
Loading
97 96
      self$task_hash = task$hash
98 97
      self$task_nrow = task$nrow
99 98
      invisible(self)
100 -
    }
101 -
  ),
102 -
99 +
    }),
103 100
  active = list(
104 101
105 102
    #' @field iters `integer(1)`\cr
@@ -108,9 +105,7 @@
Loading
108 105
    iters = function() {
109 106
      pv = self$param_set$values
110 107
      as.integer(pv$repeats) * as.integer(pv$folds)
111 -
    }
112 -
  ),
113 -
108 +
    }),
114 109
  private = list(
115 110
    .sample = function(ids, data) {
116 111
      pv = self$param_set$values
@@ -123,7 +118,6 @@
Loading
123 118
        )
124 119
      })
125 120
    },
126 -
127 121
    .get_train = function(i) {
128 122
      i = as.integer(i) - 1L
129 123
      folds = as.integer(self$param_set$values$folds)
@@ -132,7 +126,6 @@
Loading
132 126
      ii = data.table(rep = rep, fold = seq_len(folds)[-fold])
133 127
      self$instance[ii, "row_id", on = names(ii), nomatch = 0L][[1L]]
134 128
    },
135 -
136 129
    .get_test = function(i) {
137 130
      i = as.integer(i) - 1L
138 131
      folds = as.integer(self$param_set$values$folds)
@@ -140,6 +133,5 @@
Loading
140 133
      fold = i %% folds + 1L
141 134
      ii = data.table(rep = rep, fold = fold)
142 135
      self$instance[ii, "row_id", on = names(ii), nomatch = 0L][[1L]]
143 -
    }
144 -
  )
136 +
    })
145 137
)
Files Coverage
R 95.43%
Project Totals (24 files) 95.43%
Sunburst
The inner-most circle is the entire project, moving away from the center are folders then, finally, a single file. The size and color of each slice is representing the number of statements and the coverage, respectively.
Icicle
The top section represents the entire project. Proceeding with folders and finally individual files. The size and color of each slice is representing the number of statements and the coverage, respectively.
Grid
Each block represents a single file in the project. The size and color of each block is represented by the number of statements and the coverage, respectively.
Loading