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 / kernelPol.m  Maximize  Restore  History

Download this file

180 lines (178 with data), 6.8 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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179

function f = kernelPol(d,x1,x2,x3,x4,ind)

switch d.name

case 'rbf'

if nargin==3

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

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

f = x1' * x1;

for i=1:size(x1,2)

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

end

elseif nargin==5

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) = x4(i) * (exp(d.sigma * (2 * f(:,i) - dot_a' - dot_b(i) * unitvec)) .* x3);

end

else

error('wrong number of input arguments');

end

case 'rbfmax'

if nargin==5

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

for i=1:size(x2,2)

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

end

else

error('wrong number of input arguments');

end

case 'rbf1'

if nargin==5

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

for i=1:size(x2,2)

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

end

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 = x1' * x1;

for i=1:size(x1,2)

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

end

elseif nargin==5

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) = x4(i) * (max(exp(d.sigma * (2 * f(:,i) - dot_a' - dot_b(i) * unitvec)),d.conv) .* x3);

end

else

error('wrong number of input arguments');

end

case 'ratio'

if nargin==3

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

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

f = x1' * x1;

for i=1:size(x1,2)

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

end

elseif nargin==5

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) = x4(i) * ((1-((-2 * f(:,i) + dot_a' + dot_b(i) * unitvec)./(-2 * f(:,i) + dot_a' + dot_b(i) * unitvec+d.sigma))) .* x3);

end

else

error('wrong number of input arguments');

end

case 'simq'

if nargin==3

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

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

f = x1' * x1;

for i=1:size(x1,2)

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

end

elseif nargin==5

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) = x4(i) * (sqrt(1-((-2 * f(:,i) + dot_a' + dot_b(i) * unitvec)./(-2 * f(:,i) + dot_a' + dot_b(i) * unitvec+d.sigma))) .* x3);

end

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 = x1' * x1;

for i=1:size(x1,2)

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

end

elseif nargin==5

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) = (1/sqrt(2*pi*d.sigma))*(x4(i) * (exp((2 * f(:,i) - dot_a' - dot_b(i) * unitvec)./(2*d.sigma)) .* x3));

end

else

error('wrong number of input arguments');

end

case 'poly'

if nargin==3

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

for i=1:size(x1,2)

f(:,i) = x2(i) * (f(:,i) .* x2);

end

elseif nargin==5

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

for i=1:size(x2,2)

f(:,i) = x4(i) * (f(:,i) .* x3);

end

else

error('wrong number of input arguments');

end

case 'polynorm'

temp.name = 'poly';

temp.scale = d.scale;

temp.degree = d.degree;

if nargin==3

f = kernelPol(temp, x1, x2)./(sqrt(diag(kernelPol(temp, x1, x2))*diag(kernelPol(temp, x1, x2))'));

elseif nargin==5

f = kernelPol(temp, x1, x2, x3, x4)./(sqrt(diag(kernelPol(temp, x1, x3))*diag(kernelPol(temp, x2, x4))'));

else

error('wrong number of input arguments');

end

case 'epanech'

if nargin==3

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

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

f = x1' * x1;

for i=1:size(x1,2)

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

end

elseif nargin==5

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) = x4(i) *(max(1+(d.sigma * (2 * f(:,i) - dot_a' - dot_b(i) * unitvec)),0)).* x3;

end

else

error('wrong number of input arguments');

end

case 'tanh'

if nargin==3

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

for i=1:size(x1,2)

f(:,i) = x2(i) * (f(:,i) .* x2);

end

elseif nargin==5

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

for i=1:size(x2,2)

f(:,i) = x4(i) * (f(:,i) .* x3);

end

% if nargin==3

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

% elseif nargin==5

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

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