Class: DTW::BarycenterAveraging
- Inherits:
-
Object
- Object
- DTW::BarycenterAveraging
- Defined in:
- lib/dtwrb/barycenter_averaging.rb,
sig/dtwrb.rbs
Constant Summary collapse
- DEFAULT_ITERATIONS =
DBA converges within a few refinement passes; further passes rarely move the prototype.
4- DEFAULT_TOLERANCE =
Mean absolute update per coordinate below which the prototype counts as settled.
1e-4
Instance Attribute Summary collapse
-
#aligner ⇒ Aligner
readonly
Returns the value of attribute aligner.
-
#iterations ⇒ ::Integer
readonly
Returns the value of attribute iterations.
-
#tolerance ⇒ ::Float
readonly
Returns the value of attribute tolerance.
Instance Method Summary collapse
- #call(sequences, length: nil) ⇒ Barycenter
-
#initialize(aligner: Aligner.new, aggregator: :median, dispersion: :median_absolute_deviation, iterations: DEFAULT_ITERATIONS, tolerance: DEFAULT_TOLERANCE, sample_size: Medoid::DEFAULT_SAMPLE_SIZE) ⇒ BarycenterAveraging
constructor
A new instance of BarycenterAveraging.
Constructor Details
#initialize(aligner: Aligner.new, aggregator: :median, dispersion: :median_absolute_deviation, iterations: DEFAULT_ITERATIONS, tolerance: DEFAULT_TOLERANCE, sample_size: Medoid::DEFAULT_SAMPLE_SIZE) ⇒ BarycenterAveraging
Returns a new instance of BarycenterAveraging.
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/dtwrb/barycenter_averaging.rb', line 13 def initialize( aligner: Aligner.new, aggregator: :median, dispersion: :median_absolute_deviation, iterations: DEFAULT_ITERATIONS, tolerance: DEFAULT_TOLERANCE, sample_size: Medoid::DEFAULT_SAMPLE_SIZE ) @aligner = aligner @aggregator = Statistics.resolve(aggregator) @dispersion = Statistics.resolve(dispersion) @iterations = Integer(iterations) @tolerance = Float(tolerance) @medoid = Medoid.new(aligner: aligner, sample_size: sample_size) raise ArgumentError, "iterations must be non-negative, got #{@iterations}" if @iterations.negative? raise ArgumentError, "tolerance must be non-negative, got #{@tolerance}" if @tolerance.negative? freeze end |
Instance Attribute Details
#aligner ⇒ Aligner (readonly)
Returns the value of attribute aligner.
11 12 13 |
# File 'lib/dtwrb/barycenter_averaging.rb', line 11 def aligner @aligner end |
#iterations ⇒ ::Integer (readonly)
Returns the value of attribute iterations.
11 12 13 |
# File 'lib/dtwrb/barycenter_averaging.rb', line 11 def iterations @iterations end |
#tolerance ⇒ ::Float (readonly)
Returns the value of attribute tolerance.
11 12 13 |
# File 'lib/dtwrb/barycenter_averaging.rb', line 11 def tolerance @tolerance end |
Instance Method Details
#call(sequences, length: nil) ⇒ Barycenter
34 35 36 37 38 39 40 41 42 43 |
# File 'lib/dtwrb/barycenter_averaging.rb', line 34 def call(sequences, length: nil) sample = Sample.of(sequences) width = Integer(length || sample.mean_length) raise ArgumentError, "barycenter length must be positive, got #{width}" unless width.positive? center = refine(Resampler.call(@medoid.call(sample.sequences), width), sample) spread = summarize(associate(center, sample), @dispersion) { 0.0 } build(center, spread, sample) end |