Class: Omnizip::Algorithms::PPMd8::Model

Inherits:
Object
  • Object
show all
Includes:
Constants, Omnizip::Algorithms::PPMdBase::BaseConstants
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

Instance Method Summary collapse

Constructor Details

#initialize(max_order = DEFAULT_ORDER, mem_size = DEFAULT_MEM_SIZE, restore_method = DEFAULT_RESTORE_METHOD) ⇒ Model

Initialize the PPMd8 model

Parameters:

  • max_order (Integer) (defaults to: DEFAULT_ORDER)

    Maximum context order (2-16)

  • mem_size (Integer) (defaults to: DEFAULT_MEM_SIZE)

    Memory size for context allocation

  • restore_method (Integer) (defaults to: DEFAULT_RESTORE_METHOD)

    Restoration method type



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_contextObject (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_countObject (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_orderObject (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_sizeObject (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_fallObject

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_successObject

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_methodObject (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_contextObject (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_lengthObject (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_contextsvoid

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

Parameters:

  • symbol (Integer, nil) (defaults to: nil)

    Symbol to encode (nil for decode)

Returns:

  • (Hash)

    Probability information



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

#resetvoid

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

Parameters:

  • symbol (Integer)

    The symbol that was encoded/decoded



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