diff --git a/ex-7/fisher.c b/ex-7/fisher.c index 9a48499..57cb587 100644 --- a/ex-7/fisher.c +++ b/ex-7/fisher.c @@ -86,6 +86,15 @@ gsl_vector* fisher_proj(sample_t *c1, sample_t *c2) { 0, // β = 0 w); // vector y + /* Normalise the weights and force + * positiveness for easier + * comparison with other methods. + */ + double norm = gsl_blas_dnrm2(w); + if (gsl_vector_isneg(w)) + norm = -norm; + gsl_vector_scale(w, 1/norm); + // free memory gsl_matrix_free(cov1); gsl_matrix_free(cov2); @@ -170,7 +179,7 @@ double fisher_cut( * * with a,b,c given as above. * - * */ + */ double a = var1 - var2; double b = m2*var1 + m1*var2; double c = m2*m2*var1 - m1*m1*var2 + 2*var1*var2 * log(ratio); diff --git a/ex-7/percep.c b/ex-7/percep.c index 6fd29d0..d762119 100644 --- a/ex-7/percep.c +++ b/ex-7/percep.c @@ -38,7 +38,7 @@ void iterate( gsl_blas_ddot(weight, x, &proj); /* Calculate Δ - * Note: the step functions θ(x) is computed + * Note: the step function θ(x) is computed * by negating the sign bit of the floating * point. */ @@ -80,7 +80,15 @@ gsl_vector *percep_train( iterate(signal->data, w, &bias, 1, rate); } - *cut = -bias; + /* Normalise the weights and force + * positiveness for easier + * comparison with other methods. + */ + double norm = gsl_blas_dnrm2(w); + if (gsl_vector_isneg(w)) + norm = -norm; + gsl_vector_scale(w, 1/norm); + *cut = -bias/norm; return w; }