Class: IPXACT::Tools::InterruptLineDetector

Inherits:
Object
  • Object
show all
Defined in:
lib/ipxact_tools/interrupt_line_detector.rb

Overview

InterruptLineDetector instances are used for detecting interrupt lines from a data path.

Author:

  • Guillaume Godet-Bar

Constant Summary collapse

@@detector_stats =
YAML.load(File.open(File.join(File.dirname(__FILE__), '../../config/detector.yml')).read)

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.convert_pairs(pairs) ⇒ Object



85
86
87
88
89
90
# File 'lib/ipxact_tools/interrupt_line_detector.rb', line 85

def self.convert_pairs(pairs)
  pairs.collect do |pair|
    regex = Regexp.new(pair[0].gsub(/^\/(.+)\/.?$/, '\1'), pair[0].end_with?('i'))
    [regex, pair[1]]
  end
end

Instance Method Details

#render_seq(viterbi_stack) ⇒ Object



74
75
76
77
78
79
80
81
82
83
# File 'lib/ipxact_tools/interrupt_line_detector.rb', line 74

def render_seq(viterbi_stack)
  seq = []
  stack_el = viterbi_stack.pop
  while stack_el
    el = stack_el.max{|a, b| a[1][:prob] <=> b[1][:prob]}
    seq << el[0]
    stack_el = viterbi_stack.pop
  end
  seq.reverse
end

#symbol_probability(symbol, state) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/ipxact_tools/interrupt_line_detector.rb', line 28

def symbol_probability(symbol, state)
  port = symbol

  bus_name_p = @@detector_stats[:bus_name_regex].collect {|el| port[:name] =~ el[0] ? el[1] : 0.1}.max
  bus_library_name_p = @@detector_stats[:bus_library_regex].collect {|el| port[:bus_id].name =~ el[0] ? el[1] : 0.1}.max

  res = nil
  if state == :int
    (bus_name_p * bus_library_name_p) / (bus_name_p * bus_library_name_p + (1.0 - bus_name_p) * (1.0 - bus_library_name_p))
  else
    ((1.0 - bus_name_p) * (1.0 - bus_library_name_p)) / (bus_name_p * bus_library_name_p + (1.0 - bus_name_p) * (1.0 - bus_library_name_p))
  end
end

#viterbi(symbol_queue) ⇒ Object



42
43
44
45
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
71
72
# File 'lib/ipxact_tools/interrupt_line_detector.rb', line 42

def viterbi(symbol_queue)
  return [] if symbol_queue.empty?

  current_symbol = symbol_queue.shift

  initial_values = @@detector_stats[:states].inject({}) do |acc, state|
    acc[state] = {
      :prob => @@detector_stats[:initial_state][state] * symbol_probability(current_symbol, state),
      :previous => nil
    }
    acc
  end

  stat_stack = [initial_values]

  @previous = initial_values

  stat_stack += symbol_queue.collect do |symbol|
    new_states = {}
    previous_max = @previous.max {|a, b| a[1][:prob] <=> b[1][:prob]}
    @@detector_stats[:states].inject({}) do |acc, state|
      stats = @@detector_stats[:states].collect{|o_state| {:prob => previous_max[1][:prob] * @@detector_stats[:transition_matrix][o_state][state] * symbol_probability(symbol, state), :previous => previous_max[0]}}
      acc[state] = stats.max{|a, b| a[:prob] <=> b[:prob]}
      new_states[state] = acc[state]
      acc
    end
    @previous = new_states
  end

  stat_stack
end