Class: Weka::Core::DenseInstance

Inherits:
Object
  • Object
show all
Defined in:
lib/weka/core/dense_instance.rb

Instance Method Summary collapse

Constructor Details

#initialize(data, weight: 1.0) ⇒ DenseInstance

Returns a new instance of DenseInstance.



9
10
11
# File 'lib/weka/core/dense_instance.rb', line 9

def initialize(data, weight: 1.0)
  super(weight, data.to_java(:double))
end

Instance Method Details

#attributesObject



13
14
15
# File 'lib/weka/core/dense_instance.rb', line 13

def attributes
  enumerate_attributes.to_a
end

#each_attributeObject



17
18
19
20
21
22
23
# File 'lib/weka/core/dense_instance.rb', line 17

def each_attribute
  if block_given?
    enumerate_attributes.each { |attribute| yield(attribute) }
  else
    enumerate_attributes
  end
end

#each_attribute_with_indexObject



25
26
27
28
29
# File 'lib/weka/core/dense_instance.rb', line 25

def each_attribute_with_index
  enumerate_attributes.each_with_index do |attribute, index|
    yield(attribute, index) if block_given?
  end
end

#to_aObject Also known as: values



31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/weka/core/dense_instance.rb', line 31

def to_a
  to_double_array.each_with_index.map do |value, index|
    attribute = attribute_at(index)

    if attribute.date?
      format_date(value, attribute.date_format)
    elsif attribute.numeric?
      value
    elsif attribute.nominal?
      attribute.value(value)
    end
  end
end