Skip to contents

These functions check whether the input is a one-hot matrix, i.e., a numeric matrix where each row contains exactly one entry equal to 1 and all other entries equal to 0.

Usage

check_one_hot_matrix(
  x,
  nrows = NULL,
  ncols = NULL,
  tolerance = sqrt(.Machine$double.eps)
)

assert_one_hot_matrix(
  x,
  nrows = NULL,
  ncols = NULL,
  tolerance = sqrt(.Machine$double.eps),
  .var.name = checkmate::vname(x),
  add = NULL
)

test_one_hot_matrix(
  x,
  nrows = NULL,
  ncols = NULL,
  tolerance = sqrt(.Machine$double.eps)
)

Arguments

x

[any]
Object to check.

nrows

[integer(1)]
Exact number of rows.

ncols

[integer(1)]
Exact number of columns.

tolerance

[numeric(1)]
A non-negative tolerance value.

.var.name

[character(1)]
Name of the checked object to print in assertions. Defaults to the heuristic implemented in vname.

add

[AssertCollection]
Collection to store assertion messages. See AssertCollection.

Value

Same as documented in check_matrix.

Examples

x <- matrix(c(
  1, 0, 0, 0,
  0, 1, 0, 0,
  0, 0, 0, 0
), nrow = 3, byrow = TRUE)

check_one_hot_matrix(x)
#> [1] "Each row must contain exactly one 1"
test_one_hot_matrix(x)
#> [1] FALSE
if (FALSE) { # \dontrun{
assert_one_hot_matrix(x)
} # }