Class: SameSame::CosineDistance
- Inherits:
-
Object
- Object
- SameSame::CosineDistance
- Defined in:
- lib/same_same/cosine_distance.rb
Instance Attribute Summary collapse
-
#cosin ⇒ Object
Returns the value of attribute cosin.
Instance Method Summary collapse
- #distance(x, y) ⇒ Object
-
#initialize ⇒ CosineDistance
constructor
A new instance of CosineDistance.
Constructor Details
#initialize ⇒ CosineDistance
Returns a new instance of CosineDistance.
8 9 10 |
# File 'lib/same_same/cosine_distance.rb', line 8 def initialize self.cosin = CosineSimilarity.new end |
Instance Attribute Details
#cosin ⇒ Object
Returns the value of attribute cosin.
6 7 8 |
# File 'lib/same_same/cosine_distance.rb', line 6 def cosin @cosin end |
Instance Method Details
#distance(x, y) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/same_same/cosine_distance.rb', line 12 def distance(x, y) sim = cosin.sim(x, y) if sim < 0.0 throw new ArgumentError( "Can't use this value to calculate distance." + "x[]=" + x.inspect + ", y[]=" + y.inspect + ", cosin.sim(x,y)=" + sim) end 1.0 - sim end |