I'm trying to implement a svmtrain function. It works at training and it works when classifying sample matrix of same number of samples than the training matrix. What I am doing wrong?
MAIN FUNCTION
function [ output_args ] = RBFTest( xtrain, ytrain)
output_args=svmtrain(xtrain,ytrain,'Kernel_Function',@mine,...
'boxconstraint',1);
end
KERNEL FUNCTION (it supposes to be and RBF Kernel, I'm trying to accelerate using GPU)
function [ output ] = mine( U,V )
sig=1;
n=size(U,1);
K=U*V'/sig^2;
d=diag(K);
K=K-ones(n,1)*d'/2;
K=K-d*ones(1,n)/2;
output=exp(K);
end
I train....
>> R2=RBFTest(X(1:3000,:),Y(1:3000,:))
R2 =
SupportVectors: [3000x57 double]
Alpha: [3000x1 double]
Bias: -0.0219
KernelFunction: @mine
KernelFunctionArgs: {}
GroupNames: [3000x1 double]
SupportVectorIndices: [3000x1 double]
ScaleData: [1x1 struct]
FigureHandles: []
I try to classify a smaller part of the samples...but it doesn't work
>> mean(svmclassify(R2,X(1:2000,:))==Y(1:2000))
Error using svmclassify (line 114)
An error was encountered during classification.
Matrix dimensions must agree.
I try to classify same data used to train ... work!
>> mean(svmclassify(R2,X(1:3000,:))==Y(1:3000))
ans =
0.9990
I retrain with smaller sample....
>> R2=RBFTest(X(1:1000,:),Y(1:1000,:))
R2 =
SupportVectors: [1000x57 double]
Alpha: [1000x1 double]
Bias: -0.0549
KernelFunction: @mine
KernelFunctionArgs: {}
GroupNames: [1000x1 double]
SupportVectorIndices: [1000x1 double]
ScaleData: [1x1 struct]
FigureHandles: []
I classify different samples but using same matrix and vectors size ... and it works
>> mean(svmclassify(R2,X(1001:2000,:))==Y(1001:2000))
ans =
0.4610
Why it doesn't work when using different sizes of training and classification matrices?