Class: Avsd::Avsd
- Inherits:
-
Object
- Object
- Avsd::Avsd
- Defined in:
- lib/avsd.rb
Instance Attribute Summary collapse
-
#co_mat ⇒ Object
Returns the value of attribute co_mat.
-
#labels ⇒ Object
Returns the value of attribute labels.
-
#short_mat ⇒ Object
Returns the value of attribute short_mat.
Instance Method Summary collapse
- #band(label1, label2) ⇒ Object
- #band_matrix(records) ⇒ Object
- #g_short_mat ⇒ Object
-
#initialize(records) ⇒ Avsd
constructor
A new instance of Avsd.
- #sample(num) ⇒ Object
Constructor Details
Instance Attribute Details
#co_mat ⇒ Object
Returns the value of attribute co_mat.
161 162 163 |
# File 'lib/avsd.rb', line 161 def co_mat @co_mat end |
#labels ⇒ Object
Returns the value of attribute labels.
161 162 163 |
# File 'lib/avsd.rb', line 161 def labels @labels end |
#short_mat ⇒ Object
Returns the value of attribute short_mat.
161 162 163 |
# File 'lib/avsd.rb', line 161 def short_mat @short_mat end |
Instance Method Details
#band(label1, label2) ⇒ Object
104 105 106 |
# File 'lib/avsd.rb', line 104 def band label1, label2 @co_mat[@labels.index(label1), @labels.index(label2)] += 1 end |
#band_matrix(records) ⇒ Object
108 109 110 111 112 113 114 115 116 117 118 119 |
# File 'lib/avsd.rb', line 108 def band_matrix records @labels.each do |label_a| records.each do |record| if record.include? label_a record.each do |label_b| band(label_a, label_b) end end end end @co_mat.mirror_diagonal.zero_diagonal end |
#g_short_mat ⇒ Object
121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 |
# File 'lib/avsd.rb', line 121 def g_short_mat @short_mat = Matrix.zero(@co_mat.column_size) @short_mat = @short_mat.collect { |x| x = nil } for s_id in 0..@co_mat.column_size - 1 q = PriorityQueue.new q[s_id] = 0 while not q.empty? f = q.delete_min @short_mat[s_id, f[0]] = f[1] @short_mat.inspect @co_mat.row(f[0]).each_with_index do |val, i| next if i == f[0] or val == 0 or @short_mat[s_id, i] != nil if q[i] == nil or q[i] < f[1] + val q[i] = f[1] + val end end end end end |
#sample(num) ⇒ Object
141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 |
# File 'lib/avsd.rb', line 141 def sample num arr = Array.new(@short_mat.column_size) { |idx| idx } set = arr.sample num arr = [] set.length.times do |i| for k in i + 1..set.length - 1 arr << [set[i], set[k]] end end sampled_labels = Hash.new set.each do |id| sampled_labels[@labels[id]] = id end vals = [] arr.each do |id_set| vals << @short_mat[id_set[0], id_set[1]] end [sampled_labels, vals, vals.mean, vals.sd].inspect end |