utils
add_missing_categories_and_flatten(grouped_gsf_features, groupby_fields, groupby_type_)
Add missing categories and flatten the grouped GSF features.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
grouped_gsf_features
|
DataFrame
|
The grouped GSF features. |
required |
groupby_fields
|
list
|
The fields to group by. |
required |
groupby_type_
|
str
|
The type of grouping. |
required |
Returns:
| Type | Description |
|---|---|
dict[str, int | float | float64]
|
dict[str, int | float | np.float64]: The flattened GSF features. |
Source code in src/data/utils.py
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 | |
add_missing_features(et_data, trial_groupby_columns, mode)
Add and transform features in the given DataFrame.
This function adds and transforms several features in the DataFrame. It also creates new features based on existing ones.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
et_data
|
DataFrame
|
The input DataFrame. It should have the following columns: - ptb_pos - is_content_word - NEXT_FIX_INTEREST_AREA_INDEX - CURRENT_FIX_INTEREST_AREA_INDEX - IA_REGRESSION_IN_COUNT - IA_REGRESSION_OUT_FULL_COUNT - IA_FIXATION_COUNT |
required |
trial_groupby_columns
|
list
|
A list of column names to group by when calculating sums. |
required |
Returns:
| Type | Description |
|---|---|
DataFrame
|
pd.DataFrame: The DataFrame with added and transformed features. |
DataFrame
|
The function creates the following new features: - ptb_pos: Transformed from categorical to numerical using a mapping dictionary. - is_content_word: Converted to integer type. - is_reg: Whether the next fixation interest area index is less than the current one. - is_progressive: Whether the next fixation IA index is greater than the current one. - is_reg_sum: The sum of is_reg for each group defined by trial_groupby_columns. - is_progressive_sum: The sum of is_progressive for each group defined by trial_groupby_columns. - IA_REGRESSION_IN_COUNT_sum: The sum of IA_REGRESSION_IN_COUNT for each group defined by trial_groupby_columns. - normalized_outgoing_regression_count: The ratio of IA_REGRESSION_OUT_FULL_COUNT to is_reg_sum. - normalized_outgoing_progressive_count: The ratio of the difference between IA_FIXATION_COUNT and IA_REGRESSION_OUT_FULL_COUNT to is_progressive_sum. - normalized_incoming_regression_count: The ratio of IA_REGRESSION_IN_COUNT to IA_REGRESSION_IN_COUNT_sum. These are used for Syntactic Clusters withUniversal Dependencies PoS and Information Clusters [Berzak et al. 2017]
|
Source code in src/data/utils.py
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 | |
compute_fixation_trial_level_features(trial, groupby_mappings, processed_data_path)
Compute fixation trial-level features.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
trial
|
DataFrame
|
The trial data. |
required |
groupby_mappings
|
list[tuple]
|
The groupby mappings for categorical features. |
required |
processed_data_path
|
Path
|
The path to save the trial level feature names. |
required |
Returns:
| Type | Description |
|---|---|
dict
|
pd.Series: The computed features. |
Source code in src/data/utils.py
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 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 | |
compute_ia_trial_level_features(trial, processed_data_path)
Compute IA trial-level features.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
trial
|
DataFrame
|
The trial data. |
required |
Returns:
| Type | Description |
|---|---|
dict
|
pd.Series: The computed features. |
Source code in src/data/utils.py
554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 | |
compute_trial_level_features(raw_fixation_data, raw_ia_data, trial_groupby_columns, processed_data_path)
Compute trial-level features in parallel.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
raw_fixation_data
|
DataFrame | None
|
The raw fixation data. |
required |
raw_ia_data
|
DataFrame
|
The raw IA data. |
required |
trial_groupby_columns
|
list[str]
|
The columns to group by for trials. |
required |
processed_data_path
|
Path
|
The path to save the trial level feature names. |
required |
Returns:
| Type | Description |
|---|---|
DataFrame
|
pd.DataFrame: The computed trial-level features. |
Source code in src/data/utils.py
644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 | |
get_feature_from_list(values, aggregation_function)
creates a feature for a list of values (e.g. mean or standard deviation of values in list) Args: values (list[int | float | np.int32 | np.float64]): list of values aggregation_function (str): name of function to be applied to list Returns: np.float64 | np.nan: aggregated value or np.nan if not possible
Source code in src/data/utils.py
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 | |
get_gaze_entropy_features(x_means, y_means, x_dim=2560, y_dim=1440, patch_size=138)
Compute gaze entropy features.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x_means
|
ndarray
|
The x-coordinates of fixations. |
required |
y_means
|
ndarray
|
The y-coordinates of fixations. |
required |
x_dim
|
int
|
The screen horizontal pixels. Defaults to 2560. |
2560
|
y_dim
|
int
|
The screen vertical pixels. Defaults to 1440. |
1440
|
patch_size
|
int
|
The size of patches to use. Defaults to 138. |
138
|
Returns:
| Type | Description |
|---|---|
dict[str, int | float | float64]
|
dict[str, int | float | np.float64]: The gaze entropy features. |
Source code in src/data/utils.py
328 329 330 331 332 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 | |
load_fold_data(fold_index, base_path, folds_folder_name, data_type, regime_name, set_name)
Load data for a specific fold, data type, regime, and set.
This method reads a Feather file containing the data for the specified fold index, data type, regime name, and set name.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fold_index
|
int
|
The index of the fold to load data for. |
required |
base_path
|
Path
|
The base path where the data is stored. |
required |
folds_folder_name
|
str
|
The name of the folder containing the folds. |
required |
data_type
|
DataType
|
The type of data to load (e.g., train, test, etc.). |
required |
regime_name
|
SetNames
|
The name of the regime (e.g., validation, training, etc.). |
required |
set_name
|
SetNames
|
The name of the set (e.g., train, test, etc.). |
required |
Returns:
| Type | Description |
|---|---|
DataFrame
|
pd.DataFrame: A DataFrame containing the loaded data. |
Note
The file path is currently hardcoded to 'data/OneStop/folds'. This should be replaced with a general path when a connection to the server is available.
Source code in src/data/utils.py
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 | |
save_feature_names_if_do_not_exist(features_dict, csv_path, mode)
Save feature names to a CSV file if they do not already exist.
Source code in src/data/utils.py
624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 | |