AdaptHD
- class torchhd.classifiers.AdaptHD(n_features: int, n_dimensions: int, n_classes: int, *, n_levels: int = 100, min_level: int = -1, max_level: int = 1, epochs: int = 120, lr: float = 0.035, device: device | None = None, dtype: dtype | None = None)[来源]
实现了AdaptHD: 自适应高效训练用于脑启发的高维计算。
- Parameters:
n_features (int) – 每个输入样本的大小。
n_dimensions (int) – 使用的隐藏维度数量。
n_classes (int) – 类别数量。
n_levels (int, optional) – 用于层级超向量的离散化层级数量。
min_level (int, optional) – 由级别超向量表示的范围的下限。
max_level (int, optional) – 由层级超向量表示的范围的上限。
epochs (int, optional) – 训练数据的迭代次数。
lr (float, optional) – 学习率。
device (
torch.device, 可选) – 权重的期望设备。默认值:如果None,则使用当前设备作为默认张量类型(参见torch.set_default_tensor_type())。device对于 CPU 张量类型将是 CPU,对于 CUDA 张量类型将是当前的 CUDA 设备。dtype (
torch.dtype, 可选) – 权重的期望数据类型。默认值:如果None,则使用torch.get_default_dtype()。
- __call__(samples: Tensor) Tensor
评估给定样本的分类器的logits。
- Parameters:
样本 (张量) – 待分类的样本批次。
- Returns:
每个样本对于每个类别的Logits。
- Return type:
张量
- accuracy(data_loader: Iterable[Tuple[Tensor, LongTensor]]) float
预测样本标签的准确性。
- Parameters:
data_loader (DataLoader) – 包含一批样本和标签的可迭代元组。
- Returns:
预测真实标签的准确性。
- Return type:
浮点数
- fit(data_loader: Iterable[Tuple[Tensor, LongTensor]])[来源]
将分类器拟合到提供的数据。
- Parameters:
data_loader (DataLoader) – 包含一批样本和标签的可迭代元组。
- Returns:
self
- predict(samples: Tensor) LongTensor
预测每个给定样本的类别。
- Parameters:
样本 (张量) – 待分类的样本批次。
- Returns:
每个样本的预测类别索引。
- Return type:
长整型张量