TorchSpatiotemporal / tsl

tsl: a PyTorch library for processing spatiotemporal data.
https://torch-spatiotemporal.readthedocs.io/
MIT License
267 stars 24 forks source link

Shapes of input data #22

Open LaurentBerder opened 1 year ago

LaurentBerder commented 1 year ago

Hi,

I just installed tsl, having been really interested in your code and documentation.

However, I realize that I don't know where to start to create my own dataset. The only examle codes I see are using samples already included inyour library.

If I have these three pandas DataFrame (details of their columns below), how would I go creating my SpatioTemporalDataset object?

LaurentBerder commented 1 year ago

The data I'm trying to model is a dynamic graph (my edge features evolve over time). Based on the documentation, I tried the following:

from tsl.data import SpatioTemporalDataset

connectivity = (
        edges.pivot(index=['DAY', 'ORIGIN'], columns='DESTINATION', values='EDGE_FEATURE'),
        edges[['DAY', 'ORIGIN', 'DESTINATION']].drop_duplicates()
)
dataset = SpatioTemporalDataset(target=pd.pivot(targets, index='DAY', columns='NODE', values='TARGET'),
                                                       connectivity=connectivity,
                                                       horizon=12, window=12, stride=1
)

But that only resulted in the following trace:

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
/usr/local/lib/python3.9/dist-packages/tsl/data/spatiotemporal_dataset.py in __init__(self, target, index, mask, connectivity, covariates, input_map, target_map, auxiliary_map, scalers, trend, transform, window, horizon, delay, stride, window_lag, horizon_lag, precision, name)
    187         self.edge_index: Optional[Adj] = None
    188         self.edge_weight: Optional[Tensor] = None
--> 189         self.set_connectivity(connectivity)
    190 
    191         # Store covariates (e.g., exogenous and attributes)

/usr/local/lib/python3.9/dist-packages/tsl/data/spatiotemporal_dataset.py in set_connectivity(self, connectivity, target_layout)
    835                 (default: :obj:`None`)
    836         """
--> 837         self.edge_index, self.edge_weight = self._parse_connectivity(
    838             connectivity, target_layout)
    839 

/usr/local/lib/python3.9/dist-packages/tsl/data/mixin.py in _parse_connectivity(self, connectivity, target_layout)
     67             edge_index, edge_weight = connectivity
     68             if edge_weight is not None:
---> 69                 edge_weight = casting.convert_precision_tensor(
     70                     edge_weight, self.precision)
     71         else:

/usr/local/lib/python3.9/dist-packages/tsl/utils/casting.py in convert_precision_tensor(tensor, precision)
     38     precision = precision_stoi(precision)
     39     dtype = tensor.dtype() if isinstance(tensor,
---> 40                                          SparseTensor) else tensor.dtype
     41     # float to float{precision}
     42     if dtype in [torch.float16, torch.float32, torch.float64]:

/usr/local/lib/python3.9/dist-packages/pandas/core/generic.py in __getattr__(self, name)
   5573         """
   5574         # Note: obj.x will always call obj.__getattribute__('x') prior to
-> 5575         # calling obj.__getattr__('x').
   5576         if (
   5577             name not in self._internal_names_set

AttributeError: 'DataFrame' object has no attribute 'dtype'
ghost commented 1 year ago

@LaurentBerder did you manage to figure this out? I have the same issue.

/cc @andreacini

LaurentBerder commented 1 year ago

@LaurentBerder did you manage to figure this out? I have the same issue.

Nope, I abandonned the project. Sorry.

KoperSloper commented 1 year ago

Having the same problem. Still no example of creating your own dataset?