haversine_distance
HaversineDistanceLayer ¤
HaversineDistanceLayer(
name=None,
input_dtype=None,
output_dtype=None,
lat_lon_constant=None,
unit="km",
**kwargs
)
Bases: BaseLayer
Computes the haversine distance operation on a given input tensor.
If lat_lon_constant is not set, inputs must be a list of 4 tensors, in the order of lat1, lon1, lat2, lon2. If lat_lon_constant is set, inputs must be a tensor of 2 tensors, in the order of lat1, lon1.
We DO NOT check if the lat/lon values are out of bounds. For lat, this is [-90, 90] and for lon, this is [-180, 180].
Initializes the HaversineDistanceLayer layer
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name |
Optional[str]
|
Name of the layer, defaults to |
None
|
input_dtype |
Optional[str]
|
The dtype to cast the input to. Defaults to |
None
|
output_dtype |
Optional[str]
|
The dtype to cast the output to. Defaults to |
None
|
lat_lon_constant |
Optional[List[float]]
|
The lat/lons to use in the haversine distance. |
None
|
unit |
str
|
The unit of the distance. Must be either 'km' or 'miles'. calculation. Defaults to |
'km'
|
Source code in src/kamae/keras/core/layers/haversine_distance.py
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 | |
compatible_dtypes
property
¤
compatible_dtypes
compute_haversine_distance ¤
compute_haversine_distance(lat1, lon1, lat2, lon2)
Computes the haversine distance between two lat/lon pairs.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
lat1 |
KerasTensor
|
Tensor of latitudes of the first point. |
required |
lon1 |
KerasTensor
|
Tensor of longitudes of the first point. |
required |
lat2 |
KerasTensor
|
Tensor of latitudes of the second point. |
required |
lon2 |
KerasTensor
|
Tensor of longitudes of the second point. |
required |
Returns:
| Type | Description |
|---|---|
KerasTensor
|
Tensor of haversine distances. |
Source code in src/kamae/keras/core/layers/haversine_distance.py
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 | |
get_config ¤
get_config()
Gets the configuration of the HaversineDistance layer. Used for saving and loading from a model.
Specifically, we add the lat_lon_constant and unit to the config.
Returns:
| Type | Description |
|---|---|
Dict[str, Any]
|
Dictionary of the configuration of the layer. |
Source code in src/kamae/keras/core/layers/haversine_distance.py
150 151 152 153 154 155 156 157 158 159 160 161 | |