AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Bell curve?
Goto page Previous  1, 2
 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help
View previous topic :: View next topic  
Author Message
Laszlo



Joined: 14 Feb 2005
Posts: 4016
Location: Pittsburgh

PostPosted: Sun Apr 27, 2008 2:30 am    Post subject: Reply with quote

A_index is the loop index (1,2,3...), concatenated with a tab ...
Back to top
View user's profile Send private message
Mkbailey755



Joined: 20 Aug 2007
Posts: 168

PostPosted: Sun Apr 27, 2008 2:37 am    Post subject: Reply with quote

one more thing what does the "float" mean
Edit:just saw your post thank you
Back to top
View user's profile Send private message
Laszlo



Joined: 14 Feb 2005
Posts: 4016
Location: Pittsburgh

PostPosted: Sun Apr 27, 2008 2:40 am    Post subject: Reply with quote

In
Code:
SetFormat, Float, 4.2
it specifies the format of floating point numbers.
Back to top
View user's profile Send private message
Mkbailey755



Joined: 20 Aug 2007
Posts: 168

PostPosted: Sun Apr 27, 2008 2:46 am    Post subject: Reply with quote

thank you again I just found my answer I really wasn't sure what Float was here is the Definition I found I love learning.. : )
Quote:
float True if var is non-empty and contains a floating point number; that is, a purely numeric string containing a decimal point. Leading and trailing spaces and tabs are allowed. The string may start with a plus sign, minus sign, or decimal point.
Back to top
View user's profile Send private message
Laszlo



Joined: 14 Feb 2005
Posts: 4016
Location: Pittsburgh

PostPosted: Sun Apr 27, 2008 3:08 am    Post subject: Reply with quote

That is in case of
Code:
If var is [not] type
Here Float is used in SetFormat. Another place in the Help...
Back to top
View user's profile Send private message
Thor
Guest





PostPosted: Sun Apr 27, 2008 12:58 pm    Post subject: Reply with quote

The bell curve works great. Just want to say thanks again!
Back to top
Laszlo



Joined: 14 Feb 2005
Posts: 4016
Location: Pittsburgh

PostPosted: Sun Apr 27, 2008 5:31 pm    Post subject: Reply with quote

Here is an alternative:
Code:
Loop 9 {
   Random x, 0, 1.
   MsgBox % ErfInv9(x)
}

ErfInv9(p) { ; 1.15e-9 accurate approximation of the inverse error function
   Static a1 := -3.969683028665376e+01, a2 :=  2.209460984245205e+02, a3 := -2.759285104469687e+02
        , a4 :=  1.383577518672690e+02, a5 := -3.066479806614716e+01, a6 :=  2.506628277459239e+00
        , b1 := -5.447609879822406e+01, b2 :=  1.615858368580409e+02, b3 := -1.556989798598866e+02
        , b4 :=  6.680131188771972e+01, b5 := -1.328068155288572e+01
        , c1 := -7.784894002430293e-03, c2 := -3.223964580411365e-01, c3 := -2.400758277161838e+00
        , c4 := -2.549732539343734e+00, c5 :=  4.374664141464968e+00, c6 :=  2.938163982698783e+00
        , d1 :=  7.784695709041462e-03, d2 :=  3.224671290700398e-01
        , d3 :=  2.445134137142996e+00, d4 :=  3.754408661907416e+00

   if (p <= 0 or p >= 1)
      Return
   if (p < 0.02425) {
      q := sqrt(-2*ln(p))
      Return % (((((c1*q+c2)*q+c3)*q+c4)*q+c5)*q+c6) / ((((d1*q+d2)*q+d3)*q+d4)*q+1)
   }
   if (0.97575 < p) {
      q := sqrt(-2*ln(1-p))
      Return % -(((((c1*q+c2)*q+c3)*q+c4)*q+c5)*q+c6) / ((((d1*q+d2)*q+d3)*q+d4)*q+1)
   }
   q := p - 0.5
   r := q*q
   Return % (((((a1*r+a2)*r+a3)*r+a4)*r+a5)*r+a6)*q / (((((b1*r+b2)*r+b3)*r+b4)*r+b5)*r+1)
}
The ErfInv9() function transforms a [0,1] real uniform random variable to one of standard normal distribution. It is fast, performing only a dozen multiplications, divisions, and the relative error is so small, that no practical application would see a difference. It was adapted from Peter J. Acklam’s work. (5% of the time it also calls the sqrt and log function.)
Back to top
View user's profile Send private message
Mkbailey755



Joined: 20 Aug 2007
Posts: 168

PostPosted: Sun Apr 27, 2008 7:56 pm    Post subject: Reply with quote

Back to top
View user's profile Send private message
engunneer



Joined: 30 Aug 2005
Posts: 6772
Location: Pacific Northwest, US

PostPosted: Mon Apr 28, 2008 12:10 am    Post subject: Reply with quote

Mkbailey755 wrote:
img


Don't worry. Laszlo is our resident math geek. (There are others as well). You can trust that his function is properly researched and works as planned. It actually looks pretty cool. And when he says it is fast, he means it.

You will note that I called my method the Brute force way.
_________________
Unless otherwise noted, all code is untested.
Common Answers: 1.(Loops, Viruses, etc.) 2. Search 3.RTFM
Back to top
View user's profile Send private message Visit poster's website
Thor
Guest





PostPosted: Sat May 03, 2008 11:35 pm    Post subject: Reply with quote

Lazlo, your function has worked great for me! It is very useful!

Is it possible to add an option to make the function asymmetric around the center? To make it fall more quickly on one side and phase out more slowly on the other?

The function is great as it is. With this addition I would have even more use of it.

Hope it is possible. Thanks!
Back to top
Laszlo



Joined: 14 Feb 2005
Posts: 4016
Location: Pittsburgh

PostPosted: Sun May 04, 2008 12:31 am    Post subject: Reply with quote

You define a probability density function, like a skewed bell curve. Its integral (from minus infinity to x) is the Cumulative distribution function, like erf(x), the error function, for the normal distribution. Finally, we need its inverse, if we want to transform uniformly distributed random samples to the desired distribution. For high accuracy it is not an easy task, and quite slow.

A rough approximation can be achieved easier. Cut the range of the distribution into intervals, and give the probability for each interval, that a sample falls there. A search loop can find the right output value pretty fast.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help All times are GMT
Goto page Previous  1, 2
Page 2 of 2

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group