Class: MM::Metric

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(ordered: true, pair: nil, scale: nil, intra_delta: nil, inter_delta: nil) ⇒ Metric

Constructor for the Metric object.

ordered - [Boolean]

Controls whether metric is ordered

pair - [Symbol, #call]

Method of +MM::Deltas+, or where +Object#call+ returns an +Array+ of
pairs.

scale - [Symbol, #call]

Method of +MM::Scaling+, or where +Object#call+ returns a scaled diff
+Array+

intra_delta - [Symbol, #call]

Method of +MM::Deltas+, or where +Object#call+ returns +Array+ of
differences between pairs of elements

inter_delta - [Symbol, #call]

Method of +MM::Deltas+, or where +Object#call+ returns +Array+ of
differences between the diffs of the two input morphologies


22
23
24
25
26
27
28
# File 'lib/mm/metric.rb', line 22

def initialize(ordered: true, pair: nil, scale: nil, intra_delta: nil, inter_delta: nil)
  @ordered = ordered
  self.pair = pair
  self.scale = scale
  self.intra_delta = intra_delta
  self.inter_delta = inter_delta
end

Instance Attribute Details

#orderedObject

Returns the value of attribute ordered.



30
31
32
# File 'lib/mm/metric.rb', line 30

def ordered
  @ordered
end

Instance Method Details

#call(v1, v2) ⇒ Object

Public: Gets the distance between two vectors, according to the Metric object. Since Metric can be duck-typed to work with intra_delta and inter_delta, it should be possible to nest Metric objects.

v1 - The vector to call on. v2 - The vector to compare against.

Returns a [Float] distance between the two vectors.



40
41
42
43
44
# File 'lib/mm/metric.rb', line 40

def call v1, v2
  # "Readable" method provided for the parenthetically inclined
  # inter_delta(scale(intra_delta(get_pairs(v1, v2))))
  inter_delta scale intra_delta get_pairs v1, v2
end

#inter_delta=(inter_delta) ⇒ Object

Public: Setter method for inter_delta.

inter_delta - Either a Proc that can process as an inter_delta, or a

Symbol where +MM::Deltas.respond_to? Symbol == true+

Returns itself. Sets the instance variable @inter_delta.



83
84
85
# File 'lib/mm/metric.rb', line 83

def inter_delta= inter_delta
  protected_use_method(MM::Deltas, :@inter_delta, inter_delta)
end

#intra_delta=(intra_delta) ⇒ Object

Public: Setter method for intra_delta.

intra_delta - Either a Proc that can process the intra_delta, or a Symbol

to look up in MM::Deltas.

Returns intra_delta.



73
74
75
# File 'lib/mm/metric.rb', line 73

def intra_delta= intra_delta
  protected_use_method(MM::Deltas, :@intra_delta, intra_delta)
end

#pair=(pair) ⇒ Object

Public: Setter method for pair.

pair - [Symbol, #call]

Method of +MM::Deltas+, or where +Object#call+ returns an +Array+ of
pairs.

Returns a [Proc] pair.



53
54
55
# File 'lib/mm/metric.rb', line 53

def pair= pair
  protected_use_method(MM::Pairs.new, :@pair, pair)
end

#scale=(scale) ⇒ Object

Public: Setter method for scale.

scale - Either a Proc that can process scaling, or a Symbol to look up in

MM::Scaling.

Returns scale.



63
64
65
# File 'lib/mm/metric.rb', line 63

def scale= scale
  protected_use_method(MM::Scaling, :@scale, scale)
end