wesselb / neuralprocesses

A framework for composing Neural Processes in Python
https://wesselb.github.io/neuralprocesses
MIT License
76 stars 12 forks source link

Is it possible to use GNP to learn sensor coverage? #11

Closed ligengen closed 1 year ago

ligengen commented 1 year ago

Hello Wessel,

Thanks a lot for the amazing work!

I have a question regarding the GNP model. From my understanding, every input sensor of shape (B, C, N) should correspond to an output value of shape (B, C', N). However, I'm interested in using the GNP to model the sensor coverage problem, where the input shape is (C, N) with N sensors, and the output is a single number representing the coverage rate.

My concern is whether the GNP is able to handle an input of shape (B, C, N) and an output of shape (B, 1). If the input is randomly subsampled sensor sets, how to greedily add the next sensor to maximize the coverage?

I would greatly appreciate any guidance or suggestions you might have on how to adapt the GNP for this use case. Thank you so much for your time and expertise!

Many thanks, Gen

wesselb commented 1 year ago

Hey @ligengen!

Thanks for opening an issue. :)

That's a very interesting problem! If I understand correctly, rather then producing predictions at target inputs, you would like to produce one (or multiple) "global" predictions.

It is certainly possible to do this with the package. The predefined models aren't currently setup in this way, and the neural network architectures aren't currently optimised for this use case, but we could definitely work on this!

Perhaps the simplest thing is to take a standard regression GNP and to strip off the last layer that "interpolates to the target inputs". You can then instead do a global pooling to get a global variable out:

import torch

import neuralprocesses.torch as nps

model = nps.construct_convgnp()

xc = torch.randn(16, 1, 10)
yc = torch.randn(16, 1, 10)

# Just set the decoder to the U-Net architecture.
model.decoder =  model.decoder[0]  

# Since we're generating a global encoding, set the target inputs to the context inputs.
z = model(xc, yc, xc)
# Now pool over the spatial dimensions, e.g. by summing.
z = torch.sum(z, axis=-1)

print(z.shape)  # (16, 64)

Is this very roughly what you're after?

ligengen commented 1 year ago

Hi @wesselb, Thanks for your prompt reply! Yes it is what I am after. Thanks for the help!

wesselb commented 1 year ago

@ligengen np at all! Please do comment here if we can be of any further help. :)

tom-andersson commented 1 year ago

hi @ligengen, @wesselb and I are in the process of publishing a paper on using a GNP for sensor placement, which sounds related to your sensor coverage problem. In case of interest, here is the arXiv: https://arxiv.org/abs/2211.10381. Happy to chat :-)