change standard deviation of normal or Gaussian distribution (faq 13.20)

Discussion in 'C Programming' started by Verbal Kint, Jun 29, 2007.

  1. Verbal Kint

    Verbal Kint Guest

    DEAR ALL,

    I just have a very short question. In the FAQ list question 13.20 the
    following text is mentioned:
    "These methods all generate numbers with mean 0 and standard deviation
    1. (To adjust to some other distribution, multiply by the standard
    deviation and add the mean.)"

    Could you please let me know, which number I have to multiply with the
    standard deviation?

    Thanks a lot!
     
    Verbal Kint, Jun 29, 2007
    #1
    1. Advertising

  2. Verbal Kint

    Guest

    On 29 Jun, 09:21, Verbal Kint <> wrote:
    > DEAR ALL,
    >
    > I just have a very short question. In the FAQ list question 13.20 the
    > following text is mentioned:
    > "These methods all generate numbers with mean 0 and standard deviation
    > 1. (To adjust to some other distribution, multiply by the standard
    > deviation and add the mean.)"
    >
    > Could you please let me know, which number I have to multiply with the
    > standard deviation?


    I'm sorely tempted to say "42" here... But ...

    The numbers generated by these methods have a specific distribution -
    right?

    To change that distribution, you can simply them (the numbers the
    methods generate) by the required standard deviation, and add the
    required mean - can't you?
     
    , Jun 29, 2007
    #2
    1. Advertising

  3. Verbal Kint

    Verbal Kint Guest

    :) I understand what you mean. Maybe I didnt express myself clear
    enough. I wanted to use to following method as mentioned in FAQ:

    double gaussrand()
    {
    static double V1, V2, S;
    static int phase = 0;
    double X;

    if(phase == 0) {
    do {
    double U1 = (double)rand() / RAND_MAX;
    double U2 = (double)rand() / RAND_MAX;

    V1 = 2 * U1 - 1;
    V2 = 2 * U2 - 1;
    S = V1 * V1 + V2 * V2;
    } while(S >= 1 || S == 0);

    X = V1 * sqrt(-2 * log(S) / S);
    } else
    X = V2 * sqrt(-2 * log(S) / S);

    phase = 1 - phase;

    return X;
    }

    Now I wonder, whether I can multiply the standard deviation of e.g.
    0.5 with X or with which variable (v1, v2, etc.) I need to multiply
    it?
    Thanks a lot.
     
    Verbal Kint, Jun 29, 2007
    #3
  4. Verbal Kint

    Guest

    On 29 Jun, 10:20, Verbal Kint <> wrote:
    > :) I understand what you mean. Maybe I didnt express myself clear
    > enough. I wanted to use to following method as mentioned in FAQ:


    If you are replying to my posting, it would be helpful and polite to
    quote at least the relevant parts of it.

    >
    > double gaussrand()
    > {

    ....
    > return X;
    >
    > }
    >
    > Now I wonder, whether I can multiply the standard deviation of e.g.
    > 0.5 with X or with which variable (v1, v2, etc.) I need to multiply
    > it?


    I said before :-
    "The numbers generated by these methods have a specific distribution -
    right?

    To change that distribution, you can simply them (the numbers the
    methods generate) by the required standard deviation, and add the
    required mean - can't you?"

    What about that didn't you understand?

    Let's try another approach. The FAQ said
    "These methods all generate numbers with mean 0 and standard deviation
    1. (To adjust to some other distribution, multiply by the standard
    deviation and add the mean.)"

    This instruction must apply no matter which method you used to
    generate your random number, so it must not relate in any way to the
    internal implementation of that random number generator - right?

    So the only thing to which we can apply the instructions "multiply by
    the standard deviation and add the mean" is the output of the random
    number generator. Is that any clearer?
     
    , Jun 29, 2007
    #4
  5. Verbal Kint

    Verbal Kint Guest

    > So the only thing to which we can apply the instructions "multiply by
    > the standard deviation and add the mean" is the output of the random
    > number generator.


    Why didn't you say that right from the beginning? ;)
     
    Verbal Kint, Jun 29, 2007
    #5
  6. Verbal Kint

    Guest

    On 29 Jun, 10:53, Verbal Kint <> wrote:
    > > So the only thing to which we can apply the instructions "multiply by
    > > the standard deviation and add the mean" is the output of the random
    > > number generator.

    >
    > Why didn't you say that right from the beginning? ;)


    Why don't you consider being polite to people who have bothered to try
    to help you? Don't hope for anymore help from me.
     
    , Jun 29, 2007
    #6
  7. Verbal Kint

    Army1987 Guest

    "Verbal Kint" <> ha scritto nel messaggio news:...
    > DEAR ALL,
    >
    > I just have a very short question. In the FAQ list question 13.20 the
    > following text is mentioned:
    > "These methods all generate numbers with mean 0 and standard deviation
    > 1. (To adjust to some other distribution, multiply by the standard
    > deviation and add the mean.)"
    >
    > Could you please let me know, which number I have to multiply with the
    > standard deviation?


    This is not really a question about C, but

    extern double std_gauss(void);
    #define gauss(mean, stdev) ((mean) + (stdev) * std_gauss())
    double (gauss)(double mean, double stdev)
    {
    return gauss(mean, stdev);
    }

    HTH.
     
    Army1987, Jun 29, 2007
    #7
  8. Re: change standard deviation of normal or Gaussian distribution(faq 13.20)

    wrote:
    > On 29 Jun, 10:20, Verbal Kint <> wrote:
    >> :) I understand what you mean. Maybe I didnt express myself clear
    >> enough. I wanted to use to following method as mentioned in FAQ:

    >
    > If you are replying to my posting, it would be helpful and polite to
    > quote at least the relevant parts of it.
    >
    >> double gaussrand()
    >> {

    > ...
    >> return X;
    >>
    >> }
    >>
    >> Now I wonder, whether I can multiply the standard deviation of e.g.
    >> 0.5 with X or with which variable (v1, v2, etc.) I need to multiply
    >> it?

    >
    > I said before :-
    > "The numbers generated by these methods have a specific distribution -
    > right?
    >
    > To change that distribution, you can simply them (the numbers the
    > methods generate) by the required standard deviation, and add the
    > required mean - can't you?"
    >
    > What about that didn't you understand?
    >

    Well, to be fair, I didn't understand what you meant by that paragraph.
    You seem to have a missing verb in there somewhere. I tried inserting
    the word "multiply" in a few places, but was not completely satisfied
    with the results.
     
    Clever Monkey, Jun 29, 2007
    #8
  9. Verbal Kint

    Guest

    On 29 Jun, 15:22, Clever Monkey <>
    wrote:
    > wrote:
    > > On 29 Jun, 10:20, Verbal Kint <> wrote:
    > >> :) I understand what you mean. Maybe I didnt express myself clear
    > >> enough. I wanted to use to following method as mentioned in FAQ:

    >
    > > If you are replying to my posting, it would be helpful and polite to
    > > quote at least the relevant parts of it.

    >
    > >> double gaussrand()
    > >> {

    > > ...
    > >> return X;

    >
    > >> }

    >
    > >> Now I wonder, whether I can multiply the standard deviation of e.g.
    > >> 0.5 with X or with which variable (v1, v2, etc.) I need to multiply
    > >> it?

    >
    > > I said before :-
    > > "The numbers generated by these methods have a specific distribution -
    > > right?

    >
    > > To change that distribution, you can simply them (the numbers the


    Should read "... you can simply multiply them ..."

    > > methods generate) by the required standard deviation, and add the
    > > required mean - can't you?"

    >
    > > What about that didn't you understand?

    >
    > Well, to be fair, I didn't understand what you meant by that paragraph.
    > You seem to have a missing verb in there somewhere. I tried inserting
    > the word "multiply" in a few places, but was not completely satisfied
    > with the results.


    Good point, inadequate proof-reading acknowledged - but, in my
    defense, I'd point out that the "multiply by std dev and add mean"
    thing was already well established.
     
    , Jun 29, 2007
    #9
  10. On Fri, 29 Jun 2007 09:53:44 -0000, in comp.lang.c , Verbal Kint
    <> wrote:

    >> So the only thing to which we can apply the instructions "multiply by
    >> the standard deviation and add the mean" is the output of the random
    >> number generator.

    >
    >Why didn't you say that right from the beginning? ;)


    He did:

    >>To change that distribution, you can simply them (the numbers the
    >>methods generate) by the required standard deviation, and add the
    >>required mean - can't you?

    --
    Mark McIntyre

    "Debugging is twice as hard as writing the code in the first place.
    Therefore, if you write the code as cleverly as possible, you are,
    by definition, not smart enough to debug it."
    --Brian Kernighan
     
    Mark McIntyre, Jun 29, 2007
    #10
  11. writes:
    > On 29 Jun, 10:53, Verbal Kint <> wrote:
    >> > So the only thing to which we can apply the instructions "multiply by
    >> > the standard deviation and add the mean" is the output of the random
    >> > number generator.

    >>
    >> Why didn't you say that right from the beginning? ;)

    >
    > Why don't you consider being polite to people who have bothered to try
    > to help you? Don't hope for anymore help from me.


    Note the smiley. I thought (and still think) that "Verbal Kint" was
    making a joke at his own expense.

    --
    Keith Thompson (The_Other_Keith) <http://www.ghoti.net/~kst>
    San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
    "We must do something. This is something. Therefore, we must do this."
    -- Antony Jay and Jonathan Lynn, "Yes Minister"
     
    Keith Thompson, Jun 30, 2007
    #11
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. LH

    gaussian distribution

    LH, Apr 5, 2004, in forum: Java
    Replies:
    2
    Views:
    3,702
  2. Replies:
    3
    Views:
    476
    Chris Uppal
    May 25, 2006
  3. Billy Mays

    Standard Deviation One-liner

    Billy Mays, Jun 3, 2011, in forum: Python
    Replies:
    5
    Views:
    298
    Ethan Furman
    Jun 5, 2011
  4. Bill Cunningham

    standard deviation

    Bill Cunningham, Jun 5, 2011, in forum: C Programming
    Replies:
    19
    Views:
    760
    Michael Press
    Jun 10, 2011
  5. Älphä Blüë

    Standard Deviation question regarding EDOM errors

    Älphä Blüë, Jul 21, 2009, in forum: Ruby
    Replies:
    4
    Views:
    121
    Älphä Blüë
    Jul 22, 2009
Loading...

Share This Page