TorchLean API

NN.Examples.Models.Supervised.LstmRegression

LSTM Seasonal Regression / Forecasting #

This is the runnable supervised sequence example: an LSTM trains on a real-valued forecasting task and works with the same CPU/CUDA runtime flags as the other model commands.

The default data path uses the UCI Individual Household Electric Power Consumption dataset: minute-level power readings from one household over almost four years. The preparation script turns that into hourly one-step forecasting windows:

past 24 hours -> next 24 shifted-by-one-hour targets

Prepare the real data once:

python3 scripts/datasets/download_example_data.py --household-power --household-power-windows 512

Recommended runs:

lake -R -K cuda=true exe torchlean lstm_regression --device cuda --steps 1 --windows 1
lake -R -K cuda=true exe torchlean lstm_regression --device cuda --steps 200 --windows 96

Dataset citation: Hebrail and Berard, "Individual Household Electric Power Consumption", UCI Machine Learning Repository, DOI 10.24432/C58K54, CC BY 4.0.

Runner subcommand: lake exe torchlean lstm_regression ....

Instances For

    Default JSON path for the before/after loss.

    Pass --log PATH to write somewhere else, or --log disabled when you only want terminal output.

    Instances For

      Prepared household-power windows contain one day of hourly samples.

      Instances For

        One scalar feature. Increase this when the prepared sequence data gains more features.

        Instances For

          Hidden width for the recurrent state used by this runnable example.

          Instances For

            One scalar power-consumption prediction at each timestep.

            Instances For
              @[reducible, inline]

              Shared recurrent-model configuration.

              The model constructor, input shape, and output shape all read from this value. The single output feature is the next power-consumption prediction at each time step.

              Instances For
                @[reducible, inline]

                Input shape: one scalar observation at each timestep.

                Instances For
                  @[reducible, inline]

                  Target/prediction shape: one next-step scalar at each timestep.

                  Instances For

                    The actual forecaster.

                    nn.models.lstm modelConfig expands to:

                    nn.lstm sequenceLength featureCount hiddenWidth followed by a time-distributed nn.linear hiddenWidth outputWidth.

                    So every timestep emits a scalar forecast. We are not using only the final hidden state here; the loss checks the whole output sequence.

                    Instances For

                      Data source tags for terminal logs and JSON metadata.

                      Instances For

                        Validate the prepared input file and return its available window count.

                        Instances For

                          Load the Float version once for reporting probes and short training.

                          Instances For

                            Read t[row,0] from a forecast tensor.

                            Instances For

                              Render the first few target values for one forecast window.

                              Instances For

                                Public trainer probe for a deterministic forecast window.

                                Instances For

                                  Executable entrypoint for CPU/CUDA Float training.

                                  Instances For