diff options
| author | Gertjan van den Burg <burg@ese.eur.nl> | 2014-03-17 11:45:57 +0100 |
|---|---|---|
| committer | Gertjan van den Burg <gertjanvandenburg@gmail.com> | 2014-05-19 22:21:34 -0700 |
| commit | b7c5d533d7fa249258c7b139996176130e7a8c80 (patch) | |
| tree | d3643b4e665e845d61ca06c5beeffed9a0230162 /src/msvmmaj_train.c | |
| parent | write eigen to data structure (diff) | |
| download | gensvm-b7c5d533d7fa249258c7b139996176130e7a8c80.tar.gz gensvm-b7c5d533d7fa249258c7b139996176130e7a8c80.zip | |
work on regularization term with nonlinearity
Diffstat (limited to 'src/msvmmaj_train.c')
| -rw-r--r-- | src/msvmmaj_train.c | 18 |
1 files changed, 11 insertions, 7 deletions
diff --git a/src/msvmmaj_train.c b/src/msvmmaj_train.c index bbd2663..5018c3f 100644 --- a/src/msvmmaj_train.c +++ b/src/msvmmaj_train.c @@ -87,7 +87,7 @@ void msvmmaj_optimize(struct MajModel *model, struct MajData *data) Lbar = L; L = msvmmaj_get_loss(model, data, ZV); - if (it%50 == 0) + if (it%1 == 0) note("iter = %li, L = %15.16f, Lbar = %15.16f, " "reldiff = %15.16f\n", it, L, Lbar, (Lbar - L)/L); it++; @@ -156,10 +156,12 @@ double msvmmaj_get_loss(struct MajModel *model, struct MajData *data, loss /= ((double) n); value = 0; - for (i=1; i<m+1; i++) { + for (i=0; i<m+1; i++) { + rowvalue = 0; for (j=0; j<K-1; j++) { - value += pow(matrix_get(model->V, K-1, i, j), 2.0); + rowvalue += pow(matrix_get(model->V, K-1, i, j), 2.0); } + value += model->J[i] * rowvalue; } loss += model->lambda * value; @@ -421,12 +423,14 @@ void msvmmaj_get_update(struct MajModel *model, struct MajData *data, double *B, ZAZV, K-1); /* - * Add lambda to all diagonal elements except the - * first one. + * Add lambda to all diagonal elements except the first one. Recall + * that ZAZ is of size m+1 and is symmetric. */ i = 0; - for (j=0; j<m; j++) - ZAZ[i+=m+1 + 1] += model->lambda; + for (j=0; j<m; j++) { + i += (m+1) + 1; + ZAZ[i] += model->lambda * model->J[j+1]; + } // For the LAPACK call we need to switch to Column- // Major order. This is unnecessary for the matrix |
