Math::SZaru::UniqueEstimator - Statistical estimator for total number of unique items
my $ue = Math::SZaru::UniqueEstimator->new($maxelems);
# add many more elems using add_elem ...
my $inserted_elems_count = $ue->tot_elems;
my $estimated_unique_count = $ue->estimate();
Math::SZaru::UniqueEstimator provides a statistical estimate of the number of unique elements in the input stream.
Quoting the documentation of the SZaru C++ implementation:
The technique used is:
- Convert all elements to unique evenly spaced hash keys.
- Keep track of the smallest N element ("nElemes") of these elements.
- "nelems" cannot glow beyond maxelems.
- Based on the coverage of the space, compute an estimate
of the total number of unique elements, where biggest-small-elem
means largest element among kept "maxelems" elements.
unique = nElemes < maxelems
: (maxelems << bits-in-hash) / biggest-small-elem
Constructor. Expects an integer indicating the total size of the underlying hash table.
Given a string, adds the string to the UniqueEstimator hash table.
Same as add_elem, but accepts an arbitrary number of strings to insert into the estimator at once.
Returns the total count of the number of elements that were added to the estimator.
Returns the estimated number of unique elements that were added to the estimator so far. See above for a description of the algorithm.
SZaru: "SZaru/" in llamerada.github.com
Steffen Mueller, <firstname.lastname@example.org>
The Perl wrapper of the SZaru library is:
Copyright (C) 2013 by Steffen Mueller
Just like SZaru itself, it is licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
To install Math::SZaru, copy and paste the appropriate command in to your terminal.
perl -MCPAN -e shell
For more information on module installation, please visit the detailed CPAN module installation guide.