ex-7: normalise weights

This commit is contained in:
Michele Guerini Rocco 2020-03-07 11:42:19 +00:00
parent 7daefc590a
commit 1c35bec015
2 changed files with 20 additions and 3 deletions

View File

@ -86,6 +86,15 @@ gsl_vector* fisher_proj(sample_t *c1, sample_t *c2) {
0, // β = 0 0, // β = 0
w); // vector y 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 // free memory
gsl_matrix_free(cov1); gsl_matrix_free(cov1);
gsl_matrix_free(cov2); gsl_matrix_free(cov2);
@ -170,7 +179,7 @@ double fisher_cut(
* *
* with a,b,c given as above. * with a,b,c given as above.
* *
* */ */
double a = var1 - var2; double a = var1 - var2;
double b = m2*var1 + m1*var2; double b = m2*var1 + m1*var2;
double c = m2*m2*var1 - m1*m1*var2 + 2*var1*var2 * log(ratio); double c = m2*m2*var1 - m1*m1*var2 + 2*var1*var2 * log(ratio);

View File

@ -38,7 +38,7 @@ void iterate(
gsl_blas_ddot(weight, x, &proj); gsl_blas_ddot(weight, x, &proj);
/* Calculate Δ /* Calculate Δ
* Note: the step functions θ(x) is computed * Note: the step function θ(x) is computed
* by negating the sign bit of the floating * by negating the sign bit of the floating
* point. * point.
*/ */
@ -80,7 +80,15 @@ gsl_vector *percep_train(
iterate(signal->data, w, &bias, 1, rate); 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; return w;
} }