 |
AutoHotkey Community Let's help each other out
|
| View previous topic :: View next topic |
| Author |
Message |
Laszlo
Joined: 14 Feb 2005 Posts: 4016 Location: Pittsburgh
|
Posted: Sun Apr 27, 2008 2:30 am Post subject: |
|
|
| A_index is the loop index (1,2,3...), concatenated with a tab ... |
|
| Back to top |
|
 |
Mkbailey755
Joined: 20 Aug 2007 Posts: 168
|
Posted: Sun Apr 27, 2008 2:37 am Post subject: |
|
|
one more thing what does the "float" mean
Edit:just saw your post thank you |
|
| Back to top |
|
 |
Laszlo
Joined: 14 Feb 2005 Posts: 4016 Location: Pittsburgh
|
Posted: Sun Apr 27, 2008 2:40 am Post subject: |
|
|
In | Code: | | SetFormat, Float, 4.2 | it specifies the format of floating point numbers. |
|
| Back to top |
|
 |
Mkbailey755
Joined: 20 Aug 2007 Posts: 168
|
Posted: Sun Apr 27, 2008 2:46 am Post subject: |
|
|
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 |
|
 |
Laszlo
Joined: 14 Feb 2005 Posts: 4016 Location: Pittsburgh
|
Posted: Sun Apr 27, 2008 3:08 am Post subject: |
|
|
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 |
|
 |
Thor Guest
|
Posted: Sun Apr 27, 2008 12:58 pm Post subject: |
|
|
| The bell curve works great. Just want to say thanks again! |
|
| Back to top |
|
 |
Laszlo
Joined: 14 Feb 2005 Posts: 4016 Location: Pittsburgh
|
Posted: Sun Apr 27, 2008 5:31 pm Post subject: |
|
|
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 |
|
 |
Mkbailey755
Joined: 20 Aug 2007 Posts: 168
|
Posted: Sun Apr 27, 2008 7:56 pm Post subject: |
|
|
 |
|
| Back to top |
|
 |
engunneer
Joined: 30 Aug 2005 Posts: 6772 Location: Pacific Northwest, US
|
Posted: Mon Apr 28, 2008 12:10 am Post subject: |
|
|
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 |
|
 |
Thor Guest
|
Posted: Sat May 03, 2008 11:35 pm Post subject: |
|
|
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
|
Posted: Sun May 04, 2008 12:31 am Post subject: |
|
|
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 |
|
 |
|
|
You can post new topics in this forum You can reply to topics in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|