celestialgod

random interval missing

Feb 1st, 2016
170
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 0.63 KB | None | 0 0
  1. numTimePoints = 50;
  2. sampleSize = 100;
  3. timePoints = 1:numTimePoints*sampleSize;
  4. totalMissingSize = numTimePoints * sampleSize * 0.3;
  5. while true
  6.   loc = randsample(timePoints, 1);
  7.   missingPeriod = min(3 + randi(21, 1, 1), length(timePoints) + totalMissingSize - numTimePoints*sampleSize);
  8.   for j = randperm(missingPeriod)
  9.     if all(ismember(loc-missingPeriod+j:loc+j-1, timePoints))
  10.       timePoints = setdiff(timePoints, loc-missingPeriod+j:loc+j-1);
  11.       break
  12.     end
  13.   end
  14.   if numTimePoints*sampleSize - totalMissingSize >= length(timePoints)
  15.     break
  16.   end
  17. end
  18. missingLabel = setdiff(1:numTimePoints*sampleSize, timePoints);
Advertisement
Add Comment
Please, Sign In to add comment