Module: TraceVisualization::RepetitionsScore
- Defined in:
- lib/trace_visualization/repetitions_score.rb
Constant Summary collapse
- ALPHA_SCORE =
Priority length when repetition score is calculated
0.5
- BETA_SCORE =
Priority positions.size when repetition score is calculated
1 - ALPHA_SCORE
Class Method Summary collapse
-
.fill_score(rs, options = {}) ⇒ Object
Options: sort true / false order order for sort (default ‘asc’) version version of importance function.
-
.function_linear(rs) ⇒ Object
f(len, size, k) = alpha * len + beta * size + gamma * k.
-
.function_relative(rs) ⇒ Object
f(len, size) = alpha * len’ + beta * size’ len’, size’ - relative to max values.
Class Method Details
.fill_score(rs, options = {}) ⇒ Object
Options: sort true / false order order for sort (default ‘asc’) version version of importance function
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/trace_visualization/repetitions_score.rb', line 14 def self.fill_score(rs, = {}) opts = { :sort => false, :order => 'asc' }.merge case opts[:version] when 'relative' function_relative(rs) when 'linear' function_linear(rs) else throw Exception.new("Unknown version") end if opts[:sort] rs.sort! do |a, b| opts[:order] == 'desc' ? b.score <=> a.score : a.score <=> b.score end end end |
.function_linear(rs) ⇒ Object
f(len, size, k) = alpha * len + beta * size + gamma * k
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/trace_visualization/repetitions_score.rb', line 57 def self.function_linear(rs) len_max, len_min, size_max, size_min, k_max = 0, 2**32, 0, 2**32, 0 rs.each do |r| len = r.length len_max = len if len > len_max len_min = len if len < len_min size = r.positions_size size_max = size if size > size_max size_min = size if size < size_min k_max = r.k if r.k > k_max end d = (len_max * size_min + size_max * k_max - size_max * len_min - len_max * k_max).to_f alpha = (size_min + k_max * (size_max - 1)) / d beta = - (len_min + k_max * (len_max - 1)) / d gamma = (len_max * size_min - size_max * len_min - size_min + len_min) / d puts "len_max = #{len_max}, len_min = #{len_min}, size_max = #{size_max}, size_min = #{size_min}, k_max = #{k_max}" puts "alpha = #{alpha}, beta = #{beta}, gamma = #{gamma}" rs.each do |r| r.score = alpha * r.length + beta * r.positions_size + gamma * r.k end end |
.function_relative(rs) ⇒ Object
f(len, size) = alpha * len’ + beta * size’ len’, size’ - relative to max values
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/trace_visualization/repetitions_score.rb', line 39 def self.function_relative(rs) len_max, size_max = 0, 0 rs.each do |r| len = r.length len_max = len if len > len_max size = r.positions_size size_max = size if size > size_max end rs.each do |r| r.score = ALPHA_SCORE * r.strict_length / len_max + BETA_SCORE * r.positions_size / size_max end end |