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 exe -K cuda=true torchlean lstm_regression --cuda --steps 1 --windows 1
lake exe -K cuda=true torchlean lstm_regression --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

      Default root for downloaded real datasets. Override with --data-dir.

      Instances For

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

        Instances For

          Short prefix used by the runnable recurrent example.

          Instances For

            One scalar feature. If you add calendar/weather features, increase this and update scalarRow.

            Instances For

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

              Instances For

                Shared recurrent-model configuration.

                The model constructor, input shape, and output shape all read from seqLen, inputSize, and hiddenSize. If a shape error appears, start here.

                Instances For
                  @[reducible, inline]

                  Input shape: one scalar observation at each of seqLen timesteps.

                  Instances For
                    @[reducible, inline]

                    Target/prediction shape: one next-step scalar at each of seqLen timesteps.

                    Instances For
                      @[reducible, inline]

                      Raw input shape stored by the prepared household-power .npy files.

                      Instances For
                        @[reducible, inline]

                        Raw target shape stored by the prepared household-power .npy files.

                        Instances For

                          The actual forecaster.

                          nn.models.lstmWithLinearHead cfg expands to:

                          nn.LSTM seqLen inputSize hiddenSize followed by a time-distributed nn.Linear hiddenSize inputSize.

                          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

                                  Convert one real 24-hour prepared window into the tiny recurrent training sample.

                                  Instances For

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

                                    The row is clamped so the reporting loop remains valid if seqLen is changed without also updating the number of displayed rows.

                                    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