Class: Parameter

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ Parameter

Returns a new instance of Parameter.



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/svm.rb', line 53

def initialize(*args)
  @param = Svm_parameter.new
  @param.svm_type = C_SVC
  @param.kernel_type = RBF
  @param.degree = 3
  @param.gamma = 0    # 1/k
  @param.coef0 = 0
  @param.nu = 0.5
  @param.cache_size = 100
  @param.C = 1
  @param.eps = 1e-3
  @param.p = 0.1
  @param.shrinking = 1
  @param.nr_weight = 0
  #@param.weight_label = _int_array([])
  #@param.weight = _double_array([])
  @param.probability = 0
  
  args[0].each {|k,v| 
    self.send("#{k}=",v)
  } if !args[0].nil?
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(m, *args) ⇒ Object



76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# File 'lib/svm.rb', line 76

def method_missing(m, *args)
  if m.to_s == 'weight_label='
    @weight_label_len = args[0].size
    pargs = _int_array(args[0])
    _free_int_array(@param.weight_label)
  elsif m.to_s == 'weight='
    @weight_len = args[0].size
    pargs = _double_array(args[0])
    _free_double_array(@param.weight)
  else
    pargs = args[0]
  end
  
  if m.to_s.index('=')
    @param.send("#{m}",pargs)
  else
    @param.send("#{m}")
  end
  
end

Instance Attribute Details

#paramObject

Returns the value of attribute param.



51
52
53
# File 'lib/svm.rb', line 51

def param
  @param
end

Instance Method Details

#destroyObject



97
98
99
100
101
102
# File 'lib/svm.rb', line 97

def destroy
  _free_int_array(@param.weight_label)
  _free_double_array(@param.weight)
  #delete_svm_parameter(@param)
  @param = nil
end