Class: Omnizip::Algorithms::PPMd8::Model
- Inherits:
-
Object
- Object
- Omnizip::Algorithms::PPMd8::Model
- Defined in:
- lib/omnizip/algorithms/ppmd8/model.rb
Overview
PPMd8 prediction model with enhanced features
Extends the basic PPMd model with:
- Restoration methods (RESTART/CUT_OFF)
- Run-length encoding for repetitions
- Enhanced update algorithms
- Glue count tracking for memory management
Constant Summary
Constants included from Constants
Constants::BIN_SCALE, Constants::DEFAULT_RESTORE_METHOD, Constants::GLUE_COUNT_THRESHOLD, Constants::INIT_ESCAPE_FREQ, Constants::INTERVAL, Constants::INT_BITS, Constants::MAX_FREQ, Constants::MAX_STATES, Constants::PERIOD_BITS, Constants::PROB_TOTAL, Constants::RESTORE_METHOD_CUT_OFF, Constants::RESTORE_METHOD_RESTART, Constants::SEE_CONTEXTS, Constants::SUFFIX_CONTEXTS, Constants::UNIT_ALLOC_SIZE, Constants::UNIT_SIZE
Constants included from Omnizip::Algorithms::PPMdBase::BaseConstants
Omnizip::Algorithms::PPMdBase::BaseConstants::ALPHABET_SIZE, Omnizip::Algorithms::PPMdBase::BaseConstants::BOT_VALUE, Omnizip::Algorithms::PPMdBase::BaseConstants::DEFAULT_MEM_SIZE, Omnizip::Algorithms::PPMdBase::BaseConstants::DEFAULT_ORDER, Omnizip::Algorithms::PPMdBase::BaseConstants::MAX_MEM_SIZE, Omnizip::Algorithms::PPMdBase::BaseConstants::MAX_ORDER, Omnizip::Algorithms::PPMdBase::BaseConstants::MIN_MEM_SIZE, Omnizip::Algorithms::PPMdBase::BaseConstants::MIN_ORDER, Omnizip::Algorithms::PPMdBase::BaseConstants::TOP_VALUE
Instance Attribute Summary collapse
-
#current_context ⇒ Object
readonly
Returns the value of attribute current_context.
-
#glue_count ⇒ Object
readonly
Returns the value of attribute glue_count.
-
#max_order ⇒ Object
readonly
Returns the value of attribute max_order.
-
#mem_size ⇒ Object
readonly
Returns the value of attribute mem_size.
-
#order_fall ⇒ Object
Returns the value of attribute order_fall.
-
#prev_success ⇒ Object
Returns the value of attribute prev_success.
-
#restoration_method ⇒ Object
readonly
Returns the value of attribute restoration_method.
-
#root_context ⇒ Object
readonly
Returns the value of attribute root_context.
-
#run_length ⇒ Object
readonly
Returns the value of attribute run_length.
Instance Method Summary collapse
-
#cut_off_old_contexts ⇒ void
Cut off old contexts to free memory (CUT_OFF restoration).
-
#get_symbol_probability(symbol = nil) ⇒ Hash
Get probability information for a symbol.
-
#initialize(max_order = DEFAULT_ORDER, mem_size = DEFAULT_MEM_SIZE, restore_method = DEFAULT_RESTORE_METHOD) ⇒ Model
constructor
Initialize the PPMd8 model.
-
#reset ⇒ void
Reset model to initial state.
-
#update(symbol) ⇒ void
Update model after encoding/decoding a symbol.
Constructor Details
#initialize(max_order = DEFAULT_ORDER, mem_size = DEFAULT_MEM_SIZE, restore_method = DEFAULT_RESTORE_METHOD) ⇒ Model
Initialize the PPMd8 model
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/omnizip/algorithms/ppmd8/model.rb', line 46 def initialize( max_order = DEFAULT_ORDER, mem_size = DEFAULT_MEM_SIZE, restore_method = DEFAULT_RESTORE_METHOD ) validate_parameters(max_order, mem_size) @max_order = max_order @mem_size = mem_size @restoration_method = RestorationMethod.new(restore_method) # PPMd8-specific state @run_length = 0 @init_rl = 0 @glue_count = 0 @order_fall = max_order @prev_success = 0 # Initialize context tree @root_context = Context.new(-1, nil) @current_context = @root_context @context_history = [] initialize_root_context end |
Instance Attribute Details
#current_context ⇒ Object (readonly)
Returns the value of attribute current_context.
37 38 39 |
# File 'lib/omnizip/algorithms/ppmd8/model.rb', line 37 def current_context @current_context end |
#glue_count ⇒ Object (readonly)
Returns the value of attribute glue_count.
37 38 39 |
# File 'lib/omnizip/algorithms/ppmd8/model.rb', line 37 def glue_count @glue_count end |
#max_order ⇒ Object (readonly)
Returns the value of attribute max_order.
37 38 39 |
# File 'lib/omnizip/algorithms/ppmd8/model.rb', line 37 def max_order @max_order end |
#mem_size ⇒ Object (readonly)
Returns the value of attribute mem_size.
37 38 39 |
# File 'lib/omnizip/algorithms/ppmd8/model.rb', line 37 def mem_size @mem_size end |
#order_fall ⇒ Object
Returns the value of attribute order_fall.
39 40 41 |
# File 'lib/omnizip/algorithms/ppmd8/model.rb', line 39 def order_fall @order_fall end |
#prev_success ⇒ Object
Returns the value of attribute prev_success.
39 40 41 |
# File 'lib/omnizip/algorithms/ppmd8/model.rb', line 39 def prev_success @prev_success end |
#restoration_method ⇒ Object (readonly)
Returns the value of attribute restoration_method.
37 38 39 |
# File 'lib/omnizip/algorithms/ppmd8/model.rb', line 37 def restoration_method @restoration_method end |
#root_context ⇒ Object (readonly)
Returns the value of attribute root_context.
37 38 39 |
# File 'lib/omnizip/algorithms/ppmd8/model.rb', line 37 def root_context @root_context end |
#run_length ⇒ Object (readonly)
Returns the value of attribute run_length.
37 38 39 |
# File 'lib/omnizip/algorithms/ppmd8/model.rb', line 37 def run_length @run_length end |
Instance Method Details
#cut_off_old_contexts ⇒ void
This method returns an undefined value.
Cut off old contexts to free memory (CUT_OFF restoration)
116 117 118 119 120 |
# File 'lib/omnizip/algorithms/ppmd8/model.rb', line 116 def cut_off_old_contexts # Simplified implementation - would traverse and prune # contexts based on usage statistics @glue_count = 0 end |
#get_symbol_probability(symbol = nil) ⇒ Hash
Get probability information for a symbol
76 77 78 79 80 81 82 83 84 |
# File 'lib/omnizip/algorithms/ppmd8/model.rb', line 76 def get_symbol_probability(symbol = nil) context = find_context_with_symbol(symbol) if context && (state = context.find_symbol(symbol)) build_symbol_probability(context, state, symbol) else build_escape_probability(context || @root_context) end end |
#reset ⇒ void
This method returns an undefined value.
Reset model to initial state
102 103 104 105 106 107 108 109 110 111 |
# File 'lib/omnizip/algorithms/ppmd8/model.rb', line 102 def reset @root_context = Context.new(-1, nil) @current_context = @root_context @context_history.clear @run_length = 0 @glue_count = 0 @order_fall = @max_order @prev_success = 0 initialize_root_context end |
#update(symbol) ⇒ void
This method returns an undefined value.
Update model after encoding/decoding a symbol
PPMd8 uses more sophisticated update algorithms
92 93 94 95 96 97 |
# File 'lib/omnizip/algorithms/ppmd8/model.rb', line 92 def update(symbol) update_run_length(symbol) update_context_statistics(symbol) update_current_context(symbol) check_memory_restoration end |