Giter Site home page Giter Site logo

graph-machine-learning-group / spin Goto Github PK

View Code? Open in Web Editor NEW
37.0 4.0 8.0 1.82 MB

Official repository for the paper "Learning to Reconstruct Missing Data from Spatiotemporal Graphs with Sparse Observations" (NeurIPS 2022)

Home Page: https://arxiv.org/abs/2205.13479

License: MIT License

Python 100.00%
graph-neural-networks imputation missing-data spatiotemporal-data-analysis time-series-imputation

spin's Introduction

Learning to Reconstruct Missing Data from Spatiotemporal Graphs with Sparse Observations (NeurIPS 2022)

NeurIPS PDF arXiv

This repository contains the code for the reproducibility of the experiments presented in the paper "Learning to Reconstruct Missing Data from Spatiotemporal Graphs with Sparse Observations" (NeurIPS 2022). We propose a graph neural network that exploits a novel spatiotemporal attention to impute missing values leveraging only (sparse) valid observations.

Authors: Ivan Marisca, Andrea Cini, Cesare Alippi

SPIN in a nutshell

Spatiotemporal graphs are often highly sparse, with time series characterized by multiple, concurrent, and even long sequences of missing data, e.g., due to the unreliable underlying sensor network. In this context, autoregressive models can be brittle and exhibit unstable learning dynamics. The objective of this paper is, then, to tackle the problem of learning effective models to reconstruct, i.e., impute, missing data points by conditioning the reconstruction only on the available observations. In particular, we propose a novel class of attention-based architectures that, given a set of highly sparse discrete observations, learn a representation for points in time and space by exploiting a spatiotemporal diffusion architecture aligned with the imputation task. Representations are trained end-to-end to reconstruct observations w.r.t. the corresponding sensor and its neighboring nodes. Compared to the state of the art, our model handles sparse data without propagating prediction errors or requiring a bidirectional model to encode forward and backward time dependencies.

Example of the sparse spatiotemporal attention layer.

Example of the sparse spatiotemporal attention layer. On the left, the input spatiotemporal graph, with time series associated with every node. On the right, how the layer acts to update target representation (highlighted by the green box), by simultaneously performing inter-node spatiotemporal cross-attention (red block) and intra-node temporal self-attention (violet block).


Directory structure

The directory is structured as follows:

.
├── config/
│   ├── imputation/
│   │   ├── brits.yaml
│   │   ├── grin.yaml
│   │   ├── saits.yaml
│   │   ├── spin.yaml
│   │   ├── spin_h.yaml
│   │   └── transformer.yaml
│   └── inference.yaml
├── experiments/
│   ├── run_imputation.py
│   └── run_inference.py
├── spin/
│   ├── baselines/
│   ├── imputers/
│   ├── layers/
│   ├── models/
│   └── ...
├── conda_env.yaml
└── tsl_config.yaml

Installation

We provide a conda environment with all the project dependencies. To install the environment use:

conda env create -f conda_env.yml
conda activate spin

Configuration files

The config/ directory stores all the configuration files used to run the experiment. config/imputation/ stores model configurations used for experiments on imputation.

Python package spin

The support code, including models and baselines, are packed in a python package named spin.

Experiments

The scripts used for the experiment in the paper are in the experiments folder.

  • run_imputation.py is used to compute the metrics for the deep imputation methods. An example of usage is

     conda activate spin
     python ./experiments/run_imputation.py --config imputation/spin.yaml --model-name spin --dataset-name bay_block
  • run_inference.py is used for the experiments on sparse datasets using pre-trained models. An example of usage is

     conda activate spin
     python ./experiments/run_inference.py --config inference.yaml --model-name spin --dataset-name bay_point --exp-name {exp_name}

Bibtex reference

If you find this code useful please consider to cite our paper:

@article{marisca2022learning,
  title={Learning to Reconstruct Missing Data from Spatiotemporal Graphs with Sparse Observations},
  author={Marisca, Ivan and Cini, Andrea and Alippi, Cesare},
  journal={arXiv preprint arXiv:2205.13479},
  year={2022}
}

spin's People

Contributors

andreacini avatar marshka avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

spin's Issues

conda_env.yml

Hello, could you please provide the specific version of the environment dependency package?
conda env create -f conda_env.yml did not create correct environment successfully.
I have tried various methods but have always made various mistakes.
I look forward to receiving your help very much. Thank you

Question about masking rate and missing rate

