Lazily invokes ``bindsnet.encoding.bernoulli`` to iteratively encode a sequence of data. :param data: Tensor of shape ``[n_samples, n_1, ..., n_k]``. :param time: Length of Bernoulli spike train per input variable. :param dt: Simulation time step. :return: Tensors of shape
(
data: Union[torch.Tensor, Iterable[torch.Tensor]],
time: Optional[int] = None,
dt: float = 1.0,
**kwargs,
)
| 6 | |
| 7 | |
| 8 | def bernoulli_loader( |
| 9 | data: Union[torch.Tensor, Iterable[torch.Tensor]], |
| 10 | time: Optional[int] = None, |
| 11 | dt: float = 1.0, |
| 12 | **kwargs, |
| 13 | ) -> Iterator[torch.Tensor]: |
| 14 | # language=rst |
| 15 | """ |
| 16 | Lazily invokes ``bindsnet.encoding.bernoulli`` to iteratively encode a sequence of |
| 17 | data. |
| 18 | |
| 19 | :param data: Tensor of shape ``[n_samples, n_1, ..., n_k]``. |
| 20 | :param time: Length of Bernoulli spike train per input variable. |
| 21 | :param dt: Simulation time step. |
| 22 | :return: Tensors of shape ``[time, n_1, ..., n_k]`` of Bernoulli-distributed spikes. |
| 23 | |
| 24 | Keyword arguments: |
| 25 | |
| 26 | :param float max_prob: Maximum probability of spike per Bernoulli trial. |
| 27 | """ |
| 28 | # Setting kwargs. |
| 29 | max_prob = kwargs.get("dt", 1.0) |
| 30 | |
| 31 | for i in range(len(data)): |
| 32 | # Encode datum as Bernoulli spike trains. |
| 33 | yield bernoulli(datum=data[i], time=time, dt=dt, max_prob=max_prob) |
| 34 | |
| 35 | |
| 36 | def poisson_loader( |