C/C++ Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingC/C++ Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old March 12th, 2005, 11:20 AM
wu_weidong wu_weidong is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Feb 2005
Posts: 9 wu_weidong User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 m 37 sec
Reputation Power: 0
Simulation - Composition method

Hi all, this question doesn't really have to do with C, but it is related to simulation, and without solving this first, I can't do the random variate generator.

I'm supposed to generate random variates for p(x) ~ pi - x + x^2 + sin(x), for 0 <= x <= pi.

I got the normalization factor as 6 / (12 + 3*pi^2 + 2*pi^3), which gives me my f(x) as

f(x) = [6 / (12 + 3*pi^2 + 2*pi^3)] * (pi - x + x^2 + sin(x)).

I then run into problems decomposing the f(x). I decomposed it into the following equation:

f(x) = 6*pi / a - (3*pi^2 / a) * f_1(x) + (2*pi^3 / a) * f_2(x) + (12 / a) * f_3(x)
where a = (12 + 3*pi^2 + 2*pi^3), f_1(x) = 2x/pi^2, f_2(x) = 3x^2 / pi^3, f_3(x) = ½ sinx.


I reasoned that f_1 is proportional to x, f_2 to x^2, and f_3 to sin(x). I then normalized f_1, f_2 and f_3, obtaining the respective individual distributions.

However, I'm confused by the presence of the constant term 6*pi / a and the negative sign in front of f_1. What should I do with them?

I'm really confused with the whole composition method, and I would greatly appreciate it if someone could point me to a website that gives a clear explanation of how to decompose the distributions.

Thank you.

Regards,
Rayne

Reply With Quote
  #2  
Old March 12th, 2005, 05:27 PM
Anibal Anibal is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2005
Posts: 176 Anibal User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 Day 4 h 20 m 48 sec
Reputation Power: 4
Hey! Just...a question for you: what are you trying to do? Maybe I don't understand your intentions quite well, but why do you create 3 functions from f(x) ?
Could you explain to me what normalization factor is (I'm not from an english speaking country...and as a consecuence, I may know that with a different name!). I'm quite good on simulation, I just don't know exactly what we're talking about here!

See if I can help you later!!

ANibal.

PS: provide an example, if you have the time....

Reply With Quote
  #3  
Old March 13th, 2005, 05:29 AM
wu_weidong wu_weidong is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Feb 2005
Posts: 9 wu_weidong User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 m 37 sec
Reputation Power: 0
I'm supposed to generate random variates for p(x) ~ pi - x + x^2 + sin(x) using the composition method. The normalization factor is a factor I found for p(x) such that p(x) is normalized, i.e. when you integrate the given p(x) from 0 to pi, you get the value 1, => F(x) = 1 from 0 <= x <= pi. My normalized p(x) turned out to be [6/(12 + 3pi^2 + 2pi^3)] * (pi - x + x^2 + sin(x)).

I was taught that "the composition technique is applied when the distribution function F (or f) can be expressed as a positive combination of other distribution functions F_1, F_2, ..., from which we can generate variates easily", i.e. f(x) = sum of (p_j * f_j(x)). That was why I tried to break up the p(x) into individual "terms".

Reply With Quote
  #4  
Old March 13th, 2005, 08:15 PM
Anibal Anibal is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2005
Posts: 176 Anibal User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 Day 4 h 20 m 48 sec
Reputation Power: 4
Allright...now I see! F(x) is the acumulate probability function (that's how we know it here!). The question is: what are you really trying to generate: values for x or for the function itself?

If you want to generate values for the function itself, just give values to x between 0 and pi (easy thing to do). If you want to get values for x, that's a little harder to do. Since the F(x) has no inverse function (at least not easily found) I would use the rejection method, where lock the function inside a known area function and you generate a random point (x, y) and see if y <= F(x) (the point is inside the valid area), you accept x as the generated value (if not, just find another point).
Unfortunatly, I've never used the composition method!

I'm not sure if that's what you asked...

Good Luck

ANibal.

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingC/C++ Help > Simulation - Composition method


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway
Stay green...Green IT