Features Storage
Different classes to optimize RAM usage with repeated features over time.
ArrayStorage
Bases: Storage
Function to store features with ids as NumPy Array.
Source code in choice_learn/data/storage.py
244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 |
|
batch
property
Indexing attribute.
__getitem__(id_keys)
Subset FeaturesStorage, keeping only features which id is in keys.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
id_keys |
Iterable
|
List of ids to keep. |
required |
Returns:
Type | Description |
---|---|
FeaturesStorage
|
Subset of the FeaturesStorage, with only the features whose id is in id_keys |
Source code in choice_learn/data/storage.py
__init__(values=None, values_names=None, name=None)
Build the store.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
values |
array_like
|
list of values of features to store |
None
|
values_names |
array_like
|
Iterable of str indicating the name of the features. Must be same length as values. |
None
|
name |
name of the features store |
None
|
Source code in choice_learn/data/storage.py
__len__()
get_element_from_index(index)
Getter method with index (int).
Returns the features stored witg the index-th ID.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
index |
(int, list, slice)
|
index argument of the feature |
required |
Returns:
Type | Description |
---|---|
array_like
|
features corresponding to the index index in self.storage |
Source code in choice_learn/data/storage.py
get_storage_type()
Functions to access stored elements dtypes.
Returns:
Type | Description |
---|---|
tuple
|
tuple of dtypes of the stored elements, as returned by np.dtype |
Source code in choice_learn/data/storage.py
DictStorage
Bases: Storage
Function to store features with ids.
Source code in choice_learn/data/storage.py
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 |
|
batch
property
Indexing attribute.
__getitem__(id_keys)
Subset FeaturesStorage, keeping only features which id is in keys.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
id_keys |
Iterable
|
List of ids to keep. |
required |
Returns:
Type | Description |
---|---|
FeaturesStorage
|
Subset of the FeaturesStorage, with only the features whose id is in id_keys |
Source code in choice_learn/data/storage.py
__init__(ids=None, values=None, values_names=None, name=None, indexer=StorageIndexer)
Build the store.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
ids |
array_like or None
|
list of ids of features to store. If None is given, ids are created from apparition order of values |
None
|
values |
array_like
|
list of values of features to store |
None
|
values_names |
array_like
|
Iterable of str indicating the name of the features. Must be same length as values. |
None
|
name |
name of the features store |
None
|
Source code in choice_learn/data/storage.py
__len__()
get_element_from_index(index)
Getter method with index (int).
Returns the features stored witg the index-th ID.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
index |
(int, list, slice)
|
index argument of the feature |
required |
Returns:
Type | Description |
---|---|
array_like
|
features corresponding to the index index in self.storage |
Source code in choice_learn/data/storage.py
get_storage_type()
Functions to access stored elements dtypes.
Returns:
Type | Description |
---|---|
tuple
|
tuple of dtypes of the stored elements, as returned by np.dtype |
Source code in choice_learn/data/storage.py
FeaturesStorage
Base FeaturesStorage class that redirects toward the right one.
Source code in choice_learn/data/storage.py
__new__(ids=None, values=None, values_names=None, name=None, as_one_hot=False)
Redirects toward the right object.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
ids |
Iterable
|
IDs to references features with, by default None |
None
|
values |
Iterable
|
Features to be stored, by default None |
None
|
values_names |
list
|
List of names for the features to be stored, by default None |
None
|
name |
str
|
Name of the FeaturesStorage, to be matched in ChoiceDataset, by default None |
None
|
as_one_hot |
Whether features are OneHot representations or not. |
False
|
Returns:
Type | Description |
---|---|
FeaturesStorage
|
One of ArrayStorage, DictStorage or OneHotStorage |
Source code in choice_learn/data/storage.py
OneHotStorage
Bases: Storage
Specific Storage for one hot features storage.
Inherits from Storage. For example can be used to store a OneHot representation of the days of week.
Has the same attributes as FeaturesStoage, only differs whit some One-Hot optimized methods. It only stores the indexes of the features, and creates the OneHot matrix when needed, using .batch[].
Source code in choice_learn/data/storage.py
333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 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 |
|
batch
property
Indexing attribute.
__getitem__(id_keys)
Subset FeaturesStorage, keeping only features which id is in keys.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
id_keys |
Iterable
|
List of ids to keep. |
required |
Returns:
Type | Description |
---|---|
OneHotStorage
|
Subset of the OneHotStorage, with only the features whose id is in id_keys |
Source code in choice_learn/data/storage.py
__init__(ids=None, values=None, name=None, dtype=np.uint8, indexer=OneHotStorageIndexer)
Build the store.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
ids |
array_like or None
|
list of ids of features to store. If None is given, ids are created from apparition order of values |
None
|
values |
array_like
|
list of values of features to store |
None
|
dtype |
type for One Hot representation, usually int or float, default is np.uint8 |
uint8
|
|
name |
name of the features store |
None
|
Source code in choice_learn/data/storage.py
__len__()
astype(dtype)
Change (mainly int or float) type of returned OneHot features vectors.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
dtype |
type
|
Type to set the features as |
required |
get_element_from_index(index)
Getter method with index (int).
Returns the features stored witg the index-th ID.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
index |
(int, list, slice)
|
index argument of the feature |
required |
Returns:
Type | Description |
---|---|
array_like
|
features corresponding to the index index in self.storage |
Source code in choice_learn/data/storage.py
get_storage_type()
Functions to access stored elements dtypes.
Returns:
Type | Description |
---|---|
type
|
tuple of dtypes of the stored elements, as returned by np.dtype |
Storage
Bases: ABC
Parent Class to have OneHotStorage and FeaturesStorage with same parent.
Source code in choice_learn/data/storage.py
batch
property
Indexing method.
__getitem__(keys)
abstractmethod
Access an element. To be implemented in children classes.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
keys |
float, int, str or list of
|
values among indexes of the stiage |
required |
__init__(features_to_store)
Instantiate the storage.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
features_to_store |
object
|
Object to store |
required |
__len__()
abstractmethod
__str__()
Return string representation method.
Returns:
Type | Description |
---|---|
str
|
Description of the storage. |
get_element_from_index(index)
abstractmethod
Getter method with index (int).
Returns the features stored witg the index-th ID.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
index |
(int, list, slice)
|
index argument of the feature |
required |
Returns:
Type | Description |
---|---|
array_like
|
features corresponding to the index index in self.storage |