ex-7: fixed some errors
This commit is contained in:
parent
3ba8189fb4
commit
7683d9e2dd
10
ex-7/main.c
10
ex-7/main.c
@ -112,16 +112,16 @@ int main(int argc, char **argv) {
|
|||||||
gsl_vector_get(w, 0),
|
gsl_vector_get(w, 0),
|
||||||
gsl_vector_get(w, 1));
|
gsl_vector_get(w, 1));
|
||||||
fprintf(stderr, "* cut: %.3f\n", cut);
|
fprintf(stderr, "* cut: %.3f\n", cut);
|
||||||
// gsl_vector_fprintf(stdout, w, "%g");
|
gsl_vector_fprintf(stdout, w, "%g");
|
||||||
// printf("%f\n", cut);
|
printf("%f\n", cut);
|
||||||
|
|
||||||
/* Print data to stdout for plotting.
|
/* Print data to stdout for plotting.
|
||||||
* Note: we print the sizes to be able
|
* Note: we print the sizes to be able
|
||||||
* to set apart the two matrices.
|
* to set apart the two matrices.
|
||||||
*/
|
*/
|
||||||
// printf("%ld %ld %d\n", opts.nsig, opts.nnoise, 2);
|
printf("%ld %ld %d\n", opts.nsig, opts.nnoise, 2);
|
||||||
// gsl_matrix_fprintf(stdout, signal->data, "%g");
|
gsl_matrix_fprintf(stdout, signal->data, "%g");
|
||||||
// gsl_matrix_fprintf(stdout, noise->data, "%g");
|
gsl_matrix_fprintf(stdout, noise->data, "%g");
|
||||||
|
|
||||||
// free memory
|
// free memory
|
||||||
gsl_rng_free(r);
|
gsl_rng_free(r);
|
||||||
|
19
ex-7/plot.py
19
ex-7/plot.py
@ -15,11 +15,10 @@ n, m, d = map(int, input().split())
|
|||||||
data = loadtxt(sys.stdin).reshape(n + m, d)
|
data = loadtxt(sys.stdin).reshape(n + m, d)
|
||||||
signal, noise = data[:n].T, data[n:].T
|
signal, noise = data[:n].T, data[n:].T
|
||||||
|
|
||||||
plt.figure(figsize=(3, 3))
|
# rcParams['font.size'] = 8
|
||||||
rcParams['font.size'] = 8
|
|
||||||
figure()
|
# plt.figure(figsize=(3, 3))
|
||||||
figure(figsize=(3, 3))
|
plt.figure()
|
||||||
rcParams['font.size'] = 8
|
|
||||||
subplot(aspect='equal')
|
subplot(aspect='equal')
|
||||||
scatter(*signal, edgecolor='xkcd:charcoal',
|
scatter(*signal, edgecolor='xkcd:charcoal',
|
||||||
c='xkcd:dark yellow', label='signal')
|
c='xkcd:dark yellow', label='signal')
|
||||||
@ -33,10 +32,10 @@ xlim(-1.5, 8)
|
|||||||
ylim(-1.5, 8)
|
ylim(-1.5, 8)
|
||||||
legend()
|
legend()
|
||||||
tight_layout()
|
tight_layout()
|
||||||
savefig('notes/images/7-fisher-plane.pdf')
|
# savefig('notes/images/7-fisher-plane.pdf')
|
||||||
|
|
||||||
plt.figure(figsize=(3, 3))
|
#plt.figure(figsize=(3, 3))
|
||||||
rcParams['font.size'] = 8
|
plt.figure()
|
||||||
sig_proj = np.dot(w, signal)
|
sig_proj = np.dot(w, signal)
|
||||||
noise_proj = np.dot(w, noise)
|
noise_proj = np.dot(w, noise)
|
||||||
hist(sig_proj, color='xkcd:dark yellow', label='signal')
|
hist(sig_proj, color='xkcd:dark yellow', label='signal')
|
||||||
@ -45,4 +44,6 @@ axvline(cut, c='xkcd:scarlet', label='cut')
|
|||||||
xlabel('projection line')
|
xlabel('projection line')
|
||||||
legend()
|
legend()
|
||||||
tight_layout()
|
tight_layout()
|
||||||
savefig('notes/images/7-fisher-proj.pdf')
|
# savefig('notes/images/7-fisher-proj.pdf')
|
||||||
|
|
||||||
|
show()
|
||||||
|
16
ex-7/test.c
16
ex-7/test.c
@ -50,9 +50,9 @@ int misclassified(double *weights, int expected, gsl_matrix *data) {
|
|||||||
int show_help(char **argv) {
|
int show_help(char **argv) {
|
||||||
fprintf(stderr, "Usage: %s -[hisnw] WEIGHT [WEIGHT..] CUT\n", argv[0]);
|
fprintf(stderr, "Usage: %s -[hisnw] WEIGHT [WEIGHT..] CUT\n", argv[0]);
|
||||||
fprintf(stderr, " -h\t\tShow this message.\n");
|
fprintf(stderr, " -h\t\tShow this message.\n");
|
||||||
fprintf(stderr, " -i N\t\tThe number of test iterations to run.\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.\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.\n");
|
fprintf(stderr, " -n N\t\tThe number of events in noise class. (default: 1000)\n");
|
||||||
fprintf(stderr, "\nRun tests classifying randomly generated data, "
|
fprintf(stderr, "\nRun tests classifying randomly generated data, "
|
||||||
"using the given WEIGHTs and CUTs.\n");
|
"using the given WEIGHTs and CUTs.\n");
|
||||||
return EXIT_FAILURE;
|
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], "-n")) opts.nnoise = atol(argv[++i]);
|
||||||
else if (!strcmp(argv[i], "-i")) opts.iter = atoi(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], "-h")) return show_help(argv);
|
||||||
|
else if (!strcmp(argv[i], "--help")) return show_help(argv);
|
||||||
else {
|
else {
|
||||||
for (int j = 0; j < 3; j++)
|
for (int j = 0; j < 3; j++)
|
||||||
opts.weights[j] = atof(argv[i++]);
|
opts.weights[j] = atof(argv[i++]);
|
||||||
@ -105,14 +106,15 @@ int main(int argc, char **argv) {
|
|||||||
/* Count false positive/negatives and add them to
|
/* Count false positive/negatives and add them to
|
||||||
* the running stats workspaces to calculate mean/stddev.
|
* 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, 0, noise->data), false_pos);
|
||||||
gsl_rstat_add(misclassified(opts.weights, 1, signal->data), false_pos);
|
gsl_rstat_add(misclassified(opts.weights, 1, signal->data), false_neg);
|
||||||
|
|
||||||
// free memory
|
// free memory
|
||||||
sample_t_free(signal);
|
sample_t_free(signal);
|
||||||
sample_t_free(noise);
|
sample_t_free(noise);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// print out results
|
||||||
puts("# results\n");
|
puts("# results\n");
|
||||||
puts("## false negatives");
|
puts("## false negatives");
|
||||||
printf(
|
printf(
|
||||||
@ -137,8 +139,8 @@ int main(int argc, char **argv) {
|
|||||||
gsl_rstat_max(false_pos));
|
gsl_rstat_max(false_pos));
|
||||||
|
|
||||||
puts("\n## averages");
|
puts("\n## averages");
|
||||||
printf("- purity:\t%.3e\n", 1 - gsl_rstat_mean(false_neg)/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_pos)/opts.nsig);
|
printf("- efficiency:\t%.3e\n", 1 - gsl_rstat_mean(false_neg)/opts.nsig);
|
||||||
|
|
||||||
// free memory
|
// free memory
|
||||||
gsl_rng_free(r);
|
gsl_rng_free(r);
|
||||||
|
Loading…
Reference in New Issue
Block a user