PyTorch¶
flowcean.torch provides datasets, model wrappers, neural network architectures, and a Lightning learner.
Install the torch extra as described in installation.
torch
¶
Classes¶
TorchDataset
¶
Bases: Dataset[tuple[Tensor, Tensor]]
Dataset for PyTorch.
Initialize the TorchDataset.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
inputs
|
DataFrame
|
The input data. |
required |
outputs
|
DataFrame | None
|
The output data. Defaults to None. |
None
|
LightningLearner
¶
LightningLearner(module: LightningModule, num_workers: int | None = None, batch_size: int = 32, max_epochs: int = 100, accelerator: str = 'auto', callbacks: list[LearnerCallback] | LearnerCallback | None = None)
Bases: SupervisedLearner
A learner that uses PyTorch Lightning.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
module
|
LightningModule
|
The PyTorch Lightning module. |
required |
num_workers
|
int | None
|
The number of workers to use for the DataLoader. |
None
|
batch_size
|
int
|
The batch size to use for training. |
32
|
max_epochs
|
int
|
The maximum number of epochs to train for. |
100
|
accelerator
|
str
|
The accelerator to use. |
'auto'
|
callbacks
|
list[LearnerCallback] | LearnerCallback | None
|
Optional callbacks for progress feedback. Use |
None
|
Initialize the learner.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
module
|
LightningModule
|
The PyTorch Lightning module. |
required |
num_workers
|
int | None
|
The number of workers to use for the DataLoader. |
None
|
batch_size
|
int
|
The batch size to use for training. |
32
|
max_epochs
|
int
|
The maximum number of epochs to train for. |
100
|
accelerator
|
str
|
The accelerator to use. |
'auto'
|
callbacks
|
list[LearnerCallback] | LearnerCallback | None
|
Optional callbacks for progress feedback. Use |
None
|
LinearRegression
¶
LinearRegression(*, output_size: int, learning_rate: float = 0.001, loss: Module | None = None, a: Tensor | None = None, b: Tensor | None = None)
Bases: SupervisedIncrementalLearner
Linear regression learner.
Initialize the learner.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
output_size
|
int
|
The size of the output. |
required |
learning_rate
|
float
|
The learning rate. |
0.001
|
loss
|
Module | None
|
The loss function. |
None
|
a
|
Tensor | None
|
Initial weights. If None (the default), random weights are used. |
None
|
b
|
Tensor | None
|
Initial bias. If None (the default), random bias is used. |
None
|
PyTorchModel
¶
Bases: Model
PyTorch model wrapper.
Initialize the model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
module
|
Module
|
The PyTorch module. |
required |
output_names
|
list[str]
|
The names of the output columns. |
required |
batch_size
|
int
|
The batch size to use for predictions. |
32
|
num_workers
|
int
|
Retained for backward compatibility. |
1
|
MultilayerPerceptron
¶
MultilayerPerceptron(learning_rate: float, output_size: int, hidden_dimensions: list[int] | None = None, *, activation_function: type[Module] | None = None)
Bases: LightningModule
A multilayer perceptron.
Initialize the model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
learning_rate
|
float
|
The learning rate. |
required |
output_size
|
int
|
The size of the output. |
required |
hidden_dimensions
|
list[int] | None
|
The dimensions of the hidden layers. |
None
|
activation_function
|
type[Module] | None
|
The activation function to use. Defaults to ReLU if not provided. |
None
|