473,396 Members | 1,987 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

How to generate a Guassion Sample data? used for MonteCarlo method

When using random we can get a uniform data sample. But how to transfer

this sample in to a Guassion Sample? Thanks? Did C or C++ provide any
function to do this?

Thanks a lot.
Cheers. fAnS.

Jan 3 '07 #1
4 2412
fAnSKyer wrote:
When using random we can get a uniform data sample. But how to
transfer

this sample in to a Guassion Sample? Thanks? Did C or C++ provide any
function to do this?
No, not currently. TR1 Library extension has a couple random
distributions (Bernoulli, Poisson, geometric), and you need the
'normal', I believe. If your compiler provides TR1 (or if you get
an implementation elsewhere), see std::tr1::normal_distribution.

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Jan 3 '07 #2
fAnSKyer wrote:
When using random we can get a uniform data sample. But how to transfer

this sample in to a Guassion Sample? Thanks? Did C or C++ provide any
function to do this?
Not built in for most compilers. Also, the built in random function
isn't very good. Probably you won't want to use it for anything
more important than games. And maybe not even then.

The basic idea is, you use the shape of the distribution you
want to generate, and modify the values from a uniform
generator to put them into the range you want.

For an easy to understand introduction to the topic, take a
look at _Numerical Recipes in C_. But be sure to keep in
mind that it should only be treated as an introduction.
There is quite a large literature on random num generation.

Depending on your requirements, you may need a very good
random num generator. You may need to worry about such
things as the repeat cycle, the stride, various statistics, etc.
The words "Monte Carlo" in your subject line tend to make
me think you need at least a medium good generator.

You should look round the net for some libs that provide better
random nums. There are several, and several free ones.
Be sure to read carefully the promises that the docs that
come with such libs make. Or fail to make. And you should
hunt round the net for revues of any lib before you use it.
Socks

Jan 3 '07 #3
Thanks a lot ^_^ :P

"Puppet_Sock дµÀ£º
"
fAnSKyer wrote:
When using random we can get a uniform data sample. But how to transfer

this sample in to a Guassion Sample? Thanks? Did C or C++ provide any
function to do this?

Not built in for most compilers. Also, the built in random function
isn't very good. Probably you won't want to use it for anything
more important than games. And maybe not even then.

The basic idea is, you use the shape of the distribution you
want to generate, and modify the values from a uniform
generator to put them into the range you want.

For an easy to understand introduction to the topic, take a
look at _Numerical Recipes in C_. But be sure to keep in
mind that it should only be treated as an introduction.
There is quite a large literature on random num generation.

Depending on your requirements, you may need a very good
random num generator. You may need to worry about such
things as the repeat cycle, the stride, various statistics, etc.
The words "Monte Carlo" in your subject line tend to make
me think you need at least a medium good generator.

You should look round the net for some libs that provide better
random nums. There are several, and several free ones.
Be sure to read carefully the promises that the docs that
come with such libs make. Or fail to make. And you should
hunt round the net for revues of any lib before you use it.
Socks
Jan 3 '07 #4
On Wed, 03 Jan 2007 10:05:00 -0800, fAnSKyer wrote:
When using random we can get a uniform data sample.
The "Mersenne Twister" is about as good as it gets for uniform (pseudo)
random number generation - it is fast, has a very long period and passes
most statistical tests:

http://en.wikipedia.org/wiki/Mersenne_twister
http://www.math.sci.hiroshima-u.ac.j...at/MT/emt.html
But how to transfer

this sample in to a Guassion Sample? Thanks? Did C or C++ provide any
function to do this?
No, but here is an implementation of the Box-Muller algorithm for
generating Gaussian random deviates that will do the job (note that this
version is not thread-safe). See Numerical Recipes in C and:

http://en.wikipedia.org/wiki/Box-Muller_transform

for details.

// rand() should return a random double uniform on [0,1]

double gasdev()
{
static bool iset;
static double gset;
double fac,rsq,v1,v2;
if (iset) {
iset=false;
return gset;
}
do {
v1=2.0*rand()-1.0;
v2=2.0*rand()-1.0;
rsq=v1*v1+v2*v2;
} while (rsq >= 1.0 || rsq == 0.0);
fac=std::sqrt(-2.0*std::log(rsq)/rsq);
gset=v1*fac;
iset=true;
return v2*fac;
}

--
Lionel B
Jan 4 '07 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: petermichaux | last post by:
Hi, I am interesting in using PHP to dynamically create an XML document and then use XSLT to transform to XHTML. I have come across two methods for doing this. I made two equivalent examples so...
0
by: Ravindra | last post by:
Well I installed the framework provided by microsoft , the problem is I am able to activate the smart tag in the doc file but when I Click on the Show Detils option in the information bridge the...
4
by: Zoltan Hernyak | last post by:
Hi, Can I generate a new type (a class with fields only) on-the-fly, from a running app, and use it right then? For example if I want to build a class which consists of fields which are...
8
by: Bill Rust | last post by:
I've created an "Add Item" wizard for VB.NET 2003 that allows a user to add a specialized class that works with my application framework. In the wizard, the user can select the interfaces they...
5
by: Chameleon | last post by:
I totally messed up with this: We have -------------------------------------- generate(v.begin(), v.end(), my_func); -------------------------------------- and my_func: ----------- int...
9
by: Anubhav Jain | last post by:
Hi, I am having few .net source files(.cs or .vb) and I want to dynamically generate the corresponding .net project file(.csproj or .vbproj) for them without using visual studio.So that I could...
4
by: fAnSKyer | last post by:
When using random we can get a uniform data sample. But how to transfer this sample in to a Guassion Sample? Thanks? Did C or C++ provide any function to do this? Thanks a lot. Cheers. fAnS.
5
by: sjangity | last post by:
I am generating xml file that will populate users in a database. assigned_to contains names of developers. reporter contains names of quality engineers. I can't simply just create users...
6
by: =?Utf-8?B?VGFydW4=?= | last post by:
Hi, I have to generate a fixed length text file.I have a file formats like fields details as well as its length and position.what actually i have to do that i will get the data from the databas...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.