Index
GeoVex.
¶
Bases: Dataset['torch.Tensor']
, Generic[T]
Dataset for the hexagonal encoder model.
It works by returning a 3d tensor of hexagonal regions. The tensor is a cube with the target hexagonal region in the center, and the rings of neighbors around surrounding it.
PARAMETER | DESCRIPTION |
---|---|
data |
Data to use for training. Raw counts of features in regions.
TYPE:
|
neighbourhood |
H3Neighbourhood to use for training. It has to be initialized with the same data as the data argument.
TYPE:
|
neighbor_k_ring |
The hexagonal rings of neighbors to include in the tensor. Defaults to 6.
TYPE:
|
Source code in srai/embedders/geovex/dataset.py
¶
Returns the number of valid h3 indices in the dataset.
RETURNS | DESCRIPTION |
---|---|
int
|
Number of valid h3 indices in the dataset.
TYPE:
|
¶
Return a single item from the dataset.
PARAMETER | DESCRIPTION |
---|---|
index |
The index of dataset item to return
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
HexagonalDatasetItem
|
The dataset item
TYPE:
|
Source code in srai/embedders/geovex/dataset.py
¶
Returns the list of valid h3 indices in the dataset.
RETURNS | DESCRIPTION |
---|---|
list[str]
|
List[str]: List of valid h3 indices in the dataset. |
¶
Returns the list of invalid h3 indices in the dataset.
RETURNS | DESCRIPTION |
---|---|
list[str]
|
List[str]: List of invalid h3 indices in the dataset. |
GeoVexEmbedder(
target_features,
batch_size=32,
neighbourhood_radius=4,
convolutional_layers=2,
embedding_size=32,
convolutional_layer_size=256,
)
¶
GeoVexEmbedder(
target_features,
batch_size=32,
neighbourhood_radius=4,
convolutional_layers=2,
embedding_size=32,
convolutional_layer_size=256,
)
Bases: CountEmbedder
GeoVex Embedder.
PARAMETER | DESCRIPTION |
---|---|
target_features |
The features
that are to be used in the embedding. Should be in "flat" format,
i.e. "
TYPE:
|
batch_size |
Batch size. Defaults to 32.
TYPE:
|
convolutional_layers |
Number of convolutional layers. Defaults to 2.
TYPE:
|
neighbourhood_radius |
Radius of the neighbourhood. Defaults to 4.
TYPE:
|
embedding_size |
Size of the embedding. Defaults to 32.
TYPE:
|
convolutional_layer_size |
Size of the first convolutional layer.
TYPE:
|
Source code in srai/embedders/geovex/embedder.py
invalid_cells: list[str]
property
¶
List of invalid h3s.
¶
Create region embeddings.
PARAMETER | DESCRIPTION |
---|---|
regions_gdf |
Region indexes and geometries.
TYPE:
|
features_gdf |
Feature indexes, geometries and feature values.
TYPE:
|
joint_gdf |
Joiner result with region-feature multi-index.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
DataFrame
|
pd.DataFrame: Region embeddings. |
Source code in srai/embedders/geovex/embedder.py
fit(
regions_gdf,
features_gdf,
joint_gdf,
neighbourhood,
learning_rate=0.001,
trainer_kwargs=None,
)
¶
fit(
regions_gdf,
features_gdf,
joint_gdf,
neighbourhood,
learning_rate=0.001,
trainer_kwargs=None,
)
Fit the model to the data.
PARAMETER | DESCRIPTION |
---|---|
regions_gdf |
Region indexes and geometries.
TYPE:
|
features_gdf |
Feature indexes, geometries and feature values.
TYPE:
|
joint_gdf |
Joiner result with region-feature multi-index.
TYPE:
|
neighbourhood |
The neighbourhood to use. Should be intialized with the same regions.
TYPE:
|
learning_rate |
Learning rate. Defaults to 0.001.
TYPE:
|
trainer_kwargs |
Trainer kwargs. This is where the number of epochs can be set. Defaults to None.
TYPE:
|
Source code in srai/embedders/geovex/embedder.py
fit_transform(
regions_gdf,
features_gdf,
joint_gdf,
neighbourhood,
learning_rate=0.001,
trainer_kwargs=None,
)
¶
fit_transform(
regions_gdf,
features_gdf,
joint_gdf,
neighbourhood,
learning_rate=0.001,
trainer_kwargs=None,
)
Fit the model to the data and create region embeddings.
PARAMETER | DESCRIPTION |
---|---|
regions_gdf |
Region indexes and geometries.
TYPE:
|
features_gdf |
Feature indexes, geometries and feature values.
TYPE:
|
joint_gdf |
Joiner result with region-feature multi-index.
TYPE:
|
neighbourhood |
The neighbourhood to use. Should be intialized with the same regions.
TYPE:
|
negative_sample_k_distance |
Distance of negative samples. Defaults to 2.
TYPE:
|
learning_rate |
Learning rate. Defaults to 0.001.
TYPE:
|
trainer_kwargs |
Trainer kwargs. This is where the number of epochs can be set. Defaults to None.
TYPE:
|
Source code in srai/embedders/geovex/embedder.py
¶
Save the model to a directory.
PARAMETER | DESCRIPTION |
---|---|
path |
Path to the directory.
TYPE:
|
Source code in srai/embedders/geovex/embedder.py
¶
classmethod
Load the model from a directory.
PARAMETER | DESCRIPTION |
---|---|
path |
Path to the directory.
TYPE:
|
model_module |
Model class.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
GeoVexEmbedder
|
GeoVexEmbedder object.
TYPE:
|
Source code in srai/embedders/geovex/embedder.py
¶
Bases: Model
GeoVeX Model.
This class implements the GeoVeX model. It is based on a convolutional autoencoder with a Zero- Inflated Poisson layer. The model is described in [1]. It takes a 3d tensor as input (counts of features per region) and outputs dense embeddings. The 3d tensor consists of the target region at the center and radius R neighbors around it.
PARAMETER | DESCRIPTION |
---|---|
k_dim |
the number of input channels
TYPE:
|
radius |
the radius of the hexagonal region
TYPE:
|
conv_layers |
The number of convolutional layers. Defaults to 2.
TYPE:
|
emb_size |
The dimension of the inner embedding. Defaults to 32.
TYPE:
|
learning_rate |
The learning rate. Defaults to 1e-5.
TYPE:
|
conv_layer_size |
The size of the initial convolutional layer.
TYPE:
|
Source code in srai/embedders/geovex/model.py
401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 |
|
¶
Save the model to a directory.
PARAMETER | DESCRIPTION |
---|---|
path |
Path to the directory.
TYPE:
|
¶
classmethod
Load model from a file.
PARAMETER | DESCRIPTION |
---|---|
path |
Path to the file.
TYPE:
|
**kwargs |
Additional kwargs to pass to the model constructor.
TYPE:
|
Source code in srai/embedders/_base.py
¶
Forward pass of the GeoVeX model.
PARAMETER | DESCRIPTION |
---|---|
x |
The input tensor. The dimensions are (batch_size, k_dim, R * 2 + 1, R * 2 + 1).
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
tuple[Tensor, Tensor]
|
torch.Tensor: The output tensor. |
Source code in srai/embedders/geovex/model.py
¶
Perform a training step. This is called by PyTorch Lightning.
One training step consists of a forward pass, a loss calculation, and a backward pass.
PARAMETER | DESCRIPTION |
---|---|
batch |
The batch of data.
TYPE:
|
batch_idx |
The index of the batch.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Tensor
|
torch.Tensor: The loss value. |
Source code in srai/embedders/geovex/model.py
¶
Perform a validation step. This is called by PyTorch Lightning.
PARAMETER | DESCRIPTION |
---|---|
batch |
The batch of data.
TYPE:
|
batch_idx |
The index of the batch.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Tensor
|
torch.Tensor: The loss value. |
Source code in srai/embedders/geovex/model.py
¶
Configure the optimizers. This is called by PyTorch Lightning.
RETURNS | DESCRIPTION |
---|---|
list[Optimizer]
|
List[torch.optim.Optimizer]: The optimizers. |
Source code in srai/embedders/geovex/model.py
¶
Get the model configuration.
RETURNS | DESCRIPTION |
---|---|
dict[str, Union[int, float]]
|
Dict[str, Union[int, float]]: The model configuration. |