Class: Dwarf::Classifier

Inherits:
Object
  • Object
show all
Includes:
ExampleManagement
Defined in:
lib/dwarf/classifier.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from ExampleManagement

#attribute_map, #classification_map, #eval_attribute, #filter_classifications, #invert_with_dups

Constructor Details

#initializeClassifier

Returns a new instance of Classifier.



9
10
11
12
13
# File 'lib/dwarf/classifier.rb', line 9

def initialize()
  @examples, @example_attributes = {}, []
  @decision_tree = TreeNode.new("ROOT")
  @nil_name = Object.new.to_s
end

Instance Attribute Details

#classifier_logicObject

Returns the value of attribute classifier_logic.



6
7
8
# File 'lib/dwarf/classifier.rb', line 6

def classifier_logic
  @classifier_logic
end

#decision_treeObject (readonly)

Returns the value of attribute decision_tree.



7
8
9
# File 'lib/dwarf/classifier.rb', line 7

def decision_tree
  @decision_tree
end

#example_attributesObject

Returns the value of attribute example_attributes.



5
6
7
# File 'lib/dwarf/classifier.rb', line 5

def example_attributes
  @example_attributes
end

#examplesObject

Returns the value of attribute examples.



4
5
6
# File 'lib/dwarf/classifier.rb', line 4

def examples
  @examples
end

Instance Method Details

#add_example(example_record, classification) ⇒ Object



21
22
23
24
# File 'lib/dwarf/classifier.rb', line 21

def add_example(example_record, classification)
  @examples[example_record]=classification
  @example_attributes |= example_record.attribute_names
end

#add_examples(example_hash) ⇒ Object



15
16
17
18
19
# File 'lib/dwarf/classifier.rb', line 15

def add_examples(example_hash)
  example_hash.each do |example, classification|
    add_example(example, classification)
  end
end

#classify(example) ⇒ Object



26
27
28
# File 'lib/dwarf/classifier.rb', line 26

def classify(example)
  return nil
end

#find_by_classification(world, classification) ⇒ Object



37
38
39
40
41
42
43
44
45
# File 'lib/dwarf/classifier.rb', line 37

def find_by_classification(world, classification)
  matches = []
  world.each do |instance|
    if classify(instance) == classification
      matches << instance
    end
  end
  matches
end

#learn!Object



30
31
32
33
34
35
# File 'lib/dwarf/classifier.rb', line 30

def learn!
  @decision_tree.examples = @examples.keys
  converge_tree
  self.classifier_logic = codify_tree(@decision_tree)
  implement_classify
end