-
Notifications
You must be signed in to change notification settings - Fork 15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
More timing values #96
Comments
if (is_numeric($Zcap)) {
$Zcap = abs($Zcap);
while (abs(($randVal - $mean) / $sd) > $Zcap) {
$randVal = dummyFunction();
}
} I think in your function, on the same loop iteration that declares $tooExtreme = FALSE, $randVal could then be assigned a too extreme value, since it still calls dummyFunction() again. Or, you could just make it if ($z < $zcap) {
$tooExtreme = FALSE;
} else {
$randVal = dummyFunction();
} |
Nice catch. Now we just have to write the dummyfunction. |
here is the javascript solution i used in a trial type: // user5084 on stackoverflow provided the next two functions to use the Box-Muller transformation to generate random numbers
// source http://stackoverflow.com/questions/75677/converting-a-uniform-distribution-to-a-normal-distribution
// I added an extra step to round the result to an integer, which might create some bias? I am no statistician, so I don't know
/*
* Returns member of set with a given mean and standard deviation
* mean: mean
* standard deviation: std_dev
*/
function rnorm(mean,std_dev){
return Math.round(mean + (gaussRandom()*std_dev));
}
/*
* Returns random number in normal distribution centering on 0.
* ~95% of numbers returned should fall between -2 and 2
*/
function gaussRandom() {
var u = 2*Math.random()-1;
var v = 2*Math.random()-1;
var r = u*u + v*v;
/*if outside interval [0,1] start over*/
if(r == 0 || r > 1) return gaussRandom();
var c = Math.sqrt(-2*Math.log(r)/r);
return u*c;
/* todo: optimize this algorithm by caching (v*c)
* and returning next time gaussRandom() is called.
* left out for simplicity */
} in php, this would be function rnorm($mean, $stDev) {
return round($mean + gaussRandom() * $stDev);
}
function gaussRandom() {
$u = 2 * mt_rand() / mt_getRandMax() - 1;
$v = 2 * mt_rand() / mt_getRandMax() - 1;
$r = $u * $u + $v * $v;
if ($r == 0 || $r >= 1) return gaussRandom();
$c = sqrt(-2 * log($r) / $r);
return $u * $c;
} |
I started working on this on the branch 96-moretiming. All that needs to be done next is to update the timing code in Experiment.php to compute statements like |
Currently timing can be:
User
- allow trial to go until the user submits#
- directly set the # of seconds a trial will last. Values are converted to nearest millisecond (e.g., 7 -> 7000 or 1.12453 -> 1245).We should add:
rand(min,max)
- random selection bound by minimum and maximum # of secondsnormRand(mean, sd)
- randomly sample a normal distribution of with a givenmean
and standard deviation (sd
).normRand(mean, sd, Zcap)
- same as normRand but you can set aZcap
value that will not let the function return values more extreme than the absolute value ofZcap
.The text was updated successfully, but these errors were encountered: