-1

私はこの低次再帰関数をmatlabで取得しようとしていました. ステータスである初期確率があると仮定して、次の時間ステップでサイトのステータスの確率を計算したいと思います。

P= Probability
x= status(0,1)
Dij= probability to pick a site
P(Status of Site(i) being x at next time step)= Summation[P(Status of Site(i) being x at previous time step)*Dij]

そしてこれが私がやったことです!しかし、私のインデックスは常に行列の次元を超えています! これについて助けが必要です。

clear all;
clc;

%function [t,i]= CopyingInfluenceModel
%%Define constants
%% generate some random weights vectori.e. the transition matrix=C
 % C=[0 (1,2) 0 (1,4) 0 0 0;
 %    (2,1) 0 (2,3) 0 0 0 0;
 %    0 (3,2) 0 (3,4) 0 0 0;
 %    (1,4) 0 (4,3) 0 (4,5) 0 0;
 %    0 0 0 (5,4) 0 (5,6) (5,7);
 %    0 0 0 0 (6,5) 0 (6,7);
 %    0 0 0 0 (7,5) (7,6) 0];
 %copying probabilities=branch weights
 onetwo=0.47;
 twothree=0.47;
 threefour=0.47;
 onefour=0.47;
 fourfive=0.023;
 fivesix=0.47;
 fiveseven=0.47;
 sixseven=0.47;
 selfweight1=0.06;
 selfweight2=0.037;
 % SourceNodes - a list of Nodes that are forced to be kept in one side of the cut.
 % WeightedGraph - symetric matrix of edge weights. Wi,j is the edge
 % connecting Nodes i,j  use Wi,j=0 or Wi,j == inf to indicate unconnected Nodes                  

 WeightedGraph=[0 onetwo 0 onefour 0 0 0;
 onetwo 0 twothree 0 0 0 0;
 0 twothree 0 threefour 0 0 0;
 onefour 0 threefour 0 fourfive 0 0;
 0 0 0 fourfive 0 fivesix fiveseven;
 0 0 0 0 fivesix 0 sixseven;
 0  0 0 0 fiveseven sixseven 0];
 Dij=sparse(WeightedGraph);


 % Initializing the variables
 t=[];
 i=[];
 %assigining the initial conditions
 t(1)=0;
 p(1)= 0.003; %% initial probability of status
 %set index no i to 1(initial condition for i=1)
 i=1;
 %repeating calculating new probabilities

 %% If the probability is zero, terminate while loop
 while p(i)>=0
    %calculate at the next time step for given index no
    t(i+1)= t(i);
    %calculate the status_probability at given time t=(i+1)
    [p(i+1)]=[p(i)]+sum([p(i)]*[Dij(i)]);
    [NextStatus(i)]= [p(i+1)]

%index i increases by 1 to calculate next probability
i=i+1;
end

スタック トレースは次のとおりです。

%%??? Index exceeds matrix dimensions. 
%%Error in ==> CopyingInfluenceModel at 54 
%%[p(i+1)]=[p(i)]+sum([p(i)]*[Dij(i)]);
4

2 に答える 2

1

問題はありDijませんpDijは固定長であるため、それをi超えるとプログラムはエラーをスローします。

追加した:

コードであなたのロジックを実際に見ることはできませんが、あなたが何か間違った計算をしていると強く感じています。Dijは7x7の行列ですが、を呼び出すことでベクトルとして扱いますDij(i)。行または列で何かを乗算しようとしている場合は、Dij(i,:)orDij(:, i)表記が必要です。

于 2012-11-16T19:19:00.290 に答える
0

あなたが投稿したロジックは機能しません。基本的に、 p(i+i) はまだ定義されていません。p を保持するかどうかに応じて、いくつかの方法があります。p を維持するメソッドを投稿しますが、コードをより効率的にするためにいくつかの作業を行うことができます。

p=[p;p(i)+sum(p(i)*Dij(i))];
NextStatus(i)= p(i+1)
于 2012-11-16T17:27:56.950 に答える