k_means_pp 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 25114f424713579b656eddb1a275a59103a860c5
4
- data.tar.gz: f3ef959b9a7044a048903c44b2c55a4c0bc11583
3
+ metadata.gz: c559a4b71f8e96d813e46b25c718956c209561e3
4
+ data.tar.gz: fbf9650f96cffa2108bc10dbd687bd80318d992a
5
5
  SHA512:
6
- metadata.gz: ea81b5f48c62e0654cee9a635ffbc16e829c5129e1e26a02477217287a517416ce5adfe41a150199acc87dec26d335b9d89d738ea94bd31441ce419002d23625
7
- data.tar.gz: 9587a9d3a4d0c7d6d3e14d945d92bab9c81e9779699ef4f53dc8e232ea56f073d2fae1f0baad6c96ea2af6fc0ae01bd709964491ed9333f6e379e530acaf6bc4
6
+ metadata.gz: 33c2ec2d2ace4de6cad7752185fa0f5014a47c1e02b1f56571c75f03d8aa1b32940565ae2d2f10525879a50648f32b29331a8b81d1975567c975533ff44284d1
7
+ data.tar.gz: 6e7cb457d33d97f3f7e331978e57781193a039b750c7e683908a536b9fe76670d048f84d6d0191f8a3de24d58d46aad05532d0babbdd3d32d91e5377fe151780
data/.rspec CHANGED
@@ -1,2 +1,3 @@
1
1
  --color
2
2
  --format documentation
3
+ --require spec_helper.rb
data/.travis.yml ADDED
@@ -0,0 +1,18 @@
1
+ language: ruby
2
+
3
+ rvm:
4
+ - 2.0.0
5
+ - 2.1.3
6
+ - jruby-19mode
7
+
8
+ branches:
9
+ only:
10
+ - master
11
+
12
+ notifications:
13
+ email:
14
+ on_success: change
15
+ on_failure: always
16
+
17
+ install: "bundle --jobs 4"
18
+ script: bundle exec rspec
data/README.md CHANGED
@@ -1,5 +1,7 @@
1
1
  # KMeansPP
2
2
 
