From 7683d9e2ddbf1960e65813a64301af748835e1d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gi=C3=B9=20Marcer?= Date: Thu, 28 May 2020 14:59:11 +0200 Subject: [PATCH] ex-7: fixed some errors --- ex-7/main.c | 10 +++++----- ex-7/plot.py | 19 ++++++++++--------- ex-7/test.c | 16 +++++++++------- 3 files changed, 24 insertions(+), 21 deletions(-) diff --git a/ex-7/main.c b/ex-7/main.c index 7bc5b76..0bb2afa 100644 --- a/ex-7/main.c +++ b/ex-7/main.c @@ -112,16 +112,16 @@ int main(int argc, char **argv) { gsl_vector_get(w, 0), gsl_vector_get(w, 1)); fprintf(stderr, "* cut: %.3f\n", cut); -// gsl_vector_fprintf(stdout, w, "%g"); -// printf("%f\n", cut); + gsl_vector_fprintf(stdout, w, "%g"); + printf("%f\n", cut); /* Print data to stdout for plotting. * Note: we print the sizes to be able * to set apart the two matrices. */ -// printf("%ld %ld %d\n", opts.nsig, opts.nnoise, 2); -// gsl_matrix_fprintf(stdout, signal->data, "%g"); -// gsl_matrix_fprintf(stdout, noise->data, "%g"); + printf("%ld %ld %d\n", opts.nsig, opts.nnoise, 2); + gsl_matrix_fprintf(stdout, signal->data, "%g"); + gsl_matrix_fprintf(stdout, noise->data, "%g"); // free memory gsl_rng_free(r); diff --git a/ex-7/plot.py b/ex-7/plot.py index 04ea7e7..6151689 100755 --- a/ex-7/plot.py +++ b/ex-7/plot.py @@ -15,11 +15,10 @@ n, m, d = map(int, input().split()) data = loadtxt(sys.stdin).reshape(n + m, d) signal, noise = data[:n].T, data[n:].T -plt.figure(figsize=(3, 3)) -rcParams['font.size'] = 8 -figure() -figure(figsize=(3, 3)) -rcParams['font.size'] = 8 +# rcParams['font.size'] = 8 + +# plt.figure(figsize=(3, 3)) +plt.figure() subplot(aspect='equal') scatter(*signal, edgecolor='xkcd:charcoal', c='xkcd:dark yellow', label='signal') @@ -33,10 +32,10 @@ xlim(-1.5, 8) ylim(-1.5, 8) legend() tight_layout() -savefig('notes/images/7-fisher-plane.pdf') +# savefig('notes/images/7-fisher-plane.pdf') -plt.figure(figsize=(3, 3)) -rcParams['font.size'] = 8 +#plt.figure(figsize=(3, 3)) +plt.figure() sig_proj = np.dot(w, signal) noise_proj = np.dot(w, noise) hist(sig_proj, color='xkcd:dark yellow', label='signal') @@ -45,4 +44,6 @@ axvline(cut, c='xkcd:scarlet', label='cut') xlabel('projection line') legend() tight_layout() -savefig('notes/images/7-fisher-proj.pdf') +# savefig('notes/images/7-fisher-proj.pdf') + +show() diff --git a/ex-7/test.c b/ex-7/test.c index 0914bda..b2cdc4c 100644 --- a/ex-7/test.c +++ b/ex-7/test.c @@ -50,9 +50,9 @@ int misclassified(double *weights, int expected, gsl_matrix *data) { int show_help(char **argv) { fprintf(stderr, "Usage: %s -[hisnw] WEIGHT [WEIGHT..] CUT\n", argv[0]); fprintf(stderr, " -h\t\tShow this message.\n"); - fprintf(stderr, " -i N\t\tThe number of test iterations to run.\n"); - fprintf(stderr, " -s N\t\tThe number of events in signal class.\n"); - fprintf(stderr, " -n N\t\tThe number of events in noise class.\n"); + fprintf(stderr, " -i N\t\tThe number of test iterations to run. (default: 500)\n"); + fprintf(stderr, " -s N\t\tThe number of events in signal class. (default: 800)\n"); + fprintf(stderr, " -n N\t\tThe number of events in noise class. (default: 1000)\n"); fprintf(stderr, "\nRun tests classifying randomly generated data, " "using the given WEIGHTs and CUTs.\n"); return EXIT_FAILURE; @@ -73,6 +73,7 @@ int main(int argc, char **argv) { else if (!strcmp(argv[i], "-n")) opts.nnoise = atol(argv[++i]); else if (!strcmp(argv[i], "-i")) opts.iter = atoi(argv[++i]); else if (!strcmp(argv[i], "-h")) return show_help(argv); + else if (!strcmp(argv[i], "--help")) return show_help(argv); else { for (int j = 0; j < 3; j++) opts.weights[j] = atof(argv[i++]); @@ -105,14 +106,15 @@ int main(int argc, char **argv) { /* Count false positive/negatives and add them to * the running stats workspaces to calculate mean/stddev. */ - gsl_rstat_add(misclassified(opts.weights, 0, noise->data), false_neg); - gsl_rstat_add(misclassified(opts.weights, 1, signal->data), false_pos); + gsl_rstat_add(misclassified(opts.weights, 0, noise->data), false_pos); + gsl_rstat_add(misclassified(opts.weights, 1, signal->data), false_neg); // free memory sample_t_free(signal); sample_t_free(noise); } + // print out results puts("# results\n"); puts("## false negatives"); printf( @@ -137,8 +139,8 @@ int main(int argc, char **argv) { gsl_rstat_max(false_pos)); puts("\n## averages"); - printf("- purity:\t%.3e\n", 1 - gsl_rstat_mean(false_neg)/opts.nsig); - printf("- efficiency:\t%.3e\n", 1 - gsl_rstat_mean(false_pos)/opts.nsig); + printf("- purity:\t%.3e\n", 1 - gsl_rstat_mean(false_pos)/opts.nnoise); + printf("- efficiency:\t%.3e\n", 1 - gsl_rstat_mean(false_neg)/opts.nsig); // free memory gsl_rng_free(r);