Class: Liblinear::Parameter
- Inherits:
-
Object
- Object
- Liblinear::Parameter
- Defined in:
- lib/liblinear/parameter.rb
Class Method Summary collapse
Instance Method Summary collapse
- #cost ⇒ Float
- #epsilon ⇒ Float
-
#initialize(parameter = {}) ⇒ Parameter
constructor
A new instance of Parameter.
- #sensitive_loss ⇒ Float
- #solver_type ⇒ Integer
- #swig ⇒ Liblinearswig::Parameter
- #weight_labels ⇒ Array <Integer>
- #weights ⇒ Array <Float>
Constructor Details
#initialize(parameter = {}) ⇒ Parameter
Returns a new instance of Parameter.
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
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
#cost ⇒ Float
59 60 61 |
# File 'lib/liblinear/parameter.rb', line 59 def cost @parameter.C end |
#epsilon ⇒ Float
69 70 71 |
# File 'lib/liblinear/parameter.rb', line 69 def epsilon @parameter.eps end |
#sensitive_loss ⇒ Float
64 65 66 |
# File 'lib/liblinear/parameter.rb', line 64 def sensitive_loss @parameter.p end |
#solver_type ⇒ Integer
54 55 56 |
# File 'lib/liblinear/parameter.rb', line 54 def solver_type @parameter.solver_type end |
#swig ⇒ Liblinearswig::Parameter
49 50 51 |
# File 'lib/liblinear/parameter.rb', line 49 def swig @parameter end |