1
$\begingroup$

I have a CDF that is generated from the subtraction of two arrays as part of a minimization procedure. A consequence is that events in the simulation can cause the subtracted total to be less than 0:

 Do[
  rhodiff[[r]]  = rhoin[[r]] - rho[[r]]
  , {r, 1, rmax}];

Do[
  cdf[[r]]  = Total[Part[rhodiff, 1 ;; r + dp - 1]]
  , {r, 1, rmax - dp + 1}];

After the CDF is generated, I use the following code to find the desired array position by generating a random number between 0 and the highest value in the CDF:

seedmax = Max[cdf];
seed = RandomInteger[{0, seedmax}];
rstart = Ceiling[BinarySearch[cdf, seed]];

The issue begins to manifest itself after many rounds of subtraction have taken place and the CDFs begin to look like this:

{-8,-9,-6,-5,-5,-6,-8,-6,-3,-5,0,5,7,7,9,14,21,22,20,21,19,17,15,12,10,11,16,19,21,26,23,17,13,7,5,5,8,10,13,11,8,14,17,17,30,35,36,33,23,14,15,16,17,19,20,20,23,29,39,49,53,43,32,16,-7,-33,-66,-105,-136,-155,-160,-141,-108,-51,31}

Is there a way to make these values proportional weights for probability without using BinarySearch? I am thinking re-ordering the lists might be one approach but I am unsure how to keep track of the indices in that case.

$\endgroup$
  • 1
    $\begingroup$ I'm having a hard time following your description. Your CDF's aren't CDF's as they aren't nondecreasing and are not bounded between 0 and 1. $\endgroup$ – JimB Oct 13 '16 at 23:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.