Standardize

class gpype.backend.transform.standardize.Standardize[source]

Bases: Fittable, IONode

Per-channel z-score, fitted offline and applied unchanged online.

The first fittable node (D-BATCH-93): each signal channel’s mean and standard deviation, learned once from a whole recording via fit(), then subtracted and divided out of every frame afterwards – in a batch run over the same recording, or in a realtime deployment reading live from an amplifier. The two produce the same numbers because both call the same private transform; fitting and deploying are two different methods precisely so that neither can drift from the other (see gpype.backend.core.fittable).

Only the channels the port context calls signal are touched – an index or trigger channel standardized alongside the signal would lose the meaning of its own values. Those channels declare no unit afterwards: a z-score has none.

Parameters:
  • ddof (int) – Delta degrees of freedom for the fitted standard deviation, as in numpy.std. 0 (the default) is the population estimate; 1 is the sample estimate.

  • **kwargs – Additional arguments for the parent IONode.

class Configuration[source]

Bases: Configuration

Configuration class for Standardize parameters.

class OptionalKeys[source]

Bases: OptionalKeys

Optional configuration keys.

DDOF = 'ddof'

Delta degrees of freedom for the fitted standard deviation.

__init__(ddof=0, **kwargs)[source]

Initialize the IONode with input and output port configurations.

Parameters:
  • input_ports – List of input port configurations or None.

  • output_ports – List of output port configurations or None.

  • **kwargs – Additional arguments passed to parent classes.

setup(data, port_context_in)[source]

Resolve which channels are signal, ahead of fitting or applying.

Parameters:
Returns:

standardizing does not add, remove or reorder channels.

Return type:

dict[str, dict]

fit(block, context)[source]

Compute each signal channel’s mean and standard deviation.

Parameters:
  • block (ndarray) – The whole recording, shape (time, channel).

  • context (dict) – The input context. Read for the channel roles only under fit_offline(), which runs no setup(); a context naming no channel count is sized by block.

Return type:

dict

Returns:

{"mean": ..., "std": ...}, one entry per signal channel.

load_state(state)[source]

Adopt a fitted mean and standard deviation.

Parameters:

state (dict) – {"mean": ..., "std": ...}.

Return type:

None

apply_block(block)[source]

Standardize the whole block at once, for a batch run.

Parameters:

block (ndarray) – The complete input.

Return type:

ndarray

Returns:

The standardized block, same shape.

step(data)[source]

Standardize one frame, for a realtime deployment.

Parameters:

data (dict[str, ndarray]) – Input frame.

Return type:

dict[str, ndarray]

Returns:

The standardized frame.