3
+ [![Build Status](https://travis-ci.org/ollie/k_means_pp.svg?branch=master)](https://travis-ci.org/ollie/k_means_pp)
4
+
3
5
  ## What's this?
4
6
 
5
7
  This is a Ruby implementation of the k-means++ algorithm for data clustering.
@@ -1,6 +1,5 @@
1
1
  $LOAD_PATH.unshift('../lib')
2
2
 
3
- require 'bundler/setup'
4
3
  require 'k_means_pp'
5
4
 
6
5
  points = [
@@ -1,6 +1,5 @@
1
1
  $LOAD_PATH.unshift('../lib')
2
2
 
3
- require 'bundler/setup'
4
3
  require 'k_means_pp'
5
4
  require './common'
6
5
  require 'csv'
@@ -1,6 +1,5 @@
1
1
  $LOAD_PATH.unshift('../lib')
2
2
 
3
- require 'bundler/setup'
4
3
  require 'k_means_pp'
5
4
  # require './common'
6
5
  require 'ruby-prof'
@@ -1,6 +1,5 @@
1
1
  $LOAD_PATH.unshift('../lib')
2
2
 
3
- require 'bundler/setup'
4
3
  require 'k_means_pp'
5
4
  require './common'
6
5
 
@@ -1,6 +1,5 @@
1
1
  $LOAD_PATH.unshift('../lib')
2
2
 
3
- require 'bundler/setup'
4
3
  require 'k_means_pp'
5
4
  require './common'
6
5
 
data/k_means_pp.gemspec CHANGED
@@ -32,7 +32,7 @@ Gem::Specification.new do |spec|
32
32
  spec.add_development_dependency 'rake', '~> 10.3'
33
33
  spec.add_development_dependency 'rubocop', '~> 0.26'
34
34
  spec.add_development_dependency 'pry', '~> 0.10'
35
- spec.add_development_dependency 'pry-byebug', '~> 2.0'
36
- spec.add_development_dependency 'ruby-prof', '~> 0.15'
37
- spec.add_development_dependency 'gnuplot', '~> 2.6'
35
+ # spec.add_development_dependency 'pry-byebug', '~> 2.0'
36
+ # spec.add_development_dependency 'ruby-prof', '~> 0.15'
37
+ # spec.add_development_dependency 'gnuplot', '~> 2.6'
38
38
  end
data/lib/k_means_pp.rb CHANGED
@@ -34,7 +34,7 @@ class KMeansPP
34
34
  instance = new(points, clusters_count, &block)
35
35
  instance.group_points
36
36
  instance.centroids.map do |centroid|
37
- cluster_for_centroid(centroid, points, &block)
37
+ cluster_for_centroid(centroid, instance.points, &block)
38
38
  end
39
39
  end
40
40
 
@@ -113,6 +113,9 @@ class KMeansPP
113
113
  # @param clusters_count [Fixnum] Number of clusters ("k").
114
114
  # @yieldreturn [Array<Numeric>]
115
115
  def initialize(points, clusters_count)
116
+ # Do not mutate original structure
117
+ points = points.dup
118
+
116
119
  if block_given?
117
120
  points.map! do |point_obj|
118
121
  point_ary = yield(point_obj)
@@ -1,4 +1,4 @@
1
1
  class KMeansPP
2
2
  # Version number, happy now?
3
- VERSION = '0.0.1'
3
+ VERSION = '0.0.2'
4
4
  end
@@ -1,9 +1,9 @@
1
- require 'spec_helper'
2
1
  require 'csv'
3
2
 
4
3
  RSpec.describe 'Superman' do
5
4
  it 'does it again' do
6
- data = CSV.foreach('./spec/resources/points.csv').map do |row|
5
+ raw_data = File.read('./spec/resources/points.csv')
6
+ data = CSV.parse(raw_data).map do |row|
7
7
  [row[0].to_f, row[1].to_f]
8
8
  end
9
9
 
@@ -59,4 +59,17 @@ RSpec.describe 'Superman' do
59
59
  expect(clusters.size).to eq(3)
60
60
  expect(clusters.first.points.first).to be_a(Hash)
61
61
  end
62
+
63
+ it 'does not mutate original structure' do
64
+ data = [
65
+ [0.3968, 1.9431],
66
+ [9.3348, 6.7843]
67
+ ]
68
+
69
+ backup = data.dup
70
+ clusters = KMeansPP.clusters(data, 2)
71
+
72
+ expect(data).to eq(backup)
73
+ expect(clusters.size).to eq(2)
74
+ end
62
75
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: k_means_pp
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
  - Oldrich Vetesnik
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-10-03 00:00:00.000000000 Z
11
+ date: 2014-10-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -108,48 +108,6 @@ dependencies:
108
108
  - - "~>"
109
109
  - !ruby/object:Gem::Version
110
110
  version: '0.10'
111
- - !ruby/object:Gem::Dependency
112
- name: pry-byebug
113
- requirement: !ruby/object:Gem::Requirement
114
- requirements:
115
- - - "~>"
116
- - !ruby/object:Gem::Version
117
- version: '2.0'
118
- type: :development
119
- prerelease: false
120
- version_requirements: !ruby/object:Gem::Requirement
121
- requirements:
122
- - - "~>"
123
- - !ruby/object:Gem::Version
124
- version: '2.0'
125
- - !ruby/object:Gem::Dependency
126
- name: ruby-prof
127
- requirement: !ruby/object:Gem::Requirement
128
- requirements:
129
- - - "~>"
130
- - !ruby/object:Gem::Version
131
- version: '0.15'
132
- type: :development
133
- prerelease: false
134
- version_requirements: !ruby/object:Gem::Requirement
135
- requirements:
136
- - - "~>"
137
- - !ruby/object:Gem::Version
138
- version: '0.15'
139
- - !ruby/object:Gem::Dependency
140
- name: gnuplot
141
- requirement: !ruby/object:Gem::Requirement
142
- requirements:
143
- - - "~>"
144
- - !ruby/object:Gem::Version
145
- version: '2.6'
146
- type: :development
147
- prerelease: false
148
- version_requirements: !ruby/object:Gem::Requirement
149
- requirements:
150
- - - "~>"
151
- - !ruby/object:Gem::Version
152
- version: '2.6'
153
111
  description: 'This is a Ruby implementation of the k-means++ algorithm for data clustering.
154
112
  In other words: Grouping a bunch of X, Y points into K groups.'
155
113
  email:
@@ -160,6 +118,7 @@ extra_rdoc_files: []
160
118
  files:
161
119
  - ".gitignore"
162
120
  - ".rspec"
121
+ - ".travis.yml"
163
122
  - ".yardopts"
164
123
  - Gemfile
165
124
  - LICENSE.txt