I currently use datasample
for weighted random selection from within a matrix whereby each element itself contains its weight (the frequency at which the datapoint will be chosen) in this form:
A = datasample(edgeL:edgeR,1,'Replace',false,'Weights',model(edgeL:edgeR));
This approach is rather slow. I am wondering if this is due to datasample
itself or the fact that I choose a single value during each iteration of the above. The latter is needed because I am modifying the weights around each point as it is chosen and thus the entire distribution must be re-assessed during each iteration.
Is there a faster way of accomplishing this?