Class: Linalg::DMatrix
- Inherits:
-
Object
- Object
- Linalg::DMatrix
- Defined in:
- lib/appswarm/routing/matrix_math.rb
Instance Method Summary collapse
- #covariance ⇒ Object
- #cut(w, h) ⇒ Object
- #middle_col ⇒ Object
- #middle_row ⇒ Object
-
#pseudo_inverse(epsilon = nil) ⇒ Object
Pseudo-inverse.
Instance Method Details
#covariance ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/appswarm/routing/matrix_math.rb', line 33 def covariance m=middle_row colCount=self.columns.entries.length rowCount=self.rows.entries.length r=(0...colCount).to_a.map{|y| (0...colCount).to_a.map{|x| (0...rowCount).inject(0) {|old,c| old+(self[c,y]-m[0,y])*(self[c,x]-m[0,x]) }/rowCount } } DMatrix[*r] end |
#cut(w, h) ⇒ Object
47 48 49 50 51 52 53 54 |
# File 'lib/appswarm/routing/matrix_math.rb', line 47 def cut(w,h) r=(0...h).to_a.map{|y| (0...w).to_a.map{|x| self[y,x] } } DMatrix[*r] end |
#middle_col ⇒ Object
24 25 26 27 28 29 30 31 |
# File 'lib/appswarm/routing/matrix_math.rb', line 24 def middle_col startA=([[0]]*rows.entries.length) start=DMatrix[*startA] columns.entries.inject(start){|old,new| old+new }/columns.entries.length end |
#middle_row ⇒ Object
16 17 18 19 20 21 22 23 |
# File 'lib/appswarm/routing/matrix_math.rb', line 16 def middle_row startA=([0]*columns.entries.length) start=DMatrix[startA] rows.entries.inject(start){|old,new| old+new }/rows.entries.length end |