Learn R Programming

NeuralEstimators (version 0.1.3)

spatialgraphlist: spatialgraphlist

Description

Constructs a list of graph objects for use in a graph neural network.

Usage

spatialgraphlist(S, Z, isotropic = TRUE, stationary = TRUE, ...)

Value

A list of GNNGraph objects stored as a JuliaProxy object; this object can be indexed in the usual manner (e.g., using [[), and converted to an R list using a combination of indexing and lapply.

Arguments

S

A list of spatial locations, where each element of the list is:

  • An n x d matrix when locations are fixed across replicates in a given data set, where n is the number of spatial locations and d is the spatial dimension (typically d=2).

  • A list of n_i x d matrices when locations vary across replicates, where each matrix corresponds to the spatial locations of a single replicate.

Z

A list of spatial data, where each element of the list is:

  • An n x m matrix when locations are fixed, where m is the number of replicates.

  • A list of n_i vectors when locations vary across replicates, where each vector corresponds to the data for a single replicate.

isotropic

Logical. If TRUE, edge features store the spatial distance (magnitude) between nodes. If FALSE, the spatial displacement or spatial location is stored, depending on the value of stationary.

stationary

Logical. If TRUE, edge features store the spatial displacement (vector difference) between nodes, capturing both magnitude and direction. If FALSE, edge features include the full spatial locations of both nodes.

...

Additional keyword arguments from the Julia function adjacencymatrix() determine the neighborhood of each node, with the default being a randomly selected set of k=30 neighbors within a radius of r=0.15 units.

Details

Additional keyword arguments from the Julia function adjacencymatrix() determine the neighborhood of each node, with the default being a randomly selected set of k=30 neighbors within a radius of r=0.15 units.

See Also

spatialgraph() for the non-vectorised version of this function.

Examples

Run this code
if (FALSE) {
library("NeuralEstimators")

# Number of data sets, number of replicates in each data set, and spatial dimension
K <- 15
m <- 5
d <- 2

# Spatial locations fixed for all replicates within a given data set
n <- 100
S <- lapply(1:K, function(k) matrix(runif(n * d), n, d))
Z <- lapply(1:K, function(k) runif(n))
g <- spatialgraphlist(S, Z)

# Spatial locations varying between replicates within a given data set
S <- lapply(1:K, function(k) {
  lapply(1:m, function(i) {
    ni <- sample(50:100, 1)       # Randomly generate the number of locations for each replicate
    matrix(runif(ni * d), ni, d)  # Generate the spatial locations
  })
})
Z <- lapply(1:K, function(k) {
  lapply(1:m, function(i) {
    n <- nrow(S[[k]][[i]])
    runif(n)  
  })
})
g <- spatialgraphlist(S, Z)
}

Run the code above in your browser using DataLab