X-Git-Url: https://fleuret.org/cgi-bin/gitweb/gitweb.cgi?p=data-tool.git;a=blobdiff_plain;f=data-tool.cc;h=9ab7a8c39ddc5f0372c13e50ea5ea9e005ee729c;hp=0a2e04911b42bce66f20fcef6540c9eb2217e964;hb=a4f7fd0c1bea70844bb60c0951195589bf00f2da;hpb=d38ae4b64baf473b0f1b1247d93ef980ebf139f2 diff --git a/data-tool.cc b/data-tool.cc index 0a2e049..9ab7a8c 100644 --- a/data-tool.cc +++ b/data-tool.cc @@ -92,6 +92,7 @@ void print_help_and_exit(int e) { << " --help" << endl << " --roc" << endl << " --roc-surface" << endl + << " --error" << endl << " --normalize" << endl << " --histo" << endl << " --cumul" << endl @@ -121,7 +122,7 @@ int main(int argc, char **argv) { int i = 1; - enum { UNKNOWN, ROC, ROC_SURFACE, HISTO, CUMUL, MISC } processing = UNKNOWN; + enum { UNKNOWN, ROC, ROC_SURFACE, ERROR, HISTO, CUMUL, MISC } processing = UNKNOWN; // Parsing the command line arguments //////////////////////////////// @@ -141,6 +142,12 @@ int main(int argc, char **argv) { i++; } + else if(strcmp(argv[i], "--error") == 0) { + check_single_processing(processing == UNKNOWN); + processing = ERROR; + i++; + } + else if(strcmp(argv[i], "--cumul") == 0) { check_single_processing(processing == UNKNOWN); processing = CUMUL; @@ -233,7 +240,7 @@ int main(int argc, char **argv) { } } - Couple tmp[nb_samples]; + Couple *tmp = new Couple[nb_samples]; for(int n = 0; n < nb_samples; n++) { tmp[n].index = n; tmp[n].value = x[n]; @@ -242,8 +249,9 @@ int main(int argc, char **argv) { qsort(tmp, nb_samples, sizeof(Couple), compare_couple); for(int n = 0; n < nb_samples; n++) - cout << tmp[n].value << " " << double(n)/double(nb_samples) << endl; + cout << tmp[n].value << " " << double(n+1)/double(nb_samples) << endl; + delete[] tmp; delete[] x; } @@ -252,6 +260,7 @@ int main(int argc, char **argv) { case ROC: case ROC_SURFACE: + case ERROR: { int nb_samples = 0, nb_samples_max = 1000; @@ -276,7 +285,7 @@ int main(int argc, char **argv) { } } - Couple tmp[nb_samples]; + Couple *tmp = new Couple[nb_samples]; int nb_rn = 0, nb_rp = 0, nb_fp = 0, nb_fn = 0; bool binary = true; @@ -309,7 +318,7 @@ int main(int argc, char **argv) { << endl; } } - } else { + } else if(processing == ROC_SURFACE) { double surface = 0; double cx = double(nb_fp)/double(nb_rn), cy = 1 - double(nb_fn) / double(nb_rp); for(int n = 0; n < nb_samples - 1; n++) { @@ -322,9 +331,21 @@ int main(int argc, char **argv) { } } cout << surface << endl; + } else { + for(int n = 0; n < nb_samples - 1; n++) { + if(x[tmp[n].index] >= 0) nb_fn++; + else nb_fp--; + if(tmp[n].value < tmp[n+1].value) { + cout << (tmp[n].value + tmp[n+1].value)/2 << " " + << double(nb_fp + nb_fn)/double(nb_rn + nb_rp) << " " + << endl; + } + } } - delete[] x; delete[] y; + delete[] tmp; + delete[] x; + delete[] y; } @@ -356,7 +377,7 @@ int main(int argc, char **argv) { } } - int nb[nb_bins]; + int *nb = new int[nb_bins]; for(int n = 0; n < nb_bins; n++) nb[n] = 0; int nb_total = 0; @@ -378,6 +399,8 @@ int main(int argc, char **argv) { cout << xmin + ((xmax - xmin) * n) / double(nb_bins) << " " << nb[n] / double(nb_total) << endl; } + + delete[] nb; } break; @@ -412,7 +435,7 @@ int main(int argc, char **argv) { } } - Couple tmp[nb_samples]; + Couple *tmp = new Couple[nb_samples]; for(int n = 0; n < nb_samples; n++) { tmp[n].index = n; tmp[n].value = x[n]; @@ -437,6 +460,7 @@ int main(int argc, char **argv) { << " QUANTILE0.9 " << tmp[int(nb_samples * 0.9)].value << endl; + delete[] tmp; } break;