Class: FeldtRuby::Statistics::SAX::SymbolMapper

Inherits:
Object
  • Object
show all
Defined in:
lib/feldtruby/statistics/time_series/sax.rb

Overview

A mapper maps the values in a subsequence into a symbol. The standard mapper is state-less and normalizes each subsequence and then assumes a normal distribution and thus uses a fixed selection of bins.

Constant Summary collapse

NormalDistCutPoints =

Cut points based on a Normal/Gaussian distribution…

{
    2 => [-Float::INFINITY, 0.00],
    3 => [-Float::INFINITY, -0.43, 0.43],
    4 => [-Float::INFINITY, -0.67, 0.00, 0.67],
    5 => [-Float::INFINITY, -0.84, -0.25, 0.25, 0.84],
    6 => [-Float::INFINITY, -0.97, -0.43, 0.00, 0.43, 0.97],
    7 => [-Float::INFINITY, -1.07, -0.57, -0.18, 0.18, 0.57, 1.07],
    8 => [-Float::INFINITY, -1.15, -0.67, -0.32, 0.00, 0.32, 0.67, 1.15],
    9 => [-Float::INFINITY, -1.22, -0.76, -0.43, -0.14, 0.14, 0.43, 0.76, 1.22],
    10 => [-Float::INFINITY, -1.28, -0.84, -0.52, -0.25, 0.00, 0.25, 0.52, 0.84, 1.28],
    11 => [-Float::INFINITY, -1.34, -0.91, -0.60, -0.35, -0.11, 0.11, 0.35, 0.60, 0.91, 1.34],
    12 => [-Float::INFINITY, -1.38, -0.97, -0.67, -0.43, -0.21, 0.00, 0.21, 0.43, 0.67, 0.97, 1.38],
    13 => [-Float::INFINITY, -1.43, -1.02, -0.74, -0.50, -0.29, -0.10, 0.10, 0.29, 0.50, 0.74, 1.02, 1.43],
    14 => [-Float::INFINITY, -1.47, -1.07, -0.79, -0.57, -0.37, -0.18, 0.00, 0.18, 0.37, 0.57, 0.79, 1.07, 1.47],
    15 => [-Float::INFINITY, -1.5 , -1.11, -0.84, -0.62, -0.43, -0.25, -0.08, 0.08, 0.25, 0.43, 0.62, 0.84, 1.11, 1.50],
    16 => [-Float::INFINITY, -1.53, -1.15, -0.89, -0.67, -0.49, -0.32, -0.16, 0.00, 0.16, 0.32, 0.49, 0.67, 0.89, 1.15, 1.53],
    17 => [-Float::INFINITY, -1.56, -1.19, -0.93, -0.72, -0.54, -0.38, -0.22, -0.07, 0.07, 0.22, 0.38, 0.54, 0.72, 0.93, 1.19, 1.56],
    18 => [-Float::INFINITY, -1.59, -1.22, -0.97, -0.76, -0.59, -0.43, -0.28, -0.14, 0.00, 0.14, 0.28, 0.43, 0.59, 0.76, 0.97, 1.22, 1.59],
    19 => [-Float::INFINITY, -1.62, -1.25, -1.00, -0.80, -0.63, -0.48, -0.34, -0.20, -0.07, 0.07, 0.20, 0.34, 0.48, 0.63, 0.80, 1.0, 1.25, 1.62],
    20 => [-Float::INFINITY, -1.64, -1.28, -1.04, -0.84, -0.67, -0.52, -0.39, -0.25, -0.13, 0.00, 0.13, 0.25, 0.39, 0.52, 0.67, 0.84, 1.04, 1.28, 1.64]
}

Instance Method Summary collapse

Constructor Details

#initialize(data = nil) ⇒ SymbolMapper

Returns a new instance of SymbolMapper.



27
28
29
# File 'lib/feldtruby/statistics/time_series/sax.rb', line 27

def initialize(data = nil)
  # This standard mapper does not utilize the whole data sequence to precalc mapping values. But subclasses might.
end

Instance Method Details

#map_sequence_to_symbol(sequence, alphabet_size) ⇒ Object



58
59
60
# File 'lib/feldtruby/statistics/time_series/sax.rb', line 58

def map_sequence_to_symbol(sequence, alphabet_size)
  symbol_for_value(sequence.mean, alphabet_size)
end

#supports_alphabet_size?(size) ⇒ Boolean

Returns:

  • (Boolean)


54
55
56
# File 'lib/feldtruby/statistics/time_series/sax.rb', line 54

def supports_alphabet_size?(size)
  NormalDistCutPoints.keys.include? size
end

#symbol_for_value(value, alphabet_size) ⇒ Object



62
63
64
65
66
67
# File 'lib/feldtruby/statistics/time_series/sax.rb', line 62

def symbol_for_value(value, alphabet_size)
  NormalDistCutPoints[alphabet_size].inject(0) do |symbol, cutpoint|
    return symbol if cutpoint > value
    symbol + 1
  end
end