Dynamic time warping の最適なワーピング パスを見つけるためにこのコードを書きました。これは struct を返します。
static inline double min (double x, double y,double z )
{
if(x < y && x < z)
return x;
else if(y < x && y < z)
return y;
else if(z < x && z < y)
return z;
}
struct backtracking_result
{
vector<int> i;
vector<int> j;
};
backtracking_result backtracking(vector<vector<double> > mGamma)
{
backtracking_result br;
cout<<"test"<<mGamma.size()<<endl;
int i=mGamma.size();
cout<<"test"<<endl;
int j=mGamma.at(0).size();
cout<<"test"<<endl;
cout<<i<<j<<endl;
do
{
cout<<"test"<<endl;
if(i == 1)
j=j-1;
else if(j == 1)
i=i-1;
else
{
if(mGamma[i-1][j] == min(mGamma[i-1][j],mGamma[i][j-1],mGamma[i-1][j-1]))
i=i-1;
else if(mGamma[i][j-1] == min(mGamma[i-1][j],mGamma[i][j-1],mGamma[i-1][j-1]))
j=j-1;
else
{
i=i-1;
j=j-1;
}
}
br.i.push_back(i);
br.j.push_back(j);
}while((i > 1)&&(j > 1));
return br;
}
この関数を呼び出すと、gdb デバッガーからこのエラーが発生します
Program received signal SIGSEGV, Segmentation fault.
0x000000000041eafb in VectorDTW::backtracking(std::vector<std::vector<double, std::allocator<double> >, std::allocator<std::vector<double, std::allocator<double> > > >) ()
エラーはどこにありますか?
スタックトレース :
#0 0x000000000041eb17 in VectorDTW::backtracking(std::vector<std::vector<double, std::allocator<double> >, std::allocator<std::vector<double, std::allocator<double> > > >) ()
#1 0x0000000000420195 in VectorDTW::fastdynamic(std::vector<DollarRecognizer::Point2D, std::allocator<DollarRecognizer::Point2D> >&, std::vector<DollarRecognizer::Point2D, std::allocator<DollarRecognizer::Point2D> >&) ()
#2 0x000000000041d18b in main ()
答えは問題を理解するのに役立ちました。行列から i & j を計算した後、これらの 2 行を追加しました。
i=i-1;
j=j-1;
これで、プログラムは最後の要素にアクセスしようとしなくなりました。ありがとう 。しかし、私は反対票の理由をまだ理解できません。