MCPcopy Create free account
hub / github.com/BindsNET/bindsnet / get_square_weights

Function get_square_weights

bindsnet/utils.py:57–85  ·  view source on GitHub ↗

Return a grid of a number of filters ``sqrt ** 2`` with side lengths ``side``. :param weights: Two-dimensional tensor of weights for two-dimensional data. :param n_sqrt: Square root of no. of filters. :param side: Side length(s) of filter. :return: Reshaped weights to square ma

(
    weights: Tensor, n_sqrt: int, side: Union[int, Tuple[int, int]]
)

Source from the content-addressed store, hash-verified

55
56
57def get_square_weights(
58 weights: Tensor, n_sqrt: int, side: Union[int, Tuple[int, int]]
59) -> Tensor:
60 # language=rst
61 """
62 Return a grid of a number of filters ``sqrt ** 2`` with side lengths ``side``.
63
64 :param weights: Two-dimensional tensor of weights for two-dimensional data.
65 :param n_sqrt: Square root of no. of filters.
66 :param side: Side length(s) of filter.
67 :return: Reshaped weights to square matrix of filters.
68 """
69 if isinstance(side, int):
70 side = (side, side)
71
72 square_weights = torch.zeros(side[0] * n_sqrt, side[1] * n_sqrt)
73 for i in range(n_sqrt):
74 for j in range(n_sqrt):
75 n = i * n_sqrt + j
76
77 if not n < weights.size(1):
78 break
79
80 x = i * side[0]
81 y = (j % n_sqrt) * side[1]
82 filter_ = weights[:, n].contiguous().view(*side)
83 square_weights[x : x + side[0], y : y + side[1]] = filter_
84
85 return square_weights
86
87
88def get_square_assignments(assignments: Tensor, n_sqrt: int) -> Tensor:

Callers 5

SOM_LM-SNNs.pyFile · 0.90
reservoir.pyFile · 0.90
batch_eth_mnist.pyFile · 0.90
eth_mnist.pyFile · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected