Class: MM::Metric
- Inherits:
-
Object
- Object
- MM::Metric
- Defined in:
- lib/mm/metric.rb
Instance Attribute Summary collapse
-
#ordered ⇒ Object
Returns the value of attribute ordered.
Instance Method Summary collapse
-
#call(v1, v2) ⇒ Object
Public: Gets the distance between two vectors, according to the Metric object.
-
#initialize(ordered: true, pair: nil, scale: nil, intra_delta: nil, inter_delta: nil) ⇒ Metric
constructor
Constructor for the Metric object.
-
#inter_delta=(inter_delta) ⇒ Object
Public: Setter method for inter_delta.
-
#intra_delta=(intra_delta) ⇒ Object
Public: Setter method for intra_delta.
-
#pair=(pair) ⇒ Object
Public: Setter method for pair.
-
#scale=(scale) ⇒ Object
Public: Setter method for scale.
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
#ordered ⇒ Object
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 |