Hi, thank you for presenting such a nice paper and project! Since I'm not familiar with tsl code format, I have several questions about the missing rate and masking rate settings in your paper:

  1. In METR-LA point missing case, you randomly drop 25% of the original data to construct an incomplete dataset (this is controlled by the 'p_noise' parameter). Then during traning stage, more missing data is generated for each input batch by setting 'whiten_prob' parameter. I'm confused about whether the 25% of missing data exists in the training data? If that is the case, the input contains missing data generated from both 'p_noise (25%)' and 'whiten_prob (e.g., 80%)' , which leads to a very sparse traning set. Is the loss only computed on the 'whiten_prob' parts during training?
  2. If I want to train the model with training data only contains 'whiten_prob', and test it on different 'p_noise' levels, like the settings in Tab. 2 of your paper. But the difference is that, I do not add 'p_noise (25%)' to training data and would like to add different levels of 'p_noise' data to testing data, how could I achieve this goal based on your code?

Thanks in advance for your help!

Missing Values for AirQuality Dataset

Hi,

To conduct experiments with different missing rates and failure probabilities for the AQI dataset, do you also use the "add_missing_values()" function for the AQI dataset?

run bug: takes 3 positional arguments but 4 were given

Hi authors, i attempt to run your great imputation algorithm spin, but the TypeError occurs as shown in the following log. Is it caused by the bug in your package "tsl"?

File "/home/user/anaconda3/envs/spin/lib/python3.8/site-packages/tsl/imputers/imputer.py", line 134, in on_train_batch_start
super(Imputer, self).on_train_batch_start(batch, batch_idx, unused)
TypeError: on_train_batch_start() takes 3 positional arguments but 4 were given.

Where can I find the temporal encoding module?

Hi, I've noticed that you have mentioned "we use sine and cosine transforms of the time step t w.r.t. a period of interest (e.g., day and/or week), to account for". However, I can't find corresponding code either in "positional_encodind" nor "utils.py". It this module not included in the repo and belonging to the dataset preprocessing part, or just because I miss some part of the repo. And I'm not very clear about how this transform works. Does it operate like positional encoding in “Attention is all you need" ?

StaticGraphEmbedding

Thank you for your contributions. I am confusing about the function of StaticGraphEmbedding, and I do not find the implementation of this function. May be I ignore some what or where can I find this function? Thank you for your help!

run bug: TypeError: Argument 'freq' has incorrect type

Hi, this is an error when I try to run the command "python ./experiments/run_imputation.py --config imputation/spin.yaml --model-name spin --dataset-name bay_block", and my pandas version is 1.5.3, is there an easy way to fix this?
Thanks for your help!

===============================
Global seed set to 561122547
Traceback (most recent call last):
File "./experiments/run_imputation.py", line 301, in
run_experiment(args)
File "./experiments/run_imputation.py", line 146, in run_experiment
dataset = get_dataset(args.dataset_name)
File "./experiments/run_imputation.py", line 64, in get_dataset
return add_missing_values(PemsBay(), p_fault=p_fault, p_noise=p_noise,
File "C:\ProgramData\Anaconda3\envs\spin\lib\site-packages\tsl\datasets\pems_bay.py", line 32, in init
df, dist, mask = self.load()
File "C:\ProgramData\Anaconda3\envs\spin\lib\site-packages\tsl\datasets\pems_bay.py", line 78, in load
df, dist = self.load_raw()
File "C:\ProgramData\Anaconda3\envs\spin\lib\site-packages\tsl\datasets\pems_bay.py", line 69, in load_raw
datetime_idx = sorted(df.index)
File "C:\ProgramData\Anaconda3\envs\spin\lib\site-packages\pandas\core\arrays\datetimes.py", line 590, in iter
converted = ints_to_pydatetime(
TypeError: Argument 'freq' has incorrect type (expected pandas.libs.tslibs.offsets.BaseOffset, got numpy.bytes)

running bug

I ran your demo code by
python ./experiments/run_imputation.py --config imputation/spin.yaml --model-name spin --dataset-name bay_block

Traceback (most recent call last):
File "./experiments/run_imputation.py", line 303, in
run_experiment(args)
File "./experiments/run_imputation.py", line 172, in run_experiment
time_emb = dataset.datetime_encoded(['day', 'week']).values
File "/home/txz/.conda/envs/spin/lib/python3.8/site-packages/tsl/datasets/prototypes/mixin.py", line 83, in datetime_encoded
mapping = {un: pd.to_timedelta('1' + un).delta
File "/home/txz/.conda/envs/spin/lib/python3.8/site-packages/tsl/datasets/prototypes/mixin.py", line 83, in
mapping = {un: pd.to_timedelta('1' + un).delta
AttributeError: 'Timedelta' object has no attribute 'delta'

The problem for evaluation metrics

Dear Authors,

I recently read your paper and reproduce the spin code. Is the performance (in terms of MAE) after the StandardScaler operation on the raw data or for the raw data?

Thank you for your time and for the insights your paper offers.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.