nntoolbox.components.rbf module

class nntoolbox.components.rbf.RBFLayer(in_features: int, out_features: int, trainable_centers: bool = True, normalized: bool = False, kernel: Optional[nntoolbox.components.kernel.DistKernel] = None, initial_centers: Optional[torch.Tensor] = None)[source]

Bases: torch.nn.modules.linear.Linear

RBF Layer (used for output or as the hidden layer for RBF network)

References:

Lecun et al. “Gradient-Based Learning Applied to Document Recognition.” http://yann.lecun.com/exdb/publis/pdf/lecun-98.pdf

centroids_initialize(input: torch.Tensor, labels: torch.Tensor)[source]

(Re-)initialize the centers based on nearest centroids algorithm

Parameters
  • input

  • labels

cluster_initialize(input: torch.Tensor)[source]

(Re-)initialize the centers based on k-mean clustering on the input

Parameters

input

forward(input: torch.Tensor) → torch.Tensor[source]

Defines the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

in_features: int
out_features: int
weight: torch.Tensor