Random Sorting within a set of columns
Show older comments
Hi,
I have a matrix (ParmXStrtMatrix) with 1 million rows and 4 columns (providing names for easy reference) :
Parm1,Parm2,XStrtPoint1, XStrtPoint2
Let's assume I have 10,000 different combinations of parameters Parm1/Parm2. Within each parameter combination, lets suppose I have 100 Start points XStrtPoint1/XStrtPoint2.
How can I randomly sort by parameter combination so that in every set of 10K rows starting from the top there is only one instance of a particular parameter combination and any one random start point combination attached to that particular parameter combination?
Background (for context): - The parameter columns in the matrix serve as inputs to definition of an anonymous function. I'm running fmincon in a loop across all the rows in order to minimize the function for different sets of parameters. For any particular combination of parameters I also have the remaining 2 columns as start points for suppyling to fmincon.
Since each individual run of fmincon takes ~2 seconds (using symbolic function for high precision), so it does take almost 3 weeks...In order to not wait till complete execution, I can pause the algorithm after let's say 2 days, look at results and depending on its quality I can be happy and quit or let it continue from the paused point.
Presently I use,
ParmXStrtMatrix = ParmXStrtMatrix(randperm(size(ParmXStrtMatrix,1)),:)
Only issue with above approach is, I would like to get representative results from fmincon whenever I pause it. But with randperm there is no specification around sorting randomly by groups so there will not be equal representation from each group. For example if at the time of pausing I have already processed 100K rows then I would like to have 10% of the start points from each of the parameter combinations.
One potentially correct (but very inefficient and hardcoded) approach is to use a loop for each of the 10,000 parameter combination and within the loop use randperm to randomly sort the Xstart points and then creating a new column to give numbers from 1 to 100 corresponding to the randomly sorted 100 X start points. Finally outside the loop sorting using the newly created column.
Any ideas appreciated.
Thanks
Accepted Answer
More Answers (0)
Categories
Find more on Logical in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!