Class: Svm::Options

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

Constant Summary collapse

DEFAULT_OPTIONS =
{
  :svm_type         => :c_svc,
  :kernel_type      => :rbf,
  :degree           => 3,
  :gamma            => 0,
  :coef0            => 0,
  :nu               => 0.5,
  :cache_size       => 100.0,
  :c                => 1,
  :eps              => 0.001,
  :p                => 0.1,
  :shrinking        => 1,
  :probability      => 0,
  :nr_weight        => 0,
  :cross_validation => 0,
  :nr_fold          => 0,
  :scale            => true
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(user_options = {}) ⇒ Options

Returns a new instance of Options.



26
27
28
29
# File 'lib/svm/options.rb', line 26

def initialize(user_options = {})
  @parameter_struct = ParameterStruct.new
  add(DEFAULT_OPTIONS.merge(user_options))
end

Instance Attribute Details

#parameter_structObject (readonly)

Returns the value of attribute parameter_struct.



5
6
7
# File 'lib/svm/options.rb', line 5

def parameter_struct
  @parameter_struct
end

Instance Method Details

#[](option) ⇒ Object



59
60
61
# File 'lib/svm/options.rb', line 59

def [](option)
  options_hash[option]
end

#add(more_options) ⇒ Object



31
32
33
34
35
36
37
# File 'lib/svm/options.rb', line 31

def add(more_options)
  options_hash.merge!(more_options)
  
  more_options.each do |key, value|
    parameter_struct[key] = value if parameter_struct.members.include?(key)
  end
end

#label_weights=(weights) ⇒ Object



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/svm/options.rb', line 39

def label_weights=(weights)
  @weights = weights
  
  num_labels = weights.keys.size
  
  parameter_struct[:nr_weight] = num_labels
  
  parameter_struct[:weight_label] = FFI::MemoryPointer.new(:int, num_labels)
  parameter_struct[:weight]       = FFI::MemoryPointer.new(:double, num_labels)
  
  labels_array = weights.keys.collect(&:to_i)
  
  parameter_struct[:weight_label].write_array_of_int(labels_array)
  parameter_struct[:weight].write_array_of_double(weights.values) 
end

#weightsObject



55
56
57
# File 'lib/svm/options.rb', line 55

def weights
  @weights ||= Hash.new(1.0)
end