scores.RandomScore

Returns random confidence scores per sample.

Usage

Source

scores.RandomScore()

This score assigns a random float in [0, 1] to each sample. It is useful as a baseline or for testing purposes. Low scores indicate likely inliers, high scores indicate likely outliers. By default, the threshold is set to 0.99, so approximately 99% of samples are selected.

Attributes

Name Description
cal_required bool(x) -> bool
ident str(object=’’) -> str
train_required bool(x) -> bool

cal_required

bool(x) -> bool

cal_required: bool = False

Returns True when the argument x is true, False otherwise. The builtins True and False are the only two instances of the class bool. The class bool is a subclass of the class int, and cannot be subclassed.


ident

str(object=’’) -> str

ident: str = "random"

str(bytes_or_buffer[, encoding[, errors]]) -> str

Create a new string object from the given object. If encoding or errors is specified, then the object must expose a data buffer that will be decoded using the given encoding and error handler. Otherwise, returns the result of object.__str__() (if defined) or repr(object). encoding defaults to sys.getdefaultencoding(). errors defaults to ‘strict’.


train_required

bool(x) -> bool

train_required: bool = False

Returns True when the argument x is true, False otherwise. The builtins True and False are the only two instances of the class bool. The class bool is a subclass of the class int, and cannot be subclassed.

Methods

Name Description
fit() Unused.
score() Compute a random confidence score for every sample in a batch.
select() Select samples for prediction based on their random confidence score.

fit()

Unused.

Usage

Source

fit(X=None, Y=None)

score()

Compute a random confidence score for every sample in a batch.

Usage

Source

score(X)

Returns random scores where low values indicate likely inliers and high values indicate likely outliers.

Parameters
X: torch.Tensor
Input batch of shape (B, ...). Only the batch size is used.
Returns
torch.Tensor
1-D tensor of shape (B,) with uniform random scores in [0, 1].
Examples
import torch
from seapig.scores import RandomScore
score = RandomScore()
scores = score.score(torch.zeros(4, 10))

select()

Select samples for prediction based on their random confidence score.

Usage

Source

select(X)

Samples with scores lower than the threshold are selected for prediction.

Parameters
X: torch.Tensor
Input batch of shape (B, ...). Only the batch size is used.
Returns
dict[str, torch.Tensor]
A dict with keys 'score' (random scores) and 'selected' (boolean mask where True means the sample is selected).
Examples
import torch
from seapig.scores import RandomScore
score = RandomScore()
result = score.select(torch.zeros(4, 10))
# result['selected'] is a boolean tensor of shape (4,)

See Also