Class: Liblinear::Problem
- Inherits:
-
Object
- Object
- Liblinear::Problem
- Includes:
- Liblinear, Liblinearswig
- Defined in:
- lib/liblinear/problem.rb
Constant Summary
Constants included from Liblinear
L1R_L2LOSS_SVC, L1R_LR, L2R_L1LOSS_SVC_DUAL, L2R_L1LOSS_SVR_DUAL, L2R_L2LOSS_SVC, L2R_L2LOSS_SVC_DUAL, L2R_L2LOSS_SVR, L2R_L2LOSS_SVR_DUAL, L2R_LR, L2R_LR_DUAL, MCSVM_CS, VERSION
Instance Attribute Summary collapse
-
#examples ⇒ Object
readonly
Returns the value of attribute examples.
-
#labels ⇒ Object
readonly
Returns the value of attribute labels.
-
#prob ⇒ Object
Returns the value of attribute prob.
Instance Method Summary collapse
-
#initialize(labels, examples, bias = -1)) ⇒ Problem
constructor
A new instance of Problem.
- #set_example_matrix ⇒ Object
Methods included from Liblinear
#array_to_hash, #convert_to_feature_node_array, #double_array_c_to_ruby, #free_double_array, #free_int_array, #int_array_c_to_ruby, #max_index, #new_double_array, #new_int_array
Constructor Details
#initialize(labels, examples, bias = -1)) ⇒ Problem
Returns a new instance of Problem.
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/liblinear/problem.rb', line 12 def initialize(labels, examples, bias = -1) unless labels.size == examples.size raise ArgumentError, 'labels and examples must be same size' end @prob = Liblinearswig::Problem.new @labels = labels c_labels = new_double_array(@labels) @examples = examples @bias = bias @max_example_index = max_index(@examples) @example_matrix = feature_node_matrix(examples.size) @c_example_array = [] set_example_matrix @prob.tap do |p| p.y = c_labels p.x = @example_matrix p.bias = bias p.l = examples.size p.n = @max_example_index p.n += 1 if bias >= 0 end end |
Instance Attribute Details
#examples ⇒ Object (readonly)
Returns the value of attribute examples.
6 7 8 |
# File 'lib/liblinear/problem.rb', line 6 def examples @examples end |
#labels ⇒ Object (readonly)
Returns the value of attribute labels.
6 7 8 |
# File 'lib/liblinear/problem.rb', line 6 def labels @labels end |
#prob ⇒ Object
Returns the value of attribute prob.
5 6 7 |
# File 'lib/liblinear/problem.rb', line 5 def prob @prob end |
Instance Method Details
#set_example_matrix ⇒ Object
37 38 39 40 41 42 43 |
# File 'lib/liblinear/problem.rb', line 37 def set_example_matrix @examples.size.times do |index| c_example = convert_to_feature_node_array(@examples[index], @max_example_index, @bias) @c_example_array << c_example feature_node_matrix_set(@example_matrix, index, c_example) end end |