Class: DTW::Bands::Slanted
- Inherits:
-
Data
- Object
- Data
- DTW::Bands::Slanted
- Defined in:
- lib/dtwrb/bands.rb,
sig/dtwrb.rbs
Overview
The band follows the diagonal of the rectangle, so the radius keeps constraining the path when the two sequences differ in length.
Instance Attribute Summary collapse
-
#ratio ⇒ Object
readonly
Returns the value of attribute ratio.
Class Method Summary collapse
Instance Method Summary collapse
- #bounds(row, rows, columns) ⇒ [::Integer, ::Integer]
-
#initialize(ratio:) ⇒ Slanted
constructor
A new instance of Slanted.
- #radius(rows, columns) ⇒ ::Integer
-
#reachable(rows, columns) ⇒ ::Integer
Half a step of the diagonal, below which consecutive rows no longer overlap.
- #to_h ⇒ ::Hash[::Symbol, untyped]
- #with ⇒ Slanted
Constructor Details
#initialize(ratio:) ⇒ Slanted
Returns a new instance of Slanted.
27 28 29 30 31 32 |
# File 'lib/dtwrb/bands.rb', line 27 def initialize(ratio:) width = Float(ratio) raise ArgumentError, "band ratio must be non-negative, got #{width}" if width.negative? super(ratio: width) end |
Instance Attribute Details
#ratio ⇒ Object (readonly)
Returns the value of attribute ratio
26 27 28 |
# File 'lib/dtwrb/bands.rb', line 26 def ratio @ratio end |
Class Method Details
Instance Method Details
#bounds(row, rows, columns) ⇒ [::Integer, ::Integer]
38 39 40 41 42 43 44 |
# File 'lib/dtwrb/bands.rb', line 38 def bounds(row, rows, columns) return [1, columns] if rows < 2 || columns < 2 width = radius(rows, columns) centre = 1.0 + ((row - 1) * (columns - 1).fdiv(rows - 1)) [(centre - width).ceil, (centre + width).floor] end |
#radius(rows, columns) ⇒ ::Integer
34 35 36 |
# File 'lib/dtwrb/bands.rb', line 34 def radius(rows, columns) [(ratio * [rows, columns].max).ceil, reachable(rows, columns)].max end |
#reachable(rows, columns) ⇒ ::Integer
Half a step of the diagonal, below which consecutive rows no longer overlap.
47 48 49 50 51 |
# File 'lib/dtwrb/bands.rb', line 47 def reachable(rows, columns) return 1 if rows < 2 || columns < 2 [((columns - 1).fdiv(rows - 1) / 2).ceil, 1].max end |
#to_h ⇒ ::Hash[::Symbol, untyped]
133 |
# File 'sig/dtwrb.rbs', line 133
def to_h: () -> ::Hash[::Symbol, untyped]
|