出生时的CTMC模拟&使用C ++的死亡过程

时间:2016-07-30 09:34:57

标签: c++ algorithm

数学不是我强大的技能。但是,我需要模拟出生时的连续时间马尔可夫链(CTMC)转换时间。使用C ++的死亡过程。

我遇到了这个模拟常规CTMC的github project,其中所有lambda的行总和将为1.但是在出生 - 死亡过程(M / M / c / K)的情况下,它将为零。所以我不能完全按照我的目的使用它。

在哪里可以找到模拟M / M / c / K CTMC的算法?如果我找到它,我可以编写算法代码。但是我无法自己构建算法,数学超出了我的想象。

我需要此模拟使用泊松分布将事件发送到M / M / c / K队列。这样我就可以在不同的到达率(lambda)下找出服务器(c)的要求,同时确保最大的服务器利用率。

1 个答案:

答案 0 :(得分:1)

仍然不是百分之百清楚你的心愿是什么,但主题非常有趣。

首先:你所指的github项目没有足够的文档来说明它的预期输入是什么,而且我没有足够的马尔可夫过程知识来说明连续部分是错误的,但对我来说它确实是错误的没有多大意义。

其次:对于所有马尔可夫过程,转换率矩阵的一行的总和为0,不仅适用于出生 - 死亡过程。

这就是我模拟跑步的方式:

  1. 给定:开始状态(可能0S,转换率矩阵Q(通过P'=PQ定义),转换次数{{1}感兴趣的。

  2. 输出:n - 转换发生的时间,times - 一系列访问状态。

  3. 这里我们使用C ++和伪代码的混合:

    states

    我希望这是你想到的。

    修改

    简短说明:

    1. 第一部分 - 过渡之前的时间。该代码基于众所周知的事实,即如果到达的是以速率λ为分布的泊松,则等待时间是以参数λ为指数分布的。例如,请参阅here

    2. 对于第二部分 - 它只是conditional probability:非常短的时间段std::default_random_engine rnd;//ini double current_time=0.0; int current_state=S; vector<doubles> times={current_time}; vector<int> states={current_state}; for (int i=0;i<n;i++){ //Part 1: simulate the time staying in current state: double decay_rate=-Q[current_state][current_state]; if(decay_rate==0.0){ //that means we are not going anywhere anymore and staying for ever in this state: return; } //we don't do error checking and expect rate to be positive, because diagonal elements of Q must be 0.0 or negative //The current state will decay with the decay_rate, so the life time in this state until the decay is exponentially distributed with parameter decay_rate //simulate the life time: std::exponential_distribution<> life_time_generator(decay_rate); double life_time=life_time_generator(rnd); times.push_back(times.back()+life_time); //Part2: to which state have we actually decayed? // The probability to decay to the state new_state is proportional to transition rate Q[current_state][new_state] //thus generate an uniformly distributed random variable [0, decay_rate] (decay_rate - sum of transition rates of all possible new states) and map it on the states: double target_value=std::generate_canonical<double,10>(rnd)*decay_rate; double sum=0.0; for (int new_state=0;new_state<Q.size();new_state++){ if (new_state==current_state)//don't forget to skip the state itself continue; sum+=Q[current_state][new_state]; if (sum>target_value){//we found our next state! current_state=new_state; states.push_back(current_state); break; } //there are still a some precision issues, if the sum of all transition rates is slightly under 1.0 //the issues should be handled somehow but not in this pseudo-code. } } // do whatever you want with times/states 的转换概率为dt。我们知道转变已经发生,因此满足了这一条件。转到状态-Q[current_state][current_state]dt的概率是new_state但是在转换发生的条件下它是Q[current_state][new_state]*dt - 这是在第二部分中计算的内容。

      < / LI>