0.9.8.10
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
DiscreteRandomGeneratorZipf.cc
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2007-2015 Hypertable, Inc.
3  *
4  * This file is part of Hypertable.
5  *
6  * Hypertable is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 3
9  * of the License, or any later version.
10  *
11  * Hypertable is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19  * 02110-1301, USA.
20  */
21 
28 
29 using namespace Hypertable;
30 
32  : DiscreteRandomGenerator(), m_initialized(false), m_s(s)
33 {
34  assert(m_s > 0 && m_s < 1);
35 }
36 
38 {
39  if (!m_initialized) {
40  m_norm = (1 - m_s) / (pow(m_value_count + 1, 1 - m_s));
41  m_initialized = true;
42  }
43  assert(val >= 0 && val <= m_value_count + 1);
44  val++;
45  double prob = m_norm / pow(val, m_s);
46  return (prob);
47 }
double m_s
The 's' of the zipfian algorithm.
Discrete Random Generator creating a zipfian distribution.
uint64_t m_value_count
Number of values in the range.
Hypertable definitions
double m_norm
Helper for calculating the probability in pmf()
bool m_initialized
true if m_norm was initialized
Generates samples from a discrete probability distribution in the range [0, max_val] by transforming ...
DiscreteRandomGeneratorZipf(double s=0.8)
Constructor; sets the "s" of the algorithm.
double pmf(uint64_t val)
Returns the probability of generating val + 1 from this distribution Uses val + 1 because dist...