Re: Algorithm needed for random number filtering

new topic     » goto parent     » topic index » view thread      » older message » newer message

My main code is below, but here is a verbal example : Say you have 120 samples of the number 1, 50 samples of the number 2, 50 of 3, 100 of 4, 70 of 5.
I would set the limit "maxi" to 100; that would allow 4 as valid, and discard 1; then add the occasions of 2 and 3 (table lookup) to give samples of 2. 5 would need to be discarded as there is nothing left to add the missing 30 to. Note I could not take some of the samples off 1 and add to 5, because then it would not be random.
I have a few files of 470K of randoms to process.

procedure tagit() 
   integer needed, stillok, pc 
   integer i1, i2, i3 
   sequence s1, s2, s3, s4, s5, s6, s7, s8, s9 
   i1 = 0 
   rc = 1 
   while i1 < 2048 do  
   	 i1 = i1 + 1 
   	 if tbl[i1] > 0 then   -- this one part of the 256 
   	 	  needed = maxi - tbl[i1]  -- data is loaded in this table 
   	 	  pc = floor(needed / 100) * vari -- percentage 
   	 	  stillok = needed - pc 
   	 	  i2 = 0 
   	 	  while i2 < length(leftovers) do -- leftovers is the distribution table 
   	 	  	 i2 = i2 + 1  
   	 	  	 s1 = leftovers[i2] 
   	 	  	 s2 = s1[001..006] -- number of samples 
   	 	  	 s3 = s1[007..010] -- number identifier 
   	 	  	 s4 = value(s2) 
   	 	  	 i3 = s4[2] 
   	 	  	 if i3 < needed then  
   	 	  	 	  if i3 > stillok then  
   	 	  	 	  	 rc = 0 
   	 	  	 	  	 s5 = sprintf("%04d",{i1})  
   	 	  	 	  	 tbl[i1] = tbl[i1] + i3   -- consolidate 
   	 	  	 	  	 s6 = sprintf("%06d",{tbl[i1]}) 
   	 	  	 	  	 leftovers[i2] = "0000000000"  -- set for removal 
   	 	  	 	  	 s8 = lookup[i1] 
   	 	  	 	  	 if length(s8) = 10 then  
   	 	  	 	  	    s7 = s5 & s6 & s3 
   	 	  	 	  	    lookup[i1] = s7 
   	 	  	 	  	    exit 
   	 	  	 	  	   else  
   	 	  	 	  	   	s9 = s8[11..length(s8)] 
   	 	  	 	  	   	s7 = s5 & s6 & s9 & s3  
   	 	  	 	  	   	lookup[i1] = s7 
   	 	  	 	  	   	exit 
   	 	  	 	  	 end if 
   	 	  	 	  end if 
   	 	  	 	end if 
   	 	  	end while 
   	 	 end if  
   	 end while	  
end procedure 	 
new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu