Join/Login

Business Software

Open Source Software

For Vendors

Blog

About

More

Articles

Create

SourceForge Podcast

Site Documentation

Subscribe to our Newsletter

Support Request

For Vendors Help Create Join Login

Business Software

Open Source Software

SourceForge Podcast

Resources

Articles

Case Studies

Blog

Menu

Help

Create

Join

Login

Home

Browse

The Simple SVM toolbox

Code

The Simple SVM toolbox Code

Brought to you by: gloosli

Summary

Files

Reviews

Support

Code

Menu ▾ ▴

Browse Commits

Browse Files

[r6]: / utils / kernelMult.m  Maximize  Restore  History

Download this file

132 lines (131 with data), 5.3 kB

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132

function f = kernelMult(d,x1,x2,x3,ind)

switch d.name

case 'rbf'

if nargin==3

dot_a = sum(x1.*x1, 1);

unitvec = ones(1,size(x1,2));

f = exp(d.sigma * (2 * x1' * x1 - dot_a - dot_a' * unitvec)) * x2;

elseif nargin==4

dot_a = sum(x1.*x1, 1);

dot_b = sum(x2.*x2, 1);

unitvec = ones(1,size(x2,2));

f =exp(d.sigma * (2 * x1' * x2 - ones(size(dot_a,2),1)*dot_b - dot_a' * unitvec)) * x3;

else

errormsg('wrong number of input arguments');

end

case 'rbfmax'

if nargin==4

unitvec = ones(1,size(x1,2));

for i=1:size(x2,2)

f(:,i) =max(exp(d.sigma * (-max(abs(x1 - x2(:,i)*unitvec) ,[], 1)')),d.conv);

end

f = f*x3;

else

error('wrong number of input arguments');

end

case 'rbf1'

if nargin==4

unitvec = ones(1,size(x1,2));

for i=1:size(x2,2)

f(:,i) =exp(d.sigma * (-sum(abs(x1 - x2(:,i)*unitvec) , 1)'));

end

f = f*x3;

else

error('wrong number of input arguments');

end

case 'rbfconv'

if nargin==3

dot_a = sum(x1.*x1, 1);

unitvec = ones(1,size(x1,2));

f = max(exp(d.sigma * (2 * x1' * x1 - dot_a - dot_a' * unitvec)),d.conv) * x2;

elseif nargin==4

dot_a = sum(x1.*x1, 1);

dot_b = sum(x2.*x2, 1);

unitvec = ones(1,size(x2,2));

f =max(exp(d.sigma * (2 * x1' * x2 - ones(size(dot_a,2),1)*dot_b - dot_a' * unitvec)),d.conv) * x3;

else

errormsg('wrong number of input arguments');

end

case 'ratio'

if nargin==3

dot_a = sum(x1.*x1, 1);

unitvec = ones(1,size(x1,2));

f = (1- (-2 * x1' * x1 + dot_a + dot_a' * unitvec)./(-2 * x1' * x1 + dot_a + dot_a' * unitvec + d.sigma)) * x2;

elseif nargin==4

dot_a = sum(x1.*x1, 1);

dot_b = sum(x2.*x2, 1);

unitvec = ones(1,size(x2,2));

f =(1- (-2 * x1' * x2 + ones(size(dot_a,2),1)*dot_b + dot_a' * unitvec)./(-2 * x1' * x2 + ones(size(dot_a,2),1)*dot_b + dot_a' * unitvec + d.sigma)) * x3;

else

errormsg('wrong number of input arguments');

end

case 'simq'

if nargin==3

dot_a = sum(x1.*x1, 1);

unitvec = ones(1,size(x1,2));

f = sqrt(1- (-2 * x1' * x1 + dot_a + dot_a' * unitvec)./(-2 * x1' * x1 + dot_a + dot_a' * unitvec + d.sigma)) * x2;

elseif nargin==4

dot_a = sum(x1.*x1, 1);

dot_b = sum(x2.*x2, 1);

unitvec = ones(1,size(x2,2));

f =sqrt(1- (-2 * x1' * x2 + ones(size(dot_a,2),1)*dot_b + dot_a' * unitvec)./(-2 * x1' * x2 + ones(size(dot_a,2),1)*dot_b + dot_a' * unitvec + d.sigma)) * x3;

else

errormsg('wrong number of input arguments');

end

case 'poly'

if nargin==3

f = (d.scale * x1' * x1 +d.offset).^d.degree * x2;

elseif nargin==4

f =(d.scale * x1' * x2 + d.offset).^d.degree * x3;

else

errormsg('wrong number of input arguments');

end

case 'polynorm'

if nargin==3

f = (((d.scale * x1' * x1 +d.offset).^d.degree)./ ...

(diag(d.scale * x1' * x1 +1).^d.degree))* x2;

elseif nargin==4

f = (((d.scale * x1' * x2 +d.offset).^d.degree)./ ...

(sqrt(diag((d.scale * x1' * x1 +d.offset).^d.degree)*...

diag((d.scale * x2' * x2 +d.offset).^d.degree)')))* x3;

else

error('wrong number of input arguments');

end

case 'gauss'

if nargin==3

dot_a = sum(x1.*x1, 1);

unitvec = ones(1,size(x1,2));

f = (1/sqrt(2*pi*d.sigma))*(exp((2 * x1' * x1 - dot_a - dot_a' * unitvec)./(2*d.sigma)) * x2);

elseif nargin==4

dot_a = sum(x1.*x1, 1);

dot_b = sum(x2.*x2, 1);

unitvec = ones(1,size(x2,2));

f = (1/sqrt(2*pi*d.sigma))*(exp((2 * x1' * x2 - ones(size(dot_a,2),1)*dot_b - dot_a' * unitvec)./(2*d.sigma)) * x3);

else

errormsg('wrong number of input arguments');

end

case 'epanech'

if nargin==3

dot_a = sum(x1.*x1, 1);

unitvec = ones(1,size(x1,2));

f = (max(1+d.sigma * (2 * x1' * x1 - dot_a - dot_a' * unitvec * x2),0));

elseif nargin==4

dot_a = sum(x1.*x1, 1);

dot_b = sum(x2.*x2, 1);

unitvec = ones(size(x1,2),1);

f = x1' * x2;

for i=1:size(x2,2)

f(:,i) = (max(1+(d.sigma * (2 * f(:,i) - dot_a' - dot_b(i) * unitvec)),0))* x3(i);

end

else

errormsg('wrong number of input arguments');

end

case 'tanh'

if nargin==3

f = tanh(d.a*(x1'*x1) + d.r)*x2;

elseif nargin==4

f = tanh(d.a*(x1'*x2) + d.r)*x3;

else

error('wrong number of input arguments');

end

end

SourceForge

Create a Project

Open Source Software

Business Software

Top Downloaded Projects

Company

About

Team

SourceForge Headquarters
225 Broadway Suite 1600
San Diego, CA 92101
+1 (858) 422-6466

Resources

Support

Site Documentation

Site Status

SourceForge Reviews

© 2025 Slashdot Media. All Rights Reserved.

Terms Privacy Opt Out Advertise

×
Want the latest updates on software, tech news, and AI?

Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.

Submit