2

I'm having a hard time to understand how I could use binomial and normal ( gaussian ) distributions in boost. I need to get a single values from these functions. I'm sure I'm probably trying to use these functions wrongly at the moment but here is what I have so far:

#include <boost/math/distributions.hpp>
#include <boost/math/tools/roots.hpp>
#include <boost/random/variate_generator.hpp>
#include <boost/random.hpp>

//valueH is assigned before
int value;
/* Should this assign value to "value" ?*/
value = boost::math::binomial_distribution<> value(1,valueH);

and normal distribution as

normal norm;

double someValue = boost::math::pdf(norm, (value1*value2+value3)/(value1*sqrt(value2)));

or should I use boost::math::normal_distribution<> here or how this works ? I've read boost documentation and still I don't get how I could assign values from distributions. I've also read C++ TR1: how to use the normal_distribution? so do I need to use some random number generator and generate numbers as the link shows and does that allow me to assign single values to variables ?

I'm sorry if this a bit messy message but anyway thanks !

Okay so far I have understood binomial and got it working, now I need to get normal distribution to work... Referring to link above, my situation differs from that I just need a one value but I would like to call normal distribution with a value. Like "give me N(0.1) with number 2 or so.

Well I thought this was getting easier but seems it isn't I would like to use boost bisection function Bisection but the problems is that sometimes I have only function, min and max, and the bisection function needs at least 4 arguments 4th argument is Tol tol.. which is some kind of tolerance but could I just assign it to 0 if I want to find an absolute value or do I need to write my own bisection with 3 arguments ?

Community
  • 1
  • 1
Mare
  • 943
  • 3
  • 11
  • 18
  • 4
    There are fully worked out examples in the [Boost documentation](http://www.boost.org/doc/libs/1_40_0/libs/math/doc/sf_and_dist/html/math_toolkit/dist/stat_tut/weg/binom_eg/binomial_coinflip_example.html). – David Schwartz Nov 22 '11 at 18:51
  • Yeah but lets take binomial flip(flips, success_fraction); does "flip" include the value after a call or do I have to extract the binomial value from the flip somehow ? – Mare Nov 22 '11 at 19:43
  • Once created, `flip` is an object representing the distribution. You can perform whatever operations you want on it -- see the example. – David Schwartz Nov 22 '11 at 19:45
  • Oh right, that seems to be working. I had completely wrong idea about how to use this, thanks David! Anyway now I have a different kind of problem. I need to form a matrix and generate random numbers by using binomial distribution. I can't find a function to get number B(n,p) out ? I assume I can solve the random number problem by using random number generator as "mt19937" and seed it every time before I create a new value ? – Mare Nov 22 '11 at 20:13
  • Yeah, but don't seed it every time. Just seed it once. – David Schwartz Nov 22 '11 at 20:29

1 Answers1

0

Random number generation using C++ TR1 http://www.johndcook.com/cpp_TR1_random.html

Boost Bisection example: http://www.cplusplus.com/forum/general/50136/

See also Boost TOMS748 example: http://programmingexamples.net/wiki/CPP/Boost/Math/Tools/TOMS748

Matt
  • 629
  • 9
  • 21