New locVar function

New locVar function

by Tricia Seow

JavaScript

function mod(x,y){
  var mod = x - Math.floor(x/y)*y;
  return mod
}

//summing numbers in arrays together
Array.prototype.SumArray = function (arr) {
  var sum = this.map(function (num, idx) {
    return num + arr[idx];
  });

  return sum;
};

// function to caluclate experiment condition
function stim_locVariables(nTrialsPerCond,stim_HazRate){

      // where the dots will land is precaluclated beore experiment starts and positions are all stored in the vars below
      var stim_refLocMean=[]; //where the current mean is
      var stim_changePoint=[]; // 0 or 1. whether it is a CP trial
      var stim_locDiff =[]; //the deviation from mean of 0

      // Change of reference location for stable block
      for (t = 1; t < nTrialsPerCond + 1 ; t++){

        if (Math.random() <= stim_HazRate || mod(t,nTrialsPerCond) == 1) { //this is where the CPP comes in, also changes every start of new block (when nTrialsperBlock=1)
          var currLoc = Math.round((stim_cirNPos-1)*Math.random()); //its ok to be zero? since its 0 to 359 here
          stim_changePoint = stim_changePoint.concat(1); //to note which trial the CPP happens
          stim_refLocMean = stim_refLocMean.concat(currLoc);
        }//to note the position it changes to
        else  {
          currLoc = Math.round(stim_refLocMean[t-2]);
          stim_changePoint = stim_changePoint.concat(0);
          stim_refLocMean=stim_refLocMean.concat(currLoc);//the dist mean stays the same as the prev trial when CPP doesnt happen
        }
      }

      return  stim_changePoint 
    }
    
    
function shuffle(o){
  for(var j, x, i = o.length; i; j = parseInt(Math.random() * i), x = o[--i], o[i] = o[j], o[j] = x);
  return o;
}

//function to set change points. [1 0 0 0 0 0 0 1 0 0 1 0 0 ] 
//first one must always be 1
//hazard rate of 0.125 means that it happens 0.125*nTrials over the course of the block
//therefore if nTrials is 75, then it happens Math.round(0.125*nTrials)

var nTrialsPerCond = 75;
var...