class GSL::Matrix

Public Instance Methods

column_size() click to toggle source
# File lib/statsample/matrix.rb, line 98
def column_size
  size2
end
determinant() click to toggle source
# File lib/statsample/matrix.rb, line 101
def determinant
  det
end
eigenpairs() click to toggle source
# File lib/statsample/matrix.rb, line 126
def eigenpairs
  eigval, eigvec= GSL::Eigen.symmv(self)
  GSL::Eigen::symmv_sort(eigval, eigvec, GSL::Eigen::SORT_VAL_DESC)
  @eigenpairs=eigval.size.times.map {|i|
    [eigval[i],eigvec.get_col(i)]
  }
end
eigenvalues() click to toggle source
# File lib/statsample/matrix.rb, line 107
def eigenvalues
  eigenpairs.collect {|v| v[0]}
end
eigenvectors() click to toggle source
# File lib/statsample/matrix.rb, line 110
def eigenvectors
  eigenpairs.collect {|v| v[1]}
end
eigenvectors_matrix() click to toggle source
# File lib/statsample/matrix.rb, line 121
def eigenvectors_matrix
  eigval, eigvec= GSL::Eigen.symmv(self)
  GSL::Eigen::symmv_sort(eigval, eigvec, GSL::Eigen::SORT_VAL_DESC)
  eigvec 
end
inverse() click to toggle source
# File lib/statsample/matrix.rb, line 104
def inverse
  GSL::Linalg::LU.invert(self)
end
mssq() click to toggle source

Matrix sum of squares

# File lib/statsample/matrix.rb, line 115
def mssq
  sum=0
  to_v.each {|i| sum+=i**2}
  sum
end
row_size() click to toggle source
# File lib/statsample/matrix.rb, line 95
def row_size
  size1
end
square?() click to toggle source

def eigenpairs_ruby

self.to_matrix.eigenpairs_ruby

end

# File lib/statsample/matrix.rb, line 137
def square?
  size1==size2
end
to_dataset() click to toggle source
# File lib/statsample/matrix.rb, line 80
def to_dataset
  f = (self.respond_to? :fields_y) ? fields_y : column_size.times.map {|i| _("VAR_%d") % (i+1) }
  ds=Statsample::Dataset.new(f)
  f.each do |ff|
    ds[ff].type=:scale
    ds[ff].name=ff
  end
  row_size.times {|i|
    ds.add_case_array(self.row(i).to_a)
  }
  ds.update_valid_data
  ds.name=self.name if self.respond_to? :name
  ds
end
to_gsl() click to toggle source
# File lib/statsample/matrix.rb, line 76
def to_gsl
  self
end
to_matrix() click to toggle source
# File lib/statsample/matrix.rb, line 140
def to_matrix
  rows=self.size1
  cols=self.size2
  out=(0...rows).collect{|i| (0...cols).collect {|j| self[i,j]} }
  ::Matrix.rows(out)
end
total_sum() click to toggle source
# File lib/statsample/matrix.rb, line 146
def total_sum
  sum=0
  size1.times {|i|
    size2.times {|j|
      sum+=self[i,j]
    }
  }
  sum
end