【问题标题】:matlab: praticle state simulationmatlab:实用状态模拟
【发布时间】:2012-04-09 04:02:40
【问题描述】:

假设我想模拟一个粒子状态,它在给定帧中可以是正常 (0) 或兴奋 (1)。粒子在 f% 的时间内处于激发态。如果粒子处于激发态,它会持续约 L 帧(具有泊松分布)。我想模拟 N 个时间点的状态。所以输入例如:

N = 1000;
f = 0.3;
L = 5;

结果会是这样的

state(1:N) = [0 0 1 1 1 1 0 0 0 0 1 1 1 0 0 0 0 0 0 0 0 0 1 1 1 1 1 0 0 0 0 0 ... and so on]

sum(state)/N 接近 0.3

如何做到这一点? 谢谢!

【问题讨论】:

  • 粒子翻转状态的概率是多少?
  • 我真的不明白你的意思。我真正想做的是模拟具有两种不同扩散系数的粒子的扩散行为,并定义了更快和更慢组分(f)的分数以及在一种或另一种状态下的某种寿命。我想先模拟状态(在这种情况下是两个,但可能更多),然后根据状态(更快或更慢......)模拟位移和坐标。我不知道这是否是最好的方法,但这是我心中的第一个 :)
  • @NoamN.Kremen 当 f=0.3 时,状态 1 的长度是 5。状态 0 的长度平均应该是 17 左右(5/0.3),所以从 0 翻转的变化到 1 是 0.06。编辑:不确定这句话是否完全正确。

标签: matlab random distribution simulation poisson


【解决方案1】:

激发态的平均长度为5。正常状态的平均长度,因此应该在12左右。

策略可以是这样的。

  • 从状态 0 开始
  • 从平均为L*(1-f)/f 的泊松分布中抽取一个随机数a
  • a 零填充状态数组
  • 从平均为L 的泊松分布中抽取一个随机数b
  • b 个填充状态数组。
  • 重复

另一种选择是考虑切换概率,其中 0->1 和 1->0 的概率不相等。

【讨论】:

    【解决方案2】:
    %% parameters
    f = 0.3; % probability of state 1
    L1 = 5;  % average time in state 1
    N = 1e4;
    s0 = 1; % init. state
    %% run simulation
    L0 = L1 * (1 / f - 1); % average time state 0 lasts
    p01 = 1 / L0; % probability to switch from 0 to 1
    p10 = 1 / L1; % probability to switch from 1 to 0
    p00 = 1 - p01;
    p11 = 1 - p10;
    sm = [p00, p01; p10, p11];  % build stochastic matrix (state machine)
    bins = [0, 1]; % possible states
    states = zeros(N, 1);
    assert(all(sum(sm, 2) == 1), 'not a stochastic matrix');
    smc = cumsum(sm, 2); % cummulative matrix
    xi = find(bins == s0);
    for k = 1 : N
        yi = find(smc(xi, :) > rand, 1, 'first');
        states(k) = bins(yi);
        xi = yi;
    end
    %% check result
    ds = [states(1); diff(states)];
    idx_begin = find(ds == 1 & states == 1);
    idx_end = find(ds == -1 & states == 0);
    if idx_end(end) < idx_begin(end)
        idx_end = [idx_end; N + 1];
    end
    df = idx_end - idx_begin;
    fprintf('prob(state = 1) = %g; avg. time(state = 1) = %g\n', sum(states) / N, mean(df));
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-03-06
      • 1970-01-01
      相关资源
      最近更新 更多