Hex2VecEmbedder
Bases: CountEmbedder
Hex2Vec Embedder.
Source code in srai/embedders/hex2vec/embedder.py
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 |
|
__init__
__init__(encoder_sizes: Optional[List[int]] = None, expected_output_features: Optional[List[str]] = None) -> None
Initialize Hex2VecEmbedder.
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:
|
expected_output_features |
List of expected output features. Defaults to None.
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 |
---|---|
pd.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
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 |
---|---|
pd.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. |