- norse.torch.functional.population_encode(input_values: ~torch.Tensor, out_features: int, scale: ~typing.Union[int, ~torch.Tensor] = None, kernel: ~typing.Callable[[~torch.Tensor], ~torch.Tensor] = <function gaussian_rbf>, distance_function: ~typing.Callable[[~torch.Tensor, ~torch.Tensor], ~torch.Tensor] = <function euclidean_distance>) Tensor #
Encodes a set of input values into population codes, such that each singular input value is represented by a list of numbers (typically calculated by a radial basis kernel), whose length is equal to the out_features.
Population encoding can be visualised by imagining a number of neurons in a list, whose activity increases if a number gets close to its “receptive field”.
>>> data = torch.as_tensor([0, 0.5, 1]) >>> out_features = 3 >>> pop_encoded = population_encode(data, out_features) tensor([[1.0000, 0.8825, 0.6065], [0.8825, 1.0000, 0.8825], [0.6065, 0.8825, 1.0000]]) >>> spikes = poisson_encode(pop_encoded, 1).squeeze() # Convert to spikes
input_values (torch.Tensor): The input data as numerical values to be encoded to population codes out_features (int): The number of output per input value scale (torch.Tensor): The scaling factor for the kernels. Defaults to the maximum value of the input.
Can also be set for each individual sample.
- kernel: A function that takes two inputs and returns a tensor. The two inputs represent the center value
(which changes for each index in the output tensor) and the actual data value to encode respectively.z Defaults to gaussian radial basis kernel function.
distance_function: A function that calculates the distance between two numbers. Defaults to euclidean.
A tensor with an extra dimension of size seq_length containing population encoded values of the input stimulus. Note: An extra step is required to convert the values to spikes, see above.