0

看来我不能在我的课堂上使用这个 Apache Commons Math 库,因为当我尝试在我的构造函数中使用 RealMatrix 时,我在 matrixSim 上得到了意外的标记,如下所示:

class vecGenUn
{
  double[][] prevMat;
  RealMatrix matrixSim;  //this is problematic
  int dataDim;
  int rowDim;
  double simVecMean;
  double simVecSD;
  double simVecUn;
  double sum;

  vecGenUn (double[][] tempPM)
  {
    prevMat = tempSM;
    matrixSim = new Array2DRowRealMatrix(prevMat);  //and possibly this
    dataDim = new int matrixSim.getColumnDimension();
    rowDim = new int matrixSim.getRowDimension();
    simVecMean = new double[dataDim];
    simVecSD = new double[dataDim];
    simVecUn = new double[dataDim];
    sum = new Sum();
  }

  public void vecGen()
  {
    for (int i = 0; i < dataDim; i++)
    {
      simVecMean[i] = sum.evaluate(matrixSim.getColumn(i), 0, rowDim)/rowDim
    }
  }
}

现在方法尚未实现,但是当我需要为所有 Appache 数学库方法使用 RealMatrix 数据类型时,我如何在此处使用它,而且我还需要从创建此类实例时提供的值(双数组)构造它。

4

1 回答 1

1

在提供的代码中,您有各种与 Apache Commons Math 无关的编译器错误。在尝试确定您是否对该库有问题之前修复这些问题。

更正注释用 (*) 标记:

class vecGenUn
{
  double[][] prevMat;
  RealMatrix matrixSim;  //this is problematic
  int dataDim;
  int rowDim;
  double simVecMean;
  double simVecSD;
  double simVecUn;
  double sum;

  vecGenUn (double[][] tempPM)
  {
    prevMat = tempSM; // (*) tempSM is undefined
    matrixSim = new Array2DRowRealMatrix(prevMat);  //and possibly this
    dataDim = new int matrixSim.getColumnDimension(); // (*) 'new int' is invalid
    rowDim = new int matrixSim.getRowDimension(); // (*) ditto
    simVecMean = new double[dataDim]; // (*) assigning an array to a scalar variable
    simVecSD = new double[dataDim]; // (*) ditto
    simVecUn = new double[dataDim]; // (*) ditto
    sum = new Sum(); // (*) assigning object to primitive
  }

  public void vecGen()
  {
    for (int i = 0; i < dataDim; i++)
    {
      simVecMean[i] = sum.evaluate(matrixSim.getColumn(i), 0, rowDim)/rowDim // (*) indexing a scalar variable
    }
  }
}
于 2012-02-18T02:22:37.087 回答