Class: LSH::MathUtil
- Inherits:
-
Object
- Object
- LSH::MathUtil
- 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
- .dot(v1, v2) ⇒ Object
- .norm(v) ⇒ Object
- .random_gaussian_matrix(k, l) ⇒ Object
- .random_gaussian_vector(l) ⇒ Object
- .random_uniform ⇒ Object
- .uniq(vs) ⇒ Object
- .zeros(k, l) ⇒ Object
Class Method Details
.dot(v1, v2) ⇒ Object
46 47 48 |
# File 'lib/lsh/math_util_gsl.rb', line 46 def self.dot(v1, v2) (v1 * v2.transpose)[0,0] end |
.norm(v) ⇒ Object
50 51 52 |
# File 'lib/lsh/math_util_gsl.rb', line 50 def self.norm(v) v.norm end |
.random_gaussian_matrix(k, l) ⇒ Object
38 39 40 41 42 43 44 |
# File 'lib/lsh/math_util_gsl.rb', line 38 def self.random_gaussian_matrix(k, l) matrix = zeros(k, l) (0..(k - 1)).each do |i| matrix.set_row(i, random_gaussian_vector(l)) end matrix end |
.random_gaussian_vector(l) ⇒ Object
34 35 36 |
# File 'lib/lsh/math_util_gsl.rb', line 34 def self.random_gaussian_vector(dim) @@gsl_random.gaussian(1, dim) end |
.random_uniform ⇒ Object
26 27 28 |
# File 'lib/lsh/math_util_gsl.rb', line 26 def self.random_uniform @@gsl_random.uniform end |
.uniq(vs) ⇒ Object
54 55 56 57 58 59 60 |
# File 'lib/lsh/math_util_gsl.rb', line 54 def self.uniq(vs) # Can't use uniq as # [ v, JSON.parse(v.to_json, :create_additions => true) ].uniq.size == 2 with GSL results = [] vs.each { |v| results << v unless results.member? v } results end |