Class: Omnizip::Algorithms::PPMd7::SymbolState
- Inherits:
-
Object
- Object
- Omnizip::Algorithms::PPMd7::SymbolState
- 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
-
#freq ⇒ Object
Returns the value of attribute freq.
-
#symbol ⇒ Object
readonly
Returns the value of attribute symbol.
Instance Method Summary collapse
-
#initialize(symbol, freq = 1) ⇒ SymbolState
constructor
Initialize a new symbol state.
-
#probability(total_freq) ⇒ Float
Get the probability of this symbol.
Constructor Details
#initialize(symbol, freq = 1) ⇒ SymbolState
Initialize a new symbol state
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
#freq ⇒ Object
Returns the value of attribute freq.
33 34 35 |
# File 'lib/omnizip/algorithms/ppmd7/symbol_state.rb', line 33 def freq @freq end |
#symbol ⇒ Object (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.
51 52 53 |
# File 'lib/omnizip/algorithms/ppmd7/symbol_state.rb', line 51 def probability(total_freq) @freq.to_f / total_freq end |