X
PrevPrev Go to previous topic
NextNext Go to next topic
Last Post 12 Dec 2011 05:05 AM by  anon
ramdom sampling in IDL
 3 Replies
Sort:
You are not authorized to post a reply.
Author Messages

anon



New Member


Posts:
New Member


--
12 Dec 2011 05:05 AM
    how to do ramdom sampling in IDL? i want to call Basic tools>statistics>generate random sample>ground truth ROI !

    Deleted User



    New Member


    Posts:
    New Member


    --
    13 Dec 2011 12:12 PM
    Hi Shreshai, I can think of two ways of doing a random sampling using IDL. Let's say that you want to work on an array of dimensions 10 by 10. One way of doing the random selection of elements of that array would be the following code: data = findgen(10,10) nrand = 20 ; quantity of random elements print, data rand = randomu(seed, 20, /double) ; 20 random values 0.0 < Y <1.0 ndata = n_elements(data) ; scale random values to whole number indices irand = round(rand * (ndata-1)) data_rand = data[irand] In that example code you basically create a random number array, and then you simple select integers that are produced by rounding up those values. You then use them as indexes for your data. Another way could be to do simple the following.: randomi=randomn(seed,10,10) sorted_randomi=sort(randomi) print, sorted_randomi data_rand = data[sorted_randomi] In other words, you first generate an array with the same dimensions as your data, but with random values in it. Then, you use the SORT() function to return the randomized indexes of that random array. In other words, the SORT function returns the indexes of the randomi array, which in turn are random too. So the next step is to use does indexes as indexes of your data. You could also get sub-samples of those already randomed indexes if you need too. I hope this helps. Cheers. Fernando

    Deleted User



    New Member


    Posts:
    New Member


    --
    21 Dec 2011 02:54 AM
    Fernando, that helps a lot. I thought there is some idl command which call ramdom sampling function in envi, which is not the case. I wanted to divide my ROIs lets say 50% training and 50% validation, which i did sucessfully in IDL with your guidance.thanks a lot !

    Deleted User



    New Member


    Posts:
    New Member


    --
    22 Dec 2011 04:36 PM
    Your question reminded me that I have wanted to write a program that can return N random indices, from a much larger selection vector, without replacement, which means that each index is unique. I wrote such a program this morning, using an efficient algorithm reported by JD Smith in the IDL newsgroup (comp.lang.idl-pvwave). The program is named cgRandomIndices: http://www.idlcoyote.com/.../cgrandomindices.pro
    You are not authorized to post a reply.