Changeset 3465


Ignore:
Timestamp:
Feb 10, 2016, 1:29:59 AM (6 years ago)
Author:
Peter
Message:

closes #856

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/test/rnd.cc

    r3446 r3465  
    77  Copyright (C) 2006 Jari Häkkinen
    88  Copyright (C) 2007, 2008 Jari Häkkinen, Peter Johansson
    9   Copyright (C) 2012, 2015 Peter Johansson
     9  Copyright (C) 2012, 2015, 2016 Peter Johansson
    1010
    1111  This file is part of the yat library, http://dev.thep.lu.se/yat
     
    6666  geo();
    6767  geo(0.1);
     68  HyperGeometric hg;
     69  hg(10, 100, 4);
     70  HyperGeometric hg2(10, 100, 4);
     71  hg2();
     72  hg2(11, 100, 4);
    6873
    6974  return suite.return_value();
  • trunk/yat/random/random.cc

    r3446 r3465  
    33/*
    44  Copyright (C) 2005, 2006, 2007, 2008 Jari Häkkinen, Peter Johansson
    5   Copyright (C) 2009, 2011, 2012, 2013, 2015 Peter Johansson
     5  Copyright (C) 2009, 2011, 2012, 2013, 2015, 2016 Peter Johansson
    66
    77  This file is part of the yat library, http://dev.thep.lu.se/yat
     
    325325
    326326
     327  HyperGeometric::HyperGeometric(void)
     328  {}
     329
     330
     331  HyperGeometric::HyperGeometric(unsigned int n1, unsigned int n2,
     332                                 unsigned int t)
     333    : n1_(n1), n2_(n2), t_(t)
     334  {}
     335
     336
     337  unsigned long int HyperGeometric::operator()(void) const
     338  {
     339    return (*this)(n1_, n2_, t_);
     340  }
     341
     342
     343  unsigned long int HyperGeometric::operator()(unsigned int n1,
     344                                               unsigned int n2,
     345                                               unsigned int t) const
     346  {
     347    return gsl_ran_hypergeometric(rng_->rng(), n1, n2, t);
     348  }
     349
     350
    327351  Poisson::Poisson(const double m)
    328352    : m_(m)
  • trunk/yat/random/random.h

    r3446 r3465  
    66/*
    77  Copyright (C) 2005, 2006, 2007, 2008 Jari Häkkinen, Peter Johansson
    8   Copyright (C) 2009, 2010, 2011, 2012, 2013, 2014, 2015 Peter Johansson
     8  Copyright (C) 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016 Peter Johansson
    99
    1010  This file is part of the yat library, http://dev.thep.lu.se/yat
     
    314314     \since New in yat 0.10
    315315   */
    316   class Binomial : Discrete
     316  class Binomial : public Discrete
    317317  {
    318318  public:
     
    483483
    484484  /**
     485     If we have \a n1 samples of type 1 and \a n2 samples of type 2
     486     and draw \a t samples with replacement, number of drawn samples
     487     of type 1 will follow the hyper geometric distribution.
     488
     489     \since New in yat 0.14
     490   */
     491  class HyperGeometric : public Discrete
     492  {
     493  public:
     494    /**
     495       \brief Defaul constructor
     496     */
     497    HyperGeometric(void);
     498
     499    /**
     500       \brief Constructor
     501       \param n1 number of samples of type 1
     502       \param n2 number of samples of type 2
     503       \param t number of samples to draw
     504     */
     505    HyperGeometric(unsigned int n1, unsigned int n2, unsigned int t);
     506
     507    /**
     508       \return random number from hypergeometric distribution using
     509       parameters set in constructor.
     510     */
     511    unsigned long int operator()(void) const;
     512
     513    /**
     514       \return random number from hypergeometric distribution using
     515       parameters passed.
     516     */
     517    unsigned long int operator()(unsigned int n1, unsigned int n2,
     518                                 unsigned int t) const;
     519  private:
     520    unsigned int n1_;
     521    unsigned int n2_;
     522    unsigned int t_;
     523  };
     524
     525  /**
    485526     @brief Poisson Distribution
    486527
Note: See TracChangeset for help on using the changeset viewer.