Top Level Namespace
Defined Under Namespace
Classes: Model, Parameter, Problem
Instance Method Summary
collapse
Instance Method Details
#_convert_to_svm_node_array(x) ⇒ Object
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
|
# File 'lib/svm.rb', line 105
def _convert_to_svm_node_array(x)
iter_range = []
if x.class == Hash
x.each {|k, v|
iter_range << k }
elsif x.class == Array
x.each_index {|j|
iter_range << j }
else
raise TypeError,"data must be a mapping or a sequence"
end
iter_range.sort
data = svm_node_array(iter_range.size+1)
svm_node_array_set(data,iter_range.size,-1,0)
j = 0
for k in iter_range
svm_node_array_set(data,j,k,x[k])
j = j + 1
end
return data
end
|
#_double_array(seq) ⇒ Object
15
16
17
18
19
20
21
22
23
24
|
# File 'lib/svm.rb', line 15
def _double_array(seq)
size = seq.size
array = new_double(size)
i = 0
for item in seq
double_setitem(array,i,item)
i = i + 1
end
return array
end
|
#_double_array_to_list(x, n) ⇒ Object
44
45
46
47
48
|
# File 'lib/svm.rb', line 44
def _double_array_to_list(x,n)
list = []
(0..n-1).each {|i| list << double_getitem(x,i) }
return list
end
|
#_free_double_array(x) ⇒ Object
32
33
34
35
36
|
# File 'lib/svm.rb', line 32
def _free_double_array(x)
if !x.nil? and !x.empty?
delete_double(x)
end
end
|
#_free_int_array(x) ⇒ Object
26
27
28
29
30
|
# File 'lib/svm.rb', line 26
def _free_int_array(x)
if !x.nil? and !x.empty?
delete_int(x)
end
end
|
#_int_array(seq) ⇒ Object
4
5
6
7
8
9
10
11
12
13
|
# File 'lib/svm.rb', line 4
def _int_array(seq)
size = seq.size
array = new_int(size)
i = 0
for item in seq
int_setitem(array,i,item)
i = i + 1
end
return array
end
|
#_int_array_to_list(x, n) ⇒ Object
38
39
40
41
42
|
# File 'lib/svm.rb', line 38
def _int_array_to_list(x,n)
list = []
(0..n-1).each {|i| list << int_getitem(x,i) }
return list
end
|
#cross_validation(prob, param, fold) ⇒ Object
328
329
330
331
332
333
334
335
336
337
|
# File 'lib/svm.rb', line 328
def cross_validation(prob, param, fold)
if param.gamma == 0
param.gamma = 1.0/prob.maxlen
end
dblarr = new_double(prob.size)
svm_cross_validation(prob.prob, param.param, fold, dblarr)
ret = _double_array_to_list(dblarr, prob.size)
delete_double(dblarr)
return ret
end
|