Hex2VecEmbedder
srai.embedders.Hex2VecEmbedder ¶
Hex2VecEmbedder(
encoder_sizes: Optional[list[int]] = None,
expected_output_features: Optional[
Union[list[str], OsmTagsFilter, GroupedOsmTagsFilter]
] = None,
count_subcategories: bool = True,
)
Bases: CountEmbedder
Hex2Vec Embedder.
PARAMETER | DESCRIPTION |
---|---|
encoder_sizes
|
Sizes of the encoder layers. The input layer size shouldn't be included - it's inferred from the data. The last element is the embedding size. Defaults to [150, 75, 50].
TYPE:
|
count_subcategories
|
Whether to count all subcategories individually or count features only on the highest level based on features column name. Defaults to False.
TYPE:
|
Source code in srai/embedders/hex2vec/embedder.py
fit ¶
fit(
regions_gdf: gpd.GeoDataFrame,
features_gdf: gpd.GeoDataFrame,
joint_gdf: gpd.GeoDataFrame,
neighbourhood: Neighbourhood[T],
negative_sample_k_distance: int = 2,
batch_size: int = 32,
learning_rate: float = 0.001,
trainer_kwargs: Optional[dict[str, Any]] = None,
) -> 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:
|
negative_sample_k_distance
|
When sampling negative samples, sample from a distance > k. Defaults to 2.
TYPE:
|
batch_size
|
Batch size. Defaults to 32.
TYPE:
|
learning_rate
|
Learning rate. Defaults to 0.001.
TYPE:
|
trainer_kwargs
|
Trainer kwargs. Defaults to None.
TYPE:
|
RAISES | DESCRIPTION |
---|---|
ValueError
|
If features_gdf is empty and self.expected_output_features is not set. |
ValueError
|
If any of the gdfs index names is None. |
ValueError
|
If joint_gdf.index is not of type pd.MultiIndex or doesn't have 2 levels. |
ValueError
|
If index levels in gdfs don't overlap correctly. |
ValueError
|
If negative_sample_k_distance < 2. |
Source code in srai/embedders/hex2vec/embedder.py
fit_transform ¶
fit_transform(
regions_gdf: gpd.GeoDataFrame,
features_gdf: gpd.GeoDataFrame,
joint_gdf: gpd.GeoDataFrame,
neighbourhood: Neighbourhood[T],
negative_sample_k_distance: int = 2,
batch_size: int = 32,
learning_rate: float = 0.001,
trainer_kwargs: Optional[dict[str, Any]] = None,
) -> pd.DataFrame
Fit the model to the data and return the 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
|
When sampling negative samples, sample from a distance > k. Defaults to 2.
TYPE:
|
batch_size
|
Batch size. Defaults to 32.
TYPE:
|
learning_rate
|
Learning rate. Defaults to 0.001.
TYPE:
|
trainer_kwargs
|
Trainer kwargs. Defaults to None.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
DataFrame
|
pd.DataFrame: Region embeddings. |
RAISES | DESCRIPTION |
---|---|
ValueError
|
If features_gdf is empty and self.expected_output_features is not set. |
ValueError
|
If any of the gdfs index names is None. |
ValueError
|
If joint_gdf.index is not of type pd.MultiIndex or doesn't have 2 levels. |
ValueError
|
If index levels in gdfs don't overlap correctly. |
ValueError
|
If negative_sample_k_distance < 2. |
Source code in srai/embedders/hex2vec/embedder.py
load ¶
classmethod
Load the model from a directory.
PARAMETER | DESCRIPTION |
---|---|
path
|
Path to the directory.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Hex2VecEmbedder
|
The loaded embedder.
TYPE:
|
Source code in srai/embedders/hex2vec/embedder.py
save ¶
Save the model to a directory.
PARAMETER | DESCRIPTION |
---|---|
path
|
Path to the directory.
TYPE:
|
Source code in srai/embedders/hex2vec/embedder.py
transform ¶
transform(
regions_gdf: gpd.GeoDataFrame,
features_gdf: gpd.GeoDataFrame,
joint_gdf: gpd.GeoDataFrame,
) -> pd.DataFrame
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: Embedding and geometry index for each region in regions_gdf. |
RAISES | DESCRIPTION |
---|---|
ValueError
|
If features_gdf is empty and self.expected_output_features is not set. |
ValueError
|
If any of the gdfs index names is None. |
ValueError
|
If joint_gdf.index is not of type pd.MultiIndex or doesn't have 2 levels. |
ValueError
|
If index levels in gdfs don't overlap correctly. |