Class: AHProcess::AHPMatrix

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Includes:
Comparable
Defined in:
lib/ahprocess/ahp_matrix.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(matrix = []) ⇒ AHPMatrix

Returns a new instance of AHPMatrix.



11
12
13
# File 'lib/ahprocess/ahp_matrix.rb', line 11

def initialize(matrix = [])
  @matrix = Matrix[*matrix]
end

Instance Attribute Details

#matrixObject (readonly)

Returns the value of attribute matrix.



9
10
11
# File 'lib/ahprocess/ahp_matrix.rb', line 9

def matrix
  @matrix
end

Instance Method Details

#<=>(other) ⇒ Object



15
16
17
# File 'lib/ahprocess/ahp_matrix.rb', line 15

def <=>(other)
  @matrix <=> other.matrix
end

#column_sumObject



27
28
29
# File 'lib/ahprocess/ahp_matrix.rb', line 27

def column_sum
  Vector[*(column_vectors.map { |v| v.inject(:+) })]
end

#consistency_indexObject



35
36
37
# File 'lib/ahprocess/ahp_matrix.rb', line 35

def consistency_index
  (lambda_max - row_count) / (row_count - 1)
end

#consistency_ratio(random_consistency_index) ⇒ Object



39
40
41
# File 'lib/ahprocess/ahp_matrix.rb', line 39

def consistency_ratio(random_consistency_index)
  consistency_index / random_consistency_index
end

#lambda_maxObject



31
32
33
# File 'lib/ahprocess/ahp_matrix.rb', line 31

def lambda_max
  preference_vector.inner_product column_sum
end

#normalizeObject



19
20
21
# File 'lib/ahprocess/ahp_matrix.rb', line 19

def normalize
  AHPMatrix.new(Matrix.columns(column_vectors.map { |cv| cv / cv.inject(:+).to_f }))
end

#preference_vectorObject



23
24
25
# File 'lib/ahprocess/ahp_matrix.rb', line 23

def preference_vector
  Vector[*(normalize.row_vectors.map { |rv| rv.inject(:+).to_f / rv.size })]
end