From: Mohammad A. Mezher on
"Bruno Luong" <b.luong(a)fogale.findmycountry> wrote in message <haq9bl$dsb$1(a)fred.mathworks.com>...
> "David Cohen" <dudu.cohen(a)gmail.com> wrote in message <haptkl$k6q$1(a)fred.mathworks.com>...
> > Hello all,
> >
> > I have bulid a Neural Network (RBF) based on data I have gathered using the SVMTrain, I have also test the results from the SVMTrain on other data sets and got satisfactory results.
> > Now I would like to take the SVMStruct which I got back from the SVMTrain procedure and extract the information from it in order to build an approximation function.
> > How can it be done?
> >
>
> Do you mean to know what formula used by svmclassify?
>
> For any x a vector, the class if is the sign of the algebraic distance.
>
> c(x) = sign(d(x)).
>
> The algebraic distance d(x) of x from the hyperplan (in the *feature* space) - scaled by the margin - is:
>
> d(x) = sum K(xi,x)*(alphai.*yi) - 0.5*sum K(xi,s)*(alphai.*yi)
>
> xi is training points; s is (any) support vector
> alphai is dual variables
> K(.,.) is kernel
> x is classify point
>
> Notes
> - Matlab classify returns (alphai.*yi) after training.
> - The second sum using *one* support vector in the formula can be calculated more accurately by replacing with the mean of the same quantity on *all* support vectors.
>
> But why bother not using svmclassify?
>
> Bruno

Hi Bruno,

Sorry to say that but i think there is something missing in the equation
d(x) = sum K(xi,x)*(alphai.*yi) - 0.5*sum K(xi,s)*(alphai.*yi)

i have couples of issues regarding measuring the distance
1- (xi, x) stands for (training data, testing data) but they have different sizes.
2- is yi the target training data??
3- the most important thing this will measure the training data only i.e. the returned score values have the size of the training data

Best



From: Bruno Luong on
"Mohammad A. Mezher" <mohabedalgani(a)yahoo.com> wrote in message
>
> Hi Bruno,
>
> Sorry to say that but i think there is something missing in the equation
> d(x) = sum K(xi,x)*(alphai.*yi) - 0.5*sum K(xi,s)*(alphai.*yi)
>
> i have couples of issues regarding measuring the distance
> 1- (xi, x) stands for (training data, testing data) but they have different sizes.

In my notation {xi} is the training data set, xi is *one* data. So xi is a vector same size as the a *single* tested data vector x, they belong to the same space.

All the sum sign in the expression is over the index {i}.

> 2- is yi the target training data??

yi is the class of traning data, each yi is either -1 or +1.

> 3- the most important thing this will measure the training data only i.e. the returned score values have the size of the training data
>

No x is *any* vector, with the algebraic distance from the hyperplane d(x) we wish to calculate.

Bruno
From: Mohammad A. Mezher on
"Bruno Luong" <b.luong(a)fogale.findmycountry> wrote in message <hr0pmo$t2e$1(a)fred.mathworks.com>...
> "Mohammad A. Mezher" <mohabedalgani(a)yahoo.com> wrote in message
> >
> > Hi Bruno,
> >
> > Sorry to say that but i think there is something missing in the equation
> > d(x) = sum K(xi,x)*(alphai.*yi) - 0.5*sum K(xi,s)*(alphai.*yi)
> >
> > i have couples of issues regarding measuring the distance
> > 1- (xi, x) stands for (training data, testing data) but they have different sizes.
>
> In my notation {xi} is the training data set, xi is *one* data. So xi is a vector same size as the a *single* tested data vector x, they belong to the same space.
>
> All the sum sign in the expression is over the index {i}.
>
> > 2- is yi the target training data??
>
> yi is the class of traning data, each yi is either -1 or +1.
>
> > 3- the most important thing this will measure the training data only i.e. the returned score values have the size of the training data
> >
>
> No x is *any* vector, with the algebraic distance from the hyperplane d(x) we wish to calculate.
>
> Bruno

this means to compute the score equation it would be something like that:

Function score= distance(trnX,trnY,tstX,tstY,kfun,alpha,sv)
Dim=size(sv,1);
DimData=size(trnX,1);
tstX(DimData,:) = ones(1, size(tstX,2));
sv(DimData,:) = ones(1, size(sv,2));
alpha(DimData,:) = ones(1, size(alpha,2));
for i=1:DimData
%d(x) = | sum K(xi,x)*(alphai.*yi) - 0.5*sum K(xi,s)*(alphai.*yi) |
kxTrXr = feval(kfun,trnX(i,:),tstX(i,:));
kxSvXr = feval(kfun,sv(i),trnX(i,:));
alphatar=alpha(i).*trnY(i);
score(i) = abs(sum(kxTrXr*alphatar)-(0.5*sum(kxSvXr*alphatar)));
end
end

so if i use the perfcurve function to compute the Area under curve
posclass=0;
[~,~,~,auc] = perfcurve(trnY,score',posclass);

or should i use the dimension of the test data to reduce the training data size, alpha and sv??


Thank you so much Bruno for your reply and your explanation.
From: Bruno Luong on
I have not tried your code (that's your duty to make sure the code return what you expect), but I draw two notes I pit in the second post:

[...
Notes
- Matlab classify returns (alphai.*yi) after training.
- The second sum using *one* support vector in the formula can be calculated more accurately by replacing with the mean of the same quantity on *all* support vectors. ]

Bruno