Class: DTW::Aligner
- Inherits:
-
Object
- Object
- DTW::Aligner
- Defined in:
- lib/dtwrb/aligner.rb,
sig/dtwrb.rbs
Instance Attribute Summary collapse
-
#band ⇒ _Band
readonly
Returns the value of attribute band.
-
#metric ⇒ _Metric
readonly
Returns the value of attribute metric.
Instance Method Summary collapse
- #align(sequence_a, sequence_b) ⇒ Alignment
- #distance(sequence_a, sequence_b) ⇒ ::Float
-
#initialize(metric: Metrics::DEFAULT, band: Bands::DEFAULT) ⇒ Aligner
constructor
A new instance of Aligner.
Constructor Details
Instance Attribute Details
#band ⇒ _Band (readonly)
Returns the value of attribute band.
5 6 7 |
# File 'lib/dtwrb/aligner.rb', line 5 def band @band end |
#metric ⇒ _Metric (readonly)
Returns the value of attribute metric.
5 6 7 |
# File 'lib/dtwrb/aligner.rb', line 5 def metric @metric end |
Instance Method Details
#align(sequence_a, sequence_b) ⇒ Alignment
13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/dtwrb/aligner.rb', line 13 def align(sequence_a, sequence_b) frames_a = Sequence.vectorize(sequence_a) frames_b = Sequence.vectorize(sequence_b) return Alignment::UNDEFINED if frames_a.empty? || frames_b.empty? grid = accumulate(frames_a, frames_b) Alignment.new( path: backtrack(grid, frames_a.length, frames_b.length), cost: grid[frames_a.length][frames_b.length] ) end |
#distance(sequence_a, sequence_b) ⇒ ::Float
25 |
# File 'lib/dtwrb/aligner.rb', line 25 def distance(sequence_a, sequence_b) = align(sequence_a, sequence_b).distance |