WinnieXi
WinnieXi

Reputation: 13

How to Prepare Inflow/Outflow Data as Tensors for PyTorch Dataset and Dataloader?

I’m working with a bike-sharing dataset that tracks trips between stations and I'm wondering if there's a better way to feed the (time series) data into a neural network using PyTorch.
Each record includes:

My goal is to create inflow and outflow matrices for each time slot (e.g., hourly), where:

Then for a given d, I would then feed the matrices from t-d to t-1 into my model. Here's my current approach:

  1. Matrix Representation:

    • For each time slot, I’ll generate an n x n matrix for both inflow and outflow.
    • Then, concatenate these matrices across all time slots to create two tensors:
      • T x n x n for inflow.
      • T x n x n for outflow.
    • Here, T is the total number of periods (hours) in the data.
  2. Dataset and Dataloader:

    • The dataset should index into these tensors to retrieve:
      • A sequence of matrices for the past ( k ) time slots (short-term dependency).
      • The same matrices for the same time slots across the past ( d ) days (long-term dependency).
    • The dataloader will batch this data for training a spatial-temporal graph neural network (STGNN).

My Question:

Any advice or code snippets would be greatly appreciated!

Upvotes: 0

Views: 45

Answers (0)

Related Questions