Class: LSH::MathUtil

Inherits:
Object
  • Object
show all
Defined in:
lib/lsh/math_util_gsl.rb,
lib/lsh/math_util_jblas.rb

Constant Summary collapse

@@gsl_random =
GSL::Rng.alloc

Class Method Summary collapse

Class Method Details

.dot(v1, v2) ⇒ Object



42
43
44
# File 'lib/lsh/math_util_gsl.rb', line 42

def self.dot(v1, v2)
  v1 * v2.col
end

.norm(v) ⇒ Object



46
47
48
# File 'lib/lsh/math_util_gsl.rb', line 46

def self.norm(v)
  v.norm
end

.random_gaussian_matrix(k, l) ⇒ Object



38
39
40
# File 'lib/lsh/math_util_gsl.rb', line 38

def self.random_gaussian_matrix(k, l)
  GSL::Matrix.randn(k, l)
end

.random_gaussian_vector(dim) ⇒ Object



30
31
32
# File 'lib/lsh/math_util_gsl.rb', line 30

def self.random_gaussian_vector(dim)
  @@gsl_random.gaussian(1, dim)
end

.random_uniformObject



26
27
28
# File 'lib/lsh/math_util_gsl.rb', line 26

def self.random_uniform
  @@gsl_random.uniform
end

.uniq(vs) ⇒ Object



50
51
52
53
54
55
56
# File 'lib/lsh/math_util_gsl.rb', line 50

def self.uniq(vs)
  # Can't use uniq as
  # [ v, JSON.parse(v.to_json) ].uniq.size == 2 with GSL
  results = []
  vs.each { |v| results << v unless results.member? v }
  results
end

.zeros(dim) ⇒ Object



34
35
36
# File 'lib/lsh/math_util_gsl.rb', line 34

def self.zeros(dim)
  GSL::Vector.alloc(dim)
end