I have a data as following. I want to add two random time points, one for birth one for death.
data={{1, 10}, {1.06117, 11}, {1.21241, 12}, {1.33893, 13}, {1.41358, 14}, {2, 14}};
ListLinePlot[data, Mesh -> Full, MeshStyle -> {Red, PointSize[0.01]},
Frame -> True, PlotTheme -> "Detailed",
FrameLabel -> {"Time", "Population"}, ImageSize -> Medium,
InterpolationOrder -> 0]
Here is one desired output
data2={{1, 10}, {1.06117, 11}, {1.10169, 11}, {1.21241, 12}, {1.33893,
13}, {1.41358, 14}, {1.51463, 14}, {2, 14}};
ListLinePlot[{data, data2}, Mesh -> Full,
MeshStyle -> {Red, PointSize[0.01]}, Frame -> True,
PlotTheme -> "Detailed", FrameLabel -> {"Time", "Population"},
ImageSize -> Medium, InterpolationOrder -> 0]
birth is added at {1.10169, 11}
and death is added at {1.51463, 14}
. I wanna keep both path, i.e. blue and yellow paths. Second path (yellow path ) must also start at {1,10}
and finish at {2,14}
. Population size can increase or decrease only by 1. Any idea?
Edit: Let me generalized the algorithm.
Given interval [i,i+1]
,in this case [1,2]
, we have 3 types of move (equal probability, 1/3 each ).
Choose one of the move.
- Type 1 move: Add 1 birth and 1 death randomly on the interval
[1,2]
which is done successfully by @Carl and @kglr. - Type 2 move: Select 1 birth and 1 death from interval and remove them. If there is no birth, don't do anything, and similarly if there is no death, don't do anything.
- Type 3 move: Select 1 reaction time, birth OR death, and shifted somewhere else between
[1,2]