Class: Problem

Inherits:
Object
  • Object
show all
Defined in:
lib/svm.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(y, x) ⇒ Problem

Returns a new instance of Problem.



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
# File 'lib/svm.rb', line 138

def initialize(y,x)
  #assert y.size == x.size
  @prob = prob = Svm_problem.new 
  @size = size = y.size
  
  @y_array = y_array = new_double(size)
  for i in (0..size-1)
    double_setitem(@y_array,i,y[i])
  end
  
  @x_matrix = x_matrix = svm_node_matrix(size)
  @data = []
  @maxlen = 0
  for i in (0..size-1)
    data = _convert_to_svm_node_array(x[i])
    @data << data
    svm_node_matrix_set(x_matrix,i,data)
    if x[i].class == Hash
      if x[i].size > 0
        @maxlen = [@maxlen,x[i].keys.max].max
      end
    else
      @maxlen = [@maxlen,x[i].size].max
    end
  end
  
  prob.l = size
  prob.y = y_array
  prob.x = x_matrix
end

Instance Attribute Details

#maxlenObject

Returns the value of attribute maxlen.



136
137
138
# File 'lib/svm.rb', line 136

def maxlen
  @maxlen
end

#probObject

Returns the value of attribute prob.



136
137
138
# File 'lib/svm.rb', line 136

def prob
  @prob
end

#sizeObject

Returns the value of attribute size.



136
137
138
# File 'lib/svm.rb', line 136

def size
  @size
end

Instance Method Details

#destroyObject



173
174
175
176
177
178
179
180
# File 'lib/svm.rb', line 173

def destroy
  delete_svm_problem(@prob)
  delete_double(@y_array)
  for i in (0..size-1)
    svm_node_array_destroy(@data[i])
  end
  svm_node_matrix_destroy(@x_matrix)
end

#inspectObject



169
170
171
# File 'lib/svm.rb', line 169

def inspect
  return "Problem: size = #{size}"
end