tdigest 0.1.0 → 0.1.1

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: 13d323c00e8ecc6fc72db137c6160f28c23a8615
4
- data.tar.gz: efad7cb62f79a512e4fc68dceca2ae5a55a693c3
3
+ metadata.gz: 5aeae6aa49816daeea269ec499590c97075a3149
4
+ data.tar.gz: dd214c32109be62d1fb145743f52d1398feb13d4
5
5
  SHA512:
6
- metadata.gz: a948d7d63a22957a34e9e1cf71d4e6904a325b1b7e4cd93de12611332c41c62be932a7fd69a6f356122c7da033bc24abaa86db29db5b03a8d1dc79031f603e59
7
- data.tar.gz: 6fb668b7bbe9f1885af98036843095f03d0a74034462c7fdd8fdde970c95b606be556074c41c042a1e02ce9c60bb29fddd0177d4eefdc6da5a32bac857e391ff
6
+ metadata.gz: 9cc95403c4e428cf3ea0443e0cda972dd78b948779bff3fccf6265c155a50d47d83489965e93aa9ef6dbee316d543107d36a9fe76bbf5b8ea76f034d3f7332c4
7
+ data.tar.gz: 1325bf0d452da07415d9a12aabf8e014c76c7ade0ab21615cf95bfb4f582d9373b4b7ba70d6265a19d449ae9f88e45d6e1c52624c82d73e96f0f8bfaf4db5678
@@ -1,6 +1,7 @@
1
1
  language: ruby
2
2
  rvm:
3
- - 1.9.3
3
+ - 2.0.0
4
4
  - 2.1.0
5
- - 2.2.3
5
+ - 2.2.4
6
+ - 2.3.1
6
7
  before_install: gem install bundler -v 1.10.6
@@ -1,10 +1,11 @@
1
1
  module TDigest
2
2
  class Centroid
3
3
  attr_accessor :mean, :n, :cumn, :mean_cumn
4
- def initialize(params = {})
5
- params.each do |p, value|
6
- send("#{p}=", value)
7
- end
4
+ def initialize(mean, n, cumn, mean_cumn = nil)
5
+ @mean = mean
6
+ @n = n
7
+ @cumn = cumn
8
+ @mean_cumn = mean_cumn
8
9
  end
9
10
 
10
11
  def as_json(_ = nil)
@@ -13,6 +13,7 @@ module TDigest
13
13
  @cx = cx
14
14
  @centroids = RBTree.new
15
15
  @nreset = 0
16
+ @n = 0
16
17
  reset!
17
18
  end
18
19
 
@@ -97,10 +98,8 @@ module TDigest
97
98
  def compress!
98
99
  points = to_a
99
100
  reset!
100
- while points.length > 0
101
- push_centroid(points.delete_at(rand(points.length)))
102
- end
103
- _cumulate(true)
101
+ push_centroid(points.shuffle)
102
+ _cumulate(true, true)
104
103
  nil
105
104
  end
106
105
 
@@ -128,10 +127,8 @@ module TDigest
128
127
  end
129
128
 
130
129
  def merge!(other)
131
- # Uses delta, k and cx from the caller
132
- t = self + other
133
- @centroids = t.centroids
134
- compress!
130
+ push_centroid(other.centroids.values.shuffle)
131
+ self
135
132
  end
136
133
 
137
134
  def p_rank(x)
@@ -277,7 +274,6 @@ module TDigest
277
274
  nearest.cumn += n
278
275
  nearest.mean_cumn += n / 2.0
279
276
  nearest.n += n
280
- @n += n
281
277
 
282
278
  nil
283
279
  end
@@ -311,6 +307,8 @@ module TDigest
311
307
  max = max.nil? ? nil : max[1]
312
308
  nearest = find_nearest(x)
313
309
 
310
+ @n += n
311
+
314
312
  if nearest && nearest.mean == x
315
313
  _add_weight(nearest, x, n)
316
314
  elsif nearest == min
@@ -341,9 +339,8 @@ module TDigest
341
339
  end
342
340
 
343
341
  def _new_centroid(x, n, cumn)
344
- c = Centroid.new({ mean: x, n: n, cumn: cumn })
342
+ c = Centroid.new(x, n, cumn)
345
343
  @centroids[x] = c
346
- @n += n
347
344
  c
348
345
  end
349
346
  end
@@ -1,3 +1,3 @@
1
1
  module TDigest
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tdigest
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sebastian Wallin
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-01-19 00:00:00.000000000 Z
11
+ date: 2016-10-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rbtree
@@ -135,7 +135,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
135
135
  version: '0'
136
136
  requirements: []
137
137
  rubyforge_project:
138
- rubygems_version: 2.4.5.1
138
+ rubygems_version: 2.5.1
139
139
  signing_key:
140
140
  specification_version: 4
141
141
  summary: Ruby implementation of Dunning's T-Digest for streaming quantile approximation