ex-7: fixed some errors

This commit is contained in:
Giù Marcer 2020-05-28 14:59:11 +02:00 committed by rnhmjoj
parent 3ba8189fb4
commit 7683d9e2dd
3 changed files with 24 additions and 21 deletions

View File

@ -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);

View File

@ -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()

View File

@ -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);