EchoStateNetwork#
- class torchdyno.models.esn.esn.EchoStateNetwork[source]#
Bases:
ModuleMethods
__init__()Initialize internal Module state, shared by both nn.Module and ScriptModule.
apply_reservoirs(x, initial_state)Apply the reservoirs to the input.
evaluate(test_loader, score_fn[, washout])Evaluate the model.
fit_from_matrices([l2])Fit the readout layer from the stored matrices.
fit_readout(train_loader[, l2_value, ...])Fit the readout layer.
forward(x[, initial_state, return_states])Forward pass of the network.
Attributes
Returns the size of the hidden state.
- __init__(input_size: int, output_size: int, layer_sizes: List[int], arch_type: Literal['stacked', 'multi', 'parallel'] = 'stacked', activation: str = 'tanh', leakage: float = 1.0, input_scaling: float = 0.9, rho: float = 0.99, bias: bool = False, kernel_initializer: str | Callable[[Size], Tensor] = 'uniform', recurrent_initializer: str | Callable[[Size], Tensor] = 'uniform', net_gain_and_bias: bool = False)[source]#
- __init__(output_size: int, combine_reservoirs: Literal['stacked', 'multi', 'parallel', 'merge'] = 'stacked', joint_scaling: float = 1.0, independent_inputs: bool = False)
Initialize internal Module state, shared by both nn.Module and ScriptModule.
- forward(x, initial_state=None, return_states=False)[source]#
Forward pass of the network.
- Parameters:
x (torch.Tensor) – input tensor.
initial_state (List[torch.Tensor]) – initial state of the reservoirs.
return_states (bool, optional) – whether to return the states. Defaults to False.
- Returns:
output tensor.
- Return type:
torch.Tensor
- apply_reservoirs(x, initial_state)[source]#
Apply the reservoirs to the input.
- Parameters:
x (torch.Tensor) – input tensor.
initial_state (Optional[torch.Tensor]) – initial state of the reservoirs.
- Returns:
output tensor.
- Return type:
torch.Tensor
- fit_readout(train_loader, l2_value=1e-09, washout=0, score_fn=None, mode=None, eval_on=None, store_matrices=False)[source]#
Fit the readout layer.
- Parameters:
train_loader (DataLoader) – training data loader.
eval_loader (DataLoader) – evaluation data loader.
l2_values (List[float]) – list of L2 regularization values.
score_fn (Callable[[Tensor, Tensor], float]) – scoring function.
mode (Literal["min", "max"]) – optimization mode.
weights (Optional[List[float]], optional) – weights for the loss. Defaults to None.
preprocess_fn (Optional[Callable], optional) – preprocessing function. Defaults to None.
device (Optional[str], optional) – device to use. Defaults to None.
l2_value (float | List[float])
washout (int)
eval_on (Literal['train'] | ~torch.utils.data.dataloader.DataLoader | None)
store_matrices (bool)
- fit_from_matrices(l2=None)[source]#
Fit the readout layer from the stored matrices.
- Parameters:
l2 (float | None)
- evaluate(test_loader, score_fn, washout=0)[source]#
Evaluate the model.
- Parameters:
test_loader (DataLoader) – test data loader.
score_fn (Callable[[Tensor, Tensor], float]) – scoring function.
washout (int, optional) – washout steps. Defaults to 0.
- Returns:
evaluation score.
- Return type:
float
Returns the size of the hidden state.