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:

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

  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:


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.

  • 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.