00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #include "InputTargetDataSet.h"
00019
00020
00021
00022 #include <iostream>
00023 #include <fstream>
00024 #include <string>
00025 #include <sstream>
00026 #include <cmath>
00027 #include <algorithm>
00028 #include <cstdlib>
00029 #include <ctime>
00030 #include <exception>
00031
00032 namespace Flood
00033 {
00034
00041
00042 InputTargetDataSet::InputTargetDataSet(int new_instances_number, int new_input_variables_number, int new_target_variables_number)
00043 {
00044 set(new_instances_number, new_input_variables_number, new_target_variables_number);
00045 }
00046
00047
00048
00049
00056
00057 InputTargetDataSet::InputTargetDataSet(int new_instances_number, int new_variables_number)
00058 {
00059 set(new_instances_number, new_variables_number);
00060 }
00061
00062
00063
00064
00068
00069 InputTargetDataSet::InputTargetDataSet(void)
00070 {
00071 set();
00072 }
00073
00074
00075
00076
00080
00081 InputTargetDataSet::InputTargetDataSet(const char* filename)
00082 {
00083 set();
00084 load(filename);
00085 }
00086
00087
00088
00089
00093
00094 InputTargetDataSet::InputTargetDataSet(const InputTargetDataSet& other_input_target_data_set)
00095 {
00096
00097
00098 #ifdef _DEBUG
00099
00100
00101
00102
00103
00104 #endif
00105
00106
00107
00108 training_instances_indices = other_input_target_data_set.training_instances_indices;
00109 validation_instances_indices = other_input_target_data_set.validation_instances_indices;
00110 testing_instances_indices = other_input_target_data_set.testing_instances_indices;
00111
00112
00113
00114 input_variables_indices = other_input_target_data_set.input_variables_indices;
00115 target_variables_indices = other_input_target_data_set.target_variables_indices;
00116
00117
00118
00119 variables_name = other_input_target_data_set.variables_name;
00120 variables_units = other_input_target_data_set.variables_units;
00121 variables_description = other_input_target_data_set.variables_description;
00122
00123
00124
00125 display = other_input_target_data_set.display;
00126
00127
00128
00129 data = other_input_target_data_set.data;
00130 }
00131
00132
00133
00134
00136
00137 InputTargetDataSet::~InputTargetDataSet(void)
00138 {
00139 }
00140
00141
00142
00143
00147
00148 InputTargetDataSet& InputTargetDataSet::operator=(const InputTargetDataSet& other_input_target_data_set)
00149 {
00150 if(this != &other_input_target_data_set)
00151 {
00152
00153
00154 training_instances_indices = other_input_target_data_set.training_instances_indices;
00155 validation_instances_indices = other_input_target_data_set.validation_instances_indices;
00156 testing_instances_indices = other_input_target_data_set.testing_instances_indices;
00157
00158
00159
00160 input_variables_indices = other_input_target_data_set.input_variables_indices;
00161 target_variables_indices = other_input_target_data_set.target_variables_indices;
00162
00163
00164
00165 variables_name = other_input_target_data_set.variables_name;
00166 variables_units = other_input_target_data_set.variables_units;
00167 variables_description = other_input_target_data_set.variables_description;
00168
00169
00170
00171 display = other_input_target_data_set.display;
00172
00173
00174
00175 data = other_input_target_data_set.data;
00176 }
00177
00178 return(*this);
00179 }
00180
00181
00182
00183
00184
00185
00187
00188 Vector<int>& InputTargetDataSet::get_training_instances_indices(void)
00189 {
00190 return(training_instances_indices);
00191 }
00192
00193
00194
00195
00197
00198 Vector<int>& InputTargetDataSet::get_validation_instances_indices(void)
00199 {
00200 return(validation_instances_indices);
00201 }
00202
00203
00204
00205
00207
00208 Vector<int>& InputTargetDataSet::get_testing_instances_indices(void)
00209 {
00210 return(testing_instances_indices);
00211 }
00212
00213
00214
00215
00217
00218 Vector<int>& InputTargetDataSet::get_input_variables_indices(void)
00219 {
00220 return(input_variables_indices);
00221 }
00222
00223
00225
00226
00227
00228 Vector<int>& InputTargetDataSet::get_target_variables_indices(void)
00229 {
00230 return(target_variables_indices);
00231 }
00232
00233
00234
00235
00237
00238 Vector<std::string>& InputTargetDataSet::get_variables_name(void)
00239 {
00240 return(variables_name);
00241 }
00242
00243
00244
00245
00248
00249 std::string& InputTargetDataSet::get_variable_name(int i)
00250 {
00251
00252
00253 #ifdef _DEBUG
00254
00255 int variables_number = get_variables_number();
00256
00257 if(i < 0)
00258 {
00259 std::cerr << "Flood Error: InputTargetDataSet class." << std::endl
00260 << "std::string& get_variable_name(int) method." << std::endl
00261 << "Index of variable must be equal or greater than zero." << std::endl;
00262
00263 exit(1);
00264 }
00265 else if(i >= variables_number)
00266 {
00267 std::cerr << "Flood Error: InputTargetDataSet class." << std::endl
00268 << "std::string& get_variable_name(int) method." << std::endl
00269 << "Index of variable must be less than number of variables." << std::endl;
00270
00271 exit(1);
00272 }
00273
00274 #endif
00275
00276 return(variables_name[i]);
00277 }
00278
00279
00280
00281
00283
00284 Vector<std::string> InputTargetDataSet::get_input_variables_name(void)
00285 {
00286 int variables_number = get_variables_number();
00287
00288 Vector<std::string> input_variables_name;
00289
00290 if(variables_name.get_size() == variables_number)
00291 {
00292 int input_variables_number = get_input_variables_number();
00293
00294 input_variables_name.set_size(input_variables_number);
00295 int index;
00296
00297 for(int i = 0; i < input_variables_number; i++)
00298 {
00299 index = input_variables_indices[i];
00300
00301 input_variables_name[i] = variables_name[index];
00302 }
00303 }
00304
00305 return(input_variables_name);
00306 }
00307
00308
00309
00310
00312
00313 Vector<std::string> InputTargetDataSet::get_target_variables_name(void)
00314 {
00315 int variables_number = get_variables_number();
00316
00317 Vector<std::string> target_variables_name;
00318
00319 if(variables_name.get_size() == variables_number)
00320 {
00321 int target_variables_number = get_target_variables_number();
00322
00323 target_variables_name.set_size(target_variables_number);
00324 int index;
00325
00326 for(int i = 0; i < target_variables_number; i++)
00327 {
00328 index = target_variables_indices[i];
00329
00330 target_variables_name[i] = variables_name[index];
00331 }
00332 }
00333
00334 return(target_variables_name);
00335 }
00336
00337
00338
00339
00341
00342 Vector<std::string>& InputTargetDataSet::get_variables_units(void)
00343 {
00344 return(variables_units);
00345 }
00346
00347
00348
00349
00352
00353 std::string& InputTargetDataSet::get_variable_units(int i)
00354 {
00355
00356
00357 #ifdef _DEBUG
00358
00359 int variables_number = get_variables_number();
00360
00361 if(i < 0)
00362 {
00363 std::cerr << "Flood Error: InputTargetDataSet class." << std::endl
00364 << "std::string& get_variable_units(int) method." << std::endl
00365 << "Index of variable must be equal or greater than zero." << std::endl;
00366
00367 exit(1);
00368 }
00369 else if(i >= variables_number)
00370 {
00371 std::cerr << "Flood Error: InputTargetDataSet class." << std::endl
00372 << "std::string& get_variable_units(int) method." << std::endl
00373 << "Index of variable must be less than number of variables." << std::endl;
00374
00375 exit(1);
00376 }
00377
00378 #endif
00379
00380 return(variables_units[i]);
00381 }
00382
00383
00384
00385
00387
00388 Vector<std::string> InputTargetDataSet::get_input_variables_units(void)
00389 {
00390 int variables_number = get_variables_number();
00391
00392 Vector<std::string> input_variables_units;
00393
00394 if(variables_units.get_size() == variables_number)
00395 {
00396 int input_variables_number = get_input_variables_number();
00397
00398 input_variables_units.set_size(input_variables_number);
00399 int index;
00400
00401 for(int i = 0; i < input_variables_number; i++)
00402 {
00403 index = input_variables_indices[i];
00404
00405 input_variables_units[i] = variables_units[index];
00406 }
00407 }
00408
00409 return(input_variables_units);
00410 }
00411
00412
00413
00414
00416
00417 Vector<std::string> InputTargetDataSet::get_target_variables_units(void)
00418 {
00419 int variables_number = get_variables_number();
00420
00421 Vector<std::string> target_variables_units;
00422
00423 if(variables_units.get_size() == variables_number)
00424 {
00425 int target_variables_number = get_target_variables_number();
00426
00427 target_variables_units.set_size(target_variables_number);
00428 int index;
00429
00430 for(int i = 0; i < target_variables_number; i++)
00431 {
00432 index = target_variables_indices[i];
00433
00434 target_variables_units[i] = variables_units[index];
00435 }
00436 }
00437
00438 return(target_variables_units);
00439 }
00440
00441
00442
00443
00445
00446 Vector<std::string>& InputTargetDataSet::get_variables_description(void)
00447 {
00448 return(variables_description);
00449 }
00450
00451
00452
00453
00456
00457 std::string& InputTargetDataSet::get_variable_description(int i)
00458 {
00459
00460
00461 #ifdef _DEBUG
00462
00463 int variables_number = get_variables_number();
00464
00465 if(i < 0)
00466 {
00467 std::cerr << "Flood Error: InputTargetDataSet class." << std::endl
00468 << "std::string& get_variable_description(int) method." << std::endl
00469 << "Index of variable must be equal or greater than zero." << std::endl;
00470
00471 exit(1);
00472 }
00473 else if(i >= variables_number)
00474 {
00475 std::cerr << "Flood Error: InputTargetDataSet class." << std::endl
00476 << "std::string& get_variable_description(int) method." << std::endl
00477 << "Index of variable must be less than number of variables." << std::endl;
00478
00479 exit(1);
00480 }
00481
00482 #endif
00483
00484 return(variables_description[i]);
00485 }
00486
00487
00488
00489
00491
00492 Vector<std::string> InputTargetDataSet::get_input_variables_description(void)
00493 {
00494 int variables_number = get_variables_number();
00495
00496 Vector<std::string> input_variables_description;
00497
00498 if(variables_units.get_size() == variables_number)
00499 {
00500 int input_variables_number = get_input_variables_number();
00501 input_variables_description.set_size(input_variables_number);
00502 int index;
00503
00504 for(int i = 0; i < input_variables_number; i++)
00505 {
00506 index = input_variables_indices[i];
00507
00508 input_variables_description[i] = variables_description[index];
00509 }
00510 }
00511
00512 return(input_variables_description);
00513 }
00514
00515
00516
00517
00519
00520 Vector<std::string> InputTargetDataSet::get_target_variables_description(void)
00521 {
00522 int variables_number = get_variables_number();
00523
00524 Vector<std::string> target_variables_description;
00525
00526 if(variables_description.get_size() == variables_number)
00527 {
00528 int target_variables_number = get_target_variables_number();
00529
00530 target_variables_description.set_size(target_variables_number);
00531 int index;
00532
00533 for(int i = 0; i < target_variables_number; i++)
00534 {
00535 index = target_variables_indices[i];
00536
00537 target_variables_description[i] = variables_description[index];
00538 }
00539 }
00540
00541 return(target_variables_description);
00542 }
00543
00544
00545
00546
00558
00559 Vector< Vector<std::string> > InputTargetDataSet::get_variables_information(void)
00560 {
00561 int variable_index;
00562
00563 int variables_number = get_variables_number();
00564
00565 int input_variables_number = get_input_variables_number();
00566
00567 Vector<std::string> input_variables_name;
00568 Vector<std::string> input_variables_units;
00569 Vector<std::string> input_variables_description;
00570
00571 for(int i = 0; i < input_variables_number; i++)
00572 {
00573 variable_index = input_variables_indices[i];
00574
00575 if(variables_name.get_size() == variables_number)
00576 {
00577 input_variables_name.set(input_variables_number);
00578 input_variables_name[i] = variables_name[variable_index];
00579 }
00580
00581 if(variables_units.get_size() == variables_number)
00582 {
00583 input_variables_units.set(input_variables_number);
00584 input_variables_units[i] = variables_units[variable_index];
00585 }
00586
00587 if(variables_description.get_size() == variables_number)
00588 {
00589 input_variables_description.set(input_variables_number);
00590 input_variables_description[i] = variables_description[variable_index];
00591 }
00592 }
00593
00594 int target_variables_number = get_target_variables_number();
00595
00596 Vector<std::string> target_variables_name;
00597 Vector<std::string> target_variables_units;
00598 Vector<std::string> target_variables_description;
00599
00600 for(int i = 0; i < target_variables_number; i++)
00601 {
00602 variable_index = target_variables_indices[i];
00603
00604 if(variables_name.get_size() == variables_number)
00605 {
00606 target_variables_name.set(target_variables_number);
00607 target_variables_name[i] = variables_name[variable_index];
00608 }
00609
00610 if(variables_units.get_size() == variables_number)
00611 {
00612 target_variables_units.set(target_variables_number);
00613 target_variables_units[i] = variables_units[variable_index];
00614 }
00615
00616 if(variables_description.get_size() == variables_number)
00617 {
00618 target_variables_description.set(target_variables_number);
00619 target_variables_description[i] = variables_description[variable_index];
00620 }
00621 }
00622
00623 Vector< Vector<std::string> > variables_information(6);
00624
00625 variables_information[0] = input_variables_name;
00626 variables_information[1] = input_variables_units;
00627 variables_information[2] = input_variables_description;
00628
00629 variables_information[3] = target_variables_name;
00630 variables_information[4] = target_variables_units;
00631 variables_information[5] = target_variables_description;
00632
00633 return(variables_information);
00634 }
00635
00636
00637
00638
00641
00642 bool InputTargetDataSet::get_display(void)
00643 {
00644 return(display);
00645 }
00646
00647
00648
00649
00653
00654 Matrix<double>& InputTargetDataSet::get_data(void)
00655 {
00656 return(data);
00657 }
00658
00659
00660
00661
00665
00666 Matrix<double> InputTargetDataSet::get_training_data(void)
00667 {
00668 int variables_number = get_variables_number();
00669 Vector<int> variables_indices(variables_number);
00670 variables_indices.initialize_sequential();
00671
00672 return(data.get_submatrix(training_instances_indices, variables_indices));
00673 }
00674
00675
00676
00677
00681
00682 Matrix<double> InputTargetDataSet::get_validation_data(void)
00683 {
00684 int variables_number = get_variables_number();
00685 Vector<int> variables_indices(variables_number);
00686 variables_indices.initialize_sequential();
00687
00688 return(data.get_submatrix(validation_instances_indices, variables_indices));
00689 }
00690
00691
00692
00693
00697
00698 Matrix<double> InputTargetDataSet::get_testing_data(void)
00699 {
00700 int variables_number = get_variables_number();
00701 Vector<int> variables_indices(variables_number);
00702 variables_indices.initialize_sequential();
00703
00704 return(data.get_submatrix(testing_instances_indices, variables_indices));
00705 }
00706
00707
00708
00709
00713
00714 Matrix<double> InputTargetDataSet::get_input_data(void)
00715 {
00716 int instances_number = get_instances_number();
00717 Vector<int> instances_indices(instances_number);
00718 instances_indices.initialize_sequential();
00719
00720 return(data.get_submatrix(instances_indices, input_variables_indices));
00721 }
00722
00723
00724
00725
00729
00730 Matrix<double> InputTargetDataSet::get_target_data(void)
00731 {
00732 int instances_number = get_instances_number();
00733 Vector<int> instances_indices(instances_number);
00734 instances_indices.initialize_sequential();
00735
00736 return(data.get_submatrix(instances_indices, target_variables_indices));
00737 }
00738
00739
00740
00741
00745
00746 Matrix<double> InputTargetDataSet::get_training_input_data(void)
00747 {
00748 return(data.get_submatrix(training_instances_indices, input_variables_indices));
00749 }
00750
00751
00752
00753
00757
00758 Matrix<double> InputTargetDataSet::get_training_target_data(void)
00759 {
00760 return(data.get_submatrix(training_instances_indices, target_variables_indices));
00761 }
00762
00763
00764
00765
00769
00770 Matrix<double> InputTargetDataSet::get_validation_input_data(void)
00771 {
00772 return(data.get_submatrix(validation_instances_indices, input_variables_indices));
00773 }
00774
00775
00776
00777
00781
00782 Matrix<double> InputTargetDataSet::get_validation_target_data(void)
00783 {
00784 return(data.get_submatrix(validation_instances_indices, target_variables_indices));
00785 }
00786
00787
00788
00789
00793
00794 Matrix<double> InputTargetDataSet::get_testing_input_data(void)
00795 {
00796 return(data.get_submatrix(testing_instances_indices, input_variables_indices));
00797 }
00798
00799
00800
00801
00805
00806 Matrix<double> InputTargetDataSet::get_testing_target_data(void)
00807 {
00808 return(data.get_submatrix(testing_instances_indices, target_variables_indices));
00809 }
00810
00811
00812
00813
00816
00817 Vector<double> InputTargetDataSet::get_instance(int i)
00818 {
00819
00820
00821 #ifdef _DEBUG
00822
00823 int instances_number = get_instances_number();
00824
00825 if(i < 0)
00826 {
00827 std::cerr << "Flood Error: InputTargetDataSet class." << std::endl
00828 << "Vector<double> get_instance(int) method." << std::endl
00829 << "Index of instance must be equal or greater than zero." << std::endl;
00830
00831 exit(1);
00832 }
00833 else if(i >= instances_number)
00834 {
00835 std::cerr << "Flood Error: InputTargetDataSet class." << std::endl
00836 << "Vector<double> get_instance(int) method." << std::endl
00837 << "Index of instance must be less than number of instances." << std::endl;
00838
00839 exit(1);
00840 }
00841
00842 #endif
00843
00844
00845
00846 Vector<double> instance = get_input_instance(i);
00847
00848 return(data.get_row(i));
00849 }
00850
00851
00852
00853
00856
00857 Vector<double> InputTargetDataSet::get_training_instance(int training_instance_index)
00858 {
00859
00860
00861 #ifdef _DEBUG
00862
00863 int training_instances_number = get_training_instances_number();
00864
00865 if(training_instance_index < 0)
00866 {
00867 std::cerr << "Flood Error: InputTargetDataSet class." << std::endl
00868 << "Vector<double> get_training_instance(int) method." << std::endl
00869 << "Index of training instance must be equal or greater than zero." << std::endl;
00870
00871 exit(1);
00872 }
00873 else if(training_instance_index >= training_instances_number)
00874 {
00875 std::cerr << "Flood Error: InputTargetDataSet class." << std::endl
00876 << "Vector<double> get_training_instance(int) method." << std::endl
00877 << "Index of training instance must be less than number of training instances." << std::endl;
00878
00879 exit(1);
00880 }
00881
00882 #endif
00883
00884 int instance_index = training_instances_indices[training_instance_index];
00885
00886 Vector<double> training_instance = data.get_row(instance_index);
00887
00888 return(training_instance);
00889 }
00890
00891
00892
00893
00896
00897 Vector<double> InputTargetDataSet::get_validation_instance(int validation_instance_index)
00898 {
00899
00900
00901 #ifdef _DEBUG
00902
00903 int validation_instances_number = get_validation_instances_number();
00904
00905 if(validation_instance_index < 0)
00906 {
00907 std::cerr << "Flood Error: InputTargetDataSet class." << std::endl
00908 << "Vector<double> get_validation_instance(int) method." << std::endl
00909 << "Index of validation instance must be equal or greater than zero." << std::endl;
00910
00911 exit(1);
00912 }
00913 else if(validation_instance_index >= validation_instances_number)
00914 {
00915 std::cerr << "Flood Error: InputTargetDataSet class." << std::endl
00916 << "Vector<double> get_validation_instance(int) method." << std::endl
00917 << "Index of validation instance must be less than number of validation instances." << std::endl;
00918
00919 exit(1);
00920 }
00921
00922 #endif
00923
00924 int instance_index = validation_instances_indices[validation_instance_index];
00925
00926 Vector<double> validation_instance = data.get_row(instance_index);
00927
00928 return(validation_instance);
00929 }
00930
00931
00932
00933
00936
00937 Vector<double> InputTargetDataSet::get_testing_instance(int testing_instance_index)
00938 {
00939
00940
00941 #ifdef _DEBUG
00942
00943 int testing_instances_number = get_testing_instances_number();
00944
00945 if(testing_instance_index < 0)
00946 {
00947 std::cerr << "Flood Error: InputTargetDataSet class." << std::endl
00948 << "Vector<double> get_testing_instance(int) method." << std::endl
00949 << "Index of testing instance must be equal or greater than zero." << std::endl;
00950
00951 exit(1);
00952 }
00953 else if(testing_instance_index >= testing_instances_number)
00954 {
00955 std::cerr << "Flood Error: InputTargetDataSet class." << std::endl
00956 << "Vector<double> get_testing_instance(int) method." << std::endl
00957 << "Index of testing instance must be less than number of testing instances." << std::endl;
00958
00959 exit(1);
00960 }
00961
00962 #endif
00963
00964 int instance_index = testing_instances_indices[testing_instance_index];
00965
00966 Vector<double> testing_instance = data.get_row(instance_index);
00967
00968 return(testing_instance);
00969 }
00970
00971
00972
00973
00976
00977 Vector<double> InputTargetDataSet::get_input_instance(int instance_index)
00978 {
00979
00980
00981 #ifdef _DEBUG
00982
00983 int instances_number = get_instances_number();
00984
00985 if(instance_index < 0)
00986 {
00987 std::cerr << "Flood Error: InputTargetDataSet class." << std::endl
00988 << "Vector<double> get_input_instance(int) method." << std::endl
00989 << "Index of instance must be equal or greater than zero." << std::endl;
00990
00991 exit(1);
00992 }
00993 else if(instance_index >= instances_number)
00994 {
00995 std::cerr << "Flood Error: InputTargetDataSet class." << std::endl
00996 << "Vector<double> get_input_instance(int) method." << std::endl
00997 << "Index of instance must be less than number of instances." << std::endl;
00998
00999 exit(1);
01000 }
01001
01002 #endif
01003
01004 int input_variables_number = get_input_variables_number();
01005
01006 Vector<double> input_instance(input_variables_number);
01007
01008 int input_variable_index;
01009
01010 for(int i = 0; i < input_variables_number; i++)
01011 {
01012 input_variable_index = input_variables_indices[i];
01013
01014 input_instance[i] = data[instance_index][input_variable_index];
01015 }
01016
01017 return(input_instance);
01018 }
01019
01020
01021
01022
01025
01026 Vector<double> InputTargetDataSet::get_target_instance(int instance_index)
01027 {
01028
01029
01030 #ifdef _DEBUG
01031
01032 int instances_number = get_instances_number();
01033
01034 if(instance_index < 0)
01035 {
01036 std::cerr << "Flood Error: InputTargetDataSet class." << std::endl
01037 << "Vector<double> get_target_instance(int) method." << std::endl
01038 << "Index of instance must be equal or greater than zero."
01039 << std::endl;
01040
01041 exit(1);
01042 }
01043 else if(instance_index >= instances_number)
01044 {
01045 std::cerr << "Flood Error: InputTargetDataSet class." << std::endl
01046 << "Vector<double> get_target_instance(int) method." << std::endl
01047 << "Index of instance must be less than number of instances." << std::endl;
01048
01049 exit(1);
01050 }
01051
01052 #endif
01053
01054 int target_variables_number = get_target_variables_number();
01055
01056 Vector<double> target_instance(target_variables_number);
01057
01058 int target_variable_index;
01059
01060 for(int i = 0; i < target_variables_number; i++)
01061 {
01062 target_variable_index = target_variables_indices[i];
01063
01064 target_instance[i] = data[instance_index][target_variable_index];
01065 }
01066
01067 return(target_instance);
01068 }
01069
01070
01071
01072
01073
01076
01077 Vector<double> InputTargetDataSet::get_training_input_instance(int training_instance_index)
01078 {
01079
01080
01081 #ifdef _DEBUG
01082
01083 int training_instances_number = get_training_instances_number();
01084
01085 if(training_instance_index < 0)
01086 {
01087 std::cerr << "Flood Error: InputTargetDataSet class." << std::endl
01088 << "Vector<double> get_training_input_instance(int) method." << std::endl
01089 << "Index of training instance must be equal or greater than zero." << std::endl;
01090
01091 exit(1);
01092 }
01093 else if(training_instance_index >= training_instances_number)
01094 {
01095 std::cerr << "Flood Error: InputTargetDataSet class." << std::endl
01096 << "Vector<double> get_training_input_instance(int) method." << std::endl
01097 << "Index of training instance (" << training_instance_index << ") must be less than number of training instances (" << training_instances_number << ")." << std::endl;
01098
01099 exit(1);
01100 }
01101
01102 #endif
01103
01104 int instance_index = training_instances_indices[training_instance_index];
01105
01106 return(get_input_instance(instance_index));
01107 }
01108
01109
01110
01111
01114
01115 Vector<double> InputTargetDataSet::get_validation_input_instance(int validation_instance_index)
01116 {
01117
01118
01119 #ifdef _DEBUG
01120
01121 int validation_instances_number = get_validation_instances_number();
01122
01123 if(validation_instance_index < 0)
01124 {
01125 std::cerr << "Flood Error: InputTargetDataSet class." << std::endl
01126 << "Vector<double> get_validation_input_instance(int) method." << std::endl
01127 << "Index of validation instance must be equal or greater than zero." << std::endl;
01128
01129 exit(1);
01130 }
01131 else if(validation_instance_index >= validation_instances_number)
01132 {
01133 std::cerr << "Flood Error: InputTargetDataSet class." << std::endl
01134 << "Vector<double> get_validation_input_instance(int) method." << std::endl
01135 << "Index of validation instance must be less than number of validation instances." << std::endl;
01136
01137 exit(1);
01138 }
01139
01140 #endif
01141
01142 int instance_index = validation_instances_indices[validation_instance_index];
01143
01144 return(get_input_instance(instance_index));
01145 }
01146
01147
01148
01149
01152
01153 Vector<double> InputTargetDataSet::get_testing_input_instance(int testing_instance_index)
01154 {
01155
01156
01157 #ifdef _DEBUG
01158
01159 int testing_instances_number = get_testing_instances_number();
01160
01161 if(testing_instance_index < 0)
01162 {
01163 std::cerr << "Flood Error: InputTargetDataSet class." << std::endl
01164 << "Vector<double> get_testing_input_instance(int) method." << std::endl
01165 << "Index of testing instance must be equal or greater than zero." << std::endl;
01166
01167 exit(1);
01168 }
01169 else if(testing_instance_index >= testing_instances_number)
01170 {
01171 std::cerr << "Flood Error: InputTargetDataSet class." << std::endl
01172 << "Vector<double> get_testing_input_instance(int) method." << std::endl
01173 << "Index of testing instance must be less than number of testing instances." << std::endl;
01174
01175 exit(1);
01176 }
01177
01178 #endif
01179
01180 int instance_index = testing_instances_indices[testing_instance_index];
01181
01182 return(get_input_instance(instance_index));
01183 }
01184
01185
01186
01187
01190
01191 Vector<double> InputTargetDataSet::get_training_target_instance(int training_instance_index)
01192 {
01193
01194
01195 #ifdef _DEBUG
01196
01197 int training_instances_number = get_training_instances_number();
01198
01199 if(training_instance_index < 0)
01200 {
01201 std::cerr << "Flood Error: InputTargetDataSet class." << std::endl
01202 << "Vector<double> get_training_target_instance(int) method." << std::endl
01203 << "Index of training instance must be equal or greater than zero." << std::endl;
01204
01205 exit(1);
01206 }
01207 else if(training_instance_index >= training_instances_number)
01208 {
01209 std::cerr << "Flood Error: InputTargetDataSet class." << std::endl
01210 << "Vector<double> get_training_target_instance(int) method." << std::endl
01211 << "Index of training instance must be less than number of training instances." << std::endl;
01212
01213 exit(1);
01214 }
01215
01216 #endif
01217
01218 int instance_index = training_instances_indices[training_instance_index];
01219
01220 return(get_target_instance(instance_index));
01221 }
01222
01223
01224
01225
01228
01229 Vector<double> InputTargetDataSet::get_validation_target_instance(int validation_instance_index)
01230 {
01231
01232
01233 #ifdef _DEBUG
01234
01235 int validation_instances_number = get_validation_instances_number();
01236
01237 if(validation_instance_index < 0)
01238 {
01239 std::cerr << "Flood Error: InputTargetDataSet class." << std::endl
01240 << "Vector<double> get_validation_target_instance(int) method." << std::endl
01241 << "Index of validation instance must be equal or greater than zero." << std::endl;
01242
01243 exit(1);
01244 }
01245 else if(validation_instance_index >= validation_instances_number)
01246 {
01247 std::cerr << "Flood Error: InputTargetDataSet class." << std::endl
01248 << "Vector<double> get_validation_target_instance(int) method." << std::endl
01249 << "Index of validation instance must be less than number of validation instances." << std::endl;
01250
01251 exit(1);
01252 }
01253
01254 #endif
01255
01256 int instance_index = validation_instances_indices[validation_instance_index];
01257
01258 return(get_target_instance(instance_index));
01259 }
01260
01261
01262
01263
01266
01267 Vector<double> InputTargetDataSet::get_testing_target_instance(int testing_instance_index)
01268 {
01269
01270
01271 #ifdef _DEBUG
01272
01273 int testing_instances_number = get_testing_instances_number();
01274
01275 if(testing_instance_index < 0)
01276 {
01277 std::cerr << "Flood Error: InputTargetDataSet class." << std::endl
01278 << "Vector<double> get_testing_target_instance(int) method." << std::endl
01279 << "Index of testing instance must be equal or greater than zero." << std::endl;
01280
01281 exit(1);
01282 }
01283 else if(testing_instance_index >= testing_instances_number)
01284 {
01285 std::cerr << "Flood Error: InputTargetDataSet class." << std::endl
01286 << "Vector<double> get_testing_target_instance(int) method." << std::endl
01287 << "Index of testing instance must be less than number of testing instances." << std::endl;
01288
01289 exit(1);
01290 }
01291
01292 #endif
01293
01294 int instance_index = testing_instances_indices[testing_instance_index];
01295
01296 return(get_target_instance(instance_index));
01297 }
01298
01299
01300
01301
01303
01304 void InputTargetDataSet::set(void)
01305 {
01306 display = true;
01307 }
01308
01309
01310
01311
01317
01318 void InputTargetDataSet::set(int new_instances_number, int new_variables_number)
01319 {
01320
01321
01322 data.set(new_instances_number, new_variables_number);
01323
01324
01325
01326 set_training();
01327
01328
01329
01330 set_input();
01331
01332
01333
01334 display = true;
01335 }
01336
01337
01338
01348
01349 void InputTargetDataSet::set(int new_instances_number, int new_input_variables_number, int new_target_variables_number)
01350 {
01351
01352
01353 int new_variables_number = new_input_variables_number + new_target_variables_number;
01354
01355 data.set(new_instances_number, new_variables_number);
01356
01357
01358
01359 set_training();
01360
01361
01362
01363 input_variables_indices.set_size(new_input_variables_number);
01364 input_variables_indices.initialize_sequential();
01365
01366 target_variables_indices.set_size(new_target_variables_number);
01367 target_variables_indices.initialize_sequential();
01368 target_variables_indices += new_input_variables_number;
01369
01370 display = true;
01371 }
01372
01373
01374
01375
01380
01381 void InputTargetDataSet::set_training_instances_indices(const Vector<int>& new_training_instances_indices)
01382 {
01383
01384
01385 #ifdef _DEBUG
01386
01387 int instances_number = get_instances_number();
01388
01389 int size = new_training_instances_indices.get_size();
01390
01391 if(size > instances_number)
01392 {
01393 std::cerr << "Flood Error: InputTargetDataSet class." << std::endl
01394 << "void set_training_instances_indices(const Vector<double>&) method." << std::endl
01395 << "Size must be less or equal than number of instances." << std::endl;
01396
01397 exit(1);
01398 }
01399
01400 #endif
01401
01402 training_instances_indices = new_training_instances_indices;
01403 }
01404
01405
01406
01407
01412
01413 void InputTargetDataSet::set_validation_instances_indices(const Vector<int>& new_validation_instances_indices)
01414 {
01415
01416
01417 #ifdef _DEBUG
01418
01419 int instances_number = get_instances_number();
01420
01421 int size = new_validation_instances_indices.get_size();
01422
01423 if(size > instances_number)
01424 {
01425 std::cerr << "Flood Error: InputTargetDataSet class." << std::endl
01426 << "void set_validation_instances_indices(const Vector<double>&) method." << std::endl
01427 << "Size must be less or equal than number of instances." << std::endl;
01428
01429 exit(1);
01430 }
01431
01432 #endif
01433
01434 validation_instances_indices = new_validation_instances_indices;
01435 }
01436
01437
01438
01439
01444
01445 void InputTargetDataSet::set_testing_instances_indices(const Vector<int>& new_testing_instances_indices)
01446 {
01447
01448
01449 #ifdef _DEBUG
01450
01451 int instances_number = get_instances_number();
01452
01453 int size = new_testing_instances_indices.get_size();
01454
01455 if(size > instances_number)
01456 {
01457 std::cerr << "Flood Error: InputTargetDataSet class." << std::endl
01458 << "void set_testing_instances_indices(const Vector<double>&) method." << std::endl
01459 << "Size must be less or equal than number of instances." << std::endl;
01460
01461 exit(1);
01462 }
01463
01464 #endif
01465
01466 testing_instances_indices = new_testing_instances_indices;
01467 }
01468
01469
01470
01471
01473
01474 void InputTargetDataSet::set_training(void)
01475 {
01476 int instances_number = get_instances_number();
01477
01478 training_instances_indices.set_size(instances_number);
01479 validation_instances_indices.set_size(0);
01480 testing_instances_indices.set_size(0);
01481
01482 training_instances_indices.initialize_sequential();
01483 }
01484
01485
01486
01487
01489
01490 void InputTargetDataSet::set_validation(void)
01491 {
01492 int instances_number = get_instances_number();
01493
01494 training_instances_indices.set_size(0);
01495 validation_instances_indices.set_size(instances_number);
01496 testing_instances_indices.set_size(0);
01497
01498 validation_instances_indices.initialize_sequential();
01499 }
01500
01501
01502
01503
01505
01506 void InputTargetDataSet::set_testing(void)
01507 {
01508 int instances_number = get_instances_number();
01509
01510 training_instances_indices.set_size(0);
01511 validation_instances_indices.set_size(0);
01512 testing_instances_indices.set_size(instances_number);
01513
01514 testing_instances_indices.initialize_sequential();
01515 }
01516
01517
01518
01519
01524
01525 void InputTargetDataSet::set_input_variables_indices(const Vector<int>& new_input_variables_indices)
01526 {
01527 input_variables_indices = new_input_variables_indices;
01528 }
01529
01530
01531
01532
01537
01538 void InputTargetDataSet::set_target_variables_indices(const Vector<int>& new_target_variables_indices)
01539 {
01540 target_variables_indices = new_target_variables_indices;
01541 }
01542
01543
01544
01545
01547
01548 void InputTargetDataSet::set_input(void)
01549 {
01550 int variables_number = get_variables_number();
01551
01552 input_variables_indices.resize(variables_number);
01553
01554 input_variables_indices.initialize_sequential();
01555 }
01556
01557
01558
01559
01561
01562 void InputTargetDataSet::set_target(void)
01563 {
01564 int variables_number = get_variables_number();
01565
01566 target_variables_indices.resize(variables_number);
01567
01568 target_variables_indices.initialize_sequential();
01569 }
01570
01571
01572
01573
01577
01578 void InputTargetDataSet::set_variables_name(const Vector<std::string>& new_variables_name)
01579 {
01580
01581
01582 #ifdef _DEBUG
01583
01584 int variables_number = get_variables_number();
01585
01586 int size = new_variables_name.get_size();
01587
01588 if(size != variables_number)
01589 {
01590 std::cerr << "Flood Error: InputTargetDataSet class." << std::endl
01591 << "void set_variables_name(const Vector<std::string>&) method." << std::endl
01592 << "Size must be equal to number of variables." << std::endl;
01593
01594 exit(1);
01595 }
01596
01597 #endif
01598
01599 variables_name = new_variables_name;
01600 }
01601
01602
01603
01604
01609
01610 void InputTargetDataSet::set_variable_name(int i, const std::string& new_variable_name)
01611 {
01612 int variables_number = get_variables_number();
01613
01614
01615
01616 #ifdef _DEBUG
01617
01618 if(i < 0)
01619 {
01620 std::cerr << "Flood Error: InputTargetDataSet class." << std::endl
01621 << "void set_variable_name(int, const std::string&) method." << std::endl
01622 << "Index of variable must be equal or greater than zero." << std::endl;
01623
01624 exit(1);
01625 }
01626 else if(i >= variables_number)
01627 {
01628 std::cerr << "Flood Error: InputTargetDataSet class." << std::endl
01629 << "void set_variable_name(int, const std::string&) method." << std::endl
01630 << "Index of variable must be less than number of variables." << std::endl;
01631
01632 exit(1);
01633 }
01634
01635 #endif
01636
01637 if(variables_name.get_size() != variables_number)
01638 {
01639 variables_name.set(variables_number);
01640 }
01641
01642
01643
01644 variables_name[i] = new_variable_name;
01645 }
01646
01647
01648
01649
01653
01654 void InputTargetDataSet::set_variables_units(const Vector<std::string>& new_variables_units)
01655 {
01656
01657
01658 #ifdef _DEBUG
01659
01660 int variables_number = get_variables_number();
01661
01662 int size = new_variables_units.get_size();
01663
01664 if(size != variables_number)
01665 {
01666 std::cerr << "Flood Error: InputTargetDataSet class." << std::endl
01667 << "void set_variables_units(const Vector<std::string>&) method." << std::endl
01668 << "Size must be equal to number of variables." << std::endl;
01669
01670 exit(1);
01671 }
01672
01673 #endif
01674
01675 variables_units = new_variables_units;
01676 }
01677
01678
01679
01680
01685
01686 void InputTargetDataSet::set_variable_units(int i, const std::string& new_variable_units)
01687 {
01688 int variables_number = get_variables_number();
01689
01690
01691
01692 #ifdef _DEBUG
01693
01694 if(i < 0)
01695 {
01696 std::cerr << "Flood Error: InputTargetDataSet class." << std::endl
01697 << "void set_variable_units(int, const std::string&) method." << std::endl
01698 << "Index of variable must be equal or greater than zero." << std::endl;
01699
01700 exit(1);
01701 }
01702 else if(i >= variables_number)
01703 {
01704 std::cerr << "Flood Error: InputTargetDataSet class." << std::endl
01705 << "void set_variable_units(int, const std::string&) method." << std::endl
01706 << "Index of variable must be less than number of variables." << std::endl;
01707
01708 exit(1);
01709 }
01710
01711 #endif
01712
01713 if(variables_units.get_size() != variables_number)
01714 {
01715 variables_units.set(variables_number);
01716 }
01717
01718
01719
01720 variables_units[i] = new_variable_units;
01721 }
01722
01723
01724
01725
01729
01730 void InputTargetDataSet::set_variables_description(const Vector<std::string>& new_variables_description)
01731 {
01732
01733
01734 #ifdef _DEBUG
01735
01736 int variables_number = get_variables_number();
01737
01738 int size = new_variables_description.get_size();
01739
01740 if(size != variables_number)
01741 {
01742 std::cerr << "Flood Error: InputTargetDataSet class." << std::endl
01743 << "void set_variables_description(const Vector<std::string>&) method." << std::endl
01744 << "Size must be equal to number of variables." << std::endl;
01745
01746 exit(1);
01747 }
01748
01749 #endif
01750
01751 variables_description = new_variables_description;
01752 }
01753
01754
01755
01756
01761
01762 void InputTargetDataSet::set_variable_description(int i, const std::string& new_variable_description)
01763 {
01764 int variables_number = get_variables_number();
01765
01766
01767
01768 #ifdef _DEBUG
01769
01770 if(i < 0)
01771 {
01772 std::cerr << "Flood Error: InputTargetDataSet class." << std::endl
01773 << "void set_variable_description(int, const std::string&) method." << std::endl
01774 << "Index of variable must be equal or greater than zero." << std::endl;
01775
01776 exit(1);
01777 }
01778 else if(i >= variables_number)
01779 {
01780 std::cerr << "Flood Error: InputTargetDataSet class." << std::endl
01781 << "void set_variable_description(int, const std::string&) method." << std::endl
01782 << "Index of variable must be less than number of variables." << std::endl;
01783
01784 exit(1);
01785 }
01786
01787 #endif
01788
01789 if(variables_description.get_size() != variables_number)
01790 {
01791 variables_description.set(variables_number);
01792 }
01793
01794
01795
01796 variables_description[i] = new_variable_description;
01797 }
01798
01799
01800
01801
01806
01807 void InputTargetDataSet::set_display(const bool new_display)
01808 {
01809 display = new_display;
01810
01811 data.set_display(new_display);
01812 }
01813
01814
01815
01816
01822
01823 void InputTargetDataSet::set_data(const Matrix<double>& new_data)
01824 {
01825
01826
01827 #ifdef _DEBUG
01828
01829 int rows_number = new_data.get_rows_number();
01830 int instances_number = get_instances_number();
01831
01832 if(rows_number != instances_number)
01833 {
01834 std::cerr << "Flood Error: InputTargetDataSet class." << std::endl
01835 << "void set_data(const Matrix<double>&) method." << std::endl
01836 << "Number of rows must be equal to number of instances." << std::endl;
01837
01838 exit(1);
01839 }
01840
01841 int columns_number = new_data.get_columns_number();
01842 int variables_number = get_variables_number();
01843
01844 if(columns_number != variables_number)
01845 {
01846 std::cerr << "Flood Error: InputTargetDataSet class." << std::endl
01847 << "void set_data(const Matrix<double>&) method." << std::endl
01848 << "Number of columns must be equal to number of variables." << std::endl;
01849
01850 exit(1);
01851 }
01852
01853 #endif
01854
01855
01856
01857 data = new_data;
01858 }
01859
01860
01861
01862
01867
01868 void InputTargetDataSet::set_instances_number(int new_instances_number)
01869 {
01870
01871
01872 #ifdef _DEBUG
01873
01874 if(new_instances_number < 0)
01875 {
01876 std::cerr << "Flood Error: InputTargetDataSet class." << std::endl
01877 << "void set_instances_number(int) method." << std::endl
01878 << "New number of instances must be equal or greater than zero." << std::endl;
01879
01880 exit(1);
01881 }
01882
01883 #endif
01884
01885 int variables_number = get_variables_number();
01886
01887 data.set(new_instances_number, variables_number);
01888
01889 set_training();
01890 }
01891
01892
01893
01894
01899
01900 void InputTargetDataSet::set_variables_number(int new_variables_number)
01901 {
01902
01903
01904 #ifdef _DEBUG
01905
01906 if(new_variables_number < 0)
01907 {
01908 std::cerr << "Flood Error: InputTargetDataSet class." << std::endl
01909 << "void set_variables_number(int) method." << std::endl
01910 << "New number of variables must be equal or greater than zero." << std::endl;
01911
01912 exit(1);
01913 }
01914
01915 #endif
01916
01917 int instances_number = get_instances_number();
01918
01919 data.set(instances_number, new_variables_number);
01920
01921 set_input();
01922 }
01923
01924
01925
01926
01930
01931 void InputTargetDataSet::set_instance(int instance_index, const Vector<double>& instance)
01932 {
01933
01934
01935 #ifdef _DEBUG
01936
01937 int instances_number = get_instances_number();
01938
01939 if(instance_index < 0)
01940 {
01941 std::cerr << "Flood Error: InputTargetDataSet class." << std::endl
01942 << "void set_instance(int, const Vector<double>&) method." << std::endl
01943 << "Index of instance must be equal or greater than zero." << std::endl;
01944
01945 exit(1);
01946 }
01947 else if(instance_index >= instances_number)
01948 {
01949 std::cerr << "Flood Error: InputTargetDataSet class." << std::endl
01950 << "void set_instance(int, const Vector<double>&) method." << std::endl
01951 << "Index of instance must be less than number of instances." << std::endl;
01952
01953 exit(1);
01954 }
01955
01956 int size = instance.get_size();
01957 int variables_number = get_variables_number();
01958
01959 if(size != variables_number)
01960 {
01961 std::cerr << "Flood Error: InputTargetDataSet class." << std::endl
01962 << "void set_instance(int, const Vector<double>&) method." << std::endl
01963 << "Size (" << size << ") must be equal to number of variables (" << variables_number << ")."
01964 << std::endl;
01965
01966 exit(1);
01967 }
01968
01969 #endif
01970
01971
01972
01973 data.set_row(instance_index, instance);
01974 }
01975
01976
01977
01978
01982
01983 void InputTargetDataSet::set_training_instance(int i, const Vector<double>& new_training_instance)
01984 {
01985
01986
01987 #ifdef _DEBUG
01988
01989 int training_instances_number = get_training_instances_number();
01990
01991 if(i < 0)
01992 {
01993 std::cerr << "Flood Error: InputTargetDataSet class." << std::endl
01994 << "void set_training_instance(int, const Vector<double>&) method." << std::endl
01995 << "Training instance index must be equal or greater than zero." << std::endl;
01996
01997 exit(1);
01998 }
01999 else if(i >= training_instances_number)
02000 {
02001 std::cerr << "Flood Error: InputTargetDataSet class." << std::endl
02002 << "void set_training_instance(int, const Vector<double>&) method." << std::endl
02003 << "Training instance index must be less than number of training instances." << std::endl;
02004
02005 exit(1);
02006 }
02007
02008 #endif
02009
02010 int index = training_instances_indices[i];
02011
02012 set_instance(index, new_training_instance);
02013 }
02014
02015
02016
02017
02021
02022 void InputTargetDataSet::set_validation_instance(int i, const Vector<double>& new_validation_instance)
02023 {
02024
02025
02026 #ifdef _DEBUG
02027
02028 int validation_instances_number = get_validation_instances_number();
02029
02030 if(i < 0)
02031 {
02032 std::cerr << "Flood Error: InputTargetDataSet class." << std::endl
02033 << "void set_validation_instance(int, const Vector<double>&) method." << std::endl
02034 << "Validation instance index must be equal or greater than zero." << std::endl;
02035
02036 exit(1);
02037 }
02038 else if(i >= validation_instances_number)
02039 {
02040 std::cerr << "Flood Error: InputTargetDataSet class." << std::endl
02041 << "void set_validation_instance(int, const Vector<double>&) method." << std::endl
02042 << "Validation instance index must be less than number of validation instances." << std::endl;
02043
02044 exit(1);
02045 }
02046
02047 #endif
02048
02049 int index = validation_instances_indices[i];
02050
02051 set_instance(index, new_validation_instance);
02052 }
02053
02054
02055
02056
02060
02061 void InputTargetDataSet::set_testing_instance(int i, const Vector<double>& new_testing_instance)
02062 {
02063
02064
02065 #ifdef _DEBUG
02066
02067 int testing_instances_number = get_testing_instances_number();
02068
02069 if(i < 0)
02070 {
02071 std::cerr << "Flood Error: InputTargetDataSet class." << std::endl
02072 << "void set_testing_instance(int, const Vector<double>&) method." << std::endl
02073 << "Testing instance index must be equal or greater than zero." << std::endl;
02074
02075 exit(1);
02076 }
02077 else if(i >= testing_instances_number)
02078 {
02079 std::cerr << "Flood Error: InputTargetDataSet class." << std::endl
02080 << "void set_testing_instance(int, const Vector<double>&) method." << std::endl
02081 << "Testing instance index must be less than number of testing instances." << std::endl;
02082
02083 exit(1);
02084 }
02085
02086 #endif
02087
02088 int index = testing_instances_indices[i];
02089
02090 set_instance(index, new_testing_instance);
02091 }
02092
02093
02094
02095
02099
02100 void InputTargetDataSet::set_input_instance(int instance_index, const Vector<double>& input_instance)
02101 {
02102
02103
02104 #ifdef _DEBUG
02105
02106 int instances_number = get_instances_number();
02107
02108 if(instance_index < 0)
02109 {
02110 std::cerr << "Flood Error: InputTargetDataSet class." << std::endl
02111 << "void set_input_instance(int, const Vector<double>&) method." << std::endl
02112 << "Index of instance must be equal or greater than zero." << std::endl;
02113
02114 exit(1);
02115 }
02116 else if(instance_index >= instances_number)
02117 {
02118 std::cerr << "Flood Error: InputTargetDataSet class." << std::endl
02119 << "void set_input_instance(int, const Vector<double>&) method." << std::endl
02120 << "Index of instance must be less than number of instances." << std::endl;
02121
02122 exit(1);
02123 }
02124
02125 #endif
02126
02127 int input_variables_number = get_input_variables_number();
02128
02129 #ifdef _DEBUG
02130
02131 int size = input_instance.get_size();
02132
02133 if(size != input_variables_number)
02134 {
02135 std::cerr << "Flood Error: InputTargetDataSet class." << std::endl
02136 << "void set_input_instance(int, const Vector<double>&) method." << std::endl
02137 << "Size of input instance must be equal to number of input variables." << std::endl;
02138
02139 exit(1);
02140 }
02141
02142 #endif
02143
02144 int input_variable_index;
02145
02146 for(int i = 0; i < input_variables_number; i++)
02147 {
02148 input_variable_index = input_variables_indices[i];
02149
02150 data[instance_index][input_variable_index] = input_instance[i];
02151 }
02152 }
02153
02154
02155
02156
02160
02161 void InputTargetDataSet::set_target_instance(int instance_index, const Vector<double>& target_instance)
02162 {
02163
02164
02165 #ifdef _DEBUG
02166
02167 int instances_number = get_instances_number();
02168
02169 if(instance_index < 0)
02170 {
02171 std::cerr << "Flood Error: InputTargetDataSet class." << std::endl
02172 << "void set_target_instance(int, const Vector<double>&) method." << std::endl
02173 << "Index of instance must be equal or greater than zero." << std::endl;
02174
02175 exit(1);
02176 }
02177 else if(instance_index >= instances_number)
02178 {
02179 std::cerr << "Flood Error: InputTargetDataSet class." << std::endl
02180 << "void set_target_instance(int, const Vector<double>&) method." << std::endl
02181 << "Index of instance must be less than number of instances." << std::endl;
02182
02183 exit(1);
02184 }
02185
02186 #endif
02187
02188 int target_variables_number = get_target_variables_number();
02189
02190 #ifdef _DEBUG
02191
02192 int size = target_instance.get_size();
02193
02194 if(size != target_variables_number)
02195 {
02196 std::cerr << "Flood Error: InputTargetDataSet class." << std::endl
02197 << "void set_target_instance(int, const Vector<double>&) method." << std::endl
02198 << "Size of target instance must be equal to number of target variables." << std::endl;
02199
02200 exit(1);
02201 }
02202
02203 #endif
02204
02205 int target_variable_index;
02206
02207 for(int i = 0; i < target_variables_number; i++)
02208 {
02209 target_variable_index = target_variables_indices[i];
02210
02211 data[instance_index][target_variable_index] = target_instance[i];
02212 }
02213 }
02214
02215
02216
02217
02221
02222 void InputTargetDataSet::set_training_input_instance(int i, const Vector<double>& new_training_input_instance)
02223 {
02224
02225
02226 #ifdef _DEBUG
02227
02228 int training_instances_number = get_training_instances_number();
02229
02230 if(i < 0)
02231 {
02232 std::cerr << "Flood Error: InputTargetDataSet class." << std::endl
02233 << "void set_training_input_instance(int, const Vector<double>&) method." << std::endl
02234 << "Training instance index must be equal or greater than zero." << std::endl;
02235
02236 exit(1);
02237 }
02238 else if(i >= training_instances_number)
02239 {
02240 std::cerr << "Flood Error: InputTargetDataSet class." << std::endl
02241 << "void set_training_input_instance(int, const Vector<double>&) method." << std::endl
02242 << "Training instance index must be less than number of training instances." << std::endl;
02243
02244 exit(1);
02245 }
02246
02247 #endif
02248
02249 int index = training_instances_indices[i];
02250
02251 set_input_instance(index, new_training_input_instance);
02252 }
02253
02254
02255
02256
02260
02261 void InputTargetDataSet::set_validation_input_instance(int i, const Vector<double>& new_validation_input_instance)
02262 {
02263
02264
02265 #ifdef _DEBUG
02266
02267 int validation_instances_number = get_validation_instances_number();
02268
02269 if(i < 0)
02270 {
02271 std::cerr << "Flood Error: InputTargetDataSet class." << std::endl
02272 << "void set_validation_input_instance(int, const Vector<double>&) method." << std::endl
02273 << "Validation instance index must be equal or greater than zero." << std::endl;
02274
02275 exit(1);
02276 }
02277 else if(i >= validation_instances_number)
02278 {
02279 std::cerr << "Flood Error: InputTargetDataSet class." << std::endl
02280 << "void set_validation_input_instance(int, const Vector<double>&) method." << std::endl
02281 << "Validation instance index must be less than number of validation instances." << std::endl;
02282
02283 exit(1);
02284 }
02285
02286 #endif
02287
02288 int index = validation_instances_indices[i];
02289
02290 set_input_instance(index, new_validation_input_instance);
02291 }
02292
02293
02294
02295
02299
02300 void InputTargetDataSet::set_testing_input_instance(int i, const Vector<double>& new_testing_input_instance)
02301 {
02302
02303
02304 #ifdef _DEBUG
02305
02306 int testing_instances_number = get_testing_instances_number();
02307
02308 if(i < 0)
02309 {
02310 std::cerr << "Flood Error: InputTargetDataSet class." << std::endl
02311 << "void set_testing_input_instance(int, const Vector<double>&) method." << std::endl
02312 << "Testing instance index must be equal or greater than zero." << std::endl;
02313
02314 exit(1);
02315 }
02316 else if(i >= testing_instances_number)
02317 {
02318 std::cerr << "Flood Error: InputTargetDataSet class." << std::endl
02319 << "void set_testing_input_instance(int, const Vector<double>&) method." << std::endl
02320 << "Testing instance index must be less than number of testing instances." << std::endl;
02321
02322 exit(1);
02323 }
02324
02325 #endif
02326
02327 int index = testing_instances_indices[i];
02328
02329 set_input_instance(index, new_testing_input_instance);
02330 }
02331
02332
02333
02334
02338
02339 void InputTargetDataSet::set_training_target_instance(int i, const Vector<double>& new_training_target_instance)
02340 {
02341
02342
02343 #ifdef _DEBUG
02344
02345 int training_instances_number = get_training_instances_number();
02346
02347 if(i < 0)
02348 {
02349 std::cerr << "Flood Error: InputTargetDataSet class." << std::endl
02350 << "void set_training_target_instance(int, const Vector<double>&) method." << std::endl
02351 << "Training instance index must be equal or greater than zero." << std::endl;
02352
02353 exit(1);
02354 }
02355 else if(i >= training_instances_number)
02356 {
02357 std::cerr << "Flood Error: InputTargetDataSet class." << std::endl
02358 << "void set_training_target_instance(int, const Vector<double>&) method." << std::endl
02359 << "Training instance index must be less than number of training instances." << std::endl;
02360
02361 exit(1);
02362 }
02363
02364 #endif
02365
02366 int index = training_instances_indices[i];
02367
02368 set_target_instance(index, new_training_target_instance);
02369 }
02370
02371
02372
02373
02377
02378 void InputTargetDataSet::
02379 set_validation_target_instance(int i, const Vector<double>& new_validation_target_instance)
02380 {
02381
02382
02383 #ifdef _DEBUG
02384
02385 int validation_instances_number = get_validation_instances_number();
02386
02387 if(i < 0)
02388 {
02389 std::cerr << "Flood Error: InputTargetDataSet class." << std::endl
02390 << "void set_validation_target_instance(int, const Vector<double>&) method." << std::endl
02391 << "Validation instance index must be equal or greater than zero." << std::endl;
02392
02393 exit(1);
02394 }
02395 else if(i >= validation_instances_number)
02396 {
02397 std::cerr << "Flood Error: InputTargetDataSet class." << std::endl
02398 << "void set_validation_target_instance(int, const Vector<double>&) method." << std::endl
02399 << "Validation instance index must be less than number of validation instances." << std::endl;
02400
02401 exit(1);
02402 }
02403
02404 #endif
02405
02406 int index = validation_instances_indices[i];
02407
02408 set_target_instance(index, new_validation_target_instance);
02409 }
02410
02411
02412
02413
02417
02418 void InputTargetDataSet::set_testing_target_instance(int i, const Vector<double>& new_testing_target_instance)
02419 {
02420
02421
02422 #ifdef _DEBUG
02423
02424 int testing_instances_number = get_testing_instances_number();
02425
02426 if(i < 0)
02427 {
02428 std::cerr << "Flood Error: InputTargetDataSet class." << std::endl
02429 << "void set_testing_target_instance(int, const Vector<double>&) method." << std::endl
02430 << "Testing instance index must be equal or greater than zero." << std::endl;
02431
02432 exit(1);
02433 }
02434 else if(i >= testing_instances_number)
02435 {
02436 std::cerr << "Flood Error: InputTargetDataSet class." << std::endl
02437 << "void set_testing_target_instance(int, const Vector<double>&) method." << std::endl
02438 << "Testing instance index must be less than number of testing instances." << std::endl;
02439
02440 exit(1);
02441 }
02442
02443 #endif
02444
02445 int index = testing_instances_indices[i];
02446
02447 set_target_instance(index, new_testing_target_instance);
02448 }
02449
02450
02451
02452
02458
02459 void InputTargetDataSet::add_instance(const Vector<double>& instance)
02460 {
02461
02462
02463 #ifdef _DEBUG
02464
02465 int size = instance.get_size();
02466 int variables_number = get_variables_number();
02467
02468 if(size != variables_number)
02469 {
02470 std::cerr << "Flood Error: InputTargetDataSet class." << std::endl
02471 << "void add_instance(const Vector<double>&) method." << std::endl
02472 << "Size of instance must be equal to number of variables." << std::endl;
02473
02474 exit(1);
02475 }
02476
02477 #endif
02478
02479 data.add_row(instance);
02480
02481 set_training();
02482 }
02483
02484
02485
02486
02491
02492 void InputTargetDataSet::subtract_instance(int instance_index)
02493 {
02494
02495
02496 #ifdef _DEBUG
02497
02498 int instances_number = get_instances_number();
02499
02500 if(instance_index < 0)
02501 {
02502 std::cerr << "Flood Error: InputTargetDataSet class." << std::endl
02503 << "void subtract_instance(int) method." << std::endl
02504 << "Index of instance must be equal or greater than zero." << std::endl;
02505
02506 exit(1);
02507 }
02508 else if(instance_index >= instances_number)
02509 {
02510 std::cerr << "Flood Error: InputTargetDataSet class." << std::endl
02511 << "void subtract_instance(int) method." << std::endl
02512 << "Index of instance must be less than number of instances." << std::endl;
02513
02514 exit(1);
02515 }
02516
02517 #endif
02518
02519 data.subtract_row(instance_index);
02520
02521 set_training();
02522 }
02523
02524
02525
02526
02535
02536 Vector< Vector<double> > InputTargetDataSet::calculate_data_statistics(void)
02537 {
02538 Vector< Vector<double> > data_mean_standard_deviation = data.calculate_mean_standard_deviation();
02539 Vector< Vector<double> > data_minimum_maximum = data.calculate_minimum_maximum();
02540
02541 Vector< Vector<double> > statistics(4);
02542
02543 statistics[0] = data_mean_standard_deviation[0];
02544 statistics[1] = data_mean_standard_deviation[1];
02545 statistics[2] = data_minimum_maximum[0];
02546 statistics[3] = data_minimum_maximum[1];
02547
02548 return(statistics);
02549 }
02550
02551
02552
02553
02562
02563 Vector< Vector<double> > InputTargetDataSet::calculate_training_instances_statistics(void)
02564 {
02565 int variables_number = get_variables_number();
02566 Vector<int> variables_indices(variables_number);
02567 variables_indices.initialize_sequential();
02568
02569 Vector< Vector<double> > mean_standard_deviation = data.calculate_mean_standard_deviation(training_instances_indices, variables_indices);
02570
02571 Vector< Vector<double> > minimum_maximum = data.calculate_minimum_maximum(training_instances_indices, variables_indices);
02572
02573 Vector< Vector<double> > statistics(4);
02574
02575 statistics[0] = mean_standard_deviation[0];
02576 statistics[1] = mean_standard_deviation[1];
02577 statistics[2] = minimum_maximum[0];
02578 statistics[3] = minimum_maximum[1];
02579
02580 return(statistics);
02581 }
02582
02583
02584
02585
02594
02595 Vector< Vector<double> > InputTargetDataSet::calculate_validation_instances_statistics(void)
02596 {
02597 int variables_number = get_variables_number();
02598 Vector<int> variables_indices(variables_number);
02599 variables_indices.initialize_sequential();
02600
02601 Vector< Vector<double> > mean_standard_deviation = data.calculate_mean_standard_deviation(validation_instances_indices, variables_indices);
02602
02603 Vector< Vector<double> > minimum_maximum = data.calculate_minimum_maximum(validation_instances_indices, variables_indices);
02604
02605 Vector< Vector<double> > statistics(4);
02606
02607 statistics[0] = mean_standard_deviation[0];
02608 statistics[1] = mean_standard_deviation[1];
02609 statistics[2] = minimum_maximum[0];
02610 statistics[3] = minimum_maximum[1];
02611
02612 return(statistics);
02613 }
02614
02615
02616
02617
02626
02627 Vector< Vector<double> > InputTargetDataSet::calculate_testing_instances_statistics(void)
02628 {
02629 int variables_number = get_variables_number();
02630 Vector<int> variables_indices(variables_number);
02631 variables_indices.initialize_sequential();
02632
02633 Vector< Vector<double> > mean_standard_deviation = data.calculate_mean_standard_deviation(testing_instances_indices, variables_indices);
02634
02635 Vector< Vector<double> > minimum_maximum = data.calculate_minimum_maximum(testing_instances_indices, variables_indices);
02636
02637 Vector< Vector<double> > statistics(4);
02638
02639 statistics[0] = mean_standard_deviation[0];
02640 statistics[1] = mean_standard_deviation[1];
02641 statistics[2] = minimum_maximum[0];
02642 statistics[3] = minimum_maximum[1];
02643
02644 return(statistics);
02645 }
02646
02647
02648
02649
02671
02672 Vector< Vector<double> > InputTargetDataSet::calculate_instances_statistics(void)
02673 {
02674 Vector< Vector<double> > data_statistics = calculate_data_statistics();
02675 Vector< Vector<double> > training_instances_statistics = calculate_training_instances_statistics();
02676 Vector< Vector<double> > validation_instances_statistics = calculate_validation_instances_statistics();
02677 Vector< Vector<double> > testing_instances_statistics = calculate_testing_instances_statistics();
02678
02679 return(data_statistics.assemble(training_instances_statistics).assemble(validation_instances_statistics).assemble(testing_instances_statistics));
02680 }
02681
02682
02683
02684
02693
02694 Vector< Vector<double> > InputTargetDataSet::calculate_input_variables_statistics(void)
02695 {
02696 Vector< Vector<double> > mean_standard_deviation = data.calculate_mean_standard_deviation(input_variables_indices);
02697 Vector< Vector<double> > minimum_maximum = data.calculate_minimum_maximum(input_variables_indices);
02698
02699 Vector< Vector<double> > statistics(4);
02700
02701 statistics[0] = mean_standard_deviation[0];
02702 statistics[1] = mean_standard_deviation[1];
02703 statistics[2] = minimum_maximum[0];
02704 statistics[3] = minimum_maximum[1];
02705
02706 return(statistics);
02707 }
02708
02709
02710
02711
02720
02721 Vector< Vector<double> > InputTargetDataSet::calculate_target_variables_statistics(void)
02722 {
02723 Vector< Vector<double> > mean_standard_deviation = data.calculate_mean_standard_deviation(target_variables_indices);
02724 Vector< Vector<double> > minimum_maximum = data.calculate_minimum_maximum(target_variables_indices);
02725
02726 Vector< Vector<double> > statistics(4);
02727
02728 statistics[0] = mean_standard_deviation[0];
02729 statistics[1] = mean_standard_deviation[1];
02730 statistics[2] = minimum_maximum[0];
02731 statistics[3] = minimum_maximum[1];
02732
02733 return(statistics);
02734 }
02735
02736
02737
02738
02739
02752
02753 Vector< Vector<double> > InputTargetDataSet::calculate_variables_statistics(void)
02754 {
02755 Vector< Vector<double> > statistics(8);
02756
02757
02758
02759 Vector< Vector<double> > input_variables_mean_standard_deviation = data.calculate_mean_standard_deviation(input_variables_indices);
02760 Vector< Vector<double> > input_variables_minimum_maximum = data.calculate_minimum_maximum(input_variables_indices);
02761
02762
02763
02764 Vector< Vector<double> > target_variables_mean_standard_deviation = data.calculate_mean_standard_deviation(target_variables_indices);
02765 Vector< Vector<double> > target_variables_minimum_maximum = data.calculate_minimum_maximum(target_variables_indices);
02766
02767 statistics[0] = input_variables_mean_standard_deviation[0];
02768 statistics[1] = input_variables_mean_standard_deviation[1];
02769 statistics[2] = input_variables_minimum_maximum[0];
02770 statistics[3] = input_variables_minimum_maximum[1];
02771 statistics[4] = target_variables_mean_standard_deviation[0];
02772 statistics[5] = target_variables_mean_standard_deviation[1];
02773 statistics[6] = target_variables_minimum_maximum[0];
02774 statistics[7] = target_variables_minimum_maximum[1];
02775
02776 return(statistics);
02777 }
02778
02779
02780
02781
02783
02784 Vector<double> InputTargetDataSet::calculate_training_target_data_mean(void)
02785 {
02786 Vector< Vector<double> > training_target_data_mean_standard_deviation = data.calculate_mean_standard_deviation(training_instances_indices, target_variables_indices);
02787
02788 return(training_target_data_mean_standard_deviation[0]);
02789 }
02790
02791
02792
02793
02795
02796 Vector<double> InputTargetDataSet::calculate_validation_target_data_mean(void)
02797 {
02798 Vector< Vector<double> > validation_target_data_mean_standard_deviation = data.calculate_mean_standard_deviation(validation_instances_indices, target_variables_indices);
02799
02800 return(validation_target_data_mean_standard_deviation[0]);
02801 }
02802
02803
02804
02805
02811
02812 void InputTargetDataSet::scale_data_mean_standard_deviation(const Vector<double>& variables_mean, const Vector<double>& variables_standard_deviation)
02813 {
02814
02815
02816 #ifdef _DEBUG
02817
02818 int variables_number = get_variables_number();
02819
02820 int variables_mean_size = variables_mean.get_size();
02821 int variables_standard_deviation_size = variables_standard_deviation.get_size();
02822
02823 if(variables_mean_size != variables_number)
02824 {
02825 std::cerr << "Flood Error: InputTargetDataSet class." << std::endl
02826 << "void scale_data_mean_standard_deviation(const Vector<double>&, const Vector<double>&) method." << std::endl
02827 << "Size of variables mean must be equal to number of variables." << std::endl;
02828
02829 exit(1);
02830 }
02831
02832 if(variables_standard_deviation_size != variables_number)
02833 {
02834 std::cerr << "Flood Error: InputTargetDataSet class." << std::endl
02835 << "void scale_data_mean_standard_deviation(const Vector<double>&, const Vector<double>&) method." << std::endl
02836 << "Size of variables standard deviation must be equal to number of variables." << std::endl;
02837
02838 exit(1);
02839 }
02840
02841 #endif
02842
02843 data.scale_mean_standard_deviation(variables_mean, variables_standard_deviation);
02844 }
02845
02846
02847
02848
02854
02855 void InputTargetDataSet::scale_data_minimum_maximum(const Vector<double>& variables_minimum, const Vector<double>& variables_maximum)
02856 {
02857
02858
02859 #ifdef _DEBUG
02860
02861 int variables_number = get_variables_number();
02862
02863 int variables_minimum_size = variables_minimum.get_size();
02864 int variables_maximum_size = variables_maximum.get_size();
02865
02866 if(variables_minimum_size != variables_number)
02867 {
02868 std::cerr << "Flood Error: InputTargetDataSet class." << std::endl
02869 << "void scale_data_minimum_maximum(const Vector<double>&, const Vector<double>&) method." << std::endl
02870 << "Size of variables minimum must be equal to number of variables." << std::endl;
02871
02872 exit(1);
02873 }
02874
02875 if(variables_maximum_size != variables_number)
02876 {
02877 std::cerr << "Flood Error: InputTargetDataSet class." << std::endl
02878 << "void scale_data_minimumn_maximum(const Vector<double>&, const Vector<double>&) method." << std::endl
02879 << "Size of variables maximum must be equal to number of variables." << std::endl;
02880
02881 exit(1);
02882 }
02883
02884 #endif
02885
02886 data.scale_minimum_maximum(variables_minimum, variables_maximum);
02887 }
02888
02889
02890
02891
02897
02898 void InputTargetDataSet::scale_input_variables_mean_standard_deviation(const Vector<double>& input_variables_mean,
02899 const Vector<double>& input_variables_standard_deviation)
02900 {
02901 int input_variables_number = get_input_variables_number();
02902
02903
02904
02905 #ifdef _DEBUG
02906
02907 int input_variables_mean_size = input_variables_mean.get_size();
02908 int input_variables_standard_deviation_size = input_variables_standard_deviation.get_size();
02909
02910 if(input_variables_mean_size != input_variables_number)
02911 {
02912 std::cerr << "Flood Error: InputTargetDataSet class." << std::endl
02913 << "void scale_input_variables_mean_standard_deviation(const Vector<double>&, const Vector<double>&) method." << std::endl
02914 << "Size of input variables mean must be equal to number of input variables." << std::endl;
02915
02916 exit(1);
02917 }
02918
02919 if(input_variables_standard_deviation_size != input_variables_number)
02920 {
02921 std::cerr << "Flood Error: InputTargetDataSet class." << std::endl
02922 << "void scale_input_variables_mean_standard_deviation(const Vector<double>&, const Vector<double>&) method." << std::endl
02923 << "Size of input variables standard deviation must be equal to number of input variables." << std::endl;
02924
02925 exit(1);
02926 }
02927
02928 #endif
02929
02930 int instances_number = get_instances_number();
02931
02932 int variable_index;
02933
02934
02935
02936 for(int j = 0; j < input_variables_number; j++)
02937 {
02938 variable_index = input_variables_indices[j];
02939
02940 if(input_variables_standard_deviation[j] < 1e-99)
02941 {
02942 if(display)
02943 {
02944 std::cout << "Flood Warning: InputTargetDataSet class." << std::endl
02945 << "void scale_input_variables_mean_standard_deviation(const Vector<double>&, const Vector<double>&) method." << std::endl
02946 << "Standard deviation of input variable " << j << " is zero." << std::endl
02947 << "Those inputs won't be scaled." << std::endl;
02948 }
02949
02950
02951 }
02952 else
02953 {
02954 for(int i = 0; i < instances_number; i++)
02955 {
02956 data[i][variable_index] = (data[i][variable_index] - input_variables_mean[j])/input_variables_standard_deviation[j];
02957 }
02958 }
02959 }
02960 }
02961
02962
02963
02964
02978
02979 Vector< Vector<double> > InputTargetDataSet::scale_input_variables_mean_standard_deviation(void)
02980 {
02981 Vector< Vector<double> > variables_statistics = calculate_variables_statistics();
02982
02983 scale_input_variables_mean_standard_deviation(variables_statistics[0], variables_statistics[1]);
02984
02985 return(variables_statistics);
02986 }
02987
02988
02989
02990
02996
02997 void InputTargetDataSet
02998 ::scale_input_variables_minimum_maximum(const Vector<double>& input_variables_minimum, const Vector<double>& input_variables_maximum)
02999 {
03000
03001
03002 int instances_number = get_instances_number();
03003 int input_variables_number = get_input_variables_number();
03004
03005 int variable_index;
03006
03007 for(int j = 0; j < input_variables_number; j++)
03008 {
03009 variable_index = input_variables_indices[j];
03010
03011 if(input_variables_maximum[j] - input_variables_minimum[j] < 1e-99)
03012 {
03013 if(display)
03014 {
03015 std::cout << "Flood Warning: InputTargetDataSet class." << std::endl
03016 << "void scale_input_variables_minimum_maximum(const Vector<double>&, const Vector<double>&) method." << std::endl
03017 << "Minimum and maximum values of input variable " << j << " are equal. "
03018 << "Those inputs won't be scaled." << std::endl;
03019 }
03020
03021
03022 }
03023 else
03024 {
03025 for(int i = 0; i < instances_number; i++)
03026 {
03027 data[i][variable_index] = 2.0*(data[i][variable_index] - input_variables_minimum[j])/(input_variables_maximum[j]-input_variables_minimum[j])-1.0;
03028 }
03029 }
03030 }
03031 }
03032
03033
03034
03035
03049
03050 Vector< Vector<double> > InputTargetDataSet::scale_input_variables_minimum_maximum(void)
03051 {
03052 Vector< Vector<double> > variables_statistics = calculate_variables_statistics();
03053
03054 scale_input_variables_minimum_maximum(variables_statistics[2], variables_statistics[3]);
03055
03056 return(variables_statistics);
03057 }
03058
03059
03060
03061
03067
03068 void InputTargetDataSet::scale_target_variables_mean_standard_deviation(const Vector<double>&
03069 target_variables_mean, const Vector<double>& target_variables_standard_deviation)
03070 {
03071 int target_variables_number = get_target_variables_number();
03072
03073
03074
03075 #ifdef _DEBUG
03076
03077 int target_variables_mean_size = target_variables_mean.get_size();
03078 int target_variables_standard_deviation_size = target_variables_standard_deviation.get_size();
03079
03080 if(target_variables_mean_size != target_variables_number)
03081 {
03082 std::cerr << "Flood Error: InputTargetDataSet class." << std::endl
03083 << "void scale_target_variables_mean_standard_deviation(const Vector<double>&, const Vector<double>&) method." << std::endl
03084 << "Size of target variables mean must be equal to number of target variables." << std::endl;
03085
03086 exit(1);
03087 }
03088
03089 if(target_variables_standard_deviation_size != target_variables_number)
03090 {
03091 std::cerr << "Flood Error: InputTargetDataSet class." << std::endl
03092 << "void scale_target_variables_mean_standard_deviation(const Vector<double>&, const Vector<double>&) method." << std::endl
03093 << "Size of target variables standard deviation must be equal to number of target variables." << std::endl;
03094
03095 exit(1);
03096 }
03097
03098 #endif
03099
03100 int instances_number = get_instances_number();
03101
03102 int variable_index;
03103
03104
03105
03106 for(int j = 0; j < target_variables_number; j++)
03107 {
03108 variable_index = target_variables_indices[j];
03109
03110 if(target_variables_standard_deviation[j] < 1e-99)
03111 {
03112 if(display)
03113 {
03114 std::cout << "Flood Warning: InputTargetDataSet class." << std::endl
03115 << "void scale_target_variables_mean_standard_deviation(const Vector<double>&, const Vector<double>&) method." << std::endl
03116 << "Standard deviation of target variable " << j << " is zero." << std::endl
03117 << "Those targets won't be scaled." << std::endl;
03118 }
03119
03120
03121 }
03122 else
03123 {
03124 for(int i = 0; i < instances_number; i++)
03125 {
03126 data[i][variable_index] = (data[i][variable_index] - target_variables_mean[j])/target_variables_standard_deviation[j];
03127 }
03128 }
03129 }
03130 }
03131
03132
03133
03134
03148
03149 Vector< Vector<double> > InputTargetDataSet::scale_target_variables_mean_standard_deviation(void)
03150 {
03151 Vector< Vector<double> > variables_statistics = calculate_variables_statistics();
03152
03153 scale_target_variables_mean_standard_deviation(variables_statistics[4], variables_statistics[5]);
03154
03155 return(variables_statistics);
03156 }
03157
03158
03159
03160
03166
03167 void InputTargetDataSet::scale_target_variables_minimum_maximum(const Vector<double>& target_variables_minimum,
03168 const Vector<double>& target_variables_maximum)
03169 {
03170 int instances_number = get_instances_number();
03171 int target_variables_number = get_target_variables_number();
03172
03173 int variable_index;
03174
03175
03176
03177 for(int j = 0; j < target_variables_number; j++)
03178 {
03179 variable_index = target_variables_indices[j];
03180
03181 if(target_variables_maximum[j] - target_variables_minimum[j] < 1e-99)
03182 {
03183 if(display)
03184 {
03185 std::cout << "Flood Warning: InputTargetDataSet class." << std::endl
03186 << "void scale_target_variables_minimum_maximum(const Vector<double>&, const Vector<double>&) method." << std::endl
03187 << "Minimum and maximum values of target variable " << j << " are equal. "
03188 << "Those targets won't be scaled." << std::endl;
03189 }
03190
03191
03192 }
03193 else
03194 {
03195 for(int i = 0; i < instances_number; i++)
03196 {
03197 data[i][variable_index] = 2.0*(data[i][variable_index] - target_variables_minimum[j])/(target_variables_maximum[j]-target_variables_minimum[j]) - 1.0;
03198 }
03199 }
03200 }
03201 }
03202
03203
03204
03205
03219
03220 Vector< Vector<double> > InputTargetDataSet::scale_target_variables_minimum_maximum(void)
03221 {
03222 Vector< Vector<double> > variables_statistics = calculate_variables_statistics();
03223
03224 scale_target_variables_minimum_maximum(variables_statistics[6], variables_statistics[7]);
03225
03226 return(variables_statistics);
03227 }
03228
03229
03230
03231
03237
03238 void InputTargetDataSet::scale_variables_mean_standard_deviation(const Vector< Vector<double> > variables_statistics)
03239 {
03240
03241
03242 #ifdef _DEBUG
03243
03244 int size = variables_statistics.get_size();
03245
03246 if(size != 8)
03247 {
03248 std::cerr << "Flood Error: InputTargetDataSet class." << std::endl
03249 << "void scale_variables_mean_standard_deviation(const Vector< Vector<double> >&) method." << std::endl
03250 << "Size of input target variables statistics must be 8." << std::endl;
03251
03252 exit(1);
03253 }
03254
03255 int input_variables_number = get_input_variables_number();
03256
03257 for(int i = 0; i < 4; i++)
03258 {
03259 size = variables_statistics[i].get_size();
03260
03261 if(size != input_variables_number)
03262 {
03263 std::cerr << "Flood Error: InputTargetDataSet class." << std::endl
03264 << "void scale_variables_mean_standard_deviation(const Vector< Vector<double> >&) method." << std::endl
03265 << "Size of element " << i << " must be equal to number of input variables." << std::endl;
03266
03267 exit(1);
03268 }
03269 }
03270
03271 int target_variables_number = get_target_variables_number();
03272
03273 for(int i = 4; i < 8; i++)
03274 {
03275 size = variables_statistics[i].get_size();
03276
03277 if(size != target_variables_number)
03278 {
03279 std::cerr << "Flood Error: InputTargetDataSet class." << std::endl
03280 << "void scale_variables_mean_standard_deviation(const Vector< Vector<double> >&) method." << std::endl
03281 << "Size of element " << i << " must be equal to number of target variables." << std::endl;
03282
03283 exit(1);
03284 }
03285 }
03286
03287 #endif
03288
03289 scale_input_variables_mean_standard_deviation(variables_statistics[0], variables_statistics[1]);
03290 scale_target_variables_mean_standard_deviation(variables_statistics[4], variables_statistics[5]);
03291 }
03292
03293
03294
03295
03310
03311 Vector< Vector<double> > InputTargetDataSet::scale_variables_mean_standard_deviation(void)
03312 {
03313 Vector< Vector<double> > variables_statistics = calculate_variables_statistics();
03314
03315 scale_variables_mean_standard_deviation(variables_statistics);
03316
03317 return(variables_statistics);
03318 }
03319
03320
03321
03322
03328
03329 void InputTargetDataSet::scale_variables_minimum_maximum(const Vector< Vector<double> > variables_statistics)
03330 {
03331
03332
03333 #ifdef _DEBUG
03334
03335 int size = variables_statistics.get_size();
03336
03337 if(size != 8)
03338 {
03339 std::cerr << "Flood Error: InputTargetDataSet class." << std::endl
03340 << "void scale_variables_minimum_maximum(const Vector< Vector<double> >&) method." << std::endl
03341 << "Size of input target variables statistics must be 8." << std::endl;
03342
03343 exit(1);
03344 }
03345
03346 int input_variables_number = get_input_variables_number();
03347
03348 for(int i = 0; i < 4; i++)
03349 {
03350 size = variables_statistics[i].get_size();
03351
03352 if(size != input_variables_number)
03353 {
03354 std::cerr << "Flood Error: InputTargetDataSet class." << std::endl
03355 << "void scale_variables_minimum_maximum(const Vector< Vector<double> >&) method." << std::endl
03356 << "Size of element " << i << " must be equal to number of input variables." << std::endl;
03357
03358 exit(1);
03359 }
03360 }
03361
03362 int target_variables_number = get_target_variables_number();
03363
03364 for(int i = 4; i < 8; i++)
03365 {
03366 size = variables_statistics[i].get_size();
03367
03368 if(size != target_variables_number)
03369 {
03370 std::cerr << "Flood Error: InputTargetDataSet class." << std::endl
03371 << "void scale_variables_minimum_maximum(const Vector< Vector<double> >&) method." << std::endl
03372 << "Size of element " << i << " must be equal to number of target variables." << std::endl;
03373
03374 exit(1);
03375 }
03376 }
03377
03378 #endif
03379
03380 scale_input_variables_minimum_maximum(variables_statistics[2], variables_statistics[3]);
03381 scale_target_variables_minimum_maximum(variables_statistics[6], variables_statistics[7]);
03382 }
03383
03384
03385
03386
03401
03402 Vector< Vector<double> > InputTargetDataSet::scale_variables_minimum_maximum(void)
03403 {
03404 Vector< Vector<double> > variables_statistics = calculate_variables_statistics();
03405
03406 scale_variables_minimum_maximum(variables_statistics);
03407
03408 return(variables_statistics);
03409 }
03410
03411
03412
03413
03418
03419
03421
03422 void InputTargetDataSet::unscale_data_mean_standard_deviation(const Vector<double>& mean, const Vector<double>& standard_deviation)
03423 {
03424 data.unscale_mean_standard_deviation(mean, standard_deviation);
03425 }
03426
03427
03428
03429
03435
03436 void InputTargetDataSet::unscale_data_minimum_maximum(const Vector<double>& minimum, const Vector<double>& maximum)
03437 {
03438 data.unscale_minimum_maximum(minimum, maximum);
03439 }
03440
03441
03442
03443
03449
03450 void InputTargetDataSet::unscale_input_variables_mean_standard_deviation(const Vector<double>& input_variables_mean,
03451 const Vector<double>& input_variables_standard_deviation)
03452 {
03453 int instances_number = get_instances_number();
03454 int input_variables_number = get_input_variables_number();
03455
03456
03457
03458 for(int j = 0; j < input_variables_number; j++)
03459 {
03460 if(input_variables_standard_deviation[j] < 1e-99)
03461 {
03462 if(display)
03463 {
03464 std::cout << "Flood Warning: InputTargetDataSet class." << std::endl
03465 << "void unscale_input_variables_mean_standard_deviation(const Vector<double>&, const Vector<double>&) method." << std::endl
03466 << "Standard deviation of input variable " << j << " is zero." << std::endl
03467 << "Those inputs won't be scaled." << std::endl;
03468 }
03469
03470
03471 }
03472 else
03473 {
03474 for(int i = 0; i < instances_number; i++)
03475 {
03476 data[i][j] = data[i][j]*input_variables_standard_deviation[j] + input_variables_mean[j];
03477 }
03478 }
03479 }
03480 }
03481
03482
03483
03484
03490
03491 void InputTargetDataSet::unscale_input_variables_minimum_maximum(const Vector<double>& input_variables_minimum, const Vector<double>& input_variables_maximum)
03492 {
03493 int instances_number = get_instances_number();
03494 int input_variables_number = get_input_variables_number();
03495
03496
03497
03498 for(int j = 0; j < input_variables_number; j++)
03499 {
03500 if(input_variables_maximum[j] - input_variables_minimum[j] < 1e-99)
03501 {
03502 if(display)
03503 {
03504 std::cout << "Flood Warning: InputTargetDataSet class." << std::endl
03505 << "void unscale_input_variables_minimum_maximum(const Vector<double>&, const Vector<double>&) method." << std::endl
03506 << "Minimum and maximum values of input variable " << j << " are equal." << std::endl
03507 << "Those inputs won't be unscaled." << std::endl;
03508 }
03509
03510
03511 }
03512 else
03513 {
03514 for(int i = 0; i < instances_number; i++)
03515 {
03516 data[i][j] = 0.5*(data[i][j] + 1.0)*(input_variables_maximum[j]-input_variables_minimum[j])
03517 + input_variables_minimum[j];
03518 }
03519 }
03520 }
03521 }
03522
03523
03524
03525
03531
03532 void InputTargetDataSet::unscale_target_variables_mean_standard_deviation(const Vector<double>& target_variables_mean,
03533 const Vector<double>& target_variables_standard_deviation)
03534 {
03535 int instances_number = get_instances_number();
03536 int target_variables_number = get_target_variables_number();
03537
03538
03539
03540 for(int j = 0; j < target_variables_number; j++)
03541 {
03542 if(target_variables_standard_deviation[j] < 1e-99)
03543 {
03544 if(display)
03545 {
03546 std::cout << "Flood Warning: InputTargetDataSet class." << std::endl
03547 << "void unscale_target_variables_mean_standard_deviation(const Vector<double>&) method." << std::endl
03548 << "Standard deviation of target variable " << j << " is zero." << std::endl
03549 << "Those targets won't be scaled." << std::endl;
03550 }
03551
03552
03553 }
03554 else
03555 {
03556 for(int i = 0; i < instances_number; i++)
03557 {
03558 data[i][j] = data[i][j]*target_variables_standard_deviation[j] + target_variables_mean[j];
03559 }
03560 }
03561 }
03562 }
03563
03564
03565
03566
03572
03573 void InputTargetDataSet::unscale_target_variables_minimum_maximum(const Vector<double>& target_variables_minimum,
03574 const Vector<double>& target_variables_maximum)
03575 {
03576 int instances_number = get_instances_number();
03577 int target_variables_number = get_target_variables_number();
03578
03579
03580
03581 for(int j = 0; j < target_variables_number; j++)
03582 {
03583 if(target_variables_maximum[j] - target_variables_minimum[j] < 1e-99)
03584 {
03585 if(display)
03586 {
03587 std::cout << "Flood Warning: InputTargetDataSet class." << std::endl
03588 << "void unscale_target_variables_minimum_maximum(const Vector<double>&, const Vector<double>&) method." << std::endl
03589 << "Minimum and maximum values of target variable " << j << " are equal." << std::endl
03590 << "Those targets won't be unscaled." << std::endl;
03591 }
03592
03593
03594 }
03595 else
03596 {
03597 for(int i = 0; i < instances_number; i++)
03598 {
03599 data[i][j] = 0.5*(data[i][j] + 1.0)*(target_variables_maximum[j]-target_variables_minimum[j])
03600 + target_variables_minimum[j];
03601 }
03602 }
03603 }
03604 }
03605
03606
03607
03608
03614
03615 void InputTargetDataSet::unscale_variables_mean_standard_deviation(const Vector< Vector<double> >& variables_statistics)
03616 {
03617
03618
03619 #ifdef _DEBUG
03620
03621 int size = variables_statistics.get_size();
03622
03623 if(size != 8)
03624 {
03625 std::cerr << "Flood Warning: InputTargetDataSet class." << std::endl
03626 << "void unscale_variables_mean_standard_deviation(const Vector< Vector<double> >&) method." << std::endl
03627 << "Size of statistics must be 8." << std::endl;
03628 }
03629
03630 for(int i = 0; i < 8; i++)
03631 {
03632 size = variables_statistics[i].get_size();
03633
03634 if(size != 8)
03635 {
03636 std::cerr << "Flood Warning: InputTargetDataSet class." << std::endl
03637 << "void unscale_variables_mean_standard_deviation(const Vector< Vector<double> >&) method." << std::endl
03638 << "Size of statistics element " << i << " must be equal to number of variables." << std::endl;
03639 }
03640 }
03641
03642 #endif
03643
03644 unscale_input_variables_mean_standard_deviation(variables_statistics[0], variables_statistics[1]);
03645 unscale_target_variables_mean_standard_deviation(variables_statistics[4], variables_statistics[5]);
03646 }
03647
03648
03649
03650
03651
03657
03658 void InputTargetDataSet::unscale_variables_minimum_maximum(const Vector< Vector<double> >& variables_statistics)
03659 {
03660
03661
03662 #ifdef _DEBUG
03663
03664 int size = variables_statistics.get_size();
03665
03666 if(size != 8)
03667 {
03668 std::cerr << "Flood Warning: InputTargetDataSet class." << std::endl
03669 << "void unscale_variables_minimum_maximum(const Vector< Vector<double> >&) method." << std::endl
03670 << "Size of statistics must be 8." << std::endl;
03671 }
03672
03673 #endif
03674
03675 unscale_input_variables_minimum_maximum(variables_statistics[2], variables_statistics[3]);
03676 unscale_target_variables_minimum_maximum(variables_statistics[6], variables_statistics[7]);
03677 }
03678
03679
03680
03681
03684
03685 void InputTargetDataSet::initialize_data(double new_value)
03686 {
03687 data.initialize(new_value);
03688 }
03689
03690
03691
03692
03714
03715 std::string InputTargetDataSet::to_XML(bool show_declaration)
03716 {
03717 std::stringstream buffer;
03718
03719
03720
03721 if(show_declaration)
03722 {
03723 buffer << "<Flood version='3.0' class='InputTargetDataSet'>" << std::endl;
03724 }
03725
03726
03727
03728 int instances_number = get_instances_number();
03729 int variables_number = get_variables_number();
03730
03731 buffer << "<InstancesNumber>" << std::endl
03732 << instances_number << std::endl
03733 << "</InstancesNumber>" << std::endl;
03734
03735 buffer << "<VariablesNumber>" << std::endl
03736 << variables_number << std::endl
03737 << "</VariablesNumber>" << std::endl;
03738
03739
03740
03741 int training_instances_number = get_training_instances_number();
03742
03743 buffer << "<TrainingInstancesNumber>" << std::endl
03744 << training_instances_number << std::endl
03745 << "</TrainingInstancesNumber>" << std::endl;
03746
03747 buffer << "<TrainingInstancesIndices>" << std::endl
03748 << training_instances_indices << std::endl
03749 << "</TrainingInstancesIndices>" << std::endl;
03750
03751
03752
03753 int validation_instances_number = get_validation_instances_number();
03754
03755 buffer << "<ValidationInstancesNumber>" << std::endl
03756 << validation_instances_number << std::endl
03757 << "</ValidationInstancesNumber>" << std::endl;
03758
03759 buffer << "<ValidationInstancesIndices>" << std::endl
03760 << validation_instances_indices << std::endl
03761 << "</ValidationInstancesIndices>" << std::endl;
03762
03763
03764
03765 int testing_instances_number = get_testing_instances_number();
03766
03767 buffer << "<TestingInstancesNumber>" << std::endl
03768 << testing_instances_number << std::endl
03769 << "</TestingInstancesNumber>" << std::endl;
03770
03771 buffer << "<TestingInstancesIndices>" << std::endl
03772 << testing_instances_indices << std::endl
03773 << "</TestingInstancesIndices>" << std::endl;
03774
03775
03776
03777 int input_variables_number = get_input_variables_number();
03778
03779 buffer << "<InputVariablesNumber>" << std::endl
03780 << input_variables_number << std::endl
03781 << "</InputVariablesNumber>" << std::endl;
03782
03783 buffer << "<InputVariablesIndices>" << std::endl
03784 << input_variables_indices << std::endl
03785 << "</InputVariablesIndices>" << std::endl;
03786
03787
03788
03789 int target_variables_number = get_target_variables_number();
03790
03791 buffer << "<TargetVariablesNumber>" << std::endl
03792 << target_variables_number << std::endl
03793 << "</TargetVariablesNumber>" << std::endl;
03794
03795 buffer << "<TargetVariablesIndices>" << std::endl
03796 << target_variables_indices << std::endl
03797 << "</TargetVariablesIndices>" << std::endl;
03798
03799
03800
03801 if(variables_name.get_size() != 0)
03802 {
03803 buffer << "<VariablesName>" << std::endl;
03804
03805 for(int i = 0; i < variables_number; i++)
03806 {
03807 buffer << "<Name>" << std::endl
03808 << variables_name[i] << std::endl
03809 << "</Name>" << std::endl;
03810 }
03811
03812 buffer << "</VariablesName>" << std::endl;
03813 }
03814
03815
03816
03817 if(variables_units.get_size() != 0)
03818 {
03819 buffer << "<VariablesUnits>" << std::endl;
03820
03821 for(int i = 0; i < variables_number; i++)
03822 {
03823 buffer << "<Units>" << std::endl
03824 << variables_units[i] << std::endl
03825 << "</Units>" << std::endl;
03826 }
03827
03828 buffer << "</VariablesUnits>" << std::endl;
03829 }
03830
03831
03832
03833 if(variables_description.get_size() != 0)
03834 {
03835 buffer << "<VariablesDescription>" << std::endl;
03836
03837 for(int i = 0; i < variables_number; i++)
03838 {
03839 buffer << "<Description>" << std::endl
03840 << variables_description[i] << std::endl
03841 << "</Description>" << std::endl;
03842 }
03843
03844 buffer << "</VariablesDescription>" << std::endl;
03845 }
03846
03847
03848
03849 buffer << "<Display>" << std::endl
03850 << display << std::endl
03851 << "</Display>" << std::endl;
03852
03853
03854
03855 buffer << "<Data>" << std::endl
03856 << data
03857 << "</Data>" << std::endl;
03858
03859 return(buffer.str());
03860 }
03861
03862
03863
03864
03866
03867 void InputTargetDataSet::print(void)
03868 {
03869 if(display)
03870 {
03871 std::cout << to_XML(true) << std::endl;
03872 }
03873 }
03874
03875
03876
03877
03880
03881 void InputTargetDataSet::save(const char* filename)
03882 {
03883 std::fstream file;
03884
03885 file.open(filename, std::ios::out);
03886
03887 if(!file.is_open())
03888 {
03889 std::cerr << "Flood Error: InputTargetDataSet class." << std::endl
03890 << "void save(const char*) method." << std::endl
03891 << "Cannot open input-target data set file." << std::endl;
03892
03893 exit(1);
03894 }
03895
03896
03897
03898 file << to_XML(true);
03899
03900
03901
03902 file.close();
03903 }
03904
03905
03906
03907
03930
03931 void InputTargetDataSet::load(const char* filename)
03932 {
03933 std::fstream file;
03934
03935 file.open(filename, std::ios::in);
03936
03937 if(!file.is_open())
03938 {
03939 std::cerr << "Flood Error: InputTargetDataSet class." << std::endl
03940 << "void load(const char*) method." << std::endl
03941 << "Cannot open input-target data set file." << std::endl;
03942
03943 exit(1);
03944 }
03945
03946 set();
03947
03948 std::string line;
03949 std::string word;
03950
03951
03952
03953 getline(file, line);
03954
03955 if(line != "<Flood version='3.0' class='InputTargetDataSet'>")
03956 {
03957
03958
03959
03960
03961
03962 }
03963
03964
03965
03966 file >> word;
03967
03968 if(word != "<InstancesNumber>")
03969 {
03970 std::cerr << "Flood Error: InputTargetDataSet class." << std::endl
03971 << "void load(const char*) method." << std::endl
03972 << "Unknown instances number begin tag: " << line << std::endl;
03973
03974 exit(1);
03975 }
03976
03977 int new_instances_number;
03978
03979 file >> new_instances_number;
03980
03981 file >> word;
03982
03983 if(word != "</InstancesNumber>")
03984 {
03985 std::cerr << "Flood Error: Vector template." << std::endl
03986 << "void load(const char*) method." << std::endl
03987 << "Unknown instances number end tag: " << word << std::endl;
03988
03989 exit(1);
03990 }
03991
03992
03993
03994 file >> word;
03995
03996 if(word != "<VariablesNumber>")
03997 {
03998 std::cerr << "Flood Error: InputTargetDataSet class." << std::endl
03999 << "void load(const char*) method." << std::endl
04000 << "Unknown variables number begin tag: " << word << std::endl;
04001
04002 exit(1);
04003 }
04004
04005 int new_variables_number;
04006
04007 file >> new_variables_number;
04008
04009 file >> word;
04010
04011 if(word != "</VariablesNumber>")
04012 {
04013 std::cerr << "Flood Error: Vector template." << std::endl
04014 << "void load(const char*) method." << std::endl
04015 << "Unknown variables number end tag: " << word << std::endl;
04016
04017 exit(1);
04018 }
04019
04020 data.set(new_instances_number, new_variables_number);
04021
04022 while(!file.eof())
04023 {
04024 file >> word;
04025
04026 if(word == "<TrainingInstancesNumber>")
04027 {
04028 int new_training_instances_number;
04029
04030 file >> new_training_instances_number;
04031
04032 file >> word;
04033
04034 if(word != "</TrainingInstancesNumber>")
04035 {
04036 std::cerr << "Flood Error: Vector template." << std::endl
04037 << "void load(const char*) method." << std::endl
04038 << "Unknown training instances number end tag: " << word << std::endl;
04039
04040 exit(1);
04041 }
04042
04043
04044
04045 file >> word;
04046
04047 if(word != "<TrainingInstancesIndices>")
04048 {
04049 std::cerr << "Flood Error: InputTargetDataSet class." << std::endl
04050 << "void load(const char*) method." << std::endl
04051 << "Unknown training instances indices begin tag: " << word << std::endl;
04052
04053 exit(1);
04054 }
04055
04056 Vector<int> new_training_instances_indices(new_training_instances_number);
04057 file >> new_training_instances_indices;
04058
04059 file >> word;
04060
04061 if(word != "</TrainingInstancesIndices>")
04062 {
04063 std::cerr << "Flood Error: Vector template." << std::endl
04064 << "void load(const char*) method." << std::endl
04065 << "Unknown training instances number end tag: " << word << std::endl;
04066
04067 exit(1);
04068 }
04069
04070 set_training_instances_indices(new_training_instances_indices);
04071 }
04072
04073 else if(word == "<ValidationInstancesNumber>")
04074 {
04075 int new_validation_instances_number;
04076
04077 file >> new_validation_instances_number;
04078
04079 file >> word;
04080
04081 if(word != "</ValidationInstancesNumber>")
04082 {
04083 std::cerr << "Flood Error: Vector template." << std::endl
04084 << "void load(const char*) method." << std::endl
04085 << "Unknown validation instances number end tag: " << word << std::endl;
04086
04087 exit(1);
04088 }
04089
04090
04091
04092 file >> word;
04093
04094 if(word != "<ValidationInstancesIndices>")
04095 {
04096 std::cerr << "Flood Error: InputTargetDataSet class." << std::endl
04097 << "void load(const char*) method." << std::endl
04098 << "Unknown validation instances indices begin tag: " << word << std::endl;
04099
04100 exit(1);
04101 }
04102
04103 Vector<int> new_validation_instances_indices(new_validation_instances_number);
04104
04105 file >> new_validation_instances_indices;
04106
04107 file >> word;
04108
04109 if(word != "</ValidationInstancesIndices>")
04110 {
04111 std::cerr << "Flood Error: Vector template." << std::endl
04112 << "void load(const char*) method." << std::endl
04113 << "Unknown validation instances indices end tag: " << word << std::endl;
04114
04115 exit(1);
04116 }
04117
04118 set_validation_instances_indices(new_validation_instances_indices);
04119 }
04120 else if(word == "<TestingInstancesNumber>")
04121 {
04122 int new_testing_instances_number;
04123
04124 file >> new_testing_instances_number;
04125
04126 file >> word;
04127
04128 if(word != "</TestingInstancesNumber>")
04129 {
04130 std::cerr << "Flood Error: Vector template." << std::endl
04131 << "void load(const char*) method." << std::endl
04132 << "Unknown testing instances number end tag: " << word << std::endl;
04133
04134 exit(1);
04135 }
04136
04137
04138
04139 file >> word;
04140
04141 if(word != "<TestingInstancesIndices>")
04142 {
04143 std::cerr << "Flood Error: InputTargetDataSet class." << std::endl
04144 << "void load(const char*) method." << std::endl
04145 << "Unknown validation instances indices begin tag: " << word << std::endl;
04146
04147 exit(1);
04148 }
04149
04150 Vector<int> new_testing_instances_indices(new_testing_instances_number);
04151
04152 file >> new_testing_instances_indices;
04153
04154 file >> word;
04155
04156 if(word != "</TestingInstancesIndices>")
04157 {
04158 std::cerr << "Flood Error: Vector template." << std::endl
04159 << "void load(const char*) method." << std::endl
04160 << "Unknown testing instances indices end tag: " << word << std::endl;
04161
04162 exit(1);
04163 }
04164
04165 set_testing_instances_indices(new_testing_instances_indices);
04166 }
04167
04168 else if(word == "<InputVariablesNumber>")
04169 {
04170 int new_input_variables_number;
04171
04172 file >> new_input_variables_number;
04173
04174 file >> word;
04175
04176 if(word != "</InputVariablesNumber>")
04177 {
04178 std::cerr << "Flood Error: Vector template." << std::endl
04179 << "void load(const char*) method." << std::endl
04180 << "Unknown input variables number end tag: " << word << std::endl;
04181
04182 exit(1);
04183 }
04184
04185
04186
04187 file >> word;
04188
04189 if(word != "<InputVariablesIndices>")
04190 {
04191 std::cerr << "Flood Error: InputTargetDataSet class." << std::endl
04192 << "void load(const char*) method." << std::endl
04193 << "Unknown input variables indices begin tag: " << word << std::endl;
04194
04195 exit(1);
04196 }
04197
04198 Vector<int> new_input_variables_indices(new_input_variables_number);
04199 file >> new_input_variables_indices;
04200
04201 file >> word;
04202
04203 if(word != "</InputVariablesIndices>")
04204 {
04205 std::cerr << "Flood Error: Vector template." << std::endl
04206 << "void load(const char*) method." << std::endl
04207 << "Unknown input variables indices end tag: " << word << std::endl;
04208
04209 exit(1);
04210 }
04211
04212 set_input_variables_indices(new_input_variables_indices);
04213 }
04214
04215 else if(word == "<TargetVariablesNumber>")
04216 {
04217 int new_target_variables_number;
04218
04219 file >> new_target_variables_number;
04220
04221 file >> word;
04222
04223 if(word != "</TargetVariablesNumber>")
04224 {
04225 std::cerr << "Flood Error: Vector template." << std::endl
04226 << "void load(const char*) method." << std::endl
04227 << "Unknown target variables number end tag: " << word << std::endl;
04228
04229 exit(1);
04230 }
04231
04232
04233
04234 file >> word;
04235
04236 if(word != "<TargetVariablesIndices>")
04237 {
04238 std::cerr << "Flood Error: InputTargetDataSet class." << std::endl
04239 << "void load(const char*) method." << std::endl
04240 << "Unknown target variables indices begin tag: " << word << std::endl;
04241
04242 exit(1);
04243 }
04244
04245 Vector<int> new_target_variables_indices(new_target_variables_number);
04246
04247 file >> new_target_variables_indices;
04248
04249 file >> word;
04250
04251 if(word != "</TargetVariablesIndices>")
04252 {
04253 std::cerr << "Flood Error: InputTargetDataSet class." << std::endl
04254 << "void load(const char*) method." << std::endl
04255 << "Unknown target variables indices end tag: " << word << std::endl;
04256
04257 exit(1);
04258 }
04259
04260 set_target_variables_indices(new_target_variables_indices);
04261 }
04262
04263 else if(word == "<VariablesName>")
04264 {
04265 int variables_number = get_variables_number();
04266
04267 for(int i = 0; i < variables_number; i++)
04268 {
04269 file >> word;
04270
04271 if(word != "<Name>")
04272 {
04273 std::cerr << "Flood Error: InputTargetDataSet class." << std::endl
04274 << "void load(const char*) method." << std::endl
04275 << "Unknown name begin tag: " << word << std::endl;
04276
04277 exit(1);
04278 }
04279
04280 getline(file, line);
04281 getline(file, line);
04282
04283 file >> word;
04284
04285 if(word != "</Name>")
04286 {
04287 std::cerr << "Flood Error: InputTargetDataSet class." << std::endl
04288 << "void load(const char*) method." << std::endl
04289 << "Unknown name end tag: " << word << std::endl;
04290
04291 exit(1);
04292 }
04293
04294 set_variable_name(i, line);
04295 }
04296
04297 file >> word;
04298
04299 if(word != "</VariablesName>")
04300 {
04301 std::cerr << "Flood Error: InputTargetDataSet class." << std::endl
04302 << "void load(const char*) method." << std::endl
04303 << "Unknown input variables name end tag: " << word << std::endl;
04304
04305 exit(1);
04306 }
04307 }
04308
04309 else if(word == "<VariablesUnits>")
04310 {
04311 int variables_number = get_variables_number();
04312
04313 for(int i = 0; i < variables_number; i++)
04314 {
04315 file >> word;
04316
04317 if(word != "<Units>")
04318 {
04319 std::cerr << "Flood Error: InputTargetDataSet class." << std::endl
04320 << "void load(const char*) method." << std::endl
04321 << "Unknown units begin tag: " << word << std::endl;
04322
04323 exit(1);
04324 }
04325
04326 getline(file, line);
04327 getline(file, line);
04328
04329 file >> word;
04330
04331 if(word != "</Units>")
04332 {
04333 std::cerr << "Flood Error: InputTargetDataSet class." << std::endl
04334 << "void load(const char*) method." << std::endl
04335 << "Unknown units end tag: " << word << std::endl;
04336
04337 exit(1);
04338 }
04339
04340 set_variable_units(i, line);
04341 }
04342
04343 file >> word;
04344
04345 if(word != "</VariablesUnits>")
04346 {
04347 std::cerr << "Flood Error: InputTargetDataSet class." << std::endl
04348 << "void load(const char*) method." << std::endl
04349 << "Unknown variables units end tag: " << word << std::endl;
04350
04351 exit(1);
04352 }
04353 }
04354
04355 else if(word == "<VariablesDescription>")
04356 {
04357 int variables_number = get_variables_number();
04358
04359 for(int i = 0; i < variables_number; i++)
04360 {
04361 file >> word;
04362
04363 if(word != "<Description>")
04364 {
04365 std::cerr << "Flood Error: InputTargetDataSet class." << std::endl
04366 << "void load(const char*) method." << std::endl
04367 << "Unknown description begin tag: " << word << std::endl;
04368
04369 exit(1);
04370 }
04371
04372 getline(file, line);
04373 getline(file, line);
04374
04375 file >> word;
04376
04377 if(word != "</Description>")
04378 {
04379 std::cerr << "Flood Error: InputTargetDataSet class." << std::endl
04380 << "void load(const char*) method." << std::endl
04381 << "Unknown description end tag: " << word << std::endl;
04382
04383 exit(1);
04384 }
04385
04386 set_variable_description(i, line);
04387 }
04388
04389 file >> word;
04390
04391 if(word != "</VariablesDescription>")
04392 {
04393 std::cerr << "Flood Error: InputTargetDataSet class." << std::endl
04394 << "void load(const char*) method." << std::endl
04395 << "Unknown variables description end tag: " << word << std::endl;
04396
04397 exit(1);
04398 }
04399 }
04400
04401 else if(word == "<Display>")
04402 {
04403 file >> display;
04404
04405 file >> word;
04406
04407 if(word != "</Display>")
04408 {
04409 std::cerr << "Flood Error: Vector template." << std::endl
04410 << "void load(const char*) method." << std::endl
04411 << "Unknown display end tag: " << word << std::endl;
04412
04413 exit(1);
04414 }
04415 }
04416
04417 else if(word == "<Data>")
04418 {
04419 file >> data;
04420
04421 file >> word;
04422
04423 if(word != "</Data>")
04424 {
04425 std::cerr << "Flood Error: Vector template." << std::endl
04426 << "void load(const char*) method." << std::endl
04427 << "Unknown data end tag: " << word << std::endl;
04428
04429 exit(1);
04430 }
04431 }
04432 }
04433
04434 int instances_number = get_instances_number();
04435 int training_instances_number = get_training_instances_number();
04436 int validation_instances_number = get_validation_instances_number();
04437 int testing_instances_number = get_testing_instances_number();
04438
04439 if(instances_number != 0 && training_instances_number == 0 && validation_instances_number == 0 && testing_instances_number == 0)
04440 {
04441 set_training();
04442 }
04443
04444 int variables_number = get_variables_number();
04445 int input_variables_number = get_input_variables_number();
04446 int target_variables_number = get_target_variables_number();
04447
04448 if(variables_number != 0 && input_variables_number == 0 && target_variables_number == 0)
04449 {
04450 set_input();
04451 }
04452
04453 file.close();
04454 }
04455
04456
04457
04458
04460
04461 void InputTargetDataSet::print_data(void)
04462 {
04463 std::cout << data;
04464 }
04465
04466
04467
04468
04471
04472 void InputTargetDataSet::save_data(const char* filename)
04473 {
04474 std::fstream file;
04475
04476 file.open(filename, std::ios::out);
04477
04478 if(!file.is_open())
04479 {
04480 std::cerr << "Flood Error: InputTargetDataSet class." << std::endl
04481 << "void save_data(const char*) method." << std::endl
04482 << "Cannot open data file." << std::endl;
04483
04484 exit(1);
04485 }
04486
04487
04488
04489 Matrix<double> data = get_data();
04490
04491 file << data;
04492
04493
04494
04495 file.close();
04496 }
04497
04498
04499
04500
04504
04505 void InputTargetDataSet::load_data(const char* filename)
04506 {
04507 std::fstream file;
04508
04509 file.open(filename, std::ios::in);
04510
04511 if(!file.is_open())
04512 {
04513 std::cerr << "Flood Error: InputTargetDataSet class." << std::endl
04514 << "void load_data(const char*) method." << std::endl
04515 << "Cannot open data file." << std::endl;
04516
04517 exit(1);
04518 }
04519
04520 std::string word;
04521
04522 int instances_number = get_instances_number();
04523 int variables_number = get_variables_number();
04524
04525 for(int i = 0; i < instances_number; i++)
04526 {
04527 for(int j = 0; j < variables_number; j++)
04528 {
04529 file >> data[i][j];
04530 }
04531 }
04532
04533 file.close();
04534 }
04535
04536
04537
04538
04543
04544 void InputTargetDataSet::split_given_indices
04545 (const Vector<int>& new_training_instances_indices, const Vector<int>& new_validation_instances_indices, const Vector<int>& new_testing_instances_indices)
04546 {
04547 int new_training_instances_number = new_training_instances_indices.get_size();
04548 int new_validation_instances_number = new_validation_instances_indices.get_size();
04549 int new_testing_instances_number = new_testing_instances_indices.get_size();
04550
04551 int instances_number = get_instances_number();
04552
04553 int new_instances_number = new_training_instances_number+new_validation_instances_number+new_testing_instances_number;
04554
04555 if(display && new_instances_number != instances_number)
04556 {
04557 std::cout << "Flood Warning: InputTargetDataSet class." << std::endl
04558 << "void split_given_indices(const Vector<double>&, const Vector<double>&, const Vector<double>&) method." << std::endl
04559 << "New number of instances is not equal to number of instances." << std::endl;
04560 }
04561
04562 training_instances_indices = new_training_instances_indices;
04563 validation_instances_indices = new_validation_instances_indices;
04564 testing_instances_indices = new_testing_instances_indices;
04565 }
04566
04567
04568
04569
04575
04576 void InputTargetDataSet::split_random_indices
04577 (double training_instances_ratio, double validation_instances_ratio, double testing_instances_ratio)
04578 {
04579 double total_ratio = training_instances_ratio + validation_instances_ratio + testing_instances_ratio;
04580
04581
04582
04583 int instances_number = get_instances_number();
04584
04585 int validation_instances_number = (int)(validation_instances_ratio*instances_number/total_ratio);
04586 int testing_instances_number = (int)(testing_instances_ratio*instances_number/total_ratio);
04587 int training_instances_number = instances_number - validation_instances_number - testing_instances_number;
04588
04589 int sum_instances_number = training_instances_number + validation_instances_number + testing_instances_number;
04590
04591 if(sum_instances_number != instances_number)
04592 {
04593 std::cerr << "Flood Warning: InputTargetDataSet class." << std::endl
04594 << "void split_random_indices(double, double, double) method." << std::endl
04595 << "Sum of numbers of training, validation and testing instances is not equal to number of instances." << std::endl;
04596
04597 }
04598
04599
04600
04601 validation_instances_indices.set(validation_instances_number);
04602 testing_instances_indices.set(testing_instances_number);
04603 training_instances_indices.set(training_instances_number);
04604
04605 Vector<int> indices(instances_number);
04606 indices.initialize_sequential();
04607 std::random_shuffle(indices.begin(), indices.end());
04608
04609
04610
04611 for(int i = 0; i < training_instances_number; i++)
04612 {
04613 training_instances_indices[i] = indices[i];
04614 }
04615
04616 std::sort(training_instances_indices.begin(), training_instances_indices.end());
04617
04618
04619
04620 for(int i = 0; i < validation_instances_number; i++)
04621 {
04622 validation_instances_indices[i] = indices[training_instances_number+i];
04623 }
04624
04625 std::sort(validation_instances_indices.begin(), validation_instances_indices.end());
04626
04627
04628
04629 for(int i = 0; i < testing_instances_number; i++)
04630 {
04631 testing_instances_indices[i] = indices[training_instances_number+validation_instances_number+i];
04632 }
04633
04634 std::sort(testing_instances_indices.begin(), testing_instances_indices.end());
04635 }
04636
04637
04638
04639
04647
04648 void InputTargetDataSet::split_random_indices(void)
04649 {
04650 split_random_indices(0.8, 0.2, 0.2);
04651 }
04652
04653
04654
04655
04658
04659 std::string InputTargetDataSet::get_instances_information_XML(bool show_declaration)
04660 {
04661 std::stringstream buffer;
04662
04663 int instances_number = get_instances_number();
04664
04665 int training_instances_number = get_training_instances_number();
04666 int validation_instances_number = get_validation_instances_number();
04667 int testing_instances_number = get_validation_instances_number();
04668
04669 if(show_declaration)
04670 {
04671 buffer << "<Flood version='3.0' class='InputTargetDataSet' content=<InstancesInformation>" << std::endl;
04672 }
04673
04674 buffer << "<InstancesInformation>" << std::endl;
04675
04676
04677
04678 buffer << "<InstancesNumber>" << std::endl
04679 << instances_number << std::endl
04680 << "</InstancesNumber>" << std::endl;
04681
04682
04683
04684 buffer << "<TrainingInstancesNumber>" << std::endl
04685 << training_instances_number << std::endl
04686 << "</TrainingInstancesNumber>" << std::endl;
04687
04688
04689
04690 if(training_instances_number != 0)
04691 {
04692 buffer << "<TrainingInstancesIndices>" << std::endl
04693 << training_instances_indices << std::endl
04694 << "</TrainingInstancesIndices>" << std::endl;
04695 }
04696
04697
04698
04699 buffer << "<ValidationInstancesNumber>" << std::endl
04700 << validation_instances_number << std::endl
04701 << "</ValidationInstancesNumber>" << std::endl;
04702
04703
04704
04705 if(validation_instances_number != 0)
04706 {
04707 buffer << "<ValidationInstancesIndices>" << std::endl
04708 << validation_instances_indices << std::endl
04709 << "</ValidationInstancesIndices>" << std::endl;
04710 }
04711
04712
04713
04714 buffer << "<TestingInstancesNumber>" << std::endl
04715 << testing_instances_number << std::endl
04716 << "</TestingInstancesNumber>" << std::endl;
04717
04718
04719
04720 if(testing_instances_number != 0)
04721 {
04722 buffer << "<TestingInstancesIndices>" << std::endl
04723 << testing_instances_indices << std::endl
04724 << "</TestingInstancesIndices>" << std::endl;
04725 }
04726
04727 buffer << "</InstancesInformation>" << std::endl;
04728
04729 return(buffer.str());
04730 }
04731
04732
04733
04734
04736
04737 void InputTargetDataSet::print_instances_information(void)
04738 {
04739 std::cout << get_instances_information_XML(true);
04740 }
04741
04742
04743
04744
04747
04748 void InputTargetDataSet::save_instances_information(const char* filename)
04749 {
04750 std::fstream file;
04751
04752 file.open(filename, std::ios::out);
04753
04754 if(!file.is_open())
04755 {
04756 std::cerr << "Flood Error: InputTargetDataSet class." << std::endl
04757 << "void save_variables_information(const char*) method." << std::endl
04758 << "Cannot open variables information XML-type file." << std::endl;
04759
04760 exit(1);
04761 }
04762
04763
04764
04765 file << get_instances_information_XML(true);
04766
04767
04768
04769 file.close();
04770 }
04771
04772
04773
04774
04775
04778
04779 std::string InputTargetDataSet::get_variables_information_XML(bool show_declaration)
04780 {
04781 std::stringstream buffer;
04782
04783 int variables_number = get_variables_number();
04784 int input_variables_number = get_input_variables_number();
04785 int target_variables_number = get_target_variables_number();
04786
04787 if(show_declaration)
04788 {
04789 buffer << "<Flood version='3.0' class='InputTargetDataSet' content='VariablesInformation'>" << std::endl;
04790 }
04791
04792
04793
04794 buffer << "<VariablesNumber>" << std::endl
04795 << variables_number << std::endl
04796 << "</VariablesNumber>" << std::endl;
04797
04798
04799
04800 buffer << "<InputVariablesNumber>" << std::endl
04801 << input_variables_number << std::endl
04802 << "</InputVariablesNumber>" << std::endl;
04803
04804
04805
04806 if(input_variables_number > 0)
04807 {
04808 buffer << "<InputVariablesIndices>" << std::endl
04809 << input_variables_indices << std::endl
04810 << "</InputVariablesIndices>" << std::endl;
04811 }
04812
04813
04814
04815 buffer << "<TargetVariablesNumber>" << std::endl
04816 << target_variables_number << std::endl
04817 << "</TargetVariablesNumber>" << std::endl;
04818
04819
04820
04821 if(target_variables_number > 0)
04822 {
04823 buffer << "<TargetVariablesIndices>" << std::endl
04824 << target_variables_indices << std::endl
04825 << "</TargetVariablesIndices>" << std::endl;
04826 }
04827
04828 if(variables_name.get_size() != variables_number)
04829 {
04830 buffer << "<VariablesName>" << std::endl;
04831
04832 for(int i = 0; i < variables_number; i++)
04833 {
04834 buffer << "<Name>" << std::endl
04835 << variables_name[i] << std::endl
04836 << "</Name>" << std::endl;
04837 }
04838
04839 buffer << "</VariablesName>" << std::endl;
04840 }
04841
04842
04843 if(variables_units.get_size() != variables_number)
04844 {
04845 buffer << "<VariablesUnits>" << std::endl;
04846
04847 for(int i = 0; i < variables_number; i++)
04848 {
04849 buffer << "<Units>" << std::endl
04850 << variables_units[i] << std::endl
04851 << "</Units>" << std::endl;
04852 }
04853
04854 buffer << "</VariablesUnits>" << std::endl;
04855 }
04856
04857
04858 if(variables_description.get_size() != variables_number)
04859 {
04860 buffer << "<Description>" << std::endl;
04861
04862 for(int i = 0; i < variables_number; i++)
04863 {
04864 buffer << "<Description>" << std::endl
04865 << variables_description[i] << std::endl
04866 << "</Description>" << std::endl;
04867 }
04868
04869 buffer << "</VariablesDescription>" << std::endl;
04870 }
04871
04872 return(buffer.str());
04873 }
04874
04875
04876
04877
04879
04880 void InputTargetDataSet::print_variables_information(void)
04881 {
04882 if(display)
04883 {
04884 std::cout << get_variables_information_XML(true);
04885 }
04886 }
04887
04888
04889
04890
04893
04894 void InputTargetDataSet::save_variables_information(const char* filename)
04895 {
04896 std::fstream file;
04897
04898 file.open(filename, std::ios::out);
04899
04900 if(!file.is_open())
04901 {
04902 std::cerr << "Flood Error: InputTargetDataSet class." << std::endl
04903 << "void save_variables_information(const char*) method." << std::endl
04904 << "Cannot open variables information XML-type file." << std::endl;
04905
04906 exit(1);
04907 }
04908
04909
04910
04911 file << get_variables_information_XML(true);
04912
04913
04914
04915 file.close();
04916 }
04917
04918
04919
04920
04923
04924 std::string InputTargetDataSet::get_data_statistics_XML(bool show_declaration)
04925 {
04926 std::stringstream buffer;
04927
04928
04929
04930 if(show_declaration)
04931 {
04932 buffer << "<Flood version='3.0' class='InputTargetDataSet' class='DataStatistics'>" << std::endl;
04933 }
04934
04935 Vector< Vector<double> > statistics = calculate_data_statistics();
04936
04937 buffer << "<DataMean>" << std::endl
04938 << statistics[0] << std::endl
04939 << "</DataMean>" << std::endl
04940 << "<DataStandardDeviation>" << std::endl
04941 << statistics[1] << std::endl
04942 << "</DataStandardDeviation>" << std::endl
04943 << "<DataMinimum>" << std::endl
04944 << statistics[2] << std::endl
04945 << "</DataMinimum>" << std::endl
04946 << "<DataMaximum>" << std::endl
04947 << statistics[3] << std::endl
04948 << "</DataMaximum>" << std::endl;
04949
04950 return(buffer.str());
04951 }
04952
04953
04954
04955
04957
04958 void InputTargetDataSet::print_data_statistics(void)
04959 {
04960 if(display)
04961 {
04962 std::cout << get_data_statistics_XML(true);
04963 }
04964 }
04965
04966
04967
04968
04971
04972 void InputTargetDataSet::save_data_statistics(const char* filename)
04973 {
04974 std::fstream file;
04975
04976 file.open(filename, std::ios::out);
04977
04978 if(!file.is_open())
04979 {
04980 std::cerr << "Flood Error: InputTargetDataSet class." << std::endl
04981 << "void save_data_statistics(const char*) method." << std::endl
04982 << "Cannot open statistics XML-type file." << std::endl;
04983
04984 exit(1);
04985 }
04986
04987
04988
04989 file << get_data_statistics_XML(true);
04990
04991
04992
04993 file.close();
04994 }
04995
04996
04997
04998
05001
05002 std::string InputTargetDataSet::get_training_instances_statistics_XML(bool show_declaration)
05003 {
05004 std::stringstream buffer;
05005
05006 if(show_declaration)
05007 {
05008 buffer << "<Flood version='3.0' class='InputTargetDataSet' content='TrainingInstancesStatistics'>" << std::endl;
05009 }
05010
05011 Vector< Vector<double> > training_instances_statistics = calculate_training_instances_statistics();
05012
05013 buffer << "<TrainingInstancesMean>" << std::endl
05014 << training_instances_statistics[0] << std::endl
05015 << "</TrainingInstancesMean>" << std::endl
05016 << "<TrainingInstancesStandardDeviation>" << std::endl
05017 << training_instances_statistics[1] << std::endl
05018 << "</TrainingInstancesStandardDeviation>" << std::endl
05019 << "<TrainingInstancesMinimum>" << std::endl
05020 << training_instances_statistics[2] << std::endl
05021 << "</TrainingInstancesMinimum>" << std::endl
05022 << "<TrainingInstancesMaximum>" << std::endl
05023 << training_instances_statistics[3] << std::endl
05024 << "</TrainingInstancesMaximum>" << std::endl;
05025
05026 return(buffer.str());
05027 }
05028
05029
05030
05031
05033
05034 void InputTargetDataSet::print_training_instances_statistics(void)
05035 {
05036 std::cout << get_training_instances_statistics_XML(true);
05037 }
05038
05039
05040
05041
05044
05045 void InputTargetDataSet::save_training_instances_statistics(const char* filename)
05046 {
05047 std::fstream file;
05048
05049 file.open(filename, std::ios::out);
05050
05051 if(!file.is_open())
05052 {
05053 std::cerr << "Flood Error: InputTargetDataSet class." << std::endl
05054 << "void save_training_instances_statistics(const char*) method." << std::endl
05055 << "Cannot open training data statistics XML-type file." << std::endl;
05056
05057 exit(1);
05058 }
05059
05060 file << get_training_instances_statistics_XML(true);
05061
05062 file.close();
05063 }
05064
05065
05066
05067
05070
05071 std::string InputTargetDataSet::get_validation_instances_statistics_XML(bool show_declaration)
05072 {
05073 std::stringstream buffer;
05074
05075 if(show_declaration)
05076 {
05077 buffer << "<Flood version='3.0' class='InputTargetDataSet' content='ValidationInstancesStatistics'>" << std::endl;
05078 }
05079
05080 Vector< Vector<double> > validation_instances_statistics = calculate_validation_instances_statistics();
05081
05082 buffer << "<ValidationInstancesMean>" << std::endl
05083 << validation_instances_statistics[0] << std::endl
05084 << "</ValidationInstancesMean>" << std::endl
05085 << "<ValidationInstancesStandardDeviation>" << std::endl
05086 << validation_instances_statistics[1] << std::endl
05087 << "</ValidationInstancesStandardDeviation>" << std::endl
05088 << "<ValidationInstancesMinimum>" << std::endl
05089 << validation_instances_statistics[2] << std::endl
05090 << "</ValidationInstancesMinimum>" << std::endl
05091 << "<ValidationInstancesMaximum>" << std::endl
05092 << validation_instances_statistics[3] << std::endl
05093 << "</ValidationInstancesMaximum>" << std::endl;
05094
05095 return(buffer.str());
05096 }
05097
05098
05099
05100
05102
05103 void InputTargetDataSet::print_validation_instances_statistics(void)
05104 {
05105 if(display)
05106 {
05107 std::cout << get_validation_instances_statistics_XML(true);
05108 }
05109 }
05110
05111
05112
05113
05116
05117 void InputTargetDataSet::save_validation_instances_statistics(const char* filename)
05118 {
05119 std::fstream file;
05120
05121 file.open(filename, std::ios::out);
05122
05123 if(!file.is_open())
05124 {
05125 std::cerr << "Flood Error: InputTargetDataSet class." << std::endl
05126 << "void save_validation_instances_statistics(const char*) method." << std::endl
05127 << "Cannot open validation data statistics XML-type file." << std::endl;
05128
05129 exit(1);
05130 }
05131
05132 file << get_validation_instances_statistics_XML(true);
05133
05134 file.close();
05135 }
05136
05137
05138
05139
05142
05143 std::string InputTargetDataSet::get_testing_instances_statistics_XML(bool show_declaration)
05144 {
05145 std::stringstream buffer;
05146
05147 if(show_declaration)
05148 {
05149 buffer << "<Flood version='3.0' class='InputTargetDataSet' content='TestingInstancesStatistics'>" << std::endl;
05150 }
05151
05152 Vector< Vector<double> > testing_instances_statistics = calculate_testing_instances_statistics();
05153
05154 buffer << "<TestingInstancesMean>" << std::endl
05155 << testing_instances_statistics[0] << std::endl
05156 << "</TestingInstancesMean>" << std::endl
05157 << "<TestingInstancesStandardDeviation>" << std::endl
05158 << testing_instances_statistics[1] << std::endl
05159 << "</TestingInstancesStandardDeviation>" << std::endl
05160 << "<TestingInstancesMinimum>" << std::endl
05161 << testing_instances_statistics[2] << std::endl
05162 << "</TestingInstancesMinimum>" << std::endl
05163 << "<TestingInstancesMaximum>" << std::endl
05164 << testing_instances_statistics[3] << std::endl
05165 << "</TestingInstancesMaximum>" << std::endl;
05166
05167 return(buffer.str());
05168 }
05169
05170
05171
05172
05174
05175 void InputTargetDataSet::print_testing_instances_statistics(void)
05176 {
05177 if(display)
05178 {
05179 std::cout << get_testing_instances_statistics_XML(true);
05180 }
05181 }
05182
05183
05184
05185
05188
05189 void InputTargetDataSet::save_testing_instances_statistics(const char* filename)
05190 {
05191 std::fstream file;
05192
05193 file.open(filename, std::ios::out);
05194
05195 if(!file.is_open())
05196 {
05197 std::cerr << "Flood Error: InputTargetDataSet class." << std::endl
05198 << "void save_testing_instances_statistics(const char*) method." << std::endl
05199 << "Cannot open testing data statistics XML-type file." << std::endl;
05200
05201 exit(1);
05202 }
05203
05204 file << get_testing_instances_statistics_XML(true);
05205
05206 file.close();
05207 }
05208
05209
05210
05211
05215
05216 std::string InputTargetDataSet::get_instances_statistics_XML(bool show_declaration)
05217 {
05218 std::stringstream buffer;
05219
05220 if(show_declaration)
05221 {
05222 buffer << "<Flood version='3.0' class='InputTargetDataSet' content='InstancesStatistics'>" << std::endl;
05223 }
05224
05225 buffer << get_data_statistics_XML(false)
05226 << get_training_instances_statistics_XML(false)
05227 << get_validation_instances_statistics_XML(false)
05228 << get_testing_instances_statistics_XML(false);
05229
05230 return(buffer.str());
05231 }
05232
05233
05234
05235
05238
05239 void InputTargetDataSet::print_instances_statistics(void)
05240 {
05241 std::cout << get_instances_statistics_XML(true);
05242 }
05243
05244
05245
05246
05249
05250 void InputTargetDataSet::save_instances_statistics(const char* filename)
05251 {
05252 std::fstream file;
05253
05254 file.open(filename, std::ios::out);
05255
05256 if(!file.is_open())
05257 {
05258 std::cerr << "Flood Error: InputTargetDataSet class." << std::endl
05259 << "void save_instances_statistics(const char*) method." << std::endl
05260 << "Cannot open all data statistics XML-type file." << std::endl;
05261
05262 exit(1);
05263 }
05264
05265 file << get_testing_instances_statistics_XML(true);
05266
05267 file.close();
05268 }
05269
05270 }
05271
05272
05273
05274
05275
05276
05277
05278
05279
05280
05281
05282
05283
05284
05285
05286
05287
05288