Skip to content

TimeAveragedDense

Source code

Bases: tf.keras.layers.Dense

This layer simulates continuous-temporal dynamics with time-averaged input/output.

Note

This layer is for single input, i.e., signal comes from one precedent layer. For multiple inputs equivalent, see MultiInputTimeAveraging.

Parameters:

Name Type Description Default
tau float

Time-averaging parameter, from 0 to 1.

required
average_at str

Select where to average, 'before_activation' or 'after_activation'.

required
kwargs dict

Any argument in keras.layers.Dense.

{}

Time-averaged input

See Plaut, McClelland, Seidenberg, and Patterson (1996) equation (15).

Defines as:

at=act(st) a_t = act(s_t)

st=τ(xtw+b)+(1τ)st1 s_t = \tau \cdot (x_t w + b) + (1-\tau) \cdot s_{t-1}

Warning

"\cdot" is element-wise multiplication.

  • ata_t: activation at time tt.
  • actact: activation function (provided by this layer if activation is used).
  • sts_t: state at time tt.
  • τ\tau: time constant, smaller means slower temporal dynamics.
  • xtx_t: input at time tt.
  • ww: weight matrix (provided by this layer).
  • bb: bias vector, provided by this layer if use_bias is True (Default).
  • st1s_{t-1}: state at time t1t-1, stored in self.states.

Example

layer = TimeAveragedDense(
    tau=0.1, average_at="before_activation", units=10, activation="sigmoid"
    )

Time-averaged output

Defines as:

at=τact(xtw+b)+(1τ)at1 a_t = \tau \cdot act(x_t w + b) + (1-\tau) \cdot a_{t-1}

Warning

"\cdot" is element-wise multiplication.

  • ata_t: activation at time tt.
  • τ\tau: time constant, smaller means slower temporal dynamics.
  • actact: activation function (provided by this layer if activation is used).
  • xtx_t: input at time tt.
  • ww: weight matrix (provided by this layer).
  • bb: bias vector, provided by this layer if use_bias is True (Default).
  • at1a_{t-1}: activation at time t1t-1, stored in self.states.

Example

layer = TimeAveragedDense(
    tau=0.1, average_at="after_activation", units=10, activation="sigmoid"
    )

call(inputs)

Forward pass.

Note

This function reused keras.layers.Dense.call() without activation. Time-averaging and activation are manually implemented here.

Parameters:

Name Type Description Default
inputs tf.Tensor

Input tensor xtx_t.

required

Returns:

Name Type Description
outputs tf.Tensor

Output tensor ata_t.

reset_states()

Resetting self.states to None.

Note

This is typically called when RNN unrolling is done, so that the next batch of data can start with a clean state.