Data processing
Provides methods for the ATHENA
project for procssing input files,
transforming data, writing reports and plots.
Reads data files and transforms data
compress_weights(model_str)
Compresses weights/constants to simplify the model string
Source code in src/athenage/utilities/data_processing.py
539 540 541 542 543 544 |
|
construct_nodes(modelstr)
Returns node objects representing the network
Parameters: modelstr: String containing GE network Returns nodes constructed from the model
Source code in src/athenage/utilities/data_processing.py
668 669 670 671 672 673 674 675 676 677 678 679 680 |
|
construct_nodes_nn(modelstr)
Returns node objects representing the network
Parameters: modelstr: String containing GE neural network model Returns nodes constructed from the model
Source code in src/athenage/utilities/data_processing.py
714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 |
|
construct_nodes_sr(modelstr)
Returns node objects representing the network
Parameters: modelstr: String containing GE symbolic regression model Returns nodes constructed from the model
Source code in src/athenage/utilities/data_processing.py
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 |
|
format_number(num, max_decimals=2)
Formats a number as a string with a maximum number of decimals, only if needed.
Source code in src/athenage/utilities/data_processing.py
535 536 537 |
|
generate_splits(ncvs, fitness_type, df, have_test_file=False, test_df=None, rand_seed=1234)
Generate splits for training and testing based on number of cross-validation intervals requested.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
ncvs
|
int
|
number of splits (cross-validations) |
required |
fitness_type
|
str
|
for 'r-squared' split into specified number of folds, otherwise split balancing classes in data |
required |
df
|
DataFrame
|
dataset to use for splitting |
required |
have_test_file
|
bool
|
when true use the test_df as the tesing set |
False
|
test_df
|
DataFrame
|
when using a test_file contains the testing dataset |
None
|
rand_seed
|
int
|
controls split |
1234
|
Returns:
Name | Type | Description |
---|---|---|
train_splits |
ndarray
|
2-D array of indexes to use in traininig |
test_splits |
ndarray
|
2-D array of indexes to use in testing |
df |
DataFrame
|
dataset to use with these indexes, concatenated for training and testing when test dataset provided |
Source code in src/athenage/utilities/data_processing.py
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 |
|
prepare_split_data(df, train_indexes, test_indexes)
Create and return data arrays for training and testing using indexes passed.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
df
|
DataFrame
|
data set to split |
required |
train_indexes
|
ndarray
|
rows in dataset to make training set |
required |
test_indexes
|
ndarray
|
rows in dataset to make test set |
required |
Returns:
Name | Type | Description |
---|---|---|
X_train |
ndarray
|
x values in training |
Y_train |
ndarray
|
y values in training |
X_test |
ndarray
|
x values for testing |
Y_test |
ndarray
|
y values for testing |
Source code in src/athenage/utilities/data_processing.py
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 |
|
process_continfile(fn, scale, missing=None, included_vars=None, max_missing_fraction=None)
Read in continuous data and construct dataframe from values
Parameters:
Name | Type | Description | Default |
---|---|---|---|
fn
|
str
|
Phenotypes (outcomes) filename |
required |
scale
|
bool
|
normalize values if true |
required |
missing
|
str
|
identifies any missing data in file |
None
|
included_vars
|
list[str]
|
restrict set to only variables (column names) in list |
None
|
max_missing_fraction
|
float | None
|
drop numeric columns where > this fraction are missing (0–1). If None, keep all columns (default). |
None
|
Returns:
Type | Description |
---|---|
DataFrame
|
pandas dataframe |
Source code in src/athenage/utilities/data_processing.py
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 |
|
process_genofile(fn, encoding, missing=None, included_vars=None, max_missing_fraction=None)
Read in genotype data and construct dataframe from values
Parameters:
Name | Type | Description | Default |
---|---|---|---|
fn
|
str
|
Phenotypes (outcomes) filename |
required |
encoding
|
str
|
Genotype encoding type |
required |
missing
|
str
|
identifies missing data in file |
None
|
included_vars
|
list[str]
|
restrict set to only variables in list |
None
|
max_missing_fraction
|
float | None
|
drop numeric columns where > this fraction are missing (0–1). If None, keep all columns (default). |
None
|
Returns:
Name | Type | Description |
---|---|---|
data |
DataFrame
|
pandas dataframe |
geno_map |
dict
|
dictionary with new label as key, original label as value |
Source code in src/athenage/utilities/data_processing.py
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 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 |
|
process_grammar_file(grammarfn, data)
Reads grammar file into string and adds all x variables present in dataframe
Parameters:
Name | Type | Description | Default |
---|---|---|---|
grammarfn
|
str
|
grammar filename to read and modify |
required |
data
|
DataFrame
|
dataset to be used with the grammar |
required |
Returns:
Name | Type | Description |
---|---|---|
updated_grammar |
str
|
grammar text modified for number of variables in data |
Source code in src/athenage/utilities/data_processing.py
447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 |
|
process_var_colormap(colorfn=None, node_color='lightgray', var_default='white')
Create color map for graphical output of networks. Files format is tab-delimited in order of category, color, inputs
Parameters:
Name | Type | Description | Default |
---|---|---|---|
colorfn
|
str
|
name of file to process, when no fn provided only the network nodes (PA,PD,PM,PS,PAND,PNAND,POR,PXOR,PNOR) are included |
None
|
node_color
|
str
|
color for the operator nodes |
'lightgray'
|
var_default
|
str
|
Default colors for unspecified variables |
'white'
|
Returns:
Name | Type | Description |
---|---|---|
color_map |
ColorMapping
|
node name as key and color as value |
Source code in src/athenage/utilities/data_processing.py
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 |
|
protected_variable_names(model, vmap)
Replace x variables with names in variable map ('-' removed for plotting)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
model
|
str
|
evolved model containing variables with indexed x values ('x[0],x[1],...) |
required |
vmap
|
dict
|
dict with key as x variable and value as name to replace with |
required |
Returns:
Name | Type | Description |
---|---|---|
string |
str
|
model string with variable names updated |
Source code in src/athenage/utilities/data_processing.py
435 436 437 438 439 440 441 442 443 444 445 |
|
read_input_files(outcomefn, genofn, continfn, out_scale=False, contin_scale=False, geno_encode=None, missing=None, outcome=None, missing_fract=1.0, included_vars=None)
Read in data and construct pandas dataframe
Parameters:
Name | Type | Description | Default |
---|---|---|---|
outcomefn
|
str
|
Phenotypes (outcomes) filename |
required |
genofn
|
str
|
SNP values filename |
required |
continfn
|
str
|
any continuous data filename |
required |
out_scale
|
bool
|
scale outcome values from 0 to 1.0 |
False
|
contin_scale
|
bool
|
scale each continuous variable from 0 to 1.0 |
False
|
geno_encode
|
str
|
encode genotype data. options are 'add_quad' and 'additive' |
None
|
outcome
|
str
|
column header in continfn to use for 'y' |
None
|
missing_fract
|
float
|
columns with >= fraction of missing will be dropped |
1.0
|
included_vars
|
list[str]
|
list of variable names to include in analysis; all others excluded |
None
|
Returns:
Name | Type | Description |
---|---|---|
dataset_df |
DataFrame
|
pandas dataframe |
inputs_map |
dict
|
dictionary with new label as key, original label as value |
unmatched |
list
|
list of IDs that are not in all input files |
Source code in src/athenage/utilities/data_processing.py
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 |
|
rename_variables(df)
Rename variables in dataframe to be indexed version of x
Parameters:
Name | Type | Description | Default |
---|---|---|---|
df
|
DataFrame
|
dataframe to alter |
required |
Returns:
Name | Type | Description |
---|---|---|
vmap |
dict
|
new names are keys and original names are values (with - replaced by _ to work with plotting) |
origvmap |
dict
|
original column names |
Source code in src/athenage/utilities/data_processing.py
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 |
|
reset_variable_names(model, vmap, orig_vmap)
Replace x variables with names in variable map
Parameters:
Name | Type | Description | Default |
---|---|---|---|
model
|
str
|
evolved model containing variables with indexed x values ('x[0],x[1],...) |
required |
vmap
|
dict
|
dict with key as x variable and value as name to replace with |
required |
orig_vmap
|
dict
|
dict with key as protected variable name (- removed) and the original name |
required |
Returns:
Name | Type | Description |
---|---|---|
string |
str
|
model string with variable names updated |
Source code in src/athenage/utilities/data_processing.py
422 423 424 425 426 427 428 429 430 431 432 433 |
|
write_plots(basefn, best_models, var_map, orig_var_map, inputs_map, color_map)
Produces png file displaying best models with one per cross-validation.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
basefn
|
str
|
name of file to write |
required |
best_models
|
list[Individual]
|
deap Individual objects from run |
required |
var_map
|
dict
|
key is value (x[0],x[1],etc) and value is name from dataset adjusted for multiple occurences (Ott encoding) |
required |
orig_var_map
|
dict
|
key is protected variable name ('-' removed) and value is original name in input |
required |
inputs_map
|
dict
|
key is name (adjusted for Ott encoding), value is original column name in input dataset |
required |
color_map
|
ColorMapping
|
contains colors to use in plot |
required |
Returns:
Type | Description |
---|---|
None
|
None |
Source code in src/athenage/utilities/data_processing.py
789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 |
|
write_summary(filename, best_models, score_type, var_map, orig_var_map, fitness_test, nmissing)
Produce summary file reporting results
Parameters:
Name | Type | Description | Default |
---|---|---|---|
filename
|
str
|
name of file to write |
required |
best_models
|
list[Individual]
|
deap Individual objects from run |
required |
score_type
|
str
|
test used for scoring individuals |
required |
var_map
|
dict
|
key is value (x[0],x[1],etc) and value is original column name in dataset |
required |
orig_var_map
|
dict
|
key is protect variable name ('-' removed) and value is original name in input |
required |
fitness_test
|
list[float]
|
contains testing fitness scores for each individual |
required |
nmissing
|
list[int]
|
number of missing rows for individual |
required |
Returns:
Type | Description |
---|---|
None
|
None |
Source code in src/athenage/utilities/data_processing.py
606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 |
|