geometric_space
A base class to represent a geometric space with a specified center, universe number, distance metric, and associated coordinates.
This class defines the basic structure for geometric spaces and provides methods for calculating distances, managing coordinates, and updating spatial properties. It is meant to be extended for specific geometric implementations.
Attributes:
Name | Type | Description |
---|---|---|
name |
str
|
The name of the geometric space. |
center |
coordinate
|
The center point of the geometric space. |
universe_num |
int
|
The number of universe spaces in the geometric structure. |
distance_metric |
Callable[[Tensor, Tensor], Tensor]
|
A callable function to compute the distance between two points. |
device |
str
|
The device used for computation, such as 'cpu' or 'cuda'. |
coordinates |
list[coordinate]
|
A list of coordinates defining the space. |
Methods:
Name | Description |
---|---|
calculate_distance |
Calculates the distance between two coordinates within the same universe. |
get_volume |
Returns the volume (number of points) of the geometric space. |
get_center |
Returns the center of the geometric space. |
get_universe_num |
Returns the number of universes in the geometric space. |
get_coordinates |
Returns all the coordinates in the geometric space. |
update_center |
Updates the center of the space and regenerates coordinates. |
get_relative_coordinates |
Calculates the relative coordinates with respect to a given center. |
generate_coordinates |
Abstract method for generating coordinates; must be implemented by subclasses. |
Source code in tinybig/koala/geometry/base_geometry.py
18 19 20 21 22 23 24 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 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 |
|
__init__(center, universe_num=1, name='base_geometry', distance_metric=euclidean_distance, device='cpu', *args, **kwargs)
Initializes the geometric space with a center, universes, and distance metric.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
center
|
coordinate
|
The central point of the geometric space. |
required |
universe_num
|
int
|
The number of universes in the space. Defaults to 1. |
1
|
name
|
str
|
The name of the geometric space. Defaults to 'base_geometry'. |
'base_geometry'
|
distance_metric
|
Callable
|
The metric function to calculate distances between points. Defaults to euclidean_distance. |
euclidean_distance
|
device
|
str
|
The device for computation, such as 'cpu' or 'cuda'. Defaults to 'cpu'. |
'cpu'
|
*args
|
Additional parameters for future extensibility. |
()
|
|
**kwargs
|
Additional parameters for future extensibility. |
()
|
Raises:
Type | Description |
---|---|
ValueError
|
If |
Attributes:
Name | Type | Description |
---|---|---|
name |
str
|
The name of the geometric space. |
center |
coordinate
|
The central coordinate of the space. |
universe_num |
int
|
The number of universes in the space. |
distance_metric |
Callable
|
The function used to calculate distances between coordinates. |
device |
str
|
The computation device for the space. |
coordinates |
list[coordinate]
|
A list of all coordinates in the geometric space. |
Source code in tinybig/koala/geometry/base_geometry.py
calculate_distance(coord1, universe1, coord2, universe2)
Calculates the distance between two coordinates within the same universe.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
coord1
|
coordinate
|
The first coordinate. |
required |
universe1
|
int
|
The universe ID for the first coordinate. |
required |
coord2
|
coordinate
|
The second coordinate. |
required |
universe2
|
int
|
The universe ID for the second coordinate. |
required |
Returns:
Type | Description |
---|---|
Tensor
|
The computed distance between |
Raises:
Type | Description |
---|---|
ValueError
|
If either coordinate is not in the current space, if the universe IDs are invalid, or if the coordinates belong to different universes. |
Source code in tinybig/koala/geometry/base_geometry.py
generate_coordinates(*args, **kwargs)
abstractmethod
Abstract method for generating the coordinates of the geometric space.
Must be implemented by subclasses.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
*args
|
Additional parameters for coordinate generation. |
()
|
|
**kwargs
|
Additional parameters for coordinate generation. |
()
|
Returns:
Type | Description |
---|---|
list[coordinate]
|
The generated coordinates. |
Source code in tinybig/koala/geometry/base_geometry.py
get_center()
Returns the center of the geometric space.
Returns:
Type | Description |
---|---|
coordinate
|
The center point of the space. |
get_coordinates()
Returns all the coordinates in the geometric space.
Returns:
Type | Description |
---|---|
list[coordinate]
|
A list of all coordinates in the space. |
get_relative_coordinates(center)
Calculates the relative coordinates with respect to a given center.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
center
|
coordinate
|
The reference center point. |
required |
Returns:
Type | Description |
---|---|
dict
|
A dictionary mapping relative coordinates to their occurrences. |
Source code in tinybig/koala/geometry/base_geometry.py
get_universe_num()
Returns the number of universes in the geometric space.
Returns:
Type | Description |
---|---|
int
|
The number of universes. |
get_volume(across_universe=False)
Returns the volume (number of points) of the geometric space.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
across_universe
|
bool
|
If True, includes all universes in the volume calculation. Defaults to False. |
False
|
Returns:
Type | Description |
---|---|
int
|
The total number of points in the space. |
Source code in tinybig/koala/geometry/base_geometry.py
update_center(new_center)
Updates the center of the geometric space and regenerates coordinates.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
new_center
|
coordinate
|
The new center point. |
required |
Raises:
Type | Description |
---|---|
AssertionError
|
If the dimensions of the new center do not match the current center. |