quantile_estimator 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.ruby-gemset +1 -0
- data/.ruby-version +1 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +17 -0
- data/LICENSE.txt +22 -0
- data/README.md +85 -0
- data/Rakefile +9 -0
- data/benchmark.rb +21 -0
- data/doc/Cursor.html +422 -0
- data/doc/Estimator.html +779 -0
- data/doc/Invariant.html +115 -0
- data/doc/Invariant/Biased.html +268 -0
- data/doc/Invariant/Invariant.html +193 -0
- data/doc/Invariant/SingleTarget.html +278 -0
- data/doc/Invariant/Targeted.html +278 -0
- data/doc/Item.html +620 -0
- data/doc/Quantile.html +270 -0
- data/doc/QuantileEstimator.html +117 -0
- data/doc/_index.html +211 -0
- data/doc/class_list.html +54 -0
- data/doc/compression.png +0 -0
- data/doc/css/common.css +1 -0
- data/doc/css/full_list.css +57 -0
- data/doc/css/style.css +338 -0
- data/doc/file.README.html +186 -0
- data/doc/file_list.html +56 -0
- data/doc/frames.html +26 -0
- data/doc/index.html +186 -0
- data/doc/js/app.js +219 -0
- data/doc/js/full_list.js +178 -0
- data/doc/js/jquery.js +4 -0
- data/doc/method_list.html +221 -0
- data/doc/time.png +0 -0
- data/doc/top-level-namespace.html +114 -0
- data/lib/estimator.rb +120 -0
- data/lib/quantile_estimator/cursor.rb +24 -0
- data/lib/quantile_estimator/invariant.rb +47 -0
- data/lib/quantile_estimator/item.rb +21 -0
- data/lib/quantile_estimator/quantile.rb +3 -0
- data/lib/quantile_estimator/test.rb +37 -0
- data/lib/quantile_estimator/version.rb +3 -0
- data/pkg/quantile_estimator-0.0.1.gem +0 -0
- data/quantile_estimator.gemspec +29 -0
- data/test/test_quantile_estimator.rb +85 -0
- metadata +120 -0
data/doc/Estimator.html
ADDED
|
@@ -0,0 +1,779 @@
|
|
|
1
|
+
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
|
|
2
|
+
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
|
3
|
+
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
|
4
|
+
<head>
|
|
5
|
+
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
|
6
|
+
<title>
|
|
7
|
+
Class: Estimator
|
|
8
|
+
|
|
9
|
+
— Documentation by YARD 0.8.7.3
|
|
10
|
+
|
|
11
|
+
</title>
|
|
12
|
+
|
|
13
|
+
<link rel="stylesheet" href="css/style.css" type="text/css" charset="utf-8" />
|
|
14
|
+
|
|
15
|
+
<link rel="stylesheet" href="css/common.css" type="text/css" charset="utf-8" />
|
|
16
|
+
|
|
17
|
+
<script type="text/javascript" charset="utf-8">
|
|
18
|
+
hasFrames = window.top.frames.main ? true : false;
|
|
19
|
+
relpath = '';
|
|
20
|
+
framesUrl = "frames.html#!" + escape(window.location.href);
|
|
21
|
+
</script>
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
<script type="text/javascript" charset="utf-8" src="js/jquery.js"></script>
|
|
25
|
+
|
|
26
|
+
<script type="text/javascript" charset="utf-8" src="js/app.js"></script>
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
</head>
|
|
30
|
+
<body>
|
|
31
|
+
<div id="header">
|
|
32
|
+
<div id="menu">
|
|
33
|
+
|
|
34
|
+
<a href="_index.html">Index (E)</a> »
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
<span class="title">Estimator</span>
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
<div class="noframes"><span class="title">(</span><a href="." target="_top">no frames</a><span class="title">)</span></div>
|
|
41
|
+
</div>
|
|
42
|
+
|
|
43
|
+
<div id="search">
|
|
44
|
+
|
|
45
|
+
<a class="full_list_link" id="class_list_link"
|
|
46
|
+
href="class_list.html">
|
|
47
|
+
Class List
|
|
48
|
+
</a>
|
|
49
|
+
|
|
50
|
+
<a class="full_list_link" id="method_list_link"
|
|
51
|
+
href="method_list.html">
|
|
52
|
+
Method List
|
|
53
|
+
</a>
|
|
54
|
+
|
|
55
|
+
<a class="full_list_link" id="file_list_link"
|
|
56
|
+
href="file_list.html">
|
|
57
|
+
File List
|
|
58
|
+
</a>
|
|
59
|
+
|
|
60
|
+
</div>
|
|
61
|
+
<div class="clear"></div>
|
|
62
|
+
</div>
|
|
63
|
+
|
|
64
|
+
<iframe id="search_frame"></iframe>
|
|
65
|
+
|
|
66
|
+
<div id="content"><h1>Class: Estimator
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
</h1>
|
|
71
|
+
|
|
72
|
+
<dl class="box">
|
|
73
|
+
|
|
74
|
+
<dt class="r1">Inherits:</dt>
|
|
75
|
+
<dd class="r1">
|
|
76
|
+
<span class="inheritName">Object</span>
|
|
77
|
+
|
|
78
|
+
<ul class="fullTree">
|
|
79
|
+
<li>Object</li>
|
|
80
|
+
|
|
81
|
+
<li class="next">Estimator</li>
|
|
82
|
+
|
|
83
|
+
</ul>
|
|
84
|
+
<a href="#" class="inheritanceTree">show all</a>
|
|
85
|
+
|
|
86
|
+
</dd>
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
<dt class="r2 last">Defined in:</dt>
|
|
97
|
+
<dd class="r2 last">lib/estimator.rb</dd>
|
|
98
|
+
|
|
99
|
+
</dl>
|
|
100
|
+
<div class="clear"></div>
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
<h2>Instance Attribute Summary <small>(<a href="#" class="summary_toggle">collapse</a>)</small></h2>
|
|
107
|
+
<ul class="summary">
|
|
108
|
+
|
|
109
|
+
<li class="public ">
|
|
110
|
+
<span class="summary_signature">
|
|
111
|
+
|
|
112
|
+
<a href="#invariant-instance_method" title="#invariant (instance method)">- (Object) <strong>invariant</strong> </a>
|
|
113
|
+
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
</span>
|
|
117
|
+
|
|
118
|
+
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
<span class="note title readonly">readonly</span>
|
|
122
|
+
|
|
123
|
+
|
|
124
|
+
|
|
125
|
+
|
|
126
|
+
|
|
127
|
+
|
|
128
|
+
|
|
129
|
+
|
|
130
|
+
|
|
131
|
+
<span class="summary_desc"><div class='inline'>
|
|
132
|
+
<p>Returns the value of attribute invariant.</p>
|
|
133
|
+
</div></span>
|
|
134
|
+
|
|
135
|
+
</li>
|
|
136
|
+
|
|
137
|
+
|
|
138
|
+
<li class="public ">
|
|
139
|
+
<span class="summary_signature">
|
|
140
|
+
|
|
141
|
+
<a href="#n-instance_method" title="#n (instance method)">- (Object) <strong>n</strong> </a>
|
|
142
|
+
|
|
143
|
+
|
|
144
|
+
|
|
145
|
+
</span>
|
|
146
|
+
|
|
147
|
+
|
|
148
|
+
|
|
149
|
+
|
|
150
|
+
|
|
151
|
+
|
|
152
|
+
|
|
153
|
+
|
|
154
|
+
|
|
155
|
+
|
|
156
|
+
|
|
157
|
+
|
|
158
|
+
<span class="summary_desc"><div class='inline'>
|
|
159
|
+
<p>Returns the value of attribute n.</p>
|
|
160
|
+
</div></span>
|
|
161
|
+
|
|
162
|
+
</li>
|
|
163
|
+
|
|
164
|
+
|
|
165
|
+
<li class="public ">
|
|
166
|
+
<span class="summary_signature">
|
|
167
|
+
|
|
168
|
+
<a href="#samples-instance_method" title="#samples (instance method)">- (Object) <strong>samples</strong> </a>
|
|
169
|
+
|
|
170
|
+
|
|
171
|
+
|
|
172
|
+
</span>
|
|
173
|
+
|
|
174
|
+
|
|
175
|
+
|
|
176
|
+
|
|
177
|
+
|
|
178
|
+
|
|
179
|
+
|
|
180
|
+
|
|
181
|
+
|
|
182
|
+
|
|
183
|
+
|
|
184
|
+
|
|
185
|
+
<span class="summary_desc"><div class='inline'>
|
|
186
|
+
<p>Returns the value of attribute samples.</p>
|
|
187
|
+
</div></span>
|
|
188
|
+
|
|
189
|
+
</li>
|
|
190
|
+
|
|
191
|
+
|
|
192
|
+
</ul>
|
|
193
|
+
|
|
194
|
+
|
|
195
|
+
|
|
196
|
+
|
|
197
|
+
|
|
198
|
+
<h2>
|
|
199
|
+
Instance Method Summary
|
|
200
|
+
<small>(<a href="#" class="summary_toggle">collapse</a>)</small>
|
|
201
|
+
</h2>
|
|
202
|
+
|
|
203
|
+
<ul class="summary">
|
|
204
|
+
|
|
205
|
+
<li class="public ">
|
|
206
|
+
<span class="summary_signature">
|
|
207
|
+
|
|
208
|
+
<a href="#compress%21-instance_method" title="#compress! (instance method)">- (Object) <strong>compress!</strong> </a>
|
|
209
|
+
|
|
210
|
+
|
|
211
|
+
|
|
212
|
+
</span>
|
|
213
|
+
|
|
214
|
+
|
|
215
|
+
|
|
216
|
+
|
|
217
|
+
|
|
218
|
+
|
|
219
|
+
|
|
220
|
+
|
|
221
|
+
|
|
222
|
+
<span class="summary_desc"><div class='inline'>
|
|
223
|
+
<p>Compresses the internal data-structure.</p>
|
|
224
|
+
</div></span>
|
|
225
|
+
|
|
226
|
+
</li>
|
|
227
|
+
|
|
228
|
+
|
|
229
|
+
<li class="public ">
|
|
230
|
+
<span class="summary_signature">
|
|
231
|
+
|
|
232
|
+
<a href="#initialize-instance_method" title="#initialize (instance method)">- (Estimator) <strong>initialize</strong>(invariant) </a>
|
|
233
|
+
|
|
234
|
+
|
|
235
|
+
|
|
236
|
+
</span>
|
|
237
|
+
|
|
238
|
+
|
|
239
|
+
<span class="note title constructor">constructor</span>
|
|
240
|
+
|
|
241
|
+
|
|
242
|
+
|
|
243
|
+
|
|
244
|
+
|
|
245
|
+
|
|
246
|
+
|
|
247
|
+
|
|
248
|
+
<span class="summary_desc"><div class='inline'>
|
|
249
|
+
<p>Creates a new quantile Estimator object using the provided invariant.</p>
|
|
250
|
+
</div></span>
|
|
251
|
+
|
|
252
|
+
</li>
|
|
253
|
+
|
|
254
|
+
|
|
255
|
+
<li class="public ">
|
|
256
|
+
<span class="summary_signature">
|
|
257
|
+
|
|
258
|
+
<a href="#insert-instance_method" title="#insert (instance method)">- (Object) <strong>insert</strong>(value) </a>
|
|
259
|
+
|
|
260
|
+
|
|
261
|
+
|
|
262
|
+
</span>
|
|
263
|
+
|
|
264
|
+
|
|
265
|
+
|
|
266
|
+
|
|
267
|
+
|
|
268
|
+
|
|
269
|
+
|
|
270
|
+
|
|
271
|
+
|
|
272
|
+
<span class="summary_desc"><div class='inline'>
|
|
273
|
+
<p>Inserts a new element into the quantile estimator.</p>
|
|
274
|
+
</div></span>
|
|
275
|
+
|
|
276
|
+
</li>
|
|
277
|
+
|
|
278
|
+
|
|
279
|
+
<li class="public ">
|
|
280
|
+
<span class="summary_signature">
|
|
281
|
+
|
|
282
|
+
<a href="#query-instance_method" title="#query (instance method)">- (Object) <strong>query</strong>(phi) </a>
|
|
283
|
+
|
|
284
|
+
|
|
285
|
+
|
|
286
|
+
</span>
|
|
287
|
+
|
|
288
|
+
|
|
289
|
+
|
|
290
|
+
|
|
291
|
+
|
|
292
|
+
|
|
293
|
+
|
|
294
|
+
|
|
295
|
+
|
|
296
|
+
<span class="summary_desc"><div class='inline'>
|
|
297
|
+
<p>Queries de estimator for the given rank.</p>
|
|
298
|
+
</div></span>
|
|
299
|
+
|
|
300
|
+
</li>
|
|
301
|
+
|
|
302
|
+
|
|
303
|
+
</ul>
|
|
304
|
+
|
|
305
|
+
|
|
306
|
+
<div id="constructor_details" class="method_details_list">
|
|
307
|
+
<h2>Constructor Details</h2>
|
|
308
|
+
|
|
309
|
+
<div class="method_details first">
|
|
310
|
+
<h3 class="signature first" id="initialize-instance_method">
|
|
311
|
+
|
|
312
|
+
- (<tt><span class='object_link'><a href="" title="Estimator (class)">Estimator</a></span></tt>) <strong>initialize</strong>(invariant)
|
|
313
|
+
|
|
314
|
+
|
|
315
|
+
|
|
316
|
+
|
|
317
|
+
|
|
318
|
+
</h3><div class="docstring">
|
|
319
|
+
<div class="discussion">
|
|
320
|
+
|
|
321
|
+
<p>Creates a new quantile Estimator object using the provided invariant.</p>
|
|
322
|
+
|
|
323
|
+
<h2 id="label-Parameters%3A">Parameters:</h2>
|
|
324
|
+
<dl class="rdoc-list note-list"><dt>value
|
|
325
|
+
<dd>
|
|
326
|
+
<p>An ::Invariant object</p>
|
|
327
|
+
</dd></dl>
|
|
328
|
+
|
|
329
|
+
|
|
330
|
+
</div>
|
|
331
|
+
</div>
|
|
332
|
+
<div class="tags">
|
|
333
|
+
|
|
334
|
+
|
|
335
|
+
</div><table class="source_code">
|
|
336
|
+
<tr>
|
|
337
|
+
<td>
|
|
338
|
+
<pre class="lines">
|
|
339
|
+
|
|
340
|
+
|
|
341
|
+
16
|
|
342
|
+
17
|
|
343
|
+
18
|
|
344
|
+
19
|
|
345
|
+
20</pre>
|
|
346
|
+
</td>
|
|
347
|
+
<td>
|
|
348
|
+
<pre class="code"><span class="info file"># File 'lib/estimator.rb', line 16</span>
|
|
349
|
+
|
|
350
|
+
<span class='kw'>def</span> <span class='id identifier rubyid_initialize'>initialize</span><span class='lparen'>(</span><span class='id identifier rubyid_invariant'>invariant</span><span class='rparen'>)</span>
|
|
351
|
+
<span class='ivar'>@invariant</span> <span class='op'>=</span> <span class='id identifier rubyid_invariant'>invariant</span>
|
|
352
|
+
<span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_samples'>samples</span> <span class='op'>=</span> <span class='lbracket'>[</span><span class='rbracket'>]</span>
|
|
353
|
+
<span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_n'>n</span> <span class='op'>=</span> <span class='int'>0</span>
|
|
354
|
+
<span class='kw'>end</span></pre>
|
|
355
|
+
</td>
|
|
356
|
+
</tr>
|
|
357
|
+
</table>
|
|
358
|
+
</div>
|
|
359
|
+
|
|
360
|
+
</div>
|
|
361
|
+
|
|
362
|
+
<div id="instance_attr_details" class="attr_details">
|
|
363
|
+
<h2>Instance Attribute Details</h2>
|
|
364
|
+
|
|
365
|
+
|
|
366
|
+
<span id=""></span>
|
|
367
|
+
<div class="method_details first">
|
|
368
|
+
<h3 class="signature first" id="invariant-instance_method">
|
|
369
|
+
|
|
370
|
+
- (<tt>Object</tt>) <strong>invariant</strong> <span class="extras">(readonly)</span>
|
|
371
|
+
|
|
372
|
+
|
|
373
|
+
|
|
374
|
+
|
|
375
|
+
|
|
376
|
+
</h3><div class="docstring">
|
|
377
|
+
<div class="discussion">
|
|
378
|
+
|
|
379
|
+
<p>Returns the value of attribute invariant</p>
|
|
380
|
+
|
|
381
|
+
|
|
382
|
+
</div>
|
|
383
|
+
</div>
|
|
384
|
+
<div class="tags">
|
|
385
|
+
|
|
386
|
+
|
|
387
|
+
</div><table class="source_code">
|
|
388
|
+
<tr>
|
|
389
|
+
<td>
|
|
390
|
+
<pre class="lines">
|
|
391
|
+
|
|
392
|
+
|
|
393
|
+
8
|
|
394
|
+
9
|
|
395
|
+
10</pre>
|
|
396
|
+
</td>
|
|
397
|
+
<td>
|
|
398
|
+
<pre class="code"><span class="info file"># File 'lib/estimator.rb', line 8</span>
|
|
399
|
+
|
|
400
|
+
<span class='kw'>def</span> <span class='id identifier rubyid_invariant'>invariant</span>
|
|
401
|
+
<span class='ivar'>@invariant</span>
|
|
402
|
+
<span class='kw'>end</span></pre>
|
|
403
|
+
</td>
|
|
404
|
+
</tr>
|
|
405
|
+
</table>
|
|
406
|
+
</div>
|
|
407
|
+
|
|
408
|
+
|
|
409
|
+
<span id="n=-instance_method"></span>
|
|
410
|
+
<div class="method_details ">
|
|
411
|
+
<h3 class="signature " id="n-instance_method">
|
|
412
|
+
|
|
413
|
+
- (<tt>Object</tt>) <strong>n</strong>
|
|
414
|
+
|
|
415
|
+
|
|
416
|
+
|
|
417
|
+
|
|
418
|
+
|
|
419
|
+
</h3><div class="docstring">
|
|
420
|
+
<div class="discussion">
|
|
421
|
+
|
|
422
|
+
<p>Returns the value of attribute n</p>
|
|
423
|
+
|
|
424
|
+
|
|
425
|
+
</div>
|
|
426
|
+
</div>
|
|
427
|
+
<div class="tags">
|
|
428
|
+
|
|
429
|
+
|
|
430
|
+
</div><table class="source_code">
|
|
431
|
+
<tr>
|
|
432
|
+
<td>
|
|
433
|
+
<pre class="lines">
|
|
434
|
+
|
|
435
|
+
|
|
436
|
+
7
|
|
437
|
+
8
|
|
438
|
+
9</pre>
|
|
439
|
+
</td>
|
|
440
|
+
<td>
|
|
441
|
+
<pre class="code"><span class="info file"># File 'lib/estimator.rb', line 7</span>
|
|
442
|
+
|
|
443
|
+
<span class='kw'>def</span> <span class='id identifier rubyid_n'>n</span>
|
|
444
|
+
<span class='ivar'>@n</span>
|
|
445
|
+
<span class='kw'>end</span></pre>
|
|
446
|
+
</td>
|
|
447
|
+
</tr>
|
|
448
|
+
</table>
|
|
449
|
+
</div>
|
|
450
|
+
|
|
451
|
+
|
|
452
|
+
<span id="samples=-instance_method"></span>
|
|
453
|
+
<div class="method_details ">
|
|
454
|
+
<h3 class="signature " id="samples-instance_method">
|
|
455
|
+
|
|
456
|
+
- (<tt>Object</tt>) <strong>samples</strong>
|
|
457
|
+
|
|
458
|
+
|
|
459
|
+
|
|
460
|
+
|
|
461
|
+
|
|
462
|
+
</h3><div class="docstring">
|
|
463
|
+
<div class="discussion">
|
|
464
|
+
|
|
465
|
+
<p>Returns the value of attribute samples</p>
|
|
466
|
+
|
|
467
|
+
|
|
468
|
+
</div>
|
|
469
|
+
</div>
|
|
470
|
+
<div class="tags">
|
|
471
|
+
|
|
472
|
+
|
|
473
|
+
</div><table class="source_code">
|
|
474
|
+
<tr>
|
|
475
|
+
<td>
|
|
476
|
+
<pre class="lines">
|
|
477
|
+
|
|
478
|
+
|
|
479
|
+
6
|
|
480
|
+
7
|
|
481
|
+
8</pre>
|
|
482
|
+
</td>
|
|
483
|
+
<td>
|
|
484
|
+
<pre class="code"><span class="info file"># File 'lib/estimator.rb', line 6</span>
|
|
485
|
+
|
|
486
|
+
<span class='kw'>def</span> <span class='id identifier rubyid_samples'>samples</span>
|
|
487
|
+
<span class='ivar'>@samples</span>
|
|
488
|
+
<span class='kw'>end</span></pre>
|
|
489
|
+
</td>
|
|
490
|
+
</tr>
|
|
491
|
+
</table>
|
|
492
|
+
</div>
|
|
493
|
+
|
|
494
|
+
</div>
|
|
495
|
+
|
|
496
|
+
|
|
497
|
+
<div id="instance_method_details" class="method_details_list">
|
|
498
|
+
<h2>Instance Method Details</h2>
|
|
499
|
+
|
|
500
|
+
|
|
501
|
+
<div class="method_details first">
|
|
502
|
+
<h3 class="signature first" id="compress!-instance_method">
|
|
503
|
+
|
|
504
|
+
- (<tt>Object</tt>) <strong>compress!</strong>
|
|
505
|
+
|
|
506
|
+
|
|
507
|
+
|
|
508
|
+
|
|
509
|
+
|
|
510
|
+
</h3><div class="docstring">
|
|
511
|
+
<div class="discussion">
|
|
512
|
+
|
|
513
|
+
<p>Compresses the internal data-structure. O(n), where n is the number of
|
|
514
|
+
elements of the internal data structure</p>
|
|
515
|
+
|
|
516
|
+
<h2 id="label-Parameters%3A">Parameters:</h2>
|
|
517
|
+
|
|
518
|
+
<h2 id="label-Returns%3A">Returns:</h2>
|
|
519
|
+
|
|
520
|
+
|
|
521
|
+
</div>
|
|
522
|
+
</div>
|
|
523
|
+
<div class="tags">
|
|
524
|
+
|
|
525
|
+
|
|
526
|
+
</div><table class="source_code">
|
|
527
|
+
<tr>
|
|
528
|
+
<td>
|
|
529
|
+
<pre class="lines">
|
|
530
|
+
|
|
531
|
+
|
|
532
|
+
69
|
|
533
|
+
70
|
|
534
|
+
71
|
|
535
|
+
72
|
|
536
|
+
73
|
|
537
|
+
74
|
|
538
|
+
75
|
|
539
|
+
76
|
|
540
|
+
77
|
|
541
|
+
78
|
|
542
|
+
79
|
|
543
|
+
80
|
|
544
|
+
81
|
|
545
|
+
82
|
|
546
|
+
83</pre>
|
|
547
|
+
</td>
|
|
548
|
+
<td>
|
|
549
|
+
<pre class="code"><span class="info file"># File 'lib/estimator.rb', line 69</span>
|
|
550
|
+
|
|
551
|
+
<span class='kw'>def</span> <span class='id identifier rubyid_compress!'>compress!</span>
|
|
552
|
+
<span class='id identifier rubyid_c'>c</span> <span class='op'>=</span> <span class='const'>Cursor</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span><span class='lparen'>(</span><span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_samples'>samples</span><span class='comma'>,</span> <span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_samples'>samples</span><span class='period'>.</span><span class='id identifier rubyid_length'>length</span> <span class='op'>-</span> <span class='int'>1</span><span class='rparen'>)</span>
|
|
553
|
+
<span class='kw'>while</span> <span class='lparen'>(</span><span class='op'>~</span><span class='id identifier rubyid_c'>c</span> <span class='op'>!=</span> <span class='kw'>nil</span><span class='rparen'>)</span> <span class='op'>&&</span> <span class='lparen'>(</span><span class='op'>~</span><span class='id identifier rubyid_c'>c</span><span class='period'>.</span><span class='id identifier rubyid_previous'>previous</span> <span class='op'>!=</span> <span class='kw'>nil</span><span class='rparen'>)</span>
|
|
554
|
+
<span class='kw'>if</span> <span class='lparen'>(</span><span class='lparen'>(</span><span class='op'>~</span><span class='id identifier rubyid_c'>c</span><span class='period'>.</span><span class='id identifier rubyid_previous'>previous</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_g'>g</span> <span class='op'>+</span> <span class='lparen'>(</span><span class='op'>~</span><span class='id identifier rubyid_c'>c</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_g'>g</span> <span class='op'>+</span> <span class='lparen'>(</span><span class='op'>~</span><span class='id identifier rubyid_c'>c</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_delta'>delta</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_to_f'>to_f</span> <span class='op'><=</span>
|
|
555
|
+
<span class='id identifier rubyid_invariant'>invariant</span><span class='period'>.</span><span class='id identifier rubyid_upper_bound'>upper_bound</span><span class='lparen'>(</span><span class='lparen'>(</span><span class='op'>~</span><span class='id identifier rubyid_c'>c</span><span class='period'>.</span><span class='id identifier rubyid_previous'>previous</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_rank'>rank</span><span class='comma'>,</span> <span class='id identifier rubyid_n'>n</span><span class='rparen'>)</span>
|
|
556
|
+
<span class='id identifier rubyid_removed'>removed</span> <span class='op'>=</span> <span class='op'>~</span><span class='id identifier rubyid_c'>c</span><span class='period'>.</span><span class='id identifier rubyid_previous'>previous</span>
|
|
557
|
+
<span class='lparen'>(</span><span class='op'>~</span><span class='id identifier rubyid_c'>c</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_rank'>rank</span> <span class='op'>=</span> <span class='id identifier rubyid_removed'>removed</span><span class='period'>.</span><span class='id identifier rubyid_rank'>rank</span>
|
|
558
|
+
<span class='lparen'>(</span><span class='op'>~</span><span class='id identifier rubyid_c'>c</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_g'>g</span> <span class='op'>+=</span> <span class='id identifier rubyid_removed'>removed</span><span class='period'>.</span><span class='id identifier rubyid_g'>g</span>
|
|
559
|
+
<span class='id identifier rubyid_c'>c</span><span class='period'>.</span><span class='id identifier rubyid_previous'>previous</span><span class='period'>.</span><span class='id identifier rubyid_remove!'>remove!</span>
|
|
560
|
+
<span class='id identifier rubyid_c'>c</span> <span class='op'>=</span> <span class='id identifier rubyid_c'>c</span><span class='period'>.</span><span class='id identifier rubyid_previous'>previous</span>
|
|
561
|
+
<span class='kw'>end</span>
|
|
562
|
+
<span class='id identifier rubyid_c'>c</span> <span class='op'>=</span> <span class='id identifier rubyid_c'>c</span><span class='period'>.</span><span class='id identifier rubyid_previous'>previous</span>
|
|
563
|
+
<span class='kw'>end</span>
|
|
564
|
+
<span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_samples'>samples</span>
|
|
565
|
+
<span class='kw'>end</span></pre>
|
|
566
|
+
</td>
|
|
567
|
+
</tr>
|
|
568
|
+
</table>
|
|
569
|
+
</div>
|
|
570
|
+
|
|
571
|
+
<div class="method_details ">
|
|
572
|
+
<h3 class="signature " id="insert-instance_method">
|
|
573
|
+
|
|
574
|
+
- (<tt>Object</tt>) <strong>insert</strong>(value)
|
|
575
|
+
|
|
576
|
+
|
|
577
|
+
|
|
578
|
+
|
|
579
|
+
|
|
580
|
+
</h3><div class="docstring">
|
|
581
|
+
<div class="discussion">
|
|
582
|
+
|
|
583
|
+
<p>Inserts a new element into the quantile estimator. O(n), where n is the
|
|
584
|
+
number of elements of the internal data structure</p>
|
|
585
|
+
|
|
586
|
+
<h2 id="label-Parameters%3A">Parameters:</h2>
|
|
587
|
+
<dl class="rdoc-list note-list"><dt>value
|
|
588
|
+
<dd>
|
|
589
|
+
<p>A Fixnum to observe</p>
|
|
590
|
+
</dd></dl>
|
|
591
|
+
|
|
592
|
+
<h2 id="label-Returns%3A">Returns:</h2>
|
|
593
|
+
|
|
594
|
+
<p>The number of observations after the insertion</p>
|
|
595
|
+
|
|
596
|
+
|
|
597
|
+
</div>
|
|
598
|
+
</div>
|
|
599
|
+
<div class="tags">
|
|
600
|
+
|
|
601
|
+
|
|
602
|
+
</div><table class="source_code">
|
|
603
|
+
<tr>
|
|
604
|
+
<td>
|
|
605
|
+
<pre class="lines">
|
|
606
|
+
|
|
607
|
+
|
|
608
|
+
32
|
|
609
|
+
33
|
|
610
|
+
34
|
|
611
|
+
35
|
|
612
|
+
36
|
|
613
|
+
37
|
|
614
|
+
38
|
|
615
|
+
39
|
|
616
|
+
40
|
|
617
|
+
41
|
|
618
|
+
42
|
|
619
|
+
43
|
|
620
|
+
44
|
|
621
|
+
45
|
|
622
|
+
46
|
|
623
|
+
47
|
|
624
|
+
48
|
|
625
|
+
49
|
|
626
|
+
50
|
|
627
|
+
51
|
|
628
|
+
52
|
|
629
|
+
53
|
|
630
|
+
54
|
|
631
|
+
55
|
|
632
|
+
56
|
|
633
|
+
57
|
|
634
|
+
58
|
|
635
|
+
59
|
|
636
|
+
60</pre>
|
|
637
|
+
</td>
|
|
638
|
+
<td>
|
|
639
|
+
<pre class="code"><span class="info file"># File 'lib/estimator.rb', line 32</span>
|
|
640
|
+
|
|
641
|
+
<span class='kw'>def</span> <span class='id identifier rubyid_insert'>insert</span><span class='lparen'>(</span><span class='id identifier rubyid_value'>value</span><span class='rparen'>)</span>
|
|
642
|
+
<span class='id identifier rubyid_i'>i</span> <span class='op'>=</span> <span class='int'>0</span>
|
|
643
|
+
<span class='id identifier rubyid_r_i'>r_i</span> <span class='op'>=</span> <span class='int'>0</span>
|
|
644
|
+
|
|
645
|
+
<span class='kw'>while</span><span class='lparen'>(</span><span class='id identifier rubyid_i'>i</span> <span class='op'><</span> <span class='id identifier rubyid_samples'>samples</span><span class='period'>.</span><span class='id identifier rubyid_length'>length</span><span class='rparen'>)</span>
|
|
646
|
+
<span class='id identifier rubyid_item'>item</span> <span class='op'>=</span> <span class='id identifier rubyid_samples'>samples</span><span class='lbracket'>[</span><span class='id identifier rubyid_i'>i</span><span class='rbracket'>]</span>
|
|
647
|
+
<span class='kw'>break</span> <span class='kw'>if</span> <span class='id identifier rubyid_item'>item</span><span class='period'>.</span><span class='id identifier rubyid_value'>value</span> <span class='op'>></span> <span class='id identifier rubyid_value'>value</span> <span class='comment'># determines the order
|
|
648
|
+
</span> <span class='id identifier rubyid_r_i'>r_i</span> <span class='op'>=</span> <span class='id identifier rubyid_r_i'>r_i</span> <span class='op'>+</span> <span class='id identifier rubyid_item'>item</span><span class='period'>.</span><span class='id identifier rubyid_g'>g</span>
|
|
649
|
+
<span class='id identifier rubyid_i'>i</span> <span class='op'>+=</span> <span class='int'>1</span>
|
|
650
|
+
<span class='kw'>end</span>
|
|
651
|
+
|
|
652
|
+
<span class='id identifier rubyid_delta'>delta</span> <span class='op'>=</span> <span class='kw'>if</span> <span class='lparen'>(</span><span class='id identifier rubyid_i'>i</span><span class='op'>-</span><span class='int'>1</span> <span class='op'><</span> <span class='int'>0</span><span class='rparen'>)</span> <span class='op'>||</span> <span class='lparen'>(</span><span class='id identifier rubyid_i'>i</span> <span class='op'>==</span> <span class='id identifier rubyid_samples'>samples</span><span class='period'>.</span><span class='id identifier rubyid_length'>length</span><span class='rparen'>)</span>
|
|
653
|
+
<span class='int'>0</span>
|
|
654
|
+
<span class='kw'>else</span>
|
|
655
|
+
<span class='comment'># r_i
|
|
656
|
+
</span> <span class='lbracket'>[</span><span class='int'>0</span><span class='comma'>,</span> <span class='id identifier rubyid_invariant'>invariant</span><span class='period'>.</span><span class='id identifier rubyid_upper_bound'>upper_bound</span><span class='lparen'>(</span><span class='id identifier rubyid_r_i'>r_i</span><span class='comma'>,</span> <span class='id identifier rubyid_n'>n</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_floor'>floor</span> <span class='op'>-</span> <span class='int'>1</span><span class='rbracket'>]</span><span class='period'>.</span><span class='id identifier rubyid_max'>max</span>
|
|
657
|
+
<span class='kw'>end</span>
|
|
658
|
+
|
|
659
|
+
<span class='id identifier rubyid_samples'>samples</span><span class='period'>.</span><span class='id identifier rubyid_insert'>insert</span><span class='lparen'>(</span><span class='id identifier rubyid_i'>i</span><span class='comma'>,</span> <span class='const'>Item</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span><span class='lparen'>(</span><span class='id identifier rubyid_value'>value</span><span class='comma'>,</span> <span class='int'>1</span><span class='comma'>,</span> <span class='id identifier rubyid_delta'>delta</span><span class='comma'>,</span> <span class='id identifier rubyid_r_i'>r_i</span><span class='rparen'>)</span><span class='rparen'>)</span>
|
|
660
|
+
|
|
661
|
+
<span class='kw'>while</span><span class='lparen'>(</span><span class='id identifier rubyid_i'>i</span> <span class='op'><</span> <span class='id identifier rubyid_samples'>samples</span><span class='period'>.</span><span class='id identifier rubyid_length'>length</span><span class='rparen'>)</span>
|
|
662
|
+
<span class='id identifier rubyid_item'>item</span> <span class='op'>=</span> <span class='id identifier rubyid_samples'>samples</span><span class='lbracket'>[</span><span class='id identifier rubyid_i'>i</span><span class='rbracket'>]</span>
|
|
663
|
+
<span class='id identifier rubyid_r_i'>r_i</span> <span class='op'>=</span> <span class='id identifier rubyid_r_i'>r_i</span> <span class='op'>+</span> <span class='id identifier rubyid_item'>item</span><span class='period'>.</span><span class='id identifier rubyid_g'>g</span>
|
|
664
|
+
<span class='id identifier rubyid_item'>item</span><span class='period'>.</span><span class='id identifier rubyid_rank'>rank</span> <span class='op'>=</span> <span class='id identifier rubyid_r_i'>r_i</span>
|
|
665
|
+
<span class='id identifier rubyid_i'>i</span> <span class='op'>+=</span> <span class='int'>1</span>
|
|
666
|
+
<span class='kw'>end</span>
|
|
667
|
+
|
|
668
|
+
<span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_n'>n</span> <span class='op'>+=</span> <span class='int'>1</span>
|
|
669
|
+
<span class='kw'>end</span></pre>
|
|
670
|
+
</td>
|
|
671
|
+
</tr>
|
|
672
|
+
</table>
|
|
673
|
+
</div>
|
|
674
|
+
|
|
675
|
+
<div class="method_details ">
|
|
676
|
+
<h3 class="signature " id="query-instance_method">
|
|
677
|
+
|
|
678
|
+
- (<tt>Object</tt>) <strong>query</strong>(phi)
|
|
679
|
+
|
|
680
|
+
|
|
681
|
+
|
|
682
|
+
|
|
683
|
+
|
|
684
|
+
</h3><div class="docstring">
|
|
685
|
+
<div class="discussion">
|
|
686
|
+
|
|
687
|
+
<p>Queries de estimator for the given rank. O(n), where n is the number of
|
|
688
|
+
elements of the internal data structure</p>
|
|
689
|
+
|
|
690
|
+
<h2 id="label-Parameters%3A">Parameters:</h2>
|
|
691
|
+
<dl class="rdoc-list note-list"><dt>phi
|
|
692
|
+
<dd>
|
|
693
|
+
<p>A Fixnum between (0, 1) representing the rank to be queried (i.e, 0.5
|
|
694
|
+
represents the 50% quantile)</p>
|
|
695
|
+
|
|
696
|
+
<h2 id="label-Returns%3A">Returns:</h2>
|
|
697
|
+
|
|
698
|
+
<p>The approximate value for the quantile you are checking</p>
|
|
699
|
+
</dd></dl>
|
|
700
|
+
|
|
701
|
+
|
|
702
|
+
</div>
|
|
703
|
+
</div>
|
|
704
|
+
<div class="tags">
|
|
705
|
+
|
|
706
|
+
|
|
707
|
+
</div><table class="source_code">
|
|
708
|
+
<tr>
|
|
709
|
+
<td>
|
|
710
|
+
<pre class="lines">
|
|
711
|
+
|
|
712
|
+
|
|
713
|
+
97
|
|
714
|
+
98
|
|
715
|
+
99
|
|
716
|
+
100
|
|
717
|
+
101
|
|
718
|
+
102
|
|
719
|
+
103
|
|
720
|
+
104
|
|
721
|
+
105
|
|
722
|
+
106
|
|
723
|
+
107
|
|
724
|
+
108
|
|
725
|
+
109
|
|
726
|
+
110
|
|
727
|
+
111
|
|
728
|
+
112
|
|
729
|
+
113
|
|
730
|
+
114
|
|
731
|
+
115
|
|
732
|
+
116
|
|
733
|
+
117
|
|
734
|
+
118
|
|
735
|
+
119</pre>
|
|
736
|
+
</td>
|
|
737
|
+
<td>
|
|
738
|
+
<pre class="code"><span class="info file"># File 'lib/estimator.rb', line 97</span>
|
|
739
|
+
|
|
740
|
+
<span class='kw'>def</span> <span class='id identifier rubyid_query'>query</span><span class='lparen'>(</span><span class='id identifier rubyid_phi'>phi</span><span class='rparen'>)</span>
|
|
741
|
+
<span class='kw'>if</span> <span class='id identifier rubyid_n'>n</span> <span class='op'>==</span> <span class='int'>0</span>
|
|
742
|
+
<span class='kw'>nil</span>
|
|
743
|
+
<span class='kw'>else</span>
|
|
744
|
+
<span class='id identifier rubyid_rank'>rank</span> <span class='op'>=</span> <span class='int'>0</span>
|
|
745
|
+
<span class='id identifier rubyid_c'>c</span> <span class='op'>=</span> <span class='const'>Cursor</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span><span class='lparen'>(</span><span class='id identifier rubyid_samples'>samples</span><span class='rparen'>)</span>
|
|
746
|
+
<span class='id identifier rubyid_phi_n'>phi_n</span> <span class='op'>=</span> <span class='id identifier rubyid_phi'>phi</span> <span class='op'>*</span> <span class='id identifier rubyid_n'>n</span>
|
|
747
|
+
<span class='id identifier rubyid_last'>last</span> <span class='op'>=</span> <span class='lparen'>(</span><span class='op'>~</span><span class='id identifier rubyid_c'>c</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_value'>value</span>
|
|
748
|
+
<span class='kw'>while</span> <span class='op'>~</span><span class='id identifier rubyid_c'>c</span> <span class='op'>!=</span> <span class='kw'>nil</span>
|
|
749
|
+
<span class='id identifier rubyid_last'>last</span> <span class='op'>=</span> <span class='lparen'>(</span><span class='op'>~</span><span class='id identifier rubyid_c'>c</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_value'>value</span>
|
|
750
|
+
<span class='kw'>break</span> <span class='kw'>if</span> <span class='op'>~</span><span class='id identifier rubyid_c'>c</span><span class='period'>.</span><span class='id identifier rubyid_next'>next</span> <span class='op'>==</span> <span class='kw'>nil</span>
|
|
751
|
+
<span class='id identifier rubyid_c'>c</span> <span class='op'>=</span> <span class='id identifier rubyid_c'>c</span><span class='period'>.</span><span class='id identifier rubyid_next'>next</span>
|
|
752
|
+
|
|
753
|
+
<span class='kw'>if</span> <span class='lparen'>(</span><span class='id identifier rubyid_rank'>rank</span> <span class='op'>+</span> <span class='lparen'>(</span><span class='op'>~</span><span class='id identifier rubyid_c'>c</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_g'>g</span> <span class='op'>+</span> <span class='lparen'>(</span><span class='op'>~</span><span class='id identifier rubyid_c'>c</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_delta'>delta</span><span class='rparen'>)</span> <span class='op'>></span> <span class='lparen'>(</span><span class='id identifier rubyid_phi_n'>phi_n</span> <span class='op'>+</span> <span class='lparen'>(</span><span class='id identifier rubyid_invariant'>invariant</span><span class='period'>.</span><span class='id identifier rubyid_upper_bound'>upper_bound</span><span class='lparen'>(</span><span class='id identifier rubyid_phi_n'>phi_n</span><span class='comma'>,</span> <span class='id identifier rubyid_n'>n</span><span class='rparen'>)</span> <span class='op'>/</span> <span class='int'>2</span><span class='rparen'>)</span><span class='rparen'>)</span>
|
|
754
|
+
<span class='kw'>return</span> <span class='id identifier rubyid_last'>last</span>
|
|
755
|
+
<span class='kw'>end</span>
|
|
756
|
+
|
|
757
|
+
<span class='id identifier rubyid_rank'>rank</span> <span class='op'>+=</span> <span class='lparen'>(</span><span class='op'>~</span><span class='id identifier rubyid_c'>c</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_g'>g</span>
|
|
758
|
+
<span class='kw'>end</span>
|
|
759
|
+
|
|
760
|
+
<span class='kw'>return</span> <span class='lparen'>(</span><span class='op'>~</span><span class='id identifier rubyid_c'>c</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_value'>value</span>
|
|
761
|
+
<span class='kw'>end</span>
|
|
762
|
+
<span class='kw'>end</span></pre>
|
|
763
|
+
</td>
|
|
764
|
+
</tr>
|
|
765
|
+
</table>
|
|
766
|
+
</div>
|
|
767
|
+
|
|
768
|
+
</div>
|
|
769
|
+
|
|
770
|
+
</div>
|
|
771
|
+
|
|
772
|
+
<div id="footer">
|
|
773
|
+
Generated on Fri Nov 15 15:39:43 2013 by
|
|
774
|
+
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
|
775
|
+
0.8.7.3 (ruby-2.0.0).
|
|
776
|
+
</div>
|
|
777
|
+
|
|
778
|
+
</body>
|
|
779
|
+
</html>
|