Class: Liblinear::Parameter

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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(parameter = {}) ⇒ Parameter

Returns a new instance of Parameter.

Parameters:

  • parameter (Hash) (defaults to: {})


34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/liblinear/parameter.rb', line 34

def initialize(parameter = {})
  parameter[:weight_labels] = [] if parameter[:weight_labels].nil?
  parameter[:weights]       = [] if parameter[:weights].nil?

  @parameter = Liblinearswig::Parameter.new
  @parameter.solver_type  = parameter[:solver_type] || Liblinear::L2R_L2LOSS_SVC_DUAL
  @parameter.C            = parameter[:cost] || 1.0
  @parameter.p            = parameter[:sensitive_loss] || 0.1
  @parameter.eps          = parameter[:epsilon] || self.class.default_epsilon(@parameter.solver_type)
  @parameter.nr_weight    = parameter[:weight_labels].size
  @parameter.weight_label = Liblinear::Array::Integer.new(parameter[:weight_labels]).swig
  @parameter.weight       = Liblinear::Array::Double.new(parameter[:weights]).swig
end

Class Method Details

.default_epsilon(solver_type) ⇒ Float

Returns:

  • (Float)


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

def default_epsilon(solver_type)
  case solver_type
  when Liblinear::L2R_LR              then
    0.01
  when Liblinear::L2R_L2LOSS_SVC_DUAL then
    0.1
  when Liblinear::L2R_L2LOSS_SVC      then
    0.01
  when Liblinear::L2R_L1LOSS_SVC_DUAL then
    0.1
  when Liblinear::MCSVM_CS            then
    0.1
  when Liblinear::L1R_L2LOSS_SVC      then
    0.01
  when Liblinear::L1R_LR              then
    0.01
  when Liblinear::L2R_LR_DUAL         then
    0.1
  when Liblinear::L2R_L2LOSS_SVR      then
    0.001
  when Liblinear::L2R_L2LOSS_SVR_DUAL then
    0.1
  when Liblinear::L2R_L1LOSS_SVR_DUAL then
    0.1
  end
end

Instance Method Details

#costFloat

Returns:

  • (Float)


59
60
61
# File 'lib/liblinear/parameter.rb', line 59

def cost
  @parameter.C
end

#epsilonFloat

Returns:

  • (Float)


69
70
71
# File 'lib/liblinear/parameter.rb', line 69

def epsilon
  @parameter.eps
end

#sensitive_lossFloat

Returns:

  • (Float)


64
65
66
# File 'lib/liblinear/parameter.rb', line 64

def sensitive_loss
  @parameter.p
end

#solver_typeInteger

Returns:

  • (Integer)


54
55
56
# File 'lib/liblinear/parameter.rb', line 54

def solver_type
  @parameter.solver_type
end

#swigLiblinearswig::Parameter

Returns:

  • (Liblinearswig::Parameter)


49
50
51
# File 'lib/liblinear/parameter.rb', line 49

def swig
  @parameter
end

#weight_labelsArray <Integer>

Returns:



74
75
76
# File 'lib/liblinear/parameter.rb', line 74

def weight_labels
  Liblinear::Array::Integer.decode(@parameter.weight_label, @parameter.nr_weight)
end

#weightsArray <Float>

Returns:



79
80
81
# File 'lib/liblinear/parameter.rb', line 79

def weights
  Liblinear::Array::Double.decode(@parameter.weight, @parameter.nr_weight)
end