Skip to content

Commit 08f8dbb

Browse files
author
datastream
committed
start import 3.14
1 parent 7d64895 commit 08f8dbb

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

svm.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1907,11 +1907,13 @@ func (this *SVM) SVM_train(prob *SVM_Problem, param *SVM_Parameter) *SVM_Model {
19071907
model.l = nSV
19081908
model.SV = make([][]SVM_Node, nSV)
19091909
model.sv_coef[0] = make([]float64, nSV)
1910+
model.sv_indices = make([]int, nSV)
19101911
j := 0
19111912
for i = 0; i < prob.l; i++ {
19121913
if math.Abs(f.alpha[i]) > 0 {
19131914
model.SV[j] = prob.x[i]
19141915
model.sv_coef[0][j] = f.alpha[i]
1916+
model.sv_indices[j] = i+1
19151917
j++
19161918
}
19171919
}
@@ -2065,10 +2067,12 @@ func (this *SVM) SVM_train(prob *SVM_Problem, param *SVM_Parameter) *SVM_Model {
20652067

20662068
model.l = nnz
20672069
model.SV = make([][]SVM_Node, nnz)
2070+
model.sv_indices = make([]int, nnz)
20682071
p = 0
20692072
for i = 0; i < l; i++ {
20702073
if nonzero[i] {
20712074
model.SV[p] = x[i]
2075+
model.sv_indices[p] = perm[i] + 1
20722076
p++
20732077
}
20742078
}
@@ -2244,6 +2248,18 @@ func (this *SVM) SVM_get_labels(model *SVM_Model, label []int) {
22442248
}
22452249
}
22462250

2251+
func (this *SVM) SVM_get_sv_indices(model SVM_Model, indices []int) {
2252+
if model.sv_indices != nil {
2253+
for i:=0; i<model.l; i++ {
2254+
indices[i] = model.sv_indices[i]
2255+
}
2256+
}
2257+
}
2258+
2259+
func (this *SVM) SVM_get_nr_sv(model SVM_Model) int {
2260+
return model.l
2261+
}
2262+
22472263
func (this *SVM) SVM_get_svr_probability(model *SVM_Model) float64 {
22482264
var rst float64
22492265
if (model.param.svm_type == EPSILON_SVR || model.param.svm_type == NU_SVR) && model.probA != nil {

svm_model.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ type SVM_Model struct {
99
rho []float64 // constants in decision functions (rho[k*(k-1)/2])
1010
probA []float64 // pariwise probability information
1111
probB []float64
12+
sv_indices []int // sv_indices[0,...,nSV-1] are values in [1,...,num_traning_data] to indicate SVs in the training set
1213

1314
label []int // label of each class (label[k])
1415
nSV []int // number of SVs for each class (nSV[k]) nSV[0] + nSV[1] + ... + nSV[k-1] = l

0 commit comments

Comments
 (0)