/// <summary> /// Used for computing the actual transformations (A and B matrices). These are stored in As and Bs. /// </summary> /// <param name="regLs">The reg ls.</param> /// <param name="regRs">The reg rs.</param> private void computeMllrTransforms(double[][][][][] regLs, double[][][][] regRs) { int len; for (int c = 0; c < nrOfClusters; c++) { this.As[c] = new float[loader.getNumStreams()][][]; this.Bs[c] = new float[loader.getNumStreams()][]; for (int i = 0; i < loader.getNumStreams(); i++) { len = loader.getVectorLength()[i]; //TODO: CHECK SEMANTICS //this.As[c][i] = new float[len][len]; this.As[c][i] = new float[len][]; this.Bs[c][i] = new float[len]; for (int j = 0; j < len; ++j) { var coef = new Array2DRowRealMatrix(regLs[c][i][j], false); var solver = new LUDecomposition(coef).getSolver(); var vect = new ArrayRealVector(regRs[c][i][j], false); var ABloc = solver.solve(vect); for (int k = 0; k < len; ++k) { this.As[c][i][j][k] = (float)ABloc.getEntry(k); } this.Bs[c][i][j] = (float)ABloc.getEntry(len); } } } }
/// <summary> /// Used for computing the actual transformations (A and B matrices). These are stored in As and Bs. /// </summary> /// <param name="regLs">The reg ls.</param> /// <param name="regRs">The reg rs.</param> private void ComputeMllrTransforms(double[][][][][] regLs, double[][][][] regRs) { int len; for (int c = 0; c < _nrOfClusters; c++) { As[c] = new float[_loader.NumStreams][][]; Bs[c] = new float[_loader.NumStreams][]; for (int i = 0; i < _loader.NumStreams; i++) { len = _loader.VectorLength[i]; As[c][i] = Java.CreateArray <float[][]>(len, len); //this.As[c][i] = new float[len][len]; Bs[c][i] = new float[len]; for (int j = 0; j < len; ++j) { var coef = new Array2DRowRealMatrix(regLs[c][i][j], false); var solver = new LUDecomposition(coef).getSolver(); var vect = new ArrayRealVector(regRs[c][i][j], false); var aBloc = solver.solve(vect); for (int k = 0; k < len; ++k) { As[c][i][j][k] = (float)aBloc.getEntry(k); } Bs[c][i][j] = (float)aBloc.getEntry(len); } } } }
private void computeMllrTransforms(double[][][][][] array, double[][][][] array2) { for (int c = 0; c < this.nrOfClusters; c++) { this.As[c] = new float[this.loader.getNumStreams()][][]; this.Bs[c] = new float[this.loader.getNumStreams()][]; for (int i = 0; i < this.loader.getNumStreams(); i++) { int len = this.loader.getVectorLength()[i]; float[][][] array3 = this.As[c]; int num2 = i; int num3 = len; int num4 = len; int[] array4 = new int[2]; int num5 = num4; array4[1] = num5; num5 = num3; array4[0] = num5; array3[num2] = (float[][])ByteCodeHelper.multianewarray(typeof(float[][]).TypeHandle, array4); this.Bs[c][i] = new float[len]; for (int j = 0; j < len; j++) { #if USE_MAPACK //TODO: need to check if the math is correct Matrix m = new Matrix(array[c][i][j]); int rs = array2[c][i][j].Length; Matrix rv = new Matrix(rs, 1); for (int r = 0; r < rs; r++) { rv[r, 0] = array2[c][i][j][r]; } Matrix solved = m.Solve(rv); for (int k = 0; k < len; k++) { this.As[c][i][j][k] = (float)solved[k, 0]; } //TODO: there may be a problem of index out of range? //(index == len)? this.Bs[c][i][j] = (float)solved[len, 0]; #else Array2DRowRealMatrix matrix = new Array2DRowRealMatrix(array[c][i][j], false); DecompositionSolver solver = new LUDecomposition(matrix).getSolver(); ArrayRealVector rv = new ArrayRealVector(array2[c][i][j], false); RealVector realVector = solver.solve(rv); for (int k = 0; k < len; k++) { this.As[c][i][j][k] = (float)realVector.getEntry(k); } this.Bs[c][i][j] = (float)realVector.getEntry(len); #endif } } } }
public ArrayRealVector solve(ArrayRealVector b) { int m = pivot.Length; //if (b.getDimension() != m) //{ // throw new DimensionMismatchException(b.getDimension(), m); //} //if (singular) //{ // throw new SingularMatrixException(); //} double[] bp = new double[m]; // Apply permutations to b for (int row = 0; row < m; row++) { bp[row] = b.getEntry(pivot[row]); } // Solve LY = b for (int col = 0; col < m; col++) { double bpCol = bp[col]; for (int i = col + 1; i < m; i++) { bp[i] -= bpCol * lu[i][col]; } } // Solve UX = Y for (int col = m - 1; col >= 0; col--) { bp[col] /= lu[col][col]; double bpCol = bp[col]; for (int i = 0; i < col; i++) { bp[i] -= bpCol * lu[i][col]; } } return(new ArrayRealVector(bp, false)); }