braintools.input.Transformed

braintools.input.Transformed#

class braintools.input.Transformed(input_obj, func)#

Custom transformation applied to an input.

Applies an arbitrary function to transform an input, enabling custom nonlinearities and processing.

Parameters:
  • input_obj (Input) – The input to transform.

  • func (Callable) – Function to apply to the array. Should accept and return an array-like object.

Examples

>>> import jax.numpy as jnp
>>> sine = Sinusoidal(1.0, 10 * u.Hz, 200 * u.ms)
>>>
>>> # Half-wave rectification
>>> rectified = Transformed(sine, lambda x: jnp.maximum(x, 0))
>>>
>>> # Squaring (frequency doubling)
>>> squared = Transformed(sine, lambda x: x ** 2)
>>>
>>> # Sigmoid nonlinearity
>>> sigmoid = Transformed(sine,
...     lambda x: 1 / (1 + jnp.exp(-10 * x)))
>>>
>>> # Usually created via apply() method
>>> transformed = sine.apply(lambda x: jnp.abs(x))
__init__(input_obj, func)[source]#

Initialize transformed input.

Parameters:
  • input_obj (Input) – The input to transform.

  • func (Callable) – Function to apply to the array.

Methods

__init__(input_obj, func)

Initialize transformed input.

apply(func)

Apply a custom function to the input.

clip([min_val, max_val])

Clip the input values to a range.

generate()

Generate the transformed input.

repeat(n_times)

Repeat the input pattern n times.

scale(factor)

Scale the input by a factor.

shift(time_shift)

Shift the input in time.

smooth(tau)

Apply exponential smoothing to the input.

Attributes

dt

Get the time step from global environment.

n_steps

Get the number of time steps.

shape

Get the shape of the input array.