How to model exponential holding times? Please help.
4 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
In my code, after performing some action (e.g. changing var=0 to var=1), I need to trigger a time which is representative of how long the var should be 1. I want to model it as exponential holding time as below
exprnd(5)
%outputs vary like 0.3414 or 1.9376 or 2.1120 or 8.8250...
Question: how can I know when to make the var=1 back to var=0 using this kind of output. The ouput is not a fixed integer count that I can keep decrementing. Any idea on how can I do this? Should I make use of system time?
Background: I have to make this var change multiple times. I.e. after trigerring for the above, I go back, get another input, perform the action (var=1) and then also do an exprnd(5) for that one. It is a dynamic system. Actions get removed (var reverted back) after a certain time and that time is modelled as exponential distribution.
0 commentaires
Réponse acceptée
Walter Roberson
le 30 Oct 2021
You are modeling discrete events. At a particular time step, the event fires (or expires, depending on what you are modeling). Your events do not occur at times "between" the discrete time steps, and your events do not get "partly used up" each time step -- you are not randomly determining an integer "dwell time" and "counting down" at each time step.
In such situations, you should be using Poisson distribution.
Unless, that is, you are determining an "dweel time" at the beginning and counting down from that. If that is what you are doing, then consider taking ceil() of the exponential random value.
3 commentaires
Walter Roberson
le 31 Oct 2021
The below truncates the distribution a bit, by killing everything off in the last generation.
pborn is the probability of an item being created. Additional births are tried for at the same probability until one fails.
pdie is the probability that an alive item will die.
This simulation has no built-in life-span. Any one "alive" entity is memoryless in this simulation -- it does not get less or more "vital" over a distribution of ages.
pdie = 0.09;
pborn = 0.1;
N = 2000;
state = zeros(0,1); %birthday
num_alive_at = zeros(1,N);
num_died_at = zeros(1,N);
num_born_at = zeros(1,N);
death_age_count = zeros(1,1);
for K = 1 : N
n_alive = size(state,1);
num_alive_at(K) = n_alive;
if n_alive > 0
if K == N; death_idx = 1 : n_alive; end %kill all at end
death_idx = find(rand(n_alive,1) < pdie);
num_funerals = length(death_idx);
num_died_at(K) = num_funerals;
age_at_death = K - state(death_idx,1);
oldest_death = max(age_at_death);
if oldest_death > length(death_age_count); death_age_count(oldest_death) = 0; end
for J = 1 : num_funerals
death_age_count(age_at_death(J)) = death_age_count(age_at_death(J)) + 1;
end
state(death_idx,:) = [];
end
num_birth = 0;
while K ~= N && rand < pborn; num_birth = num_birth + 1; end %no births at end
num_born_at(K) = num_birth;
if num_birth == 0; continue; end
state(end+1:end+num_birth, 1) = K;
end
subplot(4,1,1)
total_lives = sum(death_age_count);
bar(death_age_count / total_lives * 100);
xlabel('age'); ylabel('% prob'); title('prob died at age');
subplot(4,1,2)
plot(num_alive_at)
xlabel('iteration'); ylabel('lives'); title('# alive at iteration');
subplot(4,1,3)
histogram(num_born_at, 0:max(num_born_at))
xlabel('# births'); ylabel('counts'); title('births per iteration');
subplot(4,1,4)
histogram(num_died_at, 0:max(num_died_at))
xlabel('# deaths'); ylabel('counts'); title('deaths per iteration');
Plus de réponses (0)
Voir également
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!