Skip to content

kernlab's ksvm method freeze

14 messages · Heiko Strathmann, Uwe Ligges, David Winsemius +3 more

#
Hello,

I am using kernlab to do some binary classification on aminoacid
strings.

I am using a custom kernel, so i use the kernel="matrix" option of the
ksvm method.

My (normalized) kernel matrix is of size 1309*1309, my results vector
has the same length.

I am using C-svc.

My kernlab call is something similiar to this:

ksvm(kernel="matrix", kernelMatrix, trainingDataYs, type="C-svc",
cross=10, C=2)

To this point, everything works fine.

But now, i want to do a search for a good C Parameter, so I call the
ksvm method multiple times in a loop, with changing parameters.
This loop freezes after a few iterations.


The following simple example also freezes after few iterations (the
number varies). See that the ksvm call is always the same in every
iteration:

for (i in c(1:20)) {
        print(i)
        ksvm(kernel="matrix", kernelMatrix, trainingDataYs,
type="C-svc",
cross=10, C=2)
}


Does anybody have an idea what causes this? I am new to R and kernlab,
perhaps i missed something?

I put my workspace online, which contains the kernel matrix and the
training labels. Simply load workspace, kernlab library and paste the
example code to reproduce:
http://www-stud.uni-due.de/~sfhestra/

I am using R version 2.10.0 and kernlab 0.9-9.

Thanks for your help!

Regards,
Heiko Strathmann
#
Hello again,

the freeze seems to depend on the kernel matrix.
With another kernel matrix of similiar size, gernerated with the same
kernel, but on another dataset, there is no freeze.

I have put a workspace with the working matrix and one with the freezing
matrix online for testing (see old email)
http://www-stud.uni-due.de/~sfhestra/

In my eyes this behavior is really strange, and i have no clue, what to
do to solve this.

Regards,
Heiko Strathmann

Am Sonntag, den 29.11.2009, 14:21 +0100 schrieb Heiko Strathmann:
#
I just tried

ksvm(kernel="matrix", kernelMatrix, trainingDataYs, type="C-svc", 
cross=10, C=2)

several times on both workspaces and both returned some results after a 
couple of seconds under the same versions (R version 2.10.0 and kernlab 
0.9-9.) under Windows XP.

There mist be something else going on...

Best wishes,
Uwe Ligges
Heiko Strathmann wrote:
#
Hello uwe,
Thanks for trying out.
the freeze happens after about 10 to 20 iterations. Did you try as many?

Am Sonntag, den 29.11.2009, 17:22 +0100 schrieb Uwe Ligges:
#
Heiko Strathmann wrote:
I just tried again:

library("kernlab")
load("freeze_workspace.RDATA")
replicate(100, ksvm(kernel="matrix", kernelMatrix, trainingDataYs, 
type="C-svc", C=2))

and everything is still fine (same on Linux).

Uwe Ligges
#
No "freezes" on a Mac using Ligges' 100 replication script. Tried it  
twice. They took around a minute each time.

-- 
David.
#
I tried out the code you wrote, it also works for me, but it lacks a
parameter i use in my code.

The problem (at this computer) seems to be this "cross"-parameter of
ksvm - if I, for example, add the parameter cross=10, i get the old
problem:

library("kernlab")
load("freeze_workspace.RDATA")
replicate(10, ksvm(kernel="matrix", kernelMatrix, trainingDataYs, type="C-svc", C=2, cross=10))

gets me a frozen R process, CTRL-C does not work anymore, and the only thing left is to kill it.

(for cross < 4, the thing still works)

(I also just reinstalled my Ubuntu and R)

Heiko Strathmann


Am Sonntag, den 29.11.2009, 19:52 +0100 schrieb Uwe Ligges:
#
My apologies, that must have been a copy&paste error and the essential 
argument got lost. I can reproduce it now under R-2.10.0 both Windows 
and Linux.

Please report your findings to the package maintainer who might be able 
to debug this under Linux (probably easier than under Windows).

Best,
Uwe Ligges
Heiko Strathmann wrote:
#
Hi,

I have an experiment with 5 treatments, of which 2 with 10 
repetitions and 2 with 7 replications.
I conducted the test of Bartlett step-by-step and compared 
with the value calculated directly by the R and the values 
are different.
Anyone know tell me why?


#-------------------

n = length(trat)
I = 4

(M = 2.3026*((n-I)*log10(mean(tapply(valor,trat,var))) - 
(9*log10(vari[1])+9*log10(vari[2])+6*log10(vari[3])+6*log10(vari[4]))))
(C = 1 + 1/(3*(4-1))*((1/9 + 1/9 + 1/6 + 1/6) - 
1/(9+9+6+6)))
(B = M/C)
1.748670
[1] 7.814728

#-----------------------------------------
# Teste de Bartlett de forma direta no R -
#-----------------------------------------

bartlett.test(valor,trat)

        Bartlett test of homogeneity of variances

data:  valor and trat
Bartlett's K-squared = 0.7845, df = 3, p-value =
0.8532

Thanks,

--------------------------------------
Silvano Cesar da Costa
Departamento de Estat?stica
Universidade Estadual de Londrina
Fone: 3371-4346
#
Silvano wrote:
The first term in M looks wrong when group sizes differ, but it would be
much easier to check if you gave the actual group variances.


(and PLEASE don't hijack other threads. This has nothing to do with
kernlab's ksvm!)

  
    
#
Silvano wrote:
Yes. Is mean(tapply(valor,trat,var)) the pooled variance estimate?
Maybe you should look at the code of bartlett.test.default.

  -Peter Ehlers
#
Hello again,

i got this message from the maintainer:


Am Montag, den 30.11.2009, 11:22 +0100 schrieb Heiko Strathmann:
#
Sorry, heres the message:

Hi

yes the freeze is rather a result of the kernelMatrix being non-positive
definite, have a look at the eigenvalues of kernelMatrix
with eigs and you will see even small negative values. This is usualy
the result of small numerical inacuracies in the computation of the
kernel matrix that normally do not have an effect but can cause
problems.
The issue is amplified by the fact that you are doing 10-fold cross
validation and in effect training 220 models (sampled from the
kernelMatrix) in a 20 fold loop.

You can get around this issue by adding a small epsilon to the diagonal
of your kernelMatrix thus making sure that all sampled kernelMatrices
are positive semidefinite i.e.

diag(kernelMatrix) <- diag(kernelMatrix) + 0.05

seems to do the trick for me.

regards
Alexandros



Am Montag, den 30.11.2009, 11:22 +0100 schrieb Heiko Strathmann: