Class: GSL::Vector
- Inherits:
-
Object
- Object
- GSL::Vector
- Defined in:
- lib/correlation.rb
Overview
This Extension of the GNU Scientific Library bindings by Yoshiki Tsunesada (rb-gsl.rubyforge.org) provides the computation of the correlation of two GSL::Vectors. It is implemented as a method of a GSL::Vector for most easy usage. see project page: rubyforge.org/projects/extcsv
Instance Method Summary collapse
- #autocorrelation ⇒ Object
-
#correlation(other) ⇒ Object
Follow the usual definition, e.g.
Instance Method Details
#autocorrelation ⇒ Object
39 40 41 |
# File 'lib/correlation.rb', line 39 def autocorrelation correlation(self) end |
#correlation(other) ⇒ Object
Follow the usual definition, e.g. from Sheriff and Geldart “Exploitation Seismology”, p. 289: cor(v,w)(i) = sum_over_k (v*w)
This means, that
-
for positive values of i, w is shifted to the left, i.e. in the direction of smaller indizees of v
-
for negative i, w is shifted to the right, i.e. in the direction of larger indizees of v
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/correlation.rb', line 15 def correlation(other) unless size == other.size warn "Vectors/Datasets must have the same size." raise end # predefine result vector correlation = GSL::Vector.alloc(2*size) # Alternate definition, which is actually the opposite direction of the definition # (0...size).each {|i| # correlation << self[0..i]*other[-i-1..-1].col # } # (1...size).each {|i| # correlation << self[i..size-1]*other[0...size-i].col # } (0...size).each {|i| correlation[0] = (self.to_a[-i-1..-1].to_gv)*(other.to_a[0..i].to_gv.col) } (1...size).each {|i| correlation[size+i] = (self.to_a[0...size-i].to_gv)*(other.to_a[i..size-1].to_gv.col) } [GSL::Vector.linspace(-size+1, size-1, 2*size-1) , correlation] end |