data_mining 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/data_mining/dbscan.rb +14 -2
  3. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5da253c99db083a7e8a8694ef479299269b95c87
4
- data.tar.gz: 873c011a2e26d9c1c11165a7ce9aa401d0d50250
3
+ metadata.gz: 974c994068ee3cf5b01c62f5b406f5ae327d17d3
4
+ data.tar.gz: e95b21a5a62291a3342b32b2b16db1ba31ae9e99
5
5
  SHA512:
6
- metadata.gz: 6f2f01babec563518f49ddd12ac23a55865245ab6b1c9862b88836d5544eb2be6ca49574f8261ed6f0d215e5880c14804dc5f54ae1757220b1bc41a71eeb780f
7
- data.tar.gz: 027e465483ca27939f8b43167ae9aacfd3cd709545e9bfb38c3a5cc31c0d39d5f2e1b23ec74d4c3319e01c5b4552c2f9ec41f15140ae5cb34e4b6ea73185be32
6
+ metadata.gz: e81c069008ec95bcc3598b29437890a497917b33e3a873dacbca64265f98681b5f1f8e2484c7fe893597d09837574a35fc846c049cd68c33e159d17c78b5abd2
7
+ data.tar.gz: b51412c6449a85a22ca5258d2731847abea52a498202bc12f6e4167c1ad28989f60e634c015e0f19409dde655b026a2dd20b5d3eb492f3b1ddbc9db83d9faeef
@@ -4,7 +4,7 @@ module DataMining
4
4
  # Find clusters and outliers
5
5
  #
6
6
  # Example:
7
- # >> input = [[:p1, 1], [:p2, 2], [:p3, 10]]
7
+ # >> input = [[:p1, [1,1]], [:p2, [2,1]], [:p3, [10,11]]]
8
8
  # >> radius = 3
9
9
  # >> min_points = 2
10
10
  # >> dbscan = DataMining::DBScan.cluster(input, radius, min_points)
@@ -96,9 +96,21 @@ module DataMining
96
96
  end
97
97
 
98
98
  def neighbors?(p1, p2)
99
- return true if (p1.value - p2.value).abs <= @radius && p1 != p2
99
+ fail ArgumentError, 'Wrong point coordinates' unless valid_points?(p1, p2)
100
+ return true if p1 != p2 && euclidean_distance(p1, p2).abs <= @radius
100
101
  false
101
102
  end
103
+
104
+ def valid_points?(p1, p2)
105
+ return false if p1.value.length != p2.value.length
106
+ (p1.value + p2.value).all? { |x| x.is_a? Numeric }
107
+ end
108
+
109
+ def euclidean_distance(p1, p2)
110
+ p1 = p1.value
111
+ p2 = p2.value
112
+ Math.sqrt(p1.each_with_index.inject(0) { |sum, (v, i)| sum + ((v - p2[i])**2) })
113
+ end
102
114
  end
103
115
  end
104
116
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: data_mining
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Manuel Stuefer
@@ -19,7 +19,7 @@ files:
19
19
  - lib/data_mining.rb
20
20
  - lib/data_mining/dbscan.rb
21
21
  - lib/data_mining/point.rb
22
- homepage: http://rubygems.org/gems/data_mining
22
+ homepage: https://github.com/mstuefer/data_mining
23
23
  licenses:
24
24
  - MIT
25
25
  metadata: {}