Class: SVM::Problem

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(y, *x) ⇒ Problem

Returns a new instance of Problem.



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/libsvm/problem.rb', line 6

def initialize(y, *x)
  #assert y.size == x.size
  @max = x.flatten.max #aggh hate doing this...
  @prob = prob = Svm_problem.new 
  @size = size = y.size

  @y_array = y_array = new_double(size)
  y.each_with_index do |label, i|
    double_setitem(@y_array, i, label)
  end

  @x_matrix = x_matrix = svm_node_matrix(size)
  @data = []
  @maxlen = max
  x.each_with_index do |row, i|
    @data << SVM.convert_to_svm_node_array(row, max)
    svm_node_matrix_set(x_matrix, i, @data.last)
    @maxlen = [@maxlen, row.size].max
  end

  prob.l = size
  prob.y = y_array
  prob.x = x_matrix
end

Instance Attribute Details

#maxObject (readonly)

Returns the value of attribute max.



4
5
6
# File 'lib/libsvm/problem.rb', line 4

def max
  @max
end

#maxlenObject

Returns the value of attribute maxlen.



3
4
5
# File 'lib/libsvm/problem.rb', line 3

def maxlen
  @maxlen
end

#probObject

Returns the value of attribute prob.



3
4
5
# File 'lib/libsvm/problem.rb', line 3

def prob
  @prob
end

#sizeObject

Returns the value of attribute size.



3
4
5
# File 'lib/libsvm/problem.rb', line 3

def size
  @size
end

Instance Method Details

#destroyObject



35
36
37
38
39
40
41
42
# File 'lib/libsvm/problem.rb', line 35

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



31
32
33
# File 'lib/libsvm/problem.rb', line 31

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