Java类中的RealMatrix对象

时间:2012-02-18 01:25:04

标签: java matrix apache-commons-math

似乎我不能在我的班级中使用这个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数据类型,但我还需要在创建此类实例时从提供的值(双数组)构造它。

1 个答案:

答案 0 :(得分: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
    }
  }
}