Class: DTW::Bands::SakoeChiba

Inherits:
Data
  • Object
show all
Defined in:
lib/dtwrb/bands.rb,
sig/dtwrb.rbs

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(ratio:) ⇒ SakoeChiba

Returns a new instance of SakoeChiba.

Raises:

  • (ArgumentError)


6
7
8
9
10
11
# File 'lib/dtwrb/bands.rb', line 6

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

#ratioObject (readonly)

Returns the value of attribute ratio

Returns:

  • (Object)

    the current value of ratio



5
6
7
# File 'lib/dtwrb/bands.rb', line 5

def ratio
  @ratio
end

Class Method Details

.newSakoeChiba

Parameters:

  • ratio: (::Numeric)

Returns:



118
# File 'sig/dtwrb.rbs', line 118

def self.new: (ratio: ::Numeric) -> SakoeChiba

Instance Method Details

#bounds(row, rows, columns) ⇒ [::Integer, ::Integer]

Parameters:

  • (::Integer)
  • (::Integer)
  • (::Integer)

Returns:

  • ([::Integer, ::Integer])


18
19
20
21
# File 'lib/dtwrb/bands.rb', line 18

def bounds(row, rows, columns)
  width = radius(rows, columns)
  [row - width, row + width]
end

#radius(length_a, length_b) ⇒ ::Integer

The |n - m| + 1 term keeps at least one path feasible when the lengths differ widely.

Parameters:

  • (::Integer)
  • (::Integer)

Returns:

  • (::Integer)


14
15
16
# File 'lib/dtwrb/bands.rb', line 14

def radius(length_a, length_b)
  [(ratio * [length_a, length_b].max).ceil, (length_a - length_b).abs + 1].max
end

#to_h::Hash[::Symbol, untyped]

Returns:

  • (::Hash[::Symbol, untyped])


122
# File 'sig/dtwrb.rbs', line 122

def to_h: () -> ::Hash[::Symbol, untyped]

#withSakoeChiba

Parameters:

  • (Object)

Returns:



121
# File 'sig/dtwrb.rbs', line 121

def with: (**untyped) -> SakoeChiba