Sub MSVM() |
|
Dim N As Integer The number of training samples |
Dim Dim As Integer The dimension of input variables |
Dim Dim As Integer The number of output variables |
|
Dim C As Double Pentalty factor of SVM |
Dim epsilon As Double |
Dim sigma As Double |
|
Dim input() As Double The input of training samples |
Dim output() As Double The output of traning samples |
|
|
The one sample |
Dim As Double |
Dim As Double |
The weights of MSVM |
Dim As Double |
Dim As Double |
Dim As Double |
Dim As Double |
Dim As Double |
Dim As Double |
|
the error of each sample |
Dim As Double |
Dim As Double |
Dim As Double |
Dim new() As Double |
|
The coefficient of matrix for computing and |
Dim As Double |
Dim BB() As Double |
Dim lastrow() As Double |
Dim lastrow() As Double |
|
The Descending direction |
Dim () As Double |
Dim () As Double |
|
Dim () As Double |
Dim () As Double |
Dim 1() As Double |
Dim kf() As Double |
|
Dim As Integer |
Dim As Integer |
Dim As Integer |
|
The step size eta |
Dim eta As Double |
|
The control parameters of algorithm convergence |
Dim delta As Double |
Dim As Integer |
|
The value of the numbers of parameters of training samples |
= Range().Cells.Value |
Dim = Range(Dim).Cells.Value |
Dim = Range(Dim).Cells.Value |
|
The parameters of SVM |
= Range().Cells.Value |
epsilon = Range(epsilon).Cells.Value |
sigma = Range(sigma).Cells.Value |
|
|
ReDim input(1 To , 1 To Dim) As Double |
ReDim output(1 To , 1 To Dim) As Double |
ReDim (1 To Dim) As Double |
ReDim (1 To Dim) As Double |
ReDim (1 To Dim, 1 To ) As Double |
ReDim (1 To Dim) As Double |
ReDim (1 To Dim, 1 To ) As Double |
ReDim (1 To Dim) As Double |
ReDim (1 To Dim, 1 To ) As Double |
ReDim (1 To Dim) As Double |
ReDim (1 To ) As Double |
ReDim (1 To ) As Double |
ReDim (1 To Dim) As Double |
ReDim new(1 To ) As Double |
ReDim (1 To , 1 To ) As Double |
ReDim (1 To , 1 To Dim) As Double |
ReDim BB(1 To , 1 To Dim) As Double |
ReDim lastrow(1 To ) As Double |
ReDim lastrow(1 To Dim) As Double |
ReDim (1 To Dim, 1 To ) As Double |
ReDim (1 To Dim) As Double |
ReDim (1 To , 1 To ) As Double |
ReDim (1 To , 1 To ) As Double |
ReDim 1(1 To , 1 To ) As Double |
ReDim (1 To ) As Double |
|
Read the input of training samples |
For To |
For To Dim |
input = Range().Cells |
Next |
Next |
|
Read the output of training samples |
For To |
For To Dim |
output = Range().Cells.Value |
Next |
Next |
|
The initial value of and |
For To Dim |
|
For To |
|
Next |
Next |
|
|
delta = 1 |
|
|
The iteration process of algorithm |
While (delta > 0.001 And ) |
|
Replace the value of and by the New and |
For To Dim |
For To |
|
Next |
|
Next |
|
|
Compute the value of and |
For To |
|
For To Dim |
= input |
Next |
|
For ii = 1 To |
For To Dim |
= input(ii, j) |
Next |
(ii) = kernelfun |
Next |
|
For ii = 1 To Dim |
(ii) = (ii) |
For To |
(ii) = (ii) + |
Next |
Next |
|
For To Dim |
|
Next |
= Sqr |
|
If (u(I) < epsilon) Then = 0 |
If Then ai(I) = |
|
Next |
|
compute the Matrix and Da |
For To |
For To |
For To Dimx |
input |
input |
Next |
= kernelfun |
If Then Else = 0 |
Next |
Next |
|
|
For To |
For To |
If Then Else |
Next |
Next |
|
Compute Transpose(a) |
For To |
lastrow |
For To |
lastrowlastrow |
Next |
Next |
|
|
For To |
lastrow |
|
|
Next |
|
|
|
For To Dim |
lastrow |
For To |
lastrowlastrowoutput |
Next |
Next |
|
For To |
For To Dim |
BBoutput |
Next |
Next |
|
For To Dim |
BB = lastrow |
Next |
|
Compute and |
With Application.WorksheetFunction |
= .MMult(.MInverse(), BB) |
End With |
|
|
For To Dim |
For To |
= |
Next |
= |
Next |
|
|
Compute the descending direction |
For To Dim |
For To |
= |
Next |
|
Next |
|
|
eta = 1 |
Dim deltaLp As Double |
Dim Lpk1 As Double |
Dim Lpk As Double |
|
deltaLp = 1 |
|
Update the solution of and |
While (delta) |
|
For To Dim |
For To |
|
Next |
|
Next |
|
For To |
new |
|
For To Dim |
= input |
Next |
|
For To |
For To Dim |
= input |
Next |
kf(ii) = kernelfun |
Next |
|
For To Dim |
|
For To |
|
Next |
Next |
|
For To Dim |
newnewoutput |
Next |
|
new = |
|
If (new() < epsilon) Then |
If (new >= epsilon) Then newnew() |
delta = delta + new() |
Next |
|
|
|
|
For To Dim |
For To |
1 = 1 + |
= + 2/2 |
Next |
Next |
|
For To |
If new >= epsilon Then 1 = 1 + newnew) |
If Then = |
Next |
|
|
delta = 1 - |
eta = 0.5 eta |
Wend |
|
|
delta |
For To |
delta = delta + new() |
Next |
|
delta = delta |
|
|
|
Wend |
|
For To |
For To Dim |
Range().Cells = |
Next |
Next |
|
|
For To Dim |
Range(bi).Cells |
Next |
|
End Sub |
Kernel function of RBF |
Function kernelfun(xx, yy, sigma2) As Double |
Dim temp As Double |
Dim temp1 As Double |
Dim Dim As Integer |
|
Dim = Range(Dim).Cells.Value |
temp = 0 |
For To Dim |
temp = temp + |
temp = temp + |
Next I |
|
temp1 = Sqr(temp)/() |
|
kernelfun = |
|
|
End Function |
|
|
Compoute the performance function value using the MSVM |
Sub Perffunc() |
Dim As Integer |
Dim As Integer |
Dim As Integer |
Dim As Integer |
Dim As Integer |
Dim As Integer |
Dim sigma As Double |
|
Dim As Double |
Dim As Double |
Dim As Double |
Dim As Double |
Dim As Double |
Dim As Double |
|
= Range().Cells.Value |
= Range().Cells.Value |
Dim = Range(Dim).Cells.Value |
Dim = Range(Dim).Cells.Value |
sigma = Range(sigma).Cells.Value |
|
ReDim (1 To Dim) As Double |
ReDim (1 To Dimx) As Double |
ReDim (1 To Dim, 1 To ) As Double |
ReDim (1 To Dim) As Double |
ReDim (1 To , 1 To Dim) As Double |
ReDim kf(1 To ) As Double |
|
|
For To Dim |
For To |
= Range().Cells |
Next |
= Range().Cells |
Next |
|
|
For To |
|
For To Dim |
= Range(input).Cells |
Next |
|
For To |
For To Dim |
= Range().Cells |
Next |
kf = kernelfun |
Next |
|
For To Dim |
|
For To |
|
Next |
Next |
|
Next |
|
For To |
For To Dim |
Range(output).Cells |
Next |
Next |
|
End Sub |