Class: Omnizip::Algorithms::PPMd7::SymbolState

Inherits:
Object
  • Object
show all
Defined in:
lib/omnizip/algorithms/ppmd7/symbol_state.rb

Overview

Represents a symbol's state within a context

Each symbol that appears after a context has an associated state that tracks its frequency. This is used to calculate the probability of each symbol appearing next.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(symbol, freq = 1) ⇒ SymbolState

Initialize a new symbol state

Parameters:

  • symbol (Integer)

    The symbol value (0-255)

  • freq (Integer) (defaults to: 1)

    Initial frequency (default: 1)



39
40
41
42
# File 'lib/omnizip/algorithms/ppmd7/symbol_state.rb', line 39

def initialize(symbol, freq = 1)
  @symbol = symbol
  @freq = freq
end

Instance Attribute Details

#freqObject

Returns the value of attribute freq.



33
34
35
# File 'lib/omnizip/algorithms/ppmd7/symbol_state.rb', line 33

def freq
  @freq
end

#symbolObject (readonly)

Returns the value of attribute symbol.



32
33
34
# File 'lib/omnizip/algorithms/ppmd7/symbol_state.rb', line 32

def symbol
  @symbol
end

Instance Method Details

#probability(total_freq) ⇒ Float

Get the probability of this symbol

The probability is proportional to the frequency. This is used by the range coder to encode/decode.

Parameters:

  • total_freq (Integer)

    Total frequency in context

Returns:

  • (Float)

    Probability (0.0 to 1.0)



51
52
53
# File 'lib/omnizip/algorithms/ppmd7/symbol_state.rb', line 51

def probability(total_freq)
  @freq.to_f / total_freq
end