Class: Liblinear::Problem

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

Instance Method Summary collapse

Constructor Details

#initialize(labels, examples, bias = -1)) ⇒ Problem

Returns a new instance of Problem.

Parameters:

  • labels (Array <Float>)
  • examples (Array <Array <Float> or Hash>)
  • bias (Float) (defaults to: -1))


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

#biasFloat

Returns:

  • (Float)


46
47
48
# File 'lib/liblinear/problem.rb', line 46

def bias
  @problem.bias
end

#example_matrixLiblinear::FeatureNodeMatrix



41
42
43
# File 'lib/liblinear/problem.rb', line 41

def example_matrix
  Liblinear::FeatureNodeMatrix.new(@examples, @bias)
end

#example_sizeInteger

Returns:

  • (Integer)


26
27
28
# File 'lib/liblinear/problem.rb', line 26

def example_size
  @problem.l
end

#labelsArray <Float>

Returns:



36
37
38
# File 'lib/liblinear/problem.rb', line 36

def labels
  Liblinear::Array::Double.decode(@problem.y, @labels.size)
end

#max_feature_idInteger

Returns:

  • (Integer)


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

def max_feature_id
  @problem.n
end

#swigLiblinearswig::Problem

Returns:

  • (Liblinearswig::Problem)


21
22
23
# File 'lib/liblinear/problem.rb', line 21

def swig
  @problem
end