NEST  2.6.0,not_revisioned_source_dir@0
gsl_binomial_randomdev.h
Go to the documentation of this file.
1 /*
2  * gsl_binomial_randomdev.h
3  *
4  * This file is part of NEST.
5  *
6  * Copyright (C) 2004 The NEST Initiative
7  *
8  * NEST is free software: you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation, either version 2 of the License, or
11  * (at your option) any later version.
12  *
13  * NEST is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with NEST. If not, see <http://www.gnu.org/licenses/>.
20  *
21  */
22 
23 #include "config.h"
24 
25 #ifndef GSL_BINOMIAL_RANDOMDEV_H
26 #define GSL_BINOMIAL_RANDOMDEV_H
27 
28 #include "randomgen.h"
29 #include "randomdev.h"
30 #include "lockptr.h"
31 #include "dictdatum.h"
32 #include "gslrandomgen.h"
33 
34 #ifdef HAVE_GSL
35 
36 #include <gsl/gsl_rng.h>
37 #include <gsl/gsl_randist.h>
38 
39 
40 /*BeginDocumentation
41 Name: rdevdict::gsl_binomial - GSL binomial random deviate generator
42 Description:
43 This function returns a random integer from the binomial distribution,
44 the number of successes in n independent trials with probability
45 p. The probability distribution for binomial variates is,
46 
47  p(k) = (n! / k!(n-k)!) p^k (1-p)^(n-k) , 0<=k<=n, n>0
48 
49 Please note that the RNG used to initialize gsl_binomial has to be
50 from the GSL (prefixed gsl_ in rngdict)
51 
52 Parameters:
53  p - probability of success in a single trial (double)
54  n - number of trials (positive integer)
55 
56 SeeAlso: CreateRDV, RandomArray, rdevdict
57 Author: Jochen Martin Eppler
58 */
59 
60 
61 namespace librandom {
62 
82  {
83  public:
84  // accept only lockPTRs for initialization,
85  // otherwise creation of a lock ptr would
86  // occur as side effect---might be unhealthy
87  GSL_BinomialRandomDev(RngPtr, double p_s = 0.5, unsigned int n_s=1);
88  GSL_BinomialRandomDev(double p_s = 0.5, unsigned int n_s=1);
89 
96  void set_p_n (double, unsigned int);
97  void set_p (double);
98  void set_n (unsigned int);
99 
108  using RandomDev::operator();
109  using RandomDev::ldev;
110 
111  long ldev();
112  long ldev(RngPtr) const;
113  bool has_ldev() const { return true; }
114 
115  double operator()(RngPtr) const;
116 
118  void set_status(const DictionaryDatum&);
119 
121  void get_status(DictionaryDatum&) const;
122 
123  private:
124  double p_;
125  unsigned int n_;
126 
127  gsl_rng *rng_;
128  };
129 
130  inline
132  {
133  return static_cast<double>(ldev(rthrd));
134  }
135 
136 }
137 
138 #endif
139 
140 #endif
141 
gsl_rng * rng_
Definition: gsl_binomial_randomdev.h:127
virtual double operator()(void)
Operator delivering doubles.
Definition: randomdev.h:199
void set_p_n(double, unsigned int)
set parameters for p and n p - success probability for single trial n - number of trials ...
Definition: gsl_binomial_randomdev.cpp:59
void set_status(const DictionaryDatum &)
set distribution parameters from SLI dict
Definition: gsl_binomial_randomdev.cpp:76
long ldev()
draw integer
Definition: gsl_binomial_randomdev.cpp:46
Class GSL_BinomialRandomDev.
Definition: gsl_binomial_randomdev.h:81
void set_n(unsigned int)
set n
Definition: gsl_binomial_randomdev.cpp:71
double p_
probability p of binomial distribution
Definition: gsl_binomial_randomdev.h:124
GSL_BinomialRandomDev(RngPtr, double p_s=0.5, unsigned int n_s=1)
Definition: gsl_binomial_randomdev.cpp:33
Abstract base class for access to non-uniform random deviate generators.
Definition: randomdev.h:131
void get_status(DictionaryDatum &) const
get distribution parameters from SLI dict
Definition: gsl_binomial_randomdev.cpp:101
unsigned int n_
parameter n in binomial distribution
Definition: gsl_binomial_randomdev.h:125
virtual long ldev(void)
integer valued functions for discrete distributions
Definition: randomdev.h:206
bool has_ldev() const
true if RDG implements ldev function
Definition: gsl_binomial_randomdev.h:113
void set_p(double)
set p
Definition: gsl_binomial_randomdev.cpp:65