Classifier
- class torchhd.classifiers.Classifier(n_features: int, n_dimensions: int, n_classes: int, *, device: device | None = None, dtype: dtype | None = None)[source]
Base class for all classifiers
- 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.
device (
torch.device, optional) – the desired device of the weights. Default: ifNone, uses the current device for the default tensor type (seetorch.set_default_tensor_type()).devicewill 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: ifNone, usestorch.get_default_dtype().
- __call__(samples: Tensor) Tensor[source]
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[source]
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