cblearn.utils.check_query#

cblearn.utils.check_query(query, result_format=None)[source]#

Input validation for queries.

Checks query shape and datatype. Converts between array (T-STE style) and sparse matrix format for query.

Parameters:
  • query (ndarray | COO | spmatrix) – Either array_like with index-query or sparse matrix.

  • result_format (str | Tuple[QueryFormat, ResponseFormat] | None) – One of ‘list’, or ‘tensor’. If none, format is not changed.

Returns:

If response_format=’tensor’, a three-dimensional sparse.COO matrix is returned. The three dimensions all have size ‘n_objects’. The entry query[i, j, k] indicates the response on ij <= jk. It is -1 if wrong, 0 if undecidable, and 1 if correct.

If response_format=’list’, a numpy array of shape (n_samples, 3) is returned. Each row (i, j, k) indicates, ij <= ik.

Raises:

ValueError – If the array_like input has the wrong shape, or response types cannot be converted. This happens e.g. if undecided (0) response, should be converted to ordered or boolean response.

Return type:

ndarray | COO | spmatrix