0

固有値に関していくつかの初心者の質問があります。

以下は、それらを説明するための小さな関数です。

  1. h_m<n (n が指定されている) で h=1 から h=h_m に、ある反復から次の反復へとサイズが大きくなるベクトルがあります。固有オブジェクトの .reserve() 関数が見つかりませんでした。これは、反復ごとにこれらのオブジェクトのサイズを変更する必要があることを意味します。これを回避する方法を教えていただけますか?

    //we always have that h<h_m<n//
    //declare the matrix to its final size: //a.3
    MatrixXf xSub(h_m,p); //a.1 VectorXi Indexn1(n); //a.2 //declare the vector to its final size: //a.3 VectorXi RIndex(h_m); //a.4

    int h=10,j=0;

    while(h<h_m){ //b.0 Indexn1.setLinSpaced(n,0,n-1); //b.1 random_shuffle(Indexn1.data(),Indexn1.data()+n); //b.2 RIndex.resize(h); RIndex = Indexn1.segment(0,h); //b.3 .... .... j++; //b.4 h=ceil(j/(2.0*J)*(n-p-1)+p+1); //b.5 xSub.resize(h,NoChange); xS_mean = xSub.colwise().mean() //b.6 }

  2. 行 b_4 は、実行時にこのエラーを引き起こします (上記の b.0->b.4 を数回繰り返した後):

    eigen/Eigen/src/Core/Block.h:278: Eigen::Block<XprType, BlockRows, BlockCols, InnerPanel, true>::Block(XprType&, Eigen::Block<XprType, BlockRows, BlockCols, InnerPanel, true> ::Index) [with XprType = Eigen::Matrix<float, -0x00000000000000001, -0x0000000000000001>, int BlockRows = 1, int BlockCols = -0x0000000000000001, bool InnerPanel = false, Eigen::BlockBlock<XprType, BlockRows, パネル列, , true>::Index = long int]: アサーション `(i>=0) && ( ((BlockRows==1) && (BlockCols==XprType::ColsAtCompileTime) && i<xpr.rows()) ||( (BlockRows==XprType::RowsAtCompileTime) && (BlockCols==1) && i<xpr.cols()))' が失敗しました。
    中止しました

私が問題を解決できるように、それが何を意味するのか理解するのを手伝ってもらえますか?

編集: cbamber85 の発言に続いて、エラーが 1 行上で発生しているように見えます。

//index of the h smallest elements of the vector dP:
    RIndex.resize(h);
        RIndex = SSubInd(dP,h);
//constructs the corresponding sub-matrix of elements of x with index given above:
//this is the offending line.
    xSub.resize(h,NoChange);
        xSub = RSubMatrix(x,RIndex);     

RSubMatrix を調べます。

MatrixXf RSubMatrix(MatrixXf& x, VectorXi& Index){
    MatrixXf xSub(Index.size(),x.cols());  
    for(int i=0;i<Index.size();i++){
        xSub.row(i)=x.row(Index(i));
    }
    return xSub;
}

:(

4

1 に答える 1

3

エラー メッセージは、Eigen::Block (部分行列を表す) が範囲外のインデックスで構築されたことを意味します。ブロックは、メンバー関数を含む多くの場所で構築されます.row()。エラーが式 で発生したと仮定すると、がまたはの行数以上でxSub.row(i) = x.row(Index(i))あることを意味します。ixSubx

于 2012-03-05T16:59:48.893 に答える