IntRVFL

class torchhd.classifiers.IntRVFL(n_features: int, n_dimensions: int, n_classes: int, *, kappa: int | None = None, alpha: float = 1, device: device | None = None, dtype: dtype | None = None)[source]

Implements Density Encoding Enables Resource-Efficient Randomly Connected Neural Networks.

Parameters:
  • n_features (int) – Size of each input sample.

  • n_dimensions (int) – The number of hidden dimensions to use.

  • n_classes (int) – The number of classes.

  • kappa (int, optional) – Parameter of the clipping function limiting the range of values; used as the part of transforming input data.

  • alpha (float, optional) – Scalar for the variance of the samples. Default is 1.

  • device (torch.device, optional) – the desired device of the weights. Default: if None, uses the current device for the default tensor type (see torch.set_default_tensor_type()). device will be the CPU for CPU tensor types and the current CUDA device for CUDA tensor types.

  • dtype (torch.dtype, optional) – the desired data type of the weights. Default: if None, uses torch.get_default_dtype().

  • requires_grad (bool, optional) – If autograd should record operations on the returned tensor. Default: False.

__call__(samples: Tensor) Tensor

Evaluate the logits of the classifier for the given samples.

Parameters:

samples (Tensor) – Batch of samples to be classified.

Returns:

Logits of each sample for each class.

Return type:

Tensor

accuracy(data_loader: Iterable[Tuple[Tensor, LongTensor]]) float

Accuracy in predicting the labels of the samples.

Parameters:

data_loader (DataLoader) – Iterable of tuples containing a batch of samples and labels.

Returns:

The accuracy of predicting the true labels.

Return type:

float

fit(data_loader: Iterable[Tuple[Tensor, LongTensor]])[source]

Fits the classifier to the provided data.

Parameters:

data_loader (DataLoader) – Iterable of tuples containing a batch of samples and labels.

Returns:

self

predict(samples: Tensor) LongTensor

Predict the class of each given sample.

Parameters:

samples (Tensor) – Batch of samples to be classified.

Returns:

Index of the predicted class for each sample.

Return type:

LongTensor