Class: SVM::Problem
- Inherits:
-
Object
- Object
- SVM::Problem
- Defined in:
- lib/libsvm/problem.rb
Instance Attribute Summary collapse
-
#max ⇒ Object
readonly
Returns the value of attribute max.
-
#maxlen ⇒ Object
Returns the value of attribute maxlen.
-
#prob ⇒ Object
Returns the value of attribute prob.
-
#size ⇒ Object
Returns the value of attribute size.
Instance Method Summary collapse
- #destroy ⇒ Object
-
#initialize(y, *x) ⇒ Problem
constructor
A new instance of Problem.
- #inspect ⇒ Object
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
#max ⇒ Object (readonly)
Returns the value of attribute max.
4 5 6 |
# File 'lib/libsvm/problem.rb', line 4 def max @max end |
#maxlen ⇒ Object
Returns the value of attribute maxlen.
3 4 5 |
# File 'lib/libsvm/problem.rb', line 3 def maxlen @maxlen end |
#prob ⇒ Object
Returns the value of attribute prob.
3 4 5 |
# File 'lib/libsvm/problem.rb', line 3 def prob @prob end |
#size ⇒ Object
Returns the value of attribute size.
3 4 5 |
# File 'lib/libsvm/problem.rb', line 3 def size @size end |
Instance Method Details
#destroy ⇒ Object
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 |
#inspect ⇒ Object
31 32 33 |
# File 'lib/libsvm/problem.rb', line 31 def inspect return "Problem: size = #{size}" end |