我有一个数组来存储一组用于绘制一条线的坐标。所以这里有一些示例坐标
double[][] plotMatrix = {{10,20},{55,80},
{120,40},{225,30},
{327.5,100},
{427.5,30},
{529,60}};
下一步是创建一个二维的马尔可夫矩阵。
首先,我计算左列中的点后跟上列中的点的时间。因为我想要一条线,所以每个点后面跟着另一个单点。这意味着如果我们有 {10,20} 作为输入,{55,80} 成为下一个点的概率是 100%。
我不太确定这一切,所以请纠正我!
所以这是我的矩阵
double[][] markovMatrix = { {0.0,1.0,0.0,0.0,0.0,0.0,0.0},
{0.0,0.0,1.0,0.0,0.0,0.0,0.0},
{0.0,0.0,0.0,1.0,0.0,0.0,0.0},
{0.0,0.0,0.0,0.0,1.0,0.0,0.0},
{0.0,0.0,0.0,0.0,0.0,1.0,0.0},
{0.0,0.0,0.0,0.0,0.0,0.0,1.0},
{0.0,0.0,0.0,0.0,0.0,0.0,0.0}};
我的算法:
int seed = 0;
int output = 0;
for(int i = 0; i < 40;i++){
double choice = r.nextDouble();
double currentSum = 0.0;
for(;output < markovMatrix.length;output++){
currentSum += markovMatrix[seed][output];
if(choice <= currentSum){
break;
}
}
System.out.println(output);
polygon.lineTo(plotMatrix[output][0], plotMatrix[output][1]);
seed = output;
output = 0;
}
我的问题是,ArrayOutOfBoundsException:7
当我尝试访问 plotMatrix 和 markovMatrix 时,我得到了一个。但是,在每个循环结束时输出设置为 0。任何想法如何解决这个问题?