Class: Liblinear::Problem
- Inherits:
-
Object
- Object
- Liblinear::Problem
- Defined in:
- lib/liblinear/problem.rb
Instance Method Summary collapse
- #bias ⇒ Float
- #example_matrix ⇒ Liblinear::FeatureNodeMatrix
- #example_size ⇒ Integer
-
#initialize(labels, examples, bias = -1)) ⇒ Problem
constructor
A new instance of Problem.
- #labels ⇒ Array <Float>
- #max_feature_id ⇒ Integer
- #swig ⇒ Liblinearswig::Problem
Constructor Details
#initialize(labels, examples, bias = -1)) ⇒ Problem
Returns a new instance of Problem.
6 7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/liblinear/problem.rb', line 6 def initialize(labels, examples, bias = -1) @labels = labels @examples = examples @bias = bias @problem = Liblinearswig::Problem.new @problem.y = Liblinear::Array::Double.new(labels).swig @problem.x = example_matrix.swig @problem.bias = bias @problem.l = examples.size @problem.n = Liblinear::Example.max_feature_id(examples) @problem.n += 1 if bias >= 0 end |
Instance Method Details
#bias ⇒ Float
46 47 48 |
# File 'lib/liblinear/problem.rb', line 46 def bias @problem.bias end |
#example_matrix ⇒ Liblinear::FeatureNodeMatrix
41 42 43 |
# File 'lib/liblinear/problem.rb', line 41 def example_matrix Liblinear::FeatureNodeMatrix.new(@examples, @bias) end |
#example_size ⇒ Integer
26 27 28 |
# File 'lib/liblinear/problem.rb', line 26 def example_size @problem.l end |
#labels ⇒ Array <Float>
36 37 38 |
# File 'lib/liblinear/problem.rb', line 36 def labels Liblinear::Array::Double.decode(@problem.y, @labels.size) end |
#max_feature_id ⇒ Integer
31 32 33 |
# File 'lib/liblinear/problem.rb', line 31 def max_feature_id @problem.n end |
#swig ⇒ Liblinearswig::Problem
21 22 23 |
# File 'lib/liblinear/problem.rb', line 21 def swig @problem